From fcab87c9f802965318bee033c2fa3ff27cfbfec7 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 30 Jul 2009 10:59:37 -0400 Subject: Do not always propagate linker language preference The commit "Consider link dependencies for link language" taught CMake to propagate linker language preference from languages compiled into libraries linked by a target. It turns out this should only be done for some languages, such as C++, because normally the language of the program entry point (main) should be used. We introduce variable CMAKE__LINKER_PREFERENCE_PROPAGATES to tell CMake whether a language should propagate its linker preference across targets. Currently it is true only for C++. --- Modules/CMakeCXXCompiler.cmake.in | 1 + Source/cmDocumentVariables.cxx | 21 +++++++++++++++++---- Source/cmTarget.cxx | 33 ++++++++++++++++++++++----------- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in index d87c788..0b5560e 100644 --- a/Modules/CMakeCXXCompiler.cmake.in +++ b/Modules/CMakeCXXCompiler.cmake.in @@ -22,6 +22,7 @@ SET(CMAKE_CXX_COMPILER_ID_RUN 1) SET(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;H;o;O;obj;OBJ;def;DEF;rc;RC) SET(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;m;mm) SET(CMAKE_CXX_LINKER_PREFERENCE 30) +SET(CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES 1) # Save compiler ABI information. SET(CMAKE_CXX_SIZEOF_DATA_PTR "@CMAKE_CXX_SIZEOF_DATA_PTR@") diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx index fa762f6..d13a9d3 100644 --- a/Source/cmDocumentVariables.cxx +++ b/Source/cmDocumentVariables.cxx @@ -1202,11 +1202,24 @@ void cmDocumentVariables::DefineVariables(cmake* cm) "Variables for Languages"); cm->DefineProperty + ("CMAKE__LINKER_PREFERENCE_PROPAGATES", cmProperty::VARIABLE, + "True if CMAKE__LINKER_PREFERENCE propagates across targets.", + "This is used when CMake selects a linker language for a target. " + "Languages compiled directly into the target are always considered. " + "A language compiled into static libraries linked by the target is " + "considered if this variable is true.", false, + "Variables for Languages"); + + cm->DefineProperty ("CMAKE__LINKER_PREFERENCE", cmProperty::VARIABLE, - "Determine if a language should be used for linking.", - "If this is \"Preferred\" then if there is a mixed " - "language shared library or executable, then this " - "languages linker command will be used.",false, + "Preference value for linker language selection.", + "The \"linker language\" for executable, shared library, and module " + "targets is the language whose compiler will invoke the linker. " + "The LINKER_LANGUAGE target property sets the language explicitly. " + "Otherwise, the linker language is that whose linker preference value " + "is highest among languages compiled and linked into the target. " + "See also the CMAKE__LINKER_PREFERENCE_PROPAGATES variable.", + false, "Variables for Languages"); cm->DefineProperty diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 52dbb56..8fdb16a 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -441,18 +441,15 @@ void cmTarget::DefineProperties(cmake *cm) cm->DefineProperty ("LINKER_LANGUAGE", cmProperty::TARGET, - "Specifies language whose link tool should be used (obselete).", + "Specifies language whose compiler will invoke the linker.", "For executables, shared libraries, and modules, this sets the " - "language whose link tool is used to link the target " + "language whose compiler is used to link the target " "(such as \"C\" or \"CXX\"). " - "CMake 2.6 and below select a linker language automatically " - "based on the languages compiled into the target. " - "This property overrides the default in case one of the " - "linked libraries uses another language. " - "A typical example is a C executable linking to a static archive " - "containing C++ object files. " - "CMake 2.8 and above account for languages in linked targets " - "automatically, making this property unnecessary."); + "A typical value for an executable is the language of the source " + "file providing the program entry point (main). " + "If not set, the language with the highest linker preference " + "value is the default. " + "See documentation of CMAKE__LINKER_PREFERENCE variables."); cm->DefineProperty ("LOCATION", cmProperty::TARGET, @@ -2506,11 +2503,25 @@ void cmTarget::ComputeLinkClosure(const char* config, LinkClosure& lc) { // Find the language with the highest preference value. cmTargetSelectLinker tsl(this); + + // First select from the languages compiled directly in this target. + for(std::vector::const_iterator li = impl->Languages.begin(); + li != impl->Languages.end(); ++li) + { + tsl.Consider(li->c_str()); + } + + // Now consider languages that propagate from linked targets. for(std::set::const_iterator sit = languages.begin(); sit != languages.end(); ++sit) { - tsl.Consider(sit->c_str()); + std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES"; + if(this->Makefile->IsOn(propagates.c_str())) + { + tsl.Consider(sit->c_str()); + } } + lc.LinkerLanguage = tsl.Choose(); } } -- cgit v0.12