diff options
author | Brad King <brad.king@kitware.com> | 2009-07-30 14:59:37 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-07-30 14:59:37 (GMT) |
commit | fcab87c9f802965318bee033c2fa3ff27cfbfec7 (patch) | |
tree | 75000cee15b4ecd1c233c7c7c259fa15bffb6994 /Source | |
parent | fd633b33cff397b110cc69f82fd522cdf905952a (diff) | |
download | CMake-fcab87c9f802965318bee033c2fa3ff27cfbfec7.zip CMake-fcab87c9f802965318bee033c2fa3ff27cfbfec7.tar.gz CMake-fcab87c9f802965318bee033c2fa3ff27cfbfec7.tar.bz2 |
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_<LANG>_LINKER_PREFERENCE_PROPAGATES to tell
CMake whether a language should propagate its linker preference across
targets. Currently it is true only for C++.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmDocumentVariables.cxx | 21 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 33 |
2 files changed, 39 insertions, 15 deletions
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_<LANG>_LINKER_PREFERENCE_PROPAGATES", cmProperty::VARIABLE, + "True if CMAKE_<LANG>_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_<LANG>_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_<LANG>_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_<LANG>_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<std::string>::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<cmStdString>::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(); } } |