summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/VS10Project/VsPlatformToolset-check.cmake
diff options
context:
space:
mode:
authorJulien Jemine <julien.jemine@gmail.com>2020-04-28 14:55:03 (GMT)
committerBrad King <brad.king@kitware.com>2020-04-29 11:35:57 (GMT)
commit197b4cbe186cd31a490fc3cfcaace55bd7123829 (patch)
tree92b65d5e04bfa70113bf6b39b952b8168dd2b044 /Tests/RunCMake/VS10Project/VsPlatformToolset-check.cmake
parent73f81c5070e7880efe5acfc1827f60524116cee1 (diff)
downloadCMake-197b4cbe186cd31a490fc3cfcaace55bd7123829.zip
CMake-197b4cbe186cd31a490fc3cfcaace55bd7123829.tar.gz
CMake-197b4cbe186cd31a490fc3cfcaace55bd7123829.tar.bz2
VS: Add option for per-target PlatformToolset
Add a `VS_PLATFORM_TOOLSET` target property to set `PlatformToolset` in the `.vcxproj` file for specific targets. Document that this is safe only when the named toolset uses the same underlying compiler as the primary toolset. Fixes: #17429
Diffstat (limited to 'Tests/RunCMake/VS10Project/VsPlatformToolset-check.cmake')
-rw-r--r--Tests/RunCMake/VS10Project/VsPlatformToolset-check.cmake36
1 files changed, 36 insertions, 0 deletions
diff --git a/Tests/RunCMake/VS10Project/VsPlatformToolset-check.cmake b/Tests/RunCMake/VS10Project/VsPlatformToolset-check.cmake
new file mode 100644
index 0000000..416220b
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/VsPlatformToolset-check.cmake
@@ -0,0 +1,36 @@
+macro(ReadPlatformToolset tgt outvar)
+ 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_PlatformToolset 0)
+
+ file(STRINGS "${vcProjectFile}" lines)
+ foreach(line IN LISTS lines)
+ if(line MATCHES "^ *<PlatformToolset>([^<>]+)</PlatformToolset>")
+ set(${outvar} "${CMAKE_MATCH_1}")
+ set(HAVE_PlatformToolset 1)
+ break()
+ endif()
+ endforeach()
+
+ if(NOT HAVE_PlatformToolset)
+ set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <PlatformToolset> field.")
+ return()
+ endif()
+endmacro()
+
+ReadPlatformToolset(NormalPlatformToolset NORMAL_TOOLSET)
+ReadPlatformToolset(OverridenPlatformToolset OVERRIDEN_TOOLSET)
+
+if (NOT "${OVERRIDEN_TOOLSET}" STREQUAL "MyCustomToolset")
+ set(RunCMake_TEST_FAILED "Failed to override the platform toolset")
+ return()
+endif()
+
+if ("${NORMAL_TOOLSET}" STREQUAL "MyCustomToolset")
+ set(RunCMake_TEST_FAILED "Main toolset was overriden (it shouldn't)")
+ return()
+endif()