summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-10-07 14:33:41 +0000
committerKitware Robot <kwrobot@kitware.com>2019-10-07 10:33:50 -0400
commita023a2e4fe289dedd42a883464c9f7514ac0d0e9 (patch)
treee5fe9bc5656cf95a5cafeeb4869eee8433d01047
parent27928290acc81971fbaf5cac04f9667ba39d72d8 (diff)
parent9c9e66289acc7f54dfdb518a92b625f5a34c7c2d (diff)
downloadcmake-a023a2e4fe289dedd42a883464c9f7514ac0d0e9.tar.gz
Merge topic 'test-per-config-sources'
9c9e66289a Tests: Enable ConfigSources test on every configuration Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !3888
-rw-r--r--Tests/CMakeLists.txt4
-rw-r--r--Tests/ConfigSources/CMakeLists.txt22
-rw-r--r--Tests/ConfigSources/iface.h10
-rw-r--r--Tests/ConfigSources/iface_debug.h4
-rw-r--r--Tests/ConfigSources/iface_debug_src.cpp8
-rw-r--r--Tests/ConfigSources/iface_other_src.cpp13
-rw-r--r--Tests/ConfigSources/main.cpp7
-rw-r--r--Tests/ConfigSources/main_debug.cpp13
-rw-r--r--Tests/ConfigSources/main_other.cpp13
9 files changed, 71 insertions, 23 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index ed20b91bd4..32b580b30c 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -451,8 +451,8 @@ if(BUILD_TESTING)
ADD_TEST_MACRO(StagingPrefix StagingPrefix)
ADD_TEST_MACRO(ImportedSameName ImportedSameName)
ADD_TEST_MACRO(InterfaceLibrary InterfaceLibrary)
- if (CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
- set(ConfigSources_BUILD_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
+ if(NOT _isMultiConfig)
+ set(ConfigSources_BUILD_OPTIONS -DCMAKE_BUILD_TYPE=$<CONFIGURATION>)
ADD_TEST_MACRO(ConfigSources ConfigSources)
endif()
ADD_TEST_MACRO(SourcesProperty SourcesProperty)
diff --git a/Tests/ConfigSources/CMakeLists.txt b/Tests/ConfigSources/CMakeLists.txt
index 748aad8878..f5dd2765c8 100644
--- a/Tests/ConfigSources/CMakeLists.txt
+++ b/Tests/ConfigSources/CMakeLists.txt
@@ -1,17 +1,21 @@
-
cmake_minimum_required(VERSION 3.0)
-
-project(ConfigSources)
+project(ConfigSources CXX)
add_library(iface INTERFACE)
-set_property(TARGET iface PROPERTY INTERFACE_SOURCES
+target_sources(iface INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/iface_src.cpp"
"$<$<CONFIG:Debug>:${CMAKE_CURRENT_SOURCE_DIR}/iface_debug_src.cpp>"
- "$<$<CONFIG:Release>:${CMAKE_CURRENT_SOURCE_DIR}/does_not_exist.cpp>"
-)
+ "$<$<NOT:$<CONFIG:Debug>>:${CMAKE_CURRENT_SOURCE_DIR}/iface_other_src.cpp>"
+ "$<$<CONFIG:NotAConfig>:${CMAKE_CURRENT_SOURCE_DIR}/does_not_exist.cpp>"
+ )
+target_compile_definitions(iface INTERFACE
+ "$<$<CONFIG:Debug>:CFG_DEBUG>"
+ "$<$<NOT:$<CONFIG:Debug>>:CFG_OTHER>"
+ )
add_executable(ConfigSources
- $<$<CONFIG:Debug>:main.cpp>
- $<$<CONFIG:Release>:does_not_exist.cpp>
-)
+ $<$<CONFIG:Debug>:main_debug.cpp>
+ $<$<NOT:$<CONFIG:Debug>>:main_other.cpp>
+ $<$<CONFIG:NotAConfig>:does_not_exist.cpp>
+ )
target_link_libraries(ConfigSources iface)
diff --git a/Tests/ConfigSources/iface.h b/Tests/ConfigSources/iface.h
new file mode 100644
index 0000000000..810456cbc6
--- /dev/null
+++ b/Tests/ConfigSources/iface.h
@@ -0,0 +1,10 @@
+
+int iface_src();
+
+#ifdef CFG_DEBUG
+int iface_debug();
+#endif
+
+#ifdef CFG_OTHER
+int iface_other();
+#endif
diff --git a/Tests/ConfigSources/iface_debug.h b/Tests/ConfigSources/iface_debug.h
deleted file mode 100644
index a23d7374b8..0000000000
--- a/Tests/ConfigSources/iface_debug.h
+++ /dev/null
@@ -1,4 +0,0 @@
-
-int iface_src();
-
-int iface_debug();
diff --git a/Tests/ConfigSources/iface_debug_src.cpp b/Tests/ConfigSources/iface_debug_src.cpp
index 63b22fcd14..010059f1f0 100644
--- a/Tests/ConfigSources/iface_debug_src.cpp
+++ b/Tests/ConfigSources/iface_debug_src.cpp
@@ -1,5 +1,11 @@
+#ifndef CFG_DEBUG
+# error "This source should only be compiled in a Debug configuration."
+#endif
+#ifdef CFG_OTHER
+# error "This source should not be compiled in a non-Debug configuration."
+#endif
-#include "iface_debug.h"
+#include "iface.h"
int iface_debug()
{
diff --git a/Tests/ConfigSources/iface_other_src.cpp b/Tests/ConfigSources/iface_other_src.cpp
new file mode 100644
index 0000000000..8ffdfbb729
--- /dev/null
+++ b/Tests/ConfigSources/iface_other_src.cpp
@@ -0,0 +1,13 @@
+#ifndef CFG_OTHER
+# error "This source should only be compiled in a non-Debug configuration."
+#endif
+#ifdef CFG_DEBUG
+# error "This source should not be compiled in a Debug configuration."
+#endif
+
+#include "iface.h"
+
+int iface_other()
+{
+ return 0;
+}
diff --git a/Tests/ConfigSources/main.cpp b/Tests/ConfigSources/main.cpp
deleted file mode 100644
index 71af72f700..0000000000
--- a/Tests/ConfigSources/main.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-
-#include "iface_debug.h"
-
-int main(int argc, char** argv)
-{
- return iface_src() + iface_debug();
-}
diff --git a/Tests/ConfigSources/main_debug.cpp b/Tests/ConfigSources/main_debug.cpp
new file mode 100644
index 0000000000..9b1e68a265
--- /dev/null
+++ b/Tests/ConfigSources/main_debug.cpp
@@ -0,0 +1,13 @@
+#ifndef CFG_DEBUG
+# error "This source should only be compiled in a Debug configuration."
+#endif
+#ifdef CFG_OTHER
+# error "This source should not be compiled in a non-Debug configuration."
+#endif
+
+#include "iface.h"
+
+int main(int argc, char** argv)
+{
+ return iface_src() + iface_debug();
+}
diff --git a/Tests/ConfigSources/main_other.cpp b/Tests/ConfigSources/main_other.cpp
new file mode 100644
index 0000000000..3184a19d2e
--- /dev/null
+++ b/Tests/ConfigSources/main_other.cpp
@@ -0,0 +1,13 @@
+#ifndef CFG_OTHER
+# error "This source should only be compiled in a non-Debug configuration."
+#endif
+#ifdef CFG_DEBUG
+# error "This source should not be compiled in a Debug configuration."
+#endif
+
+#include "iface.h"
+
+int main(int argc, char** argv)
+{
+ return iface_src() + iface_other();
+}