mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 22:37:30 +08:00
Refactor checks for whether a target has an import library
Use `HasImportLibrary` for such checks.
This commit is contained in:
@@ -268,10 +268,6 @@ cmComputeLinkInformation::cmComputeLinkInformation(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether we should use an import library for linking a target.
|
|
||||||
this->UseImportLibrary =
|
|
||||||
this->Makefile->IsDefinitionSet("CMAKE_IMPORT_LIBRARY_SUFFIX");
|
|
||||||
|
|
||||||
// Check whether we should skip dependencies on shared library files.
|
// Check whether we should skip dependencies on shared library files.
|
||||||
this->LinkDependsNoShared =
|
this->LinkDependsNoShared =
|
||||||
this->Target->GetPropertyAsBool("LINK_DEPENDS_NO_SHARED");
|
this->Target->GetPropertyAsBool("LINK_DEPENDS_NO_SHARED");
|
||||||
@@ -280,7 +276,7 @@ cmComputeLinkInformation::cmComputeLinkInformation(
|
|||||||
// to use when creating a plugin (module) that obtains symbols from
|
// to use when creating a plugin (module) that obtains symbols from
|
||||||
// the program that will load it.
|
// the program that will load it.
|
||||||
this->LoaderFlag = nullptr;
|
this->LoaderFlag = nullptr;
|
||||||
if (!this->UseImportLibrary &&
|
if (!this->Target->IsDLLPlatform() &&
|
||||||
this->Target->GetType() == cmStateEnums::MODULE_LIBRARY) {
|
this->Target->GetType() == cmStateEnums::MODULE_LIBRARY) {
|
||||||
std::string loader_flag_var = "CMAKE_SHARED_MODULE_LOADER_";
|
std::string loader_flag_var = "CMAKE_SHARED_MODULE_LOADER_";
|
||||||
loader_flag_var += this->LinkLanguage;
|
loader_flag_var += this->LinkLanguage;
|
||||||
@@ -493,9 +489,7 @@ bool cmComputeLinkInformation::Compute()
|
|||||||
std::set<cmGeneratorTarget const*> const& wrongItems =
|
std::set<cmGeneratorTarget const*> const& wrongItems =
|
||||||
cld.GetOldWrongConfigItems();
|
cld.GetOldWrongConfigItems();
|
||||||
for (cmGeneratorTarget const* tgt : wrongItems) {
|
for (cmGeneratorTarget const* tgt : wrongItems) {
|
||||||
bool implib = (this->UseImportLibrary &&
|
cmStateEnums::ArtifactType artifact = tgt->HasImportLibrary(this->Config)
|
||||||
(tgt->GetType() == cmStateEnums::SHARED_LIBRARY));
|
|
||||||
cmStateEnums::ArtifactType artifact = implib
|
|
||||||
? cmStateEnums::ImportLibraryArtifact
|
? cmStateEnums::ImportLibraryArtifact
|
||||||
: cmStateEnums::RuntimeBinaryArtifact;
|
: cmStateEnums::RuntimeBinaryArtifact;
|
||||||
this->OldLinkDirItems.push_back(
|
this->OldLinkDirItems.push_back(
|
||||||
@@ -578,7 +572,7 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
|
|||||||
// Compute the proper name to use to link this library.
|
// Compute the proper name to use to link this library.
|
||||||
const std::string& config = this->Config;
|
const std::string& config = this->Config;
|
||||||
bool impexe = (tgt && tgt->IsExecutableWithExports());
|
bool impexe = (tgt && tgt->IsExecutableWithExports());
|
||||||
if (impexe && !this->UseImportLibrary && !this->LoaderFlag) {
|
if (impexe && !tgt->HasImportLibrary(config) && !this->LoaderFlag) {
|
||||||
// Skip linking to executables on platforms with no import
|
// Skip linking to executables on platforms with no import
|
||||||
// libraries or loader flags.
|
// libraries or loader flags.
|
||||||
return;
|
return;
|
||||||
@@ -592,7 +586,7 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
|
|||||||
// platform. Add it now.
|
// platform. Add it now.
|
||||||
std::string linkItem;
|
std::string linkItem;
|
||||||
linkItem = this->LoaderFlag;
|
linkItem = this->LoaderFlag;
|
||||||
cmStateEnums::ArtifactType artifact = this->UseImportLibrary
|
cmStateEnums::ArtifactType artifact = tgt->HasImportLibrary(config)
|
||||||
? cmStateEnums::ImportLibraryArtifact
|
? cmStateEnums::ImportLibraryArtifact
|
||||||
: cmStateEnums::RuntimeBinaryArtifact;
|
: cmStateEnums::RuntimeBinaryArtifact;
|
||||||
|
|
||||||
@@ -616,10 +610,7 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
|
|||||||
// Its object-files should already have been extracted for linking.
|
// Its object-files should already have been extracted for linking.
|
||||||
} else {
|
} else {
|
||||||
// Decide whether to use an import library.
|
// Decide whether to use an import library.
|
||||||
bool implib =
|
cmStateEnums::ArtifactType artifact = tgt->HasImportLibrary(config)
|
||||||
(this->UseImportLibrary &&
|
|
||||||
(impexe || tgt->GetType() == cmStateEnums::SHARED_LIBRARY));
|
|
||||||
cmStateEnums::ArtifactType artifact = implib
|
|
||||||
? cmStateEnums::ImportLibraryArtifact
|
? cmStateEnums::ImportLibraryArtifact
|
||||||
: cmStateEnums::RuntimeBinaryArtifact;
|
: cmStateEnums::RuntimeBinaryArtifact;
|
||||||
|
|
||||||
@@ -694,7 +685,7 @@ void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
|
|||||||
// linked will be able to find it.
|
// linked will be able to find it.
|
||||||
std::string lib;
|
std::string lib;
|
||||||
if (tgt) {
|
if (tgt) {
|
||||||
cmStateEnums::ArtifactType artifact = this->UseImportLibrary
|
cmStateEnums::ArtifactType artifact = tgt->HasImportLibrary(this->Config)
|
||||||
? cmStateEnums::ImportLibraryArtifact
|
? cmStateEnums::ImportLibraryArtifact
|
||||||
: cmStateEnums::RuntimeBinaryArtifact;
|
: cmStateEnums::RuntimeBinaryArtifact;
|
||||||
lib = tgt->GetFullPath(this->Config, artifact);
|
lib = tgt->GetFullPath(this->Config, artifact);
|
||||||
|
@@ -179,7 +179,6 @@ private:
|
|||||||
bool OldLinkDirMode;
|
bool OldLinkDirMode;
|
||||||
bool OpenBSD;
|
bool OpenBSD;
|
||||||
bool LinkDependsNoShared;
|
bool LinkDependsNoShared;
|
||||||
bool UseImportLibrary;
|
|
||||||
bool RuntimeUseChrpath;
|
bool RuntimeUseChrpath;
|
||||||
bool NoSONameUsesPath;
|
bool NoSONameUsesPath;
|
||||||
bool LinkWithRuntimePath;
|
bool LinkWithRuntimePath;
|
||||||
|
@@ -236,14 +236,15 @@ void cmExportBuildFileGenerator::SetImportLocationProperty(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the import library for windows DLLs.
|
// Add the import library for windows DLLs.
|
||||||
if (target->HasImportLibrary(config) &&
|
if (target->HasImportLibrary(config)) {
|
||||||
mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) {
|
|
||||||
std::string prop = "IMPORTED_IMPLIB";
|
std::string prop = "IMPORTED_IMPLIB";
|
||||||
prop += suffix;
|
prop += suffix;
|
||||||
std::string value =
|
std::string value =
|
||||||
target->GetFullPath(config, cmStateEnums::ImportLibraryArtifact);
|
target->GetFullPath(config, cmStateEnums::ImportLibraryArtifact);
|
||||||
|
if (mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) {
|
||||||
target->GetImplibGNUtoMS(config, value, value,
|
target->GetImplibGNUtoMS(config, value, value,
|
||||||
"${CMAKE_IMPORT_LIBRARY_SUFFIX}");
|
"${CMAKE_IMPORT_LIBRARY_SUFFIX}");
|
||||||
|
}
|
||||||
properties[prop] = value;
|
properties[prop] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1076,10 +1076,7 @@ Json::Value Target::DumpArtifacts()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add Windows-specific artifacts produced by the linker.
|
// Add Windows-specific artifacts produced by the linker.
|
||||||
if (this->GT->IsDLLPlatform() &&
|
if (this->GT->HasImportLibrary(this->Config)) {
|
||||||
this->GT->GetType() != cmStateEnums::STATIC_LIBRARY) {
|
|
||||||
if (this->GT->GetType() == cmStateEnums::SHARED_LIBRARY ||
|
|
||||||
this->GT->IsExecutableWithExports()) {
|
|
||||||
Json::Value artifact = Json::objectValue;
|
Json::Value artifact = Json::objectValue;
|
||||||
artifact["path"] =
|
artifact["path"] =
|
||||||
RelativeIfUnder(this->TopBuild,
|
RelativeIfUnder(this->TopBuild,
|
||||||
@@ -1087,6 +1084,8 @@ Json::Value Target::DumpArtifacts()
|
|||||||
this->Config, cmStateEnums::ImportLibraryArtifact));
|
this->Config, cmStateEnums::ImportLibraryArtifact));
|
||||||
artifacts.append(std::move(artifact)); // NOLINT(*)
|
artifacts.append(std::move(artifact)); // NOLINT(*)
|
||||||
}
|
}
|
||||||
|
if (this->GT->IsDLLPlatform() &&
|
||||||
|
this->GT->GetType() != cmStateEnums::STATIC_LIBRARY) {
|
||||||
cmGeneratorTarget::OutputInfo const* output =
|
cmGeneratorTarget::OutputInfo const* output =
|
||||||
this->GT->GetOutputInfo(this->Config);
|
this->GT->GetOutputInfo(this->Config);
|
||||||
if (output && !output->PdbDir.empty()) {
|
if (output && !output->PdbDir.empty()) {
|
||||||
|
@@ -468,7 +468,7 @@ std::string cmGeneratorTarget::GetFilePrefix(
|
|||||||
const std::string& config, cmStateEnums::ArtifactType artifact) const
|
const std::string& config, cmStateEnums::ArtifactType artifact) const
|
||||||
{
|
{
|
||||||
if (this->IsImported()) {
|
if (this->IsImported()) {
|
||||||
const char* prefix = this->GetFilePrefixInternal(artifact);
|
const char* prefix = this->GetFilePrefixInternal(config, artifact);
|
||||||
|
|
||||||
return prefix ? prefix : std::string();
|
return prefix ? prefix : std::string();
|
||||||
}
|
}
|
||||||
@@ -481,7 +481,7 @@ std::string cmGeneratorTarget::GetFileSuffix(
|
|||||||
const std::string& config, cmStateEnums::ArtifactType artifact) const
|
const std::string& config, cmStateEnums::ArtifactType artifact) const
|
||||||
{
|
{
|
||||||
if (this->IsImported()) {
|
if (this->IsImported()) {
|
||||||
const char* suffix = this->GetFileSuffixInternal(artifact);
|
const char* suffix = this->GetFileSuffixInternal(config, artifact);
|
||||||
|
|
||||||
return suffix ? suffix : std::string();
|
return suffix ? suffix : std::string();
|
||||||
}
|
}
|
||||||
@@ -508,7 +508,8 @@ std::string cmGeneratorTarget::GetFilePostfix(const std::string& config) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char* cmGeneratorTarget::GetFilePrefixInternal(
|
const char* cmGeneratorTarget::GetFilePrefixInternal(
|
||||||
cmStateEnums::ArtifactType artifact, const std::string& language) const
|
std::string const& config, cmStateEnums::ArtifactType artifact,
|
||||||
|
const std::string& language) const
|
||||||
{
|
{
|
||||||
// no prefix for non-main target types.
|
// no prefix for non-main target types.
|
||||||
if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
|
if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
|
||||||
@@ -523,8 +524,7 @@ const char* cmGeneratorTarget::GetFilePrefixInternal(
|
|||||||
|
|
||||||
// Return an empty prefix for the import library if this platform
|
// Return an empty prefix for the import library if this platform
|
||||||
// does not support import libraries.
|
// does not support import libraries.
|
||||||
if (isImportedLibraryArtifact &&
|
if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) {
|
||||||
!this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) {
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,7 +558,8 @@ const char* cmGeneratorTarget::GetFilePrefixInternal(
|
|||||||
return targetPrefix;
|
return targetPrefix;
|
||||||
}
|
}
|
||||||
const char* cmGeneratorTarget::GetFileSuffixInternal(
|
const char* cmGeneratorTarget::GetFileSuffixInternal(
|
||||||
cmStateEnums::ArtifactType artifact, const std::string& language) const
|
std::string const& config, cmStateEnums::ArtifactType artifact,
|
||||||
|
const std::string& language) const
|
||||||
{
|
{
|
||||||
// no suffix for non-main target types.
|
// no suffix for non-main target types.
|
||||||
if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
|
if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
|
||||||
@@ -573,8 +574,7 @@ const char* cmGeneratorTarget::GetFileSuffixInternal(
|
|||||||
|
|
||||||
// Return an empty suffix for the import library if this platform
|
// Return an empty suffix for the import library if this platform
|
||||||
// does not support import libraries.
|
// does not support import libraries.
|
||||||
if (isImportedLibraryArtifact &&
|
if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) {
|
||||||
!this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) {
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3924,8 +3924,7 @@ void cmGeneratorTarget::GetFullNameInternal(
|
|||||||
|
|
||||||
// Return an empty name for the import library if this platform
|
// Return an empty name for the import library if this platform
|
||||||
// does not support import libraries.
|
// does not support import libraries.
|
||||||
if (isImportedLibraryArtifact &&
|
if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) {
|
||||||
!this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) {
|
|
||||||
outPrefix.clear();
|
outPrefix.clear();
|
||||||
outBase.clear();
|
outBase.clear();
|
||||||
outSuffix.clear();
|
outSuffix.clear();
|
||||||
@@ -3934,8 +3933,8 @@ void cmGeneratorTarget::GetFullNameInternal(
|
|||||||
|
|
||||||
// retrieve prefix and suffix
|
// retrieve prefix and suffix
|
||||||
std::string ll = this->GetLinkerLanguage(config);
|
std::string ll = this->GetLinkerLanguage(config);
|
||||||
const char* targetPrefix = this->GetFilePrefixInternal(artifact, ll);
|
const char* targetPrefix = this->GetFilePrefixInternal(config, artifact, ll);
|
||||||
const char* targetSuffix = this->GetFileSuffixInternal(artifact, ll);
|
const char* targetSuffix = this->GetFileSuffixInternal(config, artifact, ll);
|
||||||
|
|
||||||
// The implib option is only allowed for shared libraries, module
|
// The implib option is only allowed for shared libraries, module
|
||||||
// libraries, and executables.
|
// libraries, and executables.
|
||||||
@@ -6363,6 +6362,16 @@ bool cmGeneratorTarget::HasImportLibrary(std::string const& config) const
|
|||||||
this->GetManagedType(config) != ManagedType::Managed);
|
this->GetManagedType(config) != ManagedType::Managed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cmGeneratorTarget::NeedImportLibraryName(std::string const& config) const
|
||||||
|
{
|
||||||
|
return this->HasImportLibrary(config) ||
|
||||||
|
// On DLL platforms we always generate the import library name
|
||||||
|
// just in case the sources have export markup.
|
||||||
|
(this->IsDLLPlatform() &&
|
||||||
|
(this->GetType() == cmStateEnums::EXECUTABLE ||
|
||||||
|
this->GetType() == cmStateEnums::MODULE_LIBRARY));
|
||||||
|
}
|
||||||
|
|
||||||
std::string cmGeneratorTarget::GetSupportDirectory() const
|
std::string cmGeneratorTarget::GetSupportDirectory() const
|
||||||
{
|
{
|
||||||
std::string dir = this->LocalGenerator->GetCurrentBinaryDirectory();
|
std::string dir = this->LocalGenerator->GetCurrentBinaryDirectory();
|
||||||
|
@@ -743,9 +743,13 @@ private:
|
|||||||
|
|
||||||
mutable std::map<std::string, bool> DebugCompatiblePropertiesDone;
|
mutable std::map<std::string, bool> DebugCompatiblePropertiesDone;
|
||||||
|
|
||||||
const char* GetFilePrefixInternal(cmStateEnums::ArtifactType artifact,
|
bool NeedImportLibraryName(std::string const& config) const;
|
||||||
|
|
||||||
|
const char* GetFilePrefixInternal(std::string const& config,
|
||||||
|
cmStateEnums::ArtifactType artifact,
|
||||||
const std::string& language = "") const;
|
const std::string& language = "") const;
|
||||||
const char* GetFileSuffixInternal(cmStateEnums::ArtifactType artifact,
|
const char* GetFileSuffixInternal(std::string const& config,
|
||||||
|
cmStateEnums::ArtifactType artifact,
|
||||||
const std::string& language = "") const;
|
const std::string& language = "") const;
|
||||||
|
|
||||||
std::string GetFullNameInternal(const std::string& config,
|
std::string GetFullNameInternal(const std::string& config,
|
||||||
|
@@ -516,9 +516,11 @@ static Json::Value DumpTarget(cmGeneratorTarget* target,
|
|||||||
Json::Value artifacts = Json::arrayValue;
|
Json::Value artifacts = Json::arrayValue;
|
||||||
artifacts.append(
|
artifacts.append(
|
||||||
target->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact));
|
target->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact));
|
||||||
if (target->IsDLLPlatform()) {
|
if (target->HasImportLibrary(config)) {
|
||||||
artifacts.append(
|
artifacts.append(
|
||||||
target->GetFullPath(config, cmStateEnums::ImportLibraryArtifact));
|
target->GetFullPath(config, cmStateEnums::ImportLibraryArtifact));
|
||||||
|
}
|
||||||
|
if (target->IsDLLPlatform()) {
|
||||||
const cmGeneratorTarget::OutputInfo* output =
|
const cmGeneratorTarget::OutputInfo* output =
|
||||||
target->GetOutputInfo(config);
|
target->GetOutputInfo(config);
|
||||||
if (output && !output->PdbDir.empty()) {
|
if (output && !output->PdbDir.empty()) {
|
||||||
|
@@ -110,8 +110,7 @@ std::string cmLinkLineComputer::ComputeLinkPath(
|
|||||||
if (target->GetType() == cmStateEnums::STATIC_LIBRARY ||
|
if (target->GetType() == cmStateEnums::STATIC_LIBRARY ||
|
||||||
target->GetType() == cmStateEnums::SHARED_LIBRARY) {
|
target->GetType() == cmStateEnums::SHARED_LIBRARY) {
|
||||||
cmStateEnums::ArtifactType type = cmStateEnums::RuntimeBinaryArtifact;
|
cmStateEnums::ArtifactType type = cmStateEnums::RuntimeBinaryArtifact;
|
||||||
if (target->GetType() == cmStateEnums::SHARED_LIBRARY &&
|
if (target->HasImportLibrary(cli.GetConfig())) {
|
||||||
target->IsDLLPlatform()) {
|
|
||||||
type = cmStateEnums::ImportLibraryArtifact;
|
type = cmStateEnums::ImportLibraryArtifact;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user