summaryrefslogtreecommitdiffstats
path: root/Tests/CompileOptions
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-06-03 14:40:56 (GMT)
committerBrad King <brad.king@kitware.com>2021-06-07 17:39:21 (GMT)
commit8f68bcad8fafddc82b73b69f21e122ece8603a8f (patch)
tree6989359100a0b17e3e293f17c9327e86e0790e92 /Tests/CompileOptions
parentccc83ce1623a90c9354a940370ed8c06d2fea30b (diff)
downloadCMake-8f68bcad8fafddc82b73b69f21e122ece8603a8f.zip
CMake-8f68bcad8fafddc82b73b69f21e122ece8603a8f.tar.gz
CMake-8f68bcad8fafddc82b73b69f21e122ece8603a8f.tar.bz2
Tests: Add cases verifying flag ordering rules
Diffstat (limited to 'Tests/CompileOptions')
-rw-r--r--Tests/CompileOptions/CMakeLists.txt28
-rw-r--r--Tests/CompileOptions/main.cpp18
2 files changed, 44 insertions, 2 deletions
diff --git a/Tests/CompileOptions/CMakeLists.txt b/Tests/CompileOptions/CMakeLists.txt
index cd6cacd..96bafea 100644
--- a/Tests/CompileOptions/CMakeLists.txt
+++ b/Tests/CompileOptions/CMakeLists.txt
@@ -1,5 +1,11 @@
-cmake_minimum_required(VERSION 2.8.12)
-
+cmake_minimum_required(VERSION 3.0)
+if(POLICY CMP0092)
+ cmake_policy(SET CMP0092 NEW)
+endif()
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(NOT _isMultiConfig AND NOT CMAKE_BUILD_TYPE)
+ set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build" FORCE)
+endif()
project(CompileOptions)
add_library(testlib other.cpp)
@@ -49,6 +55,24 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|Borland|Embarcadero" AND NOT "${CMAK
)
endif()
+if(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|AppleClang|MSVC)$")
+ target_compile_definitions(CompileOptions PRIVATE "DO_FLAG_TESTS")
+ if(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|AppleClang)$")
+ string(APPEND CMAKE_CXX_FLAGS " -w")
+ endif()
+ string(APPEND CMAKE_CXX_FLAGS " -DFLAG_A=1 -DFLAG_B=1")
+ string(APPEND CMAKE_CXX_FLAGS_DEBUG " -DFLAG_A=2 -DFLAG_C=1")
+ string(APPEND CMAKE_CXX_FLAGS_RELEASE " -DFLAG_A=2 -DFLAG_C=1")
+ string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -DFLAG_A=2 -DFLAG_C=1")
+ string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL " -DFLAG_A=2 -DFLAG_C=1")
+ set_property(TARGET CompileOptions APPEND PROPERTY COMPILE_OPTIONS "-DFLAG_B=2" "-DFLAG_C=2" "-DFLAG_D=1")
+ set_property(TARGET testlib APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "-DFLAG_D=2")
+ if(NOT CMAKE_GENERATOR MATCHES "^Visual Studio 9")
+ set_property(TARGET testlib APPEND PROPERTY INTERFACE_COMPILE_OPTIONS "-DFLAG_E=1")
+ set_property(SOURCE main.cpp PROPERTY COMPILE_OPTIONS "-DFLAG_E=2")
+ endif()
+endif()
+
target_link_libraries(CompileOptions testlib)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
diff --git a/Tests/CompileOptions/main.cpp b/Tests/CompileOptions/main.cpp
index ebc1017..23ce197 100644
--- a/Tests/CompileOptions/main.cpp
+++ b/Tests/CompileOptions/main.cpp
@@ -37,6 +37,24 @@
# endif
#endif
+#ifdef DO_FLAG_TESTS
+# if FLAG_A != 2
+# error "FLAG_A is not 2"
+# endif
+# if FLAG_B != 2
+# error "FLAG_B is not 2"
+# endif
+# if FLAG_C != 2
+# error "FLAG_C is not 2"
+# endif
+# if FLAG_D != 2
+# error "FLAG_D is not 2"
+# endif
+# if defined(FLAG_E) && FLAG_E != 2
+# error "FLAG_E is not 2"
+# endif
+#endif
+
#include <string.h>
int main()