From 116411b25040fc08612ecd215bbade42d1e50bcb Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 30 Sep 2026 18:12:32 +0200 Subject: [PATCH] Make the CMake integration-test wrappers consistent The six tests/cmake_* integration-test wrappers had drifted: - Only cmake_import and cmake_import_minver forwarded -A "${CMAKE_GENERATOR_PLATFORM}" to the inner configure, and none forwarded -T "${CMAKE_GENERATOR_TOOLSET}". The Windows workflow configures the outer build with -A Win32 -T ClangCL, so without forwarding, the inner projects of cmake_add_subdirectory, cmake_fetch_content, cmake_fetch_content2 and cmake_target_include_directories built with the generator defaults instead of matching the outer build's platform and toolset. Forward both consistently from all six wrappers. - cmake_fetch_content and cmake_fetch_content2 passed -Dnlohmann_json_source to their inner projects, which never read it (CMake warns "manually-specified variables were not used"); the inner projects fetch their own copy of the library instead. Drop it. - tests/CMakeLists.txt set JSON_FORCED_GLOBAL_COMPILE_OPTIONS from the matching environment variable but never read the cache variable again; the lines right below it read $ENV{JSON_FORCED_GLOBAL_COMPILE_OPTIONS} directly, like the LINK_OPTIONS counterpart already does. Remove the dead set(). This changes which platform and toolset the Win32 and ClangCL CI jobs build the four newly-forwarding wrappers' inner projects with, which may surface new failures there; CI has to confirm those jobs. Verified locally with Ninja (empty -A ""/-T "" is accepted): all 12 cmake_* tests still pass, and the inner fetch_content configures no longer warn about the unused variable. Closes #5714 item 6. Signed-off-by: Niels Lohmann --- tests/CMakeLists.txt | 1 - tests/cmake_add_subdirectory/CMakeLists.txt | 2 ++ tests/cmake_fetch_content/CMakeLists.txt | 3 ++- tests/cmake_fetch_content2/CMakeLists.txt | 3 ++- tests/cmake_import/CMakeLists.txt | 1 + tests/cmake_import_minver/CMakeLists.txt | 1 + tests/cmake_target_include_directories/CMakeLists.txt | 2 ++ 7 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8c81b9123..40a97d3b0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,7 +10,6 @@ set(JSON_32bitTest AUTO CACHE STRING "Enable the 32bit unit test (ON/OFF/AUT set(JSON_TestStandards "" CACHE STRING "The list of standards to test explicitly.") # using an env var, since this will also affect targets executing cmake (such as "ci_test_compiler_default") -set(JSON_FORCED_GLOBAL_COMPILE_OPTIONS $ENV{JSON_FORCED_GLOBAL_COMPILE_OPTIONS}) if (NOT "" STREQUAL "$ENV{JSON_FORCED_GLOBAL_COMPILE_OPTIONS}") add_compile_options($ENV{JSON_FORCED_GLOBAL_COMPILE_OPTIONS}) endif() diff --git a/tests/cmake_add_subdirectory/CMakeLists.txt b/tests/cmake_add_subdirectory/CMakeLists.txt index 7bb661075..0b82d9141 100644 --- a/tests/cmake_add_subdirectory/CMakeLists.txt +++ b/tests/cmake_add_subdirectory/CMakeLists.txt @@ -1,6 +1,8 @@ add_test(NAME cmake_add_subdirectory_configure COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" + -A "${CMAKE_GENERATOR_PLATFORM}" + -T "${CMAKE_GENERATOR_TOOLSET}" -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -Dnlohmann_json_source=${PROJECT_SOURCE_DIR} diff --git a/tests/cmake_fetch_content/CMakeLists.txt b/tests/cmake_fetch_content/CMakeLists.txt index 42fcb5816..4e819d51f 100644 --- a/tests/cmake_fetch_content/CMakeLists.txt +++ b/tests/cmake_fetch_content/CMakeLists.txt @@ -1,9 +1,10 @@ add_test(NAME cmake_fetch_content_configure COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" + -A "${CMAKE_GENERATOR_PLATFORM}" + -T "${CMAKE_GENERATOR_TOOLSET}" -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -Dnlohmann_json_source=${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/project ) add_test(NAME cmake_fetch_content_build diff --git a/tests/cmake_fetch_content2/CMakeLists.txt b/tests/cmake_fetch_content2/CMakeLists.txt index 9b24fee01..98411bf5a 100644 --- a/tests/cmake_fetch_content2/CMakeLists.txt +++ b/tests/cmake_fetch_content2/CMakeLists.txt @@ -2,9 +2,10 @@ if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14") add_test(NAME cmake_fetch_content2_configure COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" + -A "${CMAKE_GENERATOR_PLATFORM}" + -T "${CMAKE_GENERATOR_TOOLSET}" -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -Dnlohmann_json_source=${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/project ) add_test(NAME cmake_fetch_content2_build diff --git a/tests/cmake_import/CMakeLists.txt b/tests/cmake_import/CMakeLists.txt index eec526389..9acea845d 100644 --- a/tests/cmake_import/CMakeLists.txt +++ b/tests/cmake_import/CMakeLists.txt @@ -2,6 +2,7 @@ add_test(NAME cmake_import_configure COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" -A "${CMAKE_GENERATOR_PLATFORM}" + -T "${CMAKE_GENERATOR_TOOLSET}" -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -Dnlohmann_json_DIR=${PROJECT_BINARY_DIR} diff --git a/tests/cmake_import_minver/CMakeLists.txt b/tests/cmake_import_minver/CMakeLists.txt index 42e3ff3e4..029789267 100644 --- a/tests/cmake_import_minver/CMakeLists.txt +++ b/tests/cmake_import_minver/CMakeLists.txt @@ -2,6 +2,7 @@ add_test(NAME cmake_import_minver_configure COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" -A "${CMAKE_GENERATOR_PLATFORM}" + -T "${CMAKE_GENERATOR_TOOLSET}" -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -Dnlohmann_json_DIR=${PROJECT_BINARY_DIR} diff --git a/tests/cmake_target_include_directories/CMakeLists.txt b/tests/cmake_target_include_directories/CMakeLists.txt index 86fea3a5a..fac888e0f 100644 --- a/tests/cmake_target_include_directories/CMakeLists.txt +++ b/tests/cmake_target_include_directories/CMakeLists.txt @@ -1,6 +1,8 @@ add_test(NAME cmake_target_include_directories_configure COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" + -A "${CMAKE_GENERATOR_PLATFORM}" + -T "${CMAKE_GENERATOR_TOOLSET}" -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -Dnlohmann_json_source=${PROJECT_SOURCE_DIR}