From 50122456cfc7dd031c46fce2f2e70e96c24ab083 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Mon, 23 Jun 2025 16:31:13 +0200 Subject: [PATCH] Use modern FetchContent design pattern --- CMakeLists.txt | 2 +- src/taskchampion-cpp/CMakeLists.txt | 48 +++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cc597cc2..480f4b8a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.22...4.0) +cmake_minimum_required (VERSION 3.24...4.0) enable_testing() set (CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/src/taskchampion-cpp/CMakeLists.txt b/src/taskchampion-cpp/CMakeLists.txt index ef864edbe..958467001 100644 --- a/src/taskchampion-cpp/CMakeLists.txt +++ b/src/taskchampion-cpp/CMakeLists.txt @@ -1,13 +1,55 @@ -cmake_minimum_required (VERSION 3.22...4.0) +cmake_minimum_required (VERSION 3.24...4.0) + +include(FetchContent) + +option(SYSTEM_CORROSION "Use system provided corrosion instead of vendored version" OFF) +option(TASK_USE_CORROSION_SUBMODULE "Whether to use corrosion from the submodule instead of downloading" OFF) +set(TASK_CORROSION_VERSION v0.5.2 CACHE STRING "Corrosion version to use in FetchContent") + +if(TASK_USE_CORROSION_SUBMODULE) + find_package(Git QUIET) + if(GIT_FOUND AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/corrosion/.git) + # Try to initialize the submodule + message(STATUS "Submodule update: corrosion") + execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive corrosion + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + RESULT_VARIABLE submodule_res + ) + if(NOT submodule_res EQUAL 0) + message(WARNING "git submodule init failed, setting TASK_USE_CORROSION_SUBMODULE to OFF") + set(TASK_USE_CORROSION_SUBMODULE OFF CACHE BOOL "(Failed to git submodule init)" FORCE) + endif() + elseif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/corrosion/CMakeLists.txt) + # Maybe the sources were populated in a different way, use them still + message(STATUS "Could not initialize submodule corrosion, but the files were already there") + else() + message(WARNING "cannot initialize git submodule, setting TASK_USE_CORROSION_SUBMODULE to OFF") + set(TASK_USE_CORROSION_SUBMODULE OFF CACHE BOOL "(Cannot git submodule init)" FORCE) + endif() +endif() + +if(TASK_USE_CORROSION_SUBMODULE) + set(FETCHCONTENT_SOURCE_DIR_CORROSION ${CMAKE_CURRENT_SOURCE_DIR}/corrosion) +endif() +if(SYSTEM_CORROSION) + # Make sure find_package is always used without FetchContent fallback + set(CMAKE_REQUIRE_FIND_PACKAGE_Corrosion ON) +endif() + +FetchContent_Declare(Corrosion + GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git + GIT_TAG ${TASK_CORROSION_VERSION} + FIND_PACKAGE_ARGS CONFIG +) +FetchContent_MakeAvailable(Corrosion) -OPTION(SYSTEM_CORROSION "Use system provided corrosion instead of vendored version" OFF) if(SYSTEM_CORROSION) find_package(Corrosion REQUIRED) else() add_subdirectory(${CMAKE_SOURCE_DIR}/src/taskchampion-cpp/corrosion) endif() -OPTION (ENABLE_TLS_NATIVE_ROOTS "Use the system's TLS root certificates" OFF) +option (ENABLE_TLS_NATIVE_ROOTS "Use the system's TLS root certificates" OFF) if (ENABLE_TLS_NATIVE_ROOTS) message ("Enabling native TLS roots")