summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2021-02-22 10:45:11 (GMT)
committerBrad King <brad.king@kitware.com>2021-02-23 13:14:14 (GMT)
commitb722eea9253acd9e33921779175fc615d064577a (patch)
tree260955614807534a07e7ecb8895704d6f931cb81 /Tests
parentc2c31ae8969686f1909fe76fef43a232332c7b54 (diff)
downloadCMake-b722eea9253acd9e33921779175fc615d064577a.zip
CMake-b722eea9253acd9e33921779175fc615d064577a.tar.gz
CMake-b722eea9253acd9e33921779175fc615d064577a.tar.bz2
Genex: LINK_LANGUAGE respects LINKER_LANGUAGE property
If target property LINKER_LANGUAGE is set, LINK_LANGUAGE generator expression evaluation must be always successful. This fix can be helpful to elaborate a solution for issue #21818.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/func.cxx17
-rw-r--r--Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex.cmake9
-rw-r--r--Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/main.c12
4 files changed, 34 insertions, 5 deletions
diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/RunCMakeTest.cmake b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/RunCMakeTest.cmake
index 0f0e5d8..f43a7c6 100644
--- a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/RunCMakeTest.cmake
+++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/RunCMakeTest.cmake
@@ -34,6 +34,7 @@ if (RunCMake_GENERATOR MATCHES "Makefiles|Ninja|Visual Studio|Xcode|Watcom WMake
run_cmake_target(genex CXX_interface2 LinkLibraries_CXX_interface2 --config Release)
run_cmake_target(genex C_static LinkLibraries_C_static --config Release)
run_cmake_target(genex CXX_static LinkLibraries_CXX_static --config Release)
+ run_cmake_target(genex C_static_CXX LinkLibraries_C_static_CXX --config Release)
unset(RunCMake_TEST_OPTIONS)
unset(RunCMake_TEST_OUTPUT_MERGE)
diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/func.cxx b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/func.cxx
index a12caca..ee6811c 100644
--- a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/func.cxx
+++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/func.cxx
@@ -1,7 +1,18 @@
-#if defined(_WIN32)
-__declspec(dllexport)
+#if !defined(BUILD_STATIC) && defined(_WIN32)
+# define EXPORT_SYMBOL __declspec(dllexport)
+#else
+# define EXPORT_SYMBOL
#endif
- void func_cxx()
+
+EXPORT_SYMBOL
+void func_cxx()
{
}
+
+extern "C" {
+EXPORT_SYMBOL
+void func_c_cxx()
+{
+}
+}
diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex.cmake b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex.cmake
index f3fe955..22d3df7 100644
--- a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex.cmake
+++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex.cmake
@@ -7,6 +7,8 @@ enable_language(CXX)
add_library(shared_C SHARED func.c)
add_library(shared_CXX SHARED func.cxx)
+add_library(static_cxx STATIC func.cxx)
+target_compile_definitions(static_cxx PRIVATE BUILD_STATIC)
add_library(static1_C STATIC empty.c)
target_link_libraries (static1_C INTERFACE $<$<LINK_LANGUAGE:C>:shared_C>)
@@ -70,3 +72,10 @@ add_executable(LinkLibraries_C_static main.c)
target_link_libraries (LinkLibraries_C_static PRIVATE static3)
add_executable(LinkLibraries_CXX_static main.cxx)
target_link_libraries (LinkLibraries_CXX_static PRIVATE static3)
+
+# $<LINK_LANGUAGE:> change, by default, link language from C to CXX
+# but because LINKER_LANGUAGE property is set, keep C as link language
+add_executable(LinkLibraries_C_static_CXX main.c)
+target_compile_definitions (LinkLibraries_C_static_CXX PRIVATE C_USE_CXX)
+target_link_libraries (LinkLibraries_C_static_CXX PRIVATE $<$<LINK_LANGUAGE:C>:static_cxx>)
+set_property(TARGET LinkLibraries_C_static_CXX PROPERTY LINKER_LANGUAGE C)
diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/main.c b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/main.c
index a908dea..689dbd7 100644
--- a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/main.c
+++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/main.c
@@ -1,12 +1,20 @@
-#if defined(_WIN32)
+#if defined(C_USE_CXX)
+void func_c_cxx();
+#else
+# if defined(_WIN32)
__declspec(dllimport)
-#endif
+# endif
void func_c();
+#endif
int main()
{
+#if defined(C_USE_CXX)
+ func_c_cxx();
+#else
func_c();
+#endif
return 0;
}