summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Modules/CMakeCXXCompiler.cmake.in1
-rw-r--r--Source/cmDocumentVariables.cxx21
-rw-r--r--Source/cmTarget.cxx33
3 files changed, 40 insertions, 15 deletions
diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in
index d87c788fa3..0b5560e40b 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 fa762f6ae1..d13a9d314e 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 52dbb5631e..8fdb16a6fd 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();
}
}