1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

Tests: Actually test CPS generation with no config

Commit 58d9950842 (CPS: Fix empty configuration field on noconfig
builds, 2025-06-30) fixed an issue with CPS generation that would
incorrectly use the empty string to identify the configuration in some
instances. (The expected CMake behavior is that an empty configuration
is always equivalent to 'noconfig'.) However, that commit did not add
any tests for the fix.

Add those tests now. Also, tweak the tests that were added, that test
for expected non-empty configuration-specific content, to hard-code what
configuration or configurations are produced. Lastly, remove the
explicit test for existence of the CPS file in said tests; `file(READ)`
will complain if the file does not exist, so the separate test is
superfluous.
This commit is contained in:
Matthew Woehlke
2025-07-03 12:49:55 -04:00
parent a6245c9bf6
commit 4bb4bbcf59
13 changed files with 81 additions and 55 deletions

View File

@@ -1,14 +1,14 @@
include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake)
set(out_dir "${RunCMake_BINARY_DIR}/PerConfigGeneration-build")
set(out_dir "${RunCMake_BINARY_DIR}/Config-build")
file(READ "${out_dir}/foo.cps" content)
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
foreach(config ${CMAKE_CONFIGURATION_TYPES})
foreach(config FooConfig BarConfig)
expect_object("${content}" "components" "foo" "configurations" ${config})
endforeach()
else()
include(${RunCMake_TEST_BINARY_DIR}/build_type.cmake)
set(config TestConfig)
expect_object("${content}" "components" "foo" "configurations" ${config})
endif()

View File

@@ -0,0 +1,13 @@
project(Config CXX)
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
set(CMAKE_CONFIGURATION_TYPES "FooConfig;BarConfig" CACHE STRING "" FORCE)
else()
set(CMAKE_BUILD_TYPE "TestConfig" CACHE STRING "" FORCE)
endif()
add_library(foo foo.cxx)
install(TARGETS foo EXPORT foo)
export(EXPORT foo PACKAGE_INFO foo)

View File

@@ -0,0 +1,7 @@
include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake)
set(out_dir "${RunCMake_BINARY_DIR}/EmptyConfig-build")
file(READ "${out_dir}/foo.cps" content)
expect_object("${content}" "components" "foo" "configurations" "noconfig")

View File

@@ -0,0 +1,9 @@
project(EmptyConfig CXX)
set(CMAKE_BUILD_TYPE "" CACHE STRING "" FORCE)
set(CMAKE_CONFIGURATION_TYPES "" CACHE STRING "" FORCE)
add_library(foo foo.cxx)
install(TARGETS foo EXPORT foo)
export(EXPORT foo PACKAGE_INFO foo)

View File

@@ -1,13 +0,0 @@
project(PerConfigGeneration CXX)
set(config ${CMAKE_BUILD_TYPE})
if(NOT config)
set(config noconfig)
endif()
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/build_type.cmake" "set(config \"${config}\")")
add_library(foo foo.cxx)
install(TARGETS foo EXPORT foo)
export(EXPORT foo PACKAGE_INFO foo)

View File

@@ -40,5 +40,6 @@ run_cmake(Requirements)
run_cmake(TargetTypes)
run_cmake(DependsMultiple)
run_cmake(LinkOnly)
run_cmake(PerConfigGeneration)
run_cmake(Config)
run_cmake(EmptyConfig)
run_cmake(FileSetHeaders)

View File

@@ -0,0 +1,16 @@
include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake)
set(out_dir "${RunCMake_BINARY_DIR}/Config-build/CMakeFiles/Export/510c5684a4a8a792eadfb55bc9744983")
macro(check_config CONFIG)
string(TOLOWER "${CONFIG}" CONFIG_LOWER)
file(READ "${out_dir}/foo@${CONFIG_LOWER}.cps" content)
expect_value("${content}" "${CONFIG}" "configuration")
endmacro()
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
check_config(FooConfig)
check_config(BarConfig)
else()
check_config(TestConfig)
endif()

View File

@@ -0,0 +1,13 @@
project(Config CXX)
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
set(CMAKE_CONFIGURATION_TYPES "FooConfig;BarConfig" CACHE STRING "" FORCE)
else()
set(CMAKE_BUILD_TYPE "TestConfig" CACHE STRING "" FORCE)
endif()
add_library(foo foo.cxx)
install(TARGETS foo EXPORT foo)
install(PACKAGE_INFO foo DESTINATION cps EXPORT foo)

View File

@@ -0,0 +1,7 @@
include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake)
set(out_dir "${RunCMake_BINARY_DIR}/EmptyConfig-build/CMakeFiles/Export/510c5684a4a8a792eadfb55bc9744983")
file(READ "${out_dir}/foo@noconfig.cps" content)
expect_value("${content}" "noconfig" "configuration")

View File

@@ -0,0 +1,9 @@
project(EmptyConfig CXX)
set(CMAKE_BUILD_TYPE "" CACHE STRING "" FORCE)
set(CMAKE_CONFIGURATION_TYPES "" CACHE STRING "" FORCE)
add_library(foo foo.cxx)
install(TARGETS foo EXPORT foo)
install(PACKAGE_INFO foo DESTINATION cps EXPORT foo)

View File

@@ -1,24 +0,0 @@
include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake)
set(out_dir "${RunCMake_BINARY_DIR}/PerConfigGeneration-build/CMakeFiles/Export/510c5684a4a8a792eadfb55bc9744983")
macro(check_config)
string(TOLOWER "${config}" config_lower)
if(NOT EXISTS "${out_dir}/foo@${config_lower}.cps")
set(RunCMake_TEST_FAILED
"Configuration file for '${config}' does not exist")
return()
endif()
file(READ "${out_dir}/foo@${config_lower}.cps" content)
expect_value("${content}" "${config}" "configuration")
endmacro()
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
foreach(config ${CMAKE_CONFIGURATION_TYPES})
check_config()
endforeach()
else()
include(${RunCMake_TEST_BINARY_DIR}/build_type.cmake)
check_config()
endif()

View File

@@ -1,13 +0,0 @@
project(PerConfigGeneration CXX)
set(config ${CMAKE_BUILD_TYPE})
if(NOT config)
set(config noconfig)
endif()
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/build_type.cmake" "set(config \"${config}\")")
add_library(foo foo.cxx)
install(TARGETS foo EXPORT foo)
install(PACKAGE_INFO foo DESTINATION cps EXPORT foo)

View File

@@ -48,6 +48,7 @@ run_cmake(Requirements)
run_cmake(TargetTypes)
run_cmake(DependsMultiple)
run_cmake(DependsMultipleNotInstalled)
run_cmake(PerConfigGeneration)
run_cmake(Config)
run_cmake(EmptyConfig)
run_cmake(FileSetHeaders)
run_cmake_install(Destination)