1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 22:37:30 +08:00

CPS: Fix empty configuration field on noconfig builds

Fixes: #27044
This commit is contained in:
Vito Gamberini
2025-06-30 11:11:06 -04:00
parent 49120bbf2b
commit 58d9950842
10 changed files with 79 additions and 2 deletions

View File

@@ -103,7 +103,8 @@ void cmExportBuildPackageInfoGenerator::GenerateInterfacePropertiesConfig(
Json::Value component =
this->GenerateInterfaceConfigProperties(suffix, properties);
if (!component.empty()) {
configurations[config] = std::move(component);
configurations[config.empty() ? std::string{ "noconfig" } : config] =
std::move(component);
}
}

View File

@@ -117,7 +117,7 @@ void cmExportInstallPackageInfoGenerator::GenerateImportTargetsConfig(
{
Json::Value root;
root["name"] = this->GetPackageName();
root["configuration"] = config;
root["configuration"] = (config.empty() ? "noconfig" : config);
Json::Value& components = root["components"];

View File

@@ -20,6 +20,11 @@ function(expect_array content expected_length)
_expect("length" EQUAL "${actual_length}" "${expected_length}" ${ARGN})
endfunction()
function(expect_object content)
string(JSON actual_type TYPE "${content}" ${ARGN})
_expect("type" STREQUAL "${actual_type}" "OBJECT" ${ARGN})
endfunction()
function(expect_null content)
string(JSON actual_type TYPE "${content}" ${ARGN})
_expect("type" STREQUAL "${actual_type}" "NULL" ${ARGN})

View File

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

View File

@@ -0,0 +1,13 @@
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,3 +40,4 @@ run_cmake(Requirements)
run_cmake(TargetTypes)
run_cmake(DependsMultiple)
run_cmake(LinkOnly)
run_cmake(PerConfigGeneration)

View File

@@ -20,6 +20,11 @@ function(expect_array content expected_length)
_expect("length" EQUAL "${actual_length}" "${expected_length}" ${ARGN})
endfunction()
function(expect_object content)
string(JSON actual_type TYPE "${content}" ${ARGN})
_expect("type" STREQUAL "${actual_type}" "OBJECT" ${ARGN})
endfunction()
function(expect_null content)
string(JSON actual_type TYPE "${content}" ${ARGN})
_expect("type" STREQUAL "${actual_type}" "NULL" ${ARGN})

View File

@@ -0,0 +1,24 @@
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

@@ -0,0 +1,13 @@
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,4 +48,5 @@ run_cmake(Requirements)
run_cmake(TargetTypes)
run_cmake(DependsMultiple)
run_cmake(DependsMultipleNotInstalled)
run_cmake(PerConfigGeneration)
run_cmake_install(Destination)