summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/VS10Project
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-04-10 17:38:41 (GMT)
committerBrad King <brad.king@kitware.com>2019-04-17 15:00:44 (GMT)
commitfb3370b6a1681190ffd8daf63975c44ce8fc1c49 (patch)
tree1e837d6bb039320c6f38c60b69c9439abc720e5f /Tests/RunCMake/VS10Project
parentf621e7fa5df8d35cc379f9f7825f3d75b8489876 (diff)
downloadCMake-fb3370b6a1681190ffd8daf63975c44ce8fc1c49.zip
CMake-fb3370b6a1681190ffd8daf63975c44ce8fc1c49.tar.gz
CMake-fb3370b6a1681190ffd8daf63975c44ce8fc1c49.tar.bz2
MSVC: Add abstraction for runtime library selection
Replace our hard-coded defaults for `/MD` and `/MDd` with a first-class abstraction to select the runtime library from an enumeration of logical names. We've long hesitated to do this because the idea of "runtime library selection" touches on related concepts on several platforms. Avoid that scope creep by simply defining an abstraction that applies only when targeting the MSVC ABI on Windows. Removing the old default flags requires a policy because existing projects may rely on string processing to edit them and choose a runtime library under the old behavior. Add policy CMP0091 to provide compatibility. Fixes: #19108
Diffstat (limited to 'Tests/RunCMake/VS10Project')
-rw-r--r--Tests/RunCMake/VS10Project/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/VS10Project/RuntimeLibrary-check.cmake34
-rw-r--r--Tests/RunCMake/VS10Project/RuntimeLibrary.cmake16
-rw-r--r--Tests/RunCMake/VS10Project/empty.c0
-rw-r--r--Tests/RunCMake/VS10Project/empty.cxx0
5 files changed, 51 insertions, 0 deletions
diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
index df253a9..988312b 100644
--- a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
+++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
@@ -2,6 +2,7 @@ include(RunCMake)
run_cmake(VsCSharpCompilerOpts)
run_cmake(ExplicitCMakeLists)
+run_cmake(RuntimeLibrary)
run_cmake(SourceGroupCMakeLists)
run_cmake(VsConfigurationType)
diff --git a/Tests/RunCMake/VS10Project/RuntimeLibrary-check.cmake b/Tests/RunCMake/VS10Project/RuntimeLibrary-check.cmake
new file mode 100644
index 0000000..6b43d47
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/RuntimeLibrary-check.cmake
@@ -0,0 +1,34 @@
+macro(RuntimeLibrary_check tgt rtl_expect)
+ 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_Runtimelibrary 0)
+
+ file(STRINGS "${vcProjectFile}" lines)
+ foreach(line IN LISTS lines)
+ 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}'.")
+ return()
+ endif()
+ set(HAVE_Runtimelibrary 1)
+ break()
+ endif()
+ endforeach()
+
+ if(NOT HAVE_Runtimelibrary)
+ set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a RuntimeLibrary field.")
+ return()
+ endif()
+endmacro()
+
+RuntimeLibrary_check(default-C MultiThreadedDebugDLL)
+RuntimeLibrary_check(default-CXX MultiThreadedDebugDLL)
+RuntimeLibrary_check(MTd-C MultiThreadedDebug)
+RuntimeLibrary_check(MTd-CXX MultiThreadedDebug)
+RuntimeLibrary_check(MT-C MultiThreaded)
+RuntimeLibrary_check(MT-CXX MultiThreaded)
diff --git a/Tests/RunCMake/VS10Project/RuntimeLibrary.cmake b/Tests/RunCMake/VS10Project/RuntimeLibrary.cmake
new file mode 100644
index 0000000..6c77a25
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/RuntimeLibrary.cmake
@@ -0,0 +1,16 @@
+set(CMAKE_CONFIGURATION_TYPES Debug)
+cmake_policy(SET CMP0091 NEW)
+enable_language(C)
+enable_language(CXX)
+
+add_library(default-C empty.c)
+add_library(default-CXX empty.cxx)
+
+set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebug")
+add_library(MTd-C empty.c)
+add_library(MTd-CXX empty.cxx)
+
+add_library(MT-C empty.c)
+set_property(TARGET MT-C PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded")
+add_library(MT-CXX empty.cxx)
+set_property(TARGET MT-CXX PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded")
diff --git a/Tests/RunCMake/VS10Project/empty.c b/Tests/RunCMake/VS10Project/empty.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/empty.c
diff --git a/Tests/RunCMake/VS10Project/empty.cxx b/Tests/RunCMake/VS10Project/empty.cxx
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/empty.cxx