Use modern FetchContent design pattern

This commit is contained in:
Cristian Le 2025-06-23 16:31:13 +02:00
parent bdc4cc912e
commit 50122456cf
2 changed files with 46 additions and 4 deletions

View file

@ -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)

View file

@ -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")