diff options
author | Brad King <brad.king@kitware.com> | 2024-02-20 15:37:18 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-02-20 15:37:32 (GMT) |
commit | 3a171009e96a74da0c6c67030716ee83cd54a47e (patch) | |
tree | c65462fc074680d3d6a20a729236b99554f3d69e /Tests/RunCMake | |
parent | 3710358c7ed30cf1a0e19b689391140adaadba75 (diff) | |
parent | b81464144468e930acc5bf55243dbb0a0f3ae0fb (diff) | |
download | CMake-3a171009e96a74da0c6c67030716ee83cd54a47e.zip CMake-3a171009e96a74da0c6c67030716ee83cd54a47e.tar.gz CMake-3a171009e96a74da0c6c67030716ee83cd54a47e.tar.bz2 |
Merge topic 'vs-UseDebugLibraries'
b814641444 VS: Add [CMAKE_]VS_USE_DEBUG_LIBRARIES options to control UseDebugLibraries
67de5b7b82 VS: Suppress MSBuild default settings affected by UseDebugLibraries
0ae372daee VS: Factor out common MS tool configuration
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9270
Diffstat (limited to 'Tests/RunCMake')
11 files changed, 101 insertions, 2 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index d9090d6..a2a9ee9 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -731,6 +731,7 @@ if("${CMAKE_GENERATOR}" MATCHES "Visual Studio ([^9]|9[0-9])") -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID} -DCMAKE_C_COMPILER_VERSION=${CMAKE_C_COMPILER_VERSION} ) + add_RunCMake_test(VS10ProjectUseDebugLibraries) if( vs12 AND wince ) add_RunCMake_test( VS10ProjectWinCE "-DRunCMake_GENERATOR_PLATFORM=${wince_sdk}") endif() diff --git a/Tests/RunCMake/VS10Project/RuntimeLibrary-check.cmake b/Tests/RunCMake/VS10Project/RuntimeLibrary-check.cmake index 689b35f..b5b195a 100644 --- a/Tests/RunCMake/VS10Project/RuntimeLibrary-check.cmake +++ b/Tests/RunCMake/VS10Project/RuntimeLibrary-check.cmake @@ -9,7 +9,7 @@ macro(RuntimeLibrary_check tgt rtl_expect) file(STRINGS "${vcProjectFile}" lines) foreach(line IN LISTS lines) - if(line MATCHES "^ *<RuntimeLibrary>([^<>]+)</RuntimeLibrary>") + if(line MATCHES "^ *<RuntimeLibrary>([^<>]*)</RuntimeLibrary>") set(rtl_actual "${CMAKE_MATCH_1}") if(NOT "${rtl_actual}" STREQUAL "${rtl_expect}") set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj has RuntimeLibrary '${rtl_actual}', not '${rtl_expect}'.") diff --git a/Tests/RunCMake/VS10Project/VsJustMyCode-check.cmake b/Tests/RunCMake/VS10Project/VsJustMyCode-check.cmake index 7119976..e76d931 100644 --- a/Tests/RunCMake/VS10Project/VsJustMyCode-check.cmake +++ b/Tests/RunCMake/VS10Project/VsJustMyCode-check.cmake @@ -9,7 +9,7 @@ macro(VsJustMyCode_check tgt jmc_expect) file(STRINGS "${vcProjectFile}" lines) foreach(line IN LISTS lines) - if(line MATCHES "^ *<SupportJustMyCode>([^<>]+)</SupportJustMyCode>") + if(line MATCHES "^ *<SupportJustMyCode>([^<>]*)</SupportJustMyCode>") set(jmc_actual "${CMAKE_MATCH_1}") if(NOT "${jmc_actual}" STREQUAL "${jmc_expect}") set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj has <SupportJustMyCode> '${jmc_actual}', not '${jmc_expect}'.") diff --git a/Tests/RunCMake/VS10ProjectUseDebugLibraries/CMakeLists.txt b/Tests/RunCMake/VS10ProjectUseDebugLibraries/CMakeLists.txt new file mode 100644 index 0000000..94e43ba --- /dev/null +++ b/Tests/RunCMake/VS10ProjectUseDebugLibraries/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.29) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/VS10ProjectUseDebugLibraries/Default-check.cmake b/Tests/RunCMake/VS10ProjectUseDebugLibraries/Default-check.cmake new file mode 100644 index 0000000..673144e --- /dev/null +++ b/Tests/RunCMake/VS10ProjectUseDebugLibraries/Default-check.cmake @@ -0,0 +1,8 @@ +include(${CMAKE_CURRENT_LIST_DIR}/check-common.cmake) + +UseDebugLibraries_check(default "" "") +UseDebugLibraries_check(defaultCLR "" "") +UseDebugLibraries_check(defaultUtil "" "") +UseDebugLibraries_check(defaultRTL "" "") +UseDebugLibraries_check(ALL_BUILD "" "") +UseDebugLibraries_check(ZERO_CHECK "" "") diff --git a/Tests/RunCMake/VS10ProjectUseDebugLibraries/Default.cmake b/Tests/RunCMake/VS10ProjectUseDebugLibraries/Default.cmake new file mode 100644 index 0000000..6afcfb6 --- /dev/null +++ b/Tests/RunCMake/VS10ProjectUseDebugLibraries/Default.cmake @@ -0,0 +1,10 @@ +set(CMAKE_CONFIGURATION_TYPES Debug Release) +enable_language(CXX) + +# Test several generator code paths covering different target types. +add_library(default empty.cxx) +add_library(defaultCLR empty.cxx) +set_property(TARGET defaultCLR PROPERTY COMMON_LANGUAGE_RUNTIME "") +add_library(defaultRTL empty.cxx) +set_property(TARGET defaultRTL PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") +add_custom_target(defaultUtil) diff --git a/Tests/RunCMake/VS10ProjectUseDebugLibraries/Explicit-check.cmake b/Tests/RunCMake/VS10ProjectUseDebugLibraries/Explicit-check.cmake new file mode 100644 index 0000000..385b798 --- /dev/null +++ b/Tests/RunCMake/VS10ProjectUseDebugLibraries/Explicit-check.cmake @@ -0,0 +1,10 @@ +include(${CMAKE_CURRENT_LIST_DIR}/check-common.cmake) + +UseDebugLibraries_check(empty "" "") +UseDebugLibraries_check(emptyCLR "" "") +UseDebugLibraries_check(emptyUtil "" "") +UseDebugLibraries_check(genex "true" "false") +UseDebugLibraries_check(genexCLR "true" "false") +UseDebugLibraries_check(genexUtil "true" "false") +UseDebugLibraries_check(ALL_BUILD "false" "false") +UseDebugLibraries_check(ZERO_CHECK "false" "false") diff --git a/Tests/RunCMake/VS10ProjectUseDebugLibraries/Explicit.cmake b/Tests/RunCMake/VS10ProjectUseDebugLibraries/Explicit.cmake new file mode 100644 index 0000000..3433745 --- /dev/null +++ b/Tests/RunCMake/VS10ProjectUseDebugLibraries/Explicit.cmake @@ -0,0 +1,20 @@ +set(CMAKE_CONFIGURATION_TYPES Debug Release) +enable_language(CXX) + +# An empty string suppresses generation of the setting. +set(CMAKE_VS_USE_DEBUG_LIBRARIES "") +add_library(empty empty.cxx) +add_library(emptyCLR empty.cxx) +set_property(TARGET emptyCLR PROPERTY COMMON_LANGUAGE_RUNTIME "") +add_custom_target(emptyUtil) + +# A generator expression can encode per-config values. +set(CMAKE_VS_USE_DEBUG_LIBRARIES "$<CONFIG:Debug>") +add_library(genex empty.cxx) +add_library(genexCLR empty.cxx) +set_property(TARGET genexCLR PROPERTY COMMON_LANGUAGE_RUNTIME "") +add_custom_target(genexUtil) + +# The last setting in the top-level directcory affects +# the builtin targets like ALL_BUILD and ZERO_CHECK. +set(CMAKE_VS_USE_DEBUG_LIBRARIES 0) diff --git a/Tests/RunCMake/VS10ProjectUseDebugLibraries/RunCMakeTest.cmake b/Tests/RunCMake/VS10ProjectUseDebugLibraries/RunCMakeTest.cmake new file mode 100644 index 0000000..8db2028 --- /dev/null +++ b/Tests/RunCMake/VS10ProjectUseDebugLibraries/RunCMakeTest.cmake @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.29) +include(RunCMake) + +run_cmake(Default) +run_cmake(Explicit) diff --git a/Tests/RunCMake/VS10ProjectUseDebugLibraries/check-common.cmake b/Tests/RunCMake/VS10ProjectUseDebugLibraries/check-common.cmake new file mode 100644 index 0000000..311c8a7 --- /dev/null +++ b/Tests/RunCMake/VS10ProjectUseDebugLibraries/check-common.cmake @@ -0,0 +1,42 @@ +cmake_policy(SET CMP0140 NEW) +function(UseDebugLibraries_check tgt udl_expect_debug udl_expect_release) + set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/${tgt}.vcxproj") + if(NOT EXISTS "${vcProjectFile}") + set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not exist.") + return() + endif() + + set(have_udl_debug 0) + set(have_udl_release 0) + set(inConfig "") + + file(STRINGS "${vcProjectFile}" lines) + foreach(line IN LISTS lines) + if(line MATCHES [[^ *<PropertyGroup Condition="'\$\(Configuration\)\|\$\(Platform\)'=='([^"|]+)\|[^"]+" Label="Configuration">.*$]]) + string(TOLOWER "${CMAKE_MATCH_1}" inConfig) + elseif(inConfig) + if(line MATCHES "^ *</PropertyGroup>.*$") + set(inConfig "") + elseif(line MATCHES "^ *<UseDebugLibraries>([^<>]+)</UseDebugLibraries>") + set(udl_actual "${CMAKE_MATCH_1}") + set(have_udl_${inConfig} 1) + if (NOT "${udl_expect_${inConfig}}" STREQUAL "") + if(NOT "${udl_actual}" STREQUAL "${udl_expect_${inConfig}}") + string(APPEND RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj has ${inConfig} UseDebugLibraries '${udl_actual}', not '${udl_expect_${inConfig}}'.\n") + endif() + else() + string(APPEND RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj has ${inConfig} UseDebugLibraries '${udl_actual}', but should not have one.\n") + endif() + unset(udl_actual) + endif() + endif() + endforeach() + + if(NOT have_udl_debug AND NOT "${udl_expect_debug}" STREQUAL "") + string(APPEND RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a debug UseDebugLibraries field, but should have one.\n") + endif() + if(NOT have_udl_release AND NOT "${udl_expect_release}" STREQUAL "") + string(APPEND RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a release UseDebugLibraries field, but should have one.\n") + endif() + return(PROPAGATE RunCMake_TEST_FAILED) +endfunction() diff --git a/Tests/RunCMake/VS10ProjectUseDebugLibraries/empty.cxx b/Tests/RunCMake/VS10ProjectUseDebugLibraries/empty.cxx new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/VS10ProjectUseDebugLibraries/empty.cxx |