summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-06-08 12:04:11 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-06-08 12:04:16 (GMT)
commitd1517a4ef953510a65da6be29b54be2fc59409e2 (patch)
tree390cb69534420e93313a3fc763bdd39df4b87cb3 /Tests/RunCMake
parent105e108836403379cda176ec0a16fafc0a06464a (diff)
parent8f68bcad8fafddc82b73b69f21e122ece8603a8f (diff)
downloadCMake-d1517a4ef953510a65da6be29b54be2fc59409e2.zip
CMake-d1517a4ef953510a65da6be29b54be2fc59409e2.tar.gz
CMake-d1517a4ef953510a65da6be29b54be2fc59409e2.tar.bz2
Merge topic 'compile-options-order'
8f68bcad8f Tests: Add cases verifying flag ordering rules ccc83ce162 Help: Document order of flags from CMAKE_<LANG>_FLAGS and COMPILE_OPTIONS df79fe055b Help: Remove incorrect "versionadded" for CMAKE_<LANG>_FLAGS_<CONFIG> c48d2d8480 VS: Place per-source preprocessor definitions after target-wide ones Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6187
Diffstat (limited to 'Tests/RunCMake')
-rw-r--r--Tests/RunCMake/CMakeLists.txt5
-rw-r--r--Tests/RunCMake/target_compile_options/Order-build-stdout.txt3
-rw-r--r--Tests/RunCMake/target_compile_options/Order.cmake19
-rw-r--r--Tests/RunCMake/target_compile_options/RunCMakeTest.cmake13
-rw-r--r--Tests/RunCMake/target_compile_options/order.c7
5 files changed, 46 insertions, 1 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index d02d7a2..670abbc 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -595,7 +595,10 @@ set_property(TEST RunCMake.target_link_options APPEND
add_RunCMake_test(target_compile_definitions)
add_RunCMake_test(target_compile_features)
-add_RunCMake_test(target_compile_options -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID})
+add_RunCMake_test(target_compile_options
+ -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID}
+ -DCMAKE_C_SIMULATE_ID=${CMAKE_C_SIMULATE_ID}
+ )
add_RunCMake_test(target_include_directories)
add_RunCMake_test(target_sources)
add_RunCMake_test(CheckCompilerFlag -DCMake_TEST_CUDA=${CMake_TEST_CUDA}
diff --git a/Tests/RunCMake/target_compile_options/Order-build-stdout.txt b/Tests/RunCMake/target_compile_options/Order-build-stdout.txt
new file mode 100644
index 0000000..c210ff2
--- /dev/null
+++ b/Tests/RunCMake/target_compile_options/Order-build-stdout.txt
@@ -0,0 +1,3 @@
+-w +-O +-O0 [^
+]*-O1 +-O2 +-O3 [^
+]*CMakeFiles[\/]order\.dir[\/](Custom[\/])?order\.c\.o
diff --git a/Tests/RunCMake/target_compile_options/Order.cmake b/Tests/RunCMake/target_compile_options/Order.cmake
new file mode 100644
index 0000000..3d59b16
--- /dev/null
+++ b/Tests/RunCMake/target_compile_options/Order.cmake
@@ -0,0 +1,19 @@
+get_property (isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(isMultiConfig)
+ set(CMAKE_CONFIGURATION_TYPES "Custom" CACHE STRING "" FORCE)
+else()
+ set(CMAKE_BUILD_TYPE "Custom" CACHE STRING "" FORCE)
+endif()
+enable_language(C)
+
+string(APPEND CMAKE_C_FLAGS " -w -O")
+set(CMAKE_C_FLAGS_CUSTOM "-O0")
+
+add_executable(order order.c)
+set_property(TARGET order APPEND PROPERTY COMPILE_OPTIONS -O1)
+
+add_library(iface INTERFACE)
+set_property(TARGET iface APPEND PROPERTY INTERFACE_COMPILE_OPTIONS -O2)
+target_link_libraries(order PRIVATE iface)
+
+set_property(SOURCE order.c PROPERTY COMPILE_OPTIONS -O3)
diff --git a/Tests/RunCMake/target_compile_options/RunCMakeTest.cmake b/Tests/RunCMake/target_compile_options/RunCMakeTest.cmake
index 9f51a9a..806ae79 100644
--- a/Tests/RunCMake/target_compile_options/RunCMakeTest.cmake
+++ b/Tests/RunCMake/target_compile_options/RunCMakeTest.cmake
@@ -19,3 +19,16 @@ if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
run_cmake_target(CMP0101-BEFORE_keyword OLD CMP0101_OLD)
run_cmake_target(CMP0101-BEFORE_keyword NEW CMP0101_NEW)
endif()
+
+function(run_Order)
+ run_cmake_with_options(Order)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Order-build)
+ set(RunCMake_TEST_OUTPUT_MERGE 1)
+ run_cmake_command(Order-build ${CMAKE_COMMAND} --build . --verbose --config Custom)
+endfunction()
+if(RunCMake_GENERATOR MATCHES "Ninja|Make" AND
+ CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$" AND
+ NOT CMAKE_C_SIMULATE_ID STREQUAL "MSVC")
+ run_Order()
+endif()
diff --git a/Tests/RunCMake/target_compile_options/order.c b/Tests/RunCMake/target_compile_options/order.c
new file mode 100644
index 0000000..1bd81ea
--- /dev/null
+++ b/Tests/RunCMake/target_compile_options/order.c
@@ -0,0 +1,7 @@
+#ifndef __OPTIMIZE__
+# error "Optimizations not enabled!"
+#endif
+int main(void)
+{
+ return 0;
+}