summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-02-24 14:45:37 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-02-24 14:45:50 (GMT)
commit14c6a88db6ed5683688b1d9211f2466faa0e563d (patch)
tree4da5b87c0fe174b078c035decd3225126e7c8a97
parent261ba006682a064177fc1d9beee9c5ec0f3ea378 (diff)
parentb722eea9253acd9e33921779175fc615d064577a (diff)
downloadCMake-14c6a88db6ed5683688b1d9211f2466faa0e563d.zip
CMake-14c6a88db6ed5683688b1d9211f2466faa0e563d.tar.gz
CMake-14c6a88db6ed5683688b1d9211f2466faa0e563d.tar.bz2
Merge topic 'LINK_LANGUAGE-genex-respects-LINKER_LANGUAGE-property' into release-3.20
b722eea925 Genex: LINK_LANGUAGE respects LINKER_LANGUAGE property Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5841
-rw-r--r--Source/cmGeneratorTarget.cxx6
-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
5 files changed, 39 insertions, 6 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 9235faa..d7e9952 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -2648,8 +2648,12 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
LinkClosure linkClosure;
linkClosure.LinkerLanguage = this->LinkerLanguage;
+ bool hasHardCodedLinkerLanguage = this->Target->GetProperty("HAS_CXX") ||
+ !this->Target->GetSafeProperty("LINKER_LANGUAGE").empty();
+
// Get languages built in this target.
- secondPass = this->ComputeLinkClosure(config, linkClosure, false);
+ secondPass = this->ComputeLinkClosure(config, linkClosure, false) &&
+ !hasHardCodedLinkerLanguage;
this->LinkerLanguage = linkClosure.LinkerLanguage;
if (!secondPass) {
lc = std::move(linkClosure);
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;
}