ENH: Always imply CLEAN_DIRECT_OUTPUT target prop
This property was left from before CMake always linked using full path library names for targets it builds. In order to safely link with "-lfoo" we needed to avoid having both shared and static libraries in the build tree for targets that switch on BUILD_SHARED_LIBS. This meant cleaning both shared and static names before creating the library, which led to the creation of CLEAN_DIRECT_OUTPUT to disable the behavior. Now that we always link with a full path we do not need to clean old library names left from an alternate setting of BUILD_SHARED_LIBS. This change removes the CLEAN_DIRECT_OUTPUT property and instead uses its behavior always. It removes some complexity from cmTarget internally.
This commit is contained in:
parent
2740db5ede
commit
430cc2b4b7
|
@ -485,101 +485,38 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
|
|||
default: break;
|
||||
}
|
||||
|
||||
// Construct a list of files associated with this library that may
|
||||
// need to be cleaned.
|
||||
// Clean files associated with this library.
|
||||
std::vector<std::string> libCleanFiles;
|
||||
if(this->Target->GetPropertyAsBool("CLEAN_DIRECT_OUTPUT"))
|
||||
libCleanFiles.push_back(this->Convert(targetFullPath.c_str(),
|
||||
cmLocalGenerator::START_OUTPUT,
|
||||
cmLocalGenerator::UNCHANGED));
|
||||
if(targetNameReal != targetName)
|
||||
{
|
||||
// The user has requested that only the files directly built
|
||||
// by this target be cleaned instead of all possible names.
|
||||
libCleanFiles.push_back(this->Convert(targetFullPath.c_str(),
|
||||
cmLocalGenerator::START_OUTPUT,
|
||||
cmLocalGenerator::UNCHANGED));
|
||||
if(targetNameReal != targetName)
|
||||
{
|
||||
libCleanFiles.push_back(this->Convert(targetFullPathReal.c_str(),
|
||||
cmLocalGenerator::START_OUTPUT,
|
||||
cmLocalGenerator::UNCHANGED));
|
||||
}
|
||||
if(targetNameSO != targetName &&
|
||||
targetNameSO != targetNameReal)
|
||||
{
|
||||
libCleanFiles.push_back(this->Convert(targetFullPathSO.c_str(),
|
||||
cmLocalGenerator::START_OUTPUT,
|
||||
cmLocalGenerator::UNCHANGED));
|
||||
}
|
||||
if(!targetNameImport.empty())
|
||||
{
|
||||
libCleanFiles.push_back(this->Convert(targetFullPathImport.c_str(),
|
||||
cmLocalGenerator::START_OUTPUT,
|
||||
cmLocalGenerator::UNCHANGED));
|
||||
}
|
||||
libCleanFiles.push_back(this->Convert(targetFullPathReal.c_str(),
|
||||
cmLocalGenerator::START_OUTPUT,
|
||||
cmLocalGenerator::UNCHANGED));
|
||||
}
|
||||
else
|
||||
if(targetNameSO != targetName &&
|
||||
targetNameSO != targetNameReal)
|
||||
{
|
||||
// This target may switch between static and shared based
|
||||
// on a user option or the BUILD_SHARED_LIBS switch. Clean
|
||||
// all possible names.
|
||||
std::string cleanStaticName;
|
||||
std::string cleanSharedName;
|
||||
std::string cleanSharedSOName;
|
||||
std::string cleanSharedRealName;
|
||||
std::string cleanImportName;
|
||||
std::string cleanPDBName;
|
||||
this->Target->GetLibraryCleanNames(
|
||||
cleanStaticName,
|
||||
cleanSharedName,
|
||||
cleanSharedSOName,
|
||||
cleanSharedRealName,
|
||||
cleanImportName,
|
||||
cleanPDBName,
|
||||
this->LocalGenerator->ConfigurationName.c_str());
|
||||
std::string cleanFullStaticName = outpath + cleanStaticName;
|
||||
std::string cleanFullSharedName = outpath + cleanSharedName;
|
||||
std::string cleanFullSharedSOName = outpath + cleanSharedSOName;
|
||||
std::string cleanFullSharedRealName = outpath + cleanSharedRealName;
|
||||
std::string cleanFullImportName = outpathImp + cleanImportName;
|
||||
std::string cleanFullPDBName = outpath + cleanPDBName;
|
||||
libCleanFiles.push_back
|
||||
(this->Convert(cleanFullStaticName.c_str(),
|
||||
cmLocalGenerator::START_OUTPUT,
|
||||
cmLocalGenerator::UNCHANGED));
|
||||
if(cleanSharedRealName != cleanStaticName)
|
||||
{
|
||||
libCleanFiles.push_back(this->Convert(cleanFullSharedRealName.c_str(),
|
||||
cmLocalGenerator::START_OUTPUT,
|
||||
cmLocalGenerator::UNCHANGED));
|
||||
}
|
||||
if(cleanSharedSOName != cleanStaticName &&
|
||||
cleanSharedSOName != cleanSharedRealName)
|
||||
{
|
||||
libCleanFiles.push_back(this->Convert(cleanFullSharedSOName.c_str(),
|
||||
cmLocalGenerator::START_OUTPUT,
|
||||
cmLocalGenerator::UNCHANGED));
|
||||
}
|
||||
if(cleanSharedName != cleanStaticName &&
|
||||
cleanSharedName != cleanSharedSOName &&
|
||||
cleanSharedName != cleanSharedRealName)
|
||||
{
|
||||
libCleanFiles.push_back(this->Convert(cleanFullSharedName.c_str(),
|
||||
cmLocalGenerator::START_OUTPUT,
|
||||
cmLocalGenerator::UNCHANGED));
|
||||
}
|
||||
if(!cleanImportName.empty())
|
||||
{
|
||||
libCleanFiles.push_back(this->Convert(cleanFullImportName.c_str(),
|
||||
cmLocalGenerator::START_OUTPUT,
|
||||
cmLocalGenerator::UNCHANGED));
|
||||
}
|
||||
libCleanFiles.push_back(this->Convert(targetFullPathSO.c_str(),
|
||||
cmLocalGenerator::START_OUTPUT,
|
||||
cmLocalGenerator::UNCHANGED));
|
||||
}
|
||||
if(!targetNameImport.empty())
|
||||
{
|
||||
libCleanFiles.push_back(this->Convert(targetFullPathImport.c_str(),
|
||||
cmLocalGenerator::START_OUTPUT,
|
||||
cmLocalGenerator::UNCHANGED));
|
||||
}
|
||||
|
||||
// List the PDB for cleaning only when the whole target is
|
||||
// cleaned. We do not want to delete the .pdb file just before
|
||||
// linking the target.
|
||||
this->CleanFiles.push_back
|
||||
(this->Convert(cleanFullPDBName.c_str(),
|
||||
cmLocalGenerator::START_OUTPUT,
|
||||
cmLocalGenerator::UNCHANGED));
|
||||
}
|
||||
// List the PDB for cleaning only when the whole target is
|
||||
// cleaned. We do not want to delete the .pdb file just before
|
||||
// linking the target.
|
||||
this->CleanFiles.push_back
|
||||
(this->Convert(targetFullPathPDB.c_str(),
|
||||
cmLocalGenerator::START_OUTPUT,
|
||||
cmLocalGenerator::UNCHANGED));
|
||||
|
||||
#ifdef _WIN32
|
||||
// There may be a manifest file for this target. Add it to the
|
||||
|
|
|
@ -148,13 +148,6 @@ public:
|
|||
"VS_SCC_PROJECTNAME, VS_SCC_LOCALPATH, VS_SCC_PROVIDER can be set "
|
||||
"to add support for source control bindings in a Visual Studio "
|
||||
"project file.\n"
|
||||
"When a library is built CMake by default generates code to remove "
|
||||
"any existing library using all possible names. This is needed "
|
||||
"to support libraries that switch between STATIC and SHARED by "
|
||||
"a user option. However when using OUTPUT_NAME to build a static "
|
||||
"and shared library of the same name using different logical target "
|
||||
"names the two targets will remove each other's files. This can be "
|
||||
"prevented by setting the CLEAN_DIRECT_OUTPUT property to 1.\n"
|
||||
"The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
|
||||
"old way to specify CMake scripts to run before and after "
|
||||
"installing a target. They are used only when the old "
|
||||
|
|
|
@ -77,17 +77,6 @@ void cmTarget::DefineProperties(cmake *cm)
|
|||
"This property is initialized by the value of the variable "
|
||||
"CMAKE_BUILD_WITH_INSTALL_RPATH if it is set when a target is created.");
|
||||
|
||||
cm->DefineProperty
|
||||
("CLEAN_DIRECT_OUTPUT", cmProperty::TARGET,
|
||||
"Do not delete other variants of this target.",
|
||||
"When a library is built CMake by default generates code to remove "
|
||||
"any existing library using all possible names. This is needed "
|
||||
"to support libraries that switch between STATIC and SHARED by "
|
||||
"a user option. However when using OUTPUT_NAME to build a static "
|
||||
"and shared library of the same name using different logical target "
|
||||
"names the two targets will remove each other's files. This can be "
|
||||
"prevented by setting the CLEAN_DIRECT_OUTPUT property to 1.");
|
||||
|
||||
cm->DefineProperty
|
||||
("COMPILE_FLAGS", cmProperty::TARGET,
|
||||
"Additional flags to use when compiling this target's sources.",
|
||||
|
@ -2723,43 +2712,6 @@ void cmTarget::GetLibraryNames(std::string& name,
|
|||
this->GetType(), config);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmTarget::GetLibraryCleanNames(std::string& staticName,
|
||||
std::string& sharedName,
|
||||
std::string& sharedSOName,
|
||||
std::string& sharedRealName,
|
||||
std::string& importName,
|
||||
std::string& pdbName,
|
||||
const char* config)
|
||||
{
|
||||
// Get the name as if this were a static library.
|
||||
std::string soName;
|
||||
std::string realName;
|
||||
std::string impName;
|
||||
this->GetLibraryNamesInternal(staticName, soName, realName, impName,
|
||||
pdbName, cmTarget::STATIC_LIBRARY, config);
|
||||
|
||||
// Get the names as if this were a shared library.
|
||||
if(this->GetType() == cmTarget::STATIC_LIBRARY)
|
||||
{
|
||||
// Since the real type is static then the user either specified
|
||||
// STATIC or did not specify a type. In the former case the
|
||||
// shared library will never be present. In the latter case the
|
||||
// type will never be MODULE. Either way the only names that
|
||||
// might have to be cleaned are the shared library names.
|
||||
this->GetLibraryNamesInternal(sharedName, sharedSOName, sharedRealName,
|
||||
importName, pdbName,
|
||||
cmTarget::SHARED_LIBRARY, config);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use the name of the real type of the library (shared or module).
|
||||
this->GetLibraryNamesInternal(sharedName, sharedSOName, sharedRealName,
|
||||
importName, pdbName, this->GetType(),
|
||||
config);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmTarget::GetLibraryNamesInternal(std::string& name,
|
||||
std::string& soName,
|
||||
|
|
|
@ -326,18 +326,6 @@ public:
|
|||
std::string& realName, std::string& impName,
|
||||
std::string& pdbName, const char* config);
|
||||
|
||||
/** Get the names of the library used to remove existing copies of
|
||||
the library from the build tree either before linking or during
|
||||
a clean step. This should be called only on a library
|
||||
target. */
|
||||
void GetLibraryCleanNames(std::string& staticName,
|
||||
std::string& sharedName,
|
||||
std::string& sharedSOName,
|
||||
std::string& sharedRealName,
|
||||
std::string& importName,
|
||||
std::string& pdbName,
|
||||
const char* config);
|
||||
|
||||
/** Get the names of the executable needed to generate a build rule
|
||||
that takes into account executable version numbers. This should
|
||||
be called only on an executable target. */
|
||||
|
|
|
@ -66,7 +66,7 @@ IF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
|
|||
ADD_LIBRARY(CMakeTestLinkStatic STATIC TestLink.c)
|
||||
ADD_LIBRARY(CMakeTestLinkShared SHARED TestLink.c)
|
||||
SET_TARGET_PROPERTIES(CMakeTestLinkStatic CMakeTestLinkShared
|
||||
PROPERTIES OUTPUT_NAME CMakeTestLink CLEAN_DIRECT_OUTPUT 1)
|
||||
PROPERTIES OUTPUT_NAME CMakeTestLink)
|
||||
ENDIF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
|
||||
|
||||
#
|
||||
|
|
|
@ -66,7 +66,7 @@ IF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
|
|||
ADD_LIBRARY(CMakeTestLinkStatic STATIC TestLink.c)
|
||||
ADD_LIBRARY(CMakeTestLinkShared SHARED TestLink.c)
|
||||
SET_TARGET_PROPERTIES(CMakeTestLinkStatic CMakeTestLinkShared
|
||||
PROPERTIES OUTPUT_NAME CMakeTestLink CLEAN_DIRECT_OUTPUT 1)
|
||||
PROPERTIES OUTPUT_NAME CMakeTestLink)
|
||||
ENDIF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
|
||||
|
||||
#
|
||||
|
|
|
@ -66,7 +66,7 @@ IF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
|
|||
ADD_LIBRARY(CMakeTestLinkStatic STATIC TestLink.c)
|
||||
ADD_LIBRARY(CMakeTestLinkShared SHARED TestLink.c)
|
||||
SET_TARGET_PROPERTIES(CMakeTestLinkStatic CMakeTestLinkShared
|
||||
PROPERTIES OUTPUT_NAME CMakeTestLink CLEAN_DIRECT_OUTPUT 1)
|
||||
PROPERTIES OUTPUT_NAME CMakeTestLink)
|
||||
ENDIF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
|
||||
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue