From 689be6235e5be32e8ee8e37801dde1fb1c5add2a Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 8 Aug 2019 09:31:42 -0700 Subject: Generator: support per-language link library flag This enables the use of MSVC and Swift on Windows in a single project. MSVC uses no flag to indicate linked libraries while Swift uses `-l`. Add support for a language specific link library flag which takes precedence over the global `CMAKE_LINK_LIBRARY_FLAG` which preserves compatibility with earlier releases. --- Help/manual/cmake-variables.7.rst | 1 + Help/release/dev/per-lang-link-library-flag.rst | 7 +++++++ Help/variable/CMAKE_LANG_LINK_LIBRARY_FLAG.rst | 7 +++++++ Modules/CMakeSwiftInformation.cmake | 1 + Source/cmComputeLinkInformation.cxx | 9 +++++++-- 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 Help/release/dev/per-lang-link-library-flag.rst create mode 100644 Help/variable/CMAKE_LANG_LINK_LIBRARY_FLAG.rst diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 432d7fc..22ea877 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -383,6 +383,7 @@ Variables that Control the Build /variable/CMAKE_LANG_CPPCHECK /variable/CMAKE_LANG_CPPLINT /variable/CMAKE_LANG_INCLUDE_WHAT_YOU_USE + /variable/CMAKE_LANG_LINK_LIBRARY_FLAG /variable/CMAKE_LANG_VISIBILITY_PRESET /variable/CMAKE_LIBRARY_OUTPUT_DIRECTORY /variable/CMAKE_LIBRARY_OUTPUT_DIRECTORY_CONFIG diff --git a/Help/release/dev/per-lang-link-library-flag.rst b/Help/release/dev/per-lang-link-library-flag.rst new file mode 100644 index 0000000..ca1181d --- /dev/null +++ b/Help/release/dev/per-lang-link-library-flag.rst @@ -0,0 +1,7 @@ +per-lang-link-library-flag +-------------------------- + +* The new :variable:`CMAKE__LINK_LIBRARY_FLAG` flag allows you to now + control the flag used to specify linking to a library on a per-language basis. + This is useful for mixed-language projects where the different drivers may use + different flags. diff --git a/Help/variable/CMAKE_LANG_LINK_LIBRARY_FLAG.rst b/Help/variable/CMAKE_LANG_LINK_LIBRARY_FLAG.rst new file mode 100644 index 0000000..d7bb0d8 --- /dev/null +++ b/Help/variable/CMAKE_LANG_LINK_LIBRARY_FLAG.rst @@ -0,0 +1,7 @@ +CMAKE__LINK_LIBRARY_FLAG +------------------------------ + +Flag to be used to link a library into a shared library or executable. + +This flag will be used to specify a library to link to a shared library or an +executable for the specific language. On most compilers this is ``-l``. diff --git a/Modules/CMakeSwiftInformation.cmake b/Modules/CMakeSwiftInformation.cmake index 54e441c..cb161a6 100644 --- a/Modules/CMakeSwiftInformation.cmake +++ b/Modules/CMakeSwiftInformation.cmake @@ -36,6 +36,7 @@ set(CMAKE_Swift_DEFINE_FLAG -D) set(CMAKE_Swift_FRAMEWORK_SEARCH_FLAG "-F ") set(CMAKE_Swift_LIBRARY_PATH_FLAG "-L ") set(CMAKE_Swift_LIBRARY_PATH_TERMINATOR "") +set(CMAKE_Swift_LINK_LIBRARY_FLAG "-l") set(CMAKE_Swift_LINKER_WRAPPER_FLAG "-Xlinker" " ") set(CMAKE_Swift_RESPONSE_FILE_LINK_FLAG @) diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 4aa18f2..0741f8b 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -285,8 +285,13 @@ cmComputeLinkInformation::cmComputeLinkInformation( } // Get options needed to link libraries. - this->LibLinkFlag = - this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_FLAG"); + if (const char* flag = this->Makefile->GetDefinition( + "CMAKE_" + this->LinkLanguage + "_LINK_LIBRARY_FLAG")) { + this->LibLinkFlag = flag; + } else { + this->LibLinkFlag = + this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_FLAG"); + } this->LibLinkFileFlag = this->Makefile->GetSafeDefinition("CMAKE_LINK_LIBRARY_FILE_FLAG"); this->LibLinkSuffix = -- cgit v0.12