Skip to content

Commit 3ee9551

Browse files
committed
Guard functional_cpp population for CMake older than 3.18
FetchContent's SOURCE_SUBDIR handling was added in CMake 3.18, but the project's minimum is 3.14; on 3.14-3.17, MakeAvailable would have add_subdirectory'd functional_cpp's top-level CMakeLists.txt, pulling its own src/tests into this build. Branch on the CMake version: 3.18+ keeps the SOURCE_SUBDIR MakeAvailable path, older versions populate the sources via FetchContent_Populate, which never calls add_subdirectory at all. The deprecated-in-3.30 Populate call sits behind the VERSION_LESS 3.18 check, so modern CMake never executes it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NUt3c1wdseRtRSSXfg3MCK
1 parent 096d18c commit 3ee9551

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,27 @@ FetchContent_MakeAvailable(googletest)
2626

2727
# functional_cpp provides fcpp::optional_t, the nullable-field representation
2828
# (std::optional under C++17 and later, an equivalent C++11 fallback otherwise).
29-
# It is consumed header-only: SOURCE_SUBDIR points at the header directory, which
30-
# contains no CMakeLists.txt, so FetchContent only downloads the sources without
31-
# building functional_cpp's own library and test targets.
29+
# It is consumed header-only: only its sources are downloaded, and functional_cpp's
30+
# own library and test targets are never added to this build.
3231
FetchContent_Declare(
3332
functional_cpp
3433
GIT_REPOSITORY https://github.com/jkalias/functional_cpp.git
3534
GIT_TAG 1.1.1
3635
SOURCE_SUBDIR include
3736
)
38-
FetchContent_MakeAvailable(functional_cpp)
37+
if(CMAKE_VERSION VERSION_LESS 3.18)
38+
# FetchContent's SOURCE_SUBDIR support was added in CMake 3.18; on older versions
39+
# MakeAvailable would add_subdirectory functional_cpp's top-level CMakeLists.txt,
40+
# pulling its src/tests into this build. Populate without adding any subdirectory.
41+
FetchContent_GetProperties(functional_cpp)
42+
if(NOT functional_cpp_POPULATED)
43+
FetchContent_Populate(functional_cpp)
44+
endif()
45+
else()
46+
# SOURCE_SUBDIR points at the header directory, which contains no CMakeLists.txt,
47+
# so MakeAvailable populates the sources without calling add_subdirectory
48+
FetchContent_MakeAvailable(functional_cpp)
49+
endif()
3950
include_directories(${functional_cpp_SOURCE_DIR}/include)
4051

4152
# Set compiler settings based on the current platform

0 commit comments

Comments
 (0)