diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bf1629..c125127 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.11) # FetchContent requires CMake 3.11 +cmake_minimum_required(VERSION 3.16) project(chaiscript_extras) # MINGW does not yet support C++11's concurrency features diff --git a/cmake/chaiscript.cmake b/cmake/chaiscript.cmake index 1d00c2e..8f16bf6 100644 --- a/cmake/chaiscript.cmake +++ b/cmake/chaiscript.cmake @@ -4,6 +4,14 @@ find_package(chaiscript ${CHAISCRIPT_VERSION} QUIET) if (NOT chaiscript_FOUND) include(FetchContent) + # FetchContent_Populate is deprecated in CMake 3.30+, but it still gives us the + # fine-grained control (EXCLUDE_FROM_ALL on add_subdirectory) we need to keep + # the upstream `chai` REPL target out of the default build. Opt into the OLD + # behaviour explicitly. + if(POLICY CMP0169) + cmake_policy(SET CMP0169 OLD) + endif() + FetchContent_Declare( chaiscript GIT_REPOSITORY https://github.com/ChaiScript/ChaiScript.git @@ -12,14 +20,21 @@ if (NOT chaiscript_FOUND) FetchContent_GetProperties(chaiscript) if (NOT chaiscript_POPULATED) - set(FETCHCONTENT_QUIET NO) FetchContent_Populate(chaiscript) set(BUILD_SAMPLES OFF CACHE BOOL "" FORCE) - set(BUILD_MODULES ON CACHE BOOL "" FORCE) + set(BUILD_MODULES OFF CACHE BOOL "" FORCE) set(BUILD_TESTING OFF CACHE BOOL "" FORCE) set(BUILD_LIBFUZZ_TESTER OFF CACHE BOOL "" FORCE) - add_subdirectory(${chaiscript_SOURCE_DIR} ${chaiscript_BINARY_DIR}) + # ChaiScript 6.1.0's root CMakeLists.txt declares + # cmake_minimum_required(VERSION 2.8), which CMake 4.x refuses. Force a + # floor so the fetched subproject is accepted. + set(CMAKE_POLICY_VERSION_MINIMUM 3.5) + + # EXCLUDE_FROM_ALL keeps ChaiScript's `chai` REPL out of the default build. + # We only consume ChaiScript's headers here, and its src/main.cpp in 6.1.0 + # does not compile on current MSVC (missing include). + add_subdirectory(${chaiscript_SOURCE_DIR} ${chaiscript_BINARY_DIR} EXCLUDE_FROM_ALL) endif() endif()