Use modern FetchContent design patterns (#3903)

* Add higher bound to the CMake policies
* Add the latest cmake to ubuntu22.04 image
This commit is contained in:
Cristian Le 2025-07-09 03:39:54 +02:00 committed by GitHub
parent c639cc030d
commit 236b57f321
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 61 additions and 12 deletions

View file

@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.22) cmake_minimum_required (VERSION 3.24...4.0)
enable_testing() enable_testing()
set (CMAKE_EXPORT_COMPILE_COMMANDS ON) set (CMAKE_EXPORT_COMPILE_COMMANDS ON)

View file

@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.22) cmake_minimum_required (VERSION 3.22...4.0)
message ("-- Configuring man pages") message ("-- Configuring man pages")
set (man_FILES task-color.5 task-sync.5 taskrc.5 task.1) set (man_FILES task-color.5 task-sync.5 taskrc.5 task.1)
foreach (man_FILE ${man_FILES}) foreach (man_FILE ${man_FILES})

View file

@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.22) cmake_minimum_required (VERSION 3.22...4.0)
configure_file(compare_runs.py compare_runs.py COPYONLY) configure_file(compare_runs.py compare_runs.py COPYONLY)
configure_file(load load) configure_file(load load)

View file

@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.22) cmake_minimum_required (VERSION 3.22...4.0)
install (DIRECTORY bash fish vim hooks install (DIRECTORY bash fish vim hooks
DESTINATION ${TASK_DOCDIR}/scripts) DESTINATION ${TASK_DOCDIR}/scripts)
install (FILES zsh/_task install (FILES zsh/_task

View file

@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.22) cmake_minimum_required (VERSION 3.22...4.0)
include_directories (${CMAKE_SOURCE_DIR} include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/commands ${CMAKE_SOURCE_DIR}/src/commands

View file

@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.22) cmake_minimum_required (VERSION 3.22...4.0)
include_directories (${CMAKE_SOURCE_DIR} include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/commands ${CMAKE_SOURCE_DIR}/src/commands

View file

@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.22) cmake_minimum_required (VERSION 3.22...4.0)
include_directories (${CMAKE_SOURCE_DIR} include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/commands ${CMAKE_SOURCE_DIR}/src/commands

View file

@ -1,13 +1,55 @@
cmake_minimum_required (VERSION 3.22) 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) if(SYSTEM_CORROSION)
find_package(Corrosion REQUIRED) find_package(Corrosion REQUIRED)
else() else()
add_subdirectory(${CMAKE_SOURCE_DIR}/src/taskchampion-cpp/corrosion) add_subdirectory(${CMAKE_SOURCE_DIR}/src/taskchampion-cpp/corrosion)
endif() 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) if (ENABLE_TLS_NATIVE_ROOTS)
message ("Enabling native TLS roots") message ("Enabling native TLS roots")

View file

@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.22) cmake_minimum_required (VERSION 3.22...4.0)
# -- C++ tests # -- C++ tests

View file

@ -1,7 +1,14 @@
FROM ubuntu:22.04 FROM ubuntu:22.04
RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y gpg wget curl
# add Kitware's CMake apt repo
RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - > /usr/share/keyrings/kitware-archive-keyring.gpg && \
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' > /etc/apt/sources.list.d/kitware.list
RUN apt-get update RUN apt-get update
RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y build-essential cmake git uuid-dev faketime locales python3 curl RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y build-essential git uuid-dev faketime locales python3 cmake
# Setup language environment # Setup language environment
RUN locale-gen en_US.UTF-8 RUN locale-gen en_US.UTF-8