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++.
This commit is contained in:
parent
fd633b33cf
commit
fcab87c9f8
@ -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@")
|
||||
|
@ -1201,12 +1201,25 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
|
||||
"language and reports the results in this variable.", false,
|
||||
"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
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user