summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@sap.com>2017-12-13 15:34:11 (GMT)
committerMarc Chevrier <marc.chevrier@sap.com>2017-12-13 15:35:22 (GMT)
commit10f58b27ac1015e4f1615372bb5168e43afcdf3a (patch)
tree8f1db98fd525f9a4039fd9a0194b009d208a4acc /Tests
parent14fe6d431b12139ea2aeb5bcc09efd0f964597aa (diff)
downloadCMake-10f58b27ac1015e4f1615372bb5168e43afcdf3a.zip
CMake-10f58b27ac1015e4f1615372bb5168e43afcdf3a.tar.gz
CMake-10f58b27ac1015e4f1615372bb5168e43afcdf3a.tar.bz2
Genex: Per-source $<COMPILE_LANGUAGE:...> support
Fixes: #17542
Diffstat (limited to 'Tests')
-rw-r--r--Tests/GeneratorExpression/CMakeLists.txt8
-rw-r--r--Tests/GeneratorExpression/srcgenex_defs_COMPILE_LANGUAGE.c12
-rw-r--r--Tests/GeneratorExpression/srcgenex_flags_COMPILE_LANGUAGE.c12
-rw-r--r--Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions-result.txt1
-rw-r--r--Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions-stderr-VS.txt7
-rw-r--r--Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions-stderr-Xcode.txt7
-rw-r--r--Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions.cmake5
-rw-r--r--Tests/RunCMake/COMPILE_LANGUAGE-genex/RunCMakeTest.cmake7
8 files changed, 59 insertions, 0 deletions
diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt
index 5165970..0585d0c 100644
--- a/Tests/GeneratorExpression/CMakeLists.txt
+++ b/Tests/GeneratorExpression/CMakeLists.txt
@@ -263,9 +263,17 @@ add_custom_target(check-part4 ALL
add_executable(srcgenex_flags srcgenex_flags.c)
set_property(SOURCE srcgenex_flags.c PROPERTY COMPILE_FLAGS "-DNAME=$<TARGET_PROPERTY:NAME>")
+add_executable(srcgenex_flags_COMPILE_LANGUAGE srcgenex_flags_COMPILE_LANGUAGE.c)
+set_property(SOURCE srcgenex_flags_COMPILE_LANGUAGE.c PROPERTY COMPILE_FLAGS "$<$<COMPILE_LANGUAGE:C>:-DNAME=$<TARGET_PROPERTY:NAME>>")
+
add_executable(srcgenex_defs srcgenex_defs.c)
set_property(SOURCE srcgenex_defs.c PROPERTY COMPILE_DEFINITIONS NAME=$<TARGET_PROPERTY:NAME>)
+if (CMAKE_GENERATOR MATCHES "Makefiles|Ninja|Watcom WMake")
+ add_executable(srcgenex_defs_COMPILE_LANGUAGE srcgenex_defs_COMPILE_LANGUAGE.c)
+ set_property(SOURCE srcgenex_defs_COMPILE_LANGUAGE.c PROPERTY COMPILE_DEFINITIONS $<$<COMPILE_LANGUAGE:C>:NAME=$<TARGET_PROPERTY:NAME>>)
+endif()
+
#-----------------------------------------------------------------------------
# Cover test properties with generator expressions.
add_executable(echo echo.c)
diff --git a/Tests/GeneratorExpression/srcgenex_defs_COMPILE_LANGUAGE.c b/Tests/GeneratorExpression/srcgenex_defs_COMPILE_LANGUAGE.c
new file mode 100644
index 0000000..421b55b
--- /dev/null
+++ b/Tests/GeneratorExpression/srcgenex_defs_COMPILE_LANGUAGE.c
@@ -0,0 +1,12 @@
+int srcgenex_defs_COMPILE_LANGUAGE(void)
+{
+ return 0;
+}
+
+int main(int argc, char* argv[])
+{
+#ifndef NAME
+#error NAME not defined
+#endif
+ return NAME();
+}
diff --git a/Tests/GeneratorExpression/srcgenex_flags_COMPILE_LANGUAGE.c b/Tests/GeneratorExpression/srcgenex_flags_COMPILE_LANGUAGE.c
new file mode 100644
index 0000000..4e80d6e
--- /dev/null
+++ b/Tests/GeneratorExpression/srcgenex_flags_COMPILE_LANGUAGE.c
@@ -0,0 +1,12 @@
+int srcgenex_flags_COMPILE_LANGUAGE(void)
+{
+ return 0;
+}
+
+int main(int argc, char* argv[])
+{
+#ifndef NAME
+#error NAME not defined
+#endif
+ return NAME();
+}
diff --git a/Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions-result.txt b/Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions-stderr-VS.txt b/Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions-stderr-VS.txt
new file mode 100644
index 0000000..5d19153
--- /dev/null
+++ b/Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions-stderr-VS.txt
@@ -0,0 +1,7 @@
+CMake Error:
+ Error evaluating generator expression:
+
+ \$<COMPILE_LANGUAGE:CXX>
+
+ \$<COMPILE_LANGUAGE:...> may only be used for COMPILE_OPTIONS and
+ file\(GENERATE\) with the Visual Studio generator.
diff --git a/Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions-stderr-Xcode.txt b/Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions-stderr-Xcode.txt
new file mode 100644
index 0000000..4a4564e
--- /dev/null
+++ b/Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions-stderr-Xcode.txt
@@ -0,0 +1,7 @@
+CMake Error:
+ Error evaluating generator expression:
+
+ \$<COMPILE_LANGUAGE:CXX>
+
+ \$<COMPILE_LANGUAGE:...> may only be used for COMPILE_OPTIONS and
+ file\(GENERATE\) with the Xcode generator.
diff --git a/Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions.cmake b/Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions.cmake
new file mode 100644
index 0000000..3a07d7d
--- /dev/null
+++ b/Tests/RunCMake/COMPILE_LANGUAGE-genex/PerSourceCompileDefinitions.cmake
@@ -0,0 +1,5 @@
+
+enable_language(CXX)
+
+add_executable(main main.cpp)
+set_property(SOURCE main.cpp PROPERTY COMPILE_DEFINITIONS $<$<COMPILE_LANGUAGE:CXX>:ANYTHING>)
diff --git a/Tests/RunCMake/COMPILE_LANGUAGE-genex/RunCMakeTest.cmake b/Tests/RunCMake/COMPILE_LANGUAGE-genex/RunCMakeTest.cmake
index 421fa73..1a93dcd 100644
--- a/Tests/RunCMake/COMPILE_LANGUAGE-genex/RunCMakeTest.cmake
+++ b/Tests/RunCMake/COMPILE_LANGUAGE-genex/RunCMakeTest.cmake
@@ -14,3 +14,10 @@ elseif (RunCMake_GENERATOR MATCHES "Visual Studio")
set(RunCMake-stderr-file IncludeDirectories-stderr-VS.txt)
run_cmake(IncludeDirectories)
endif()
+if (RunCMake_GENERATOR STREQUAL "Xcode")
+ set(RunCMake-stderr-file PerSourceCompileDefinitions-stderr-Xcode.txt)
+ run_cmake(PerSourceCompileDefinitions)
+elseif (RunCMake_GENERATOR MATCHES "Visual Studio")
+ set(RunCMake-stderr-file PerSourceCompileDefinitions-stderr-VS.txt)
+ run_cmake(PerSourceCompileDefinitions)
+endif()