From 430cc2b4b7a817be2fbc445d6803163f1695a533 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 1 May 2009 10:38:35 -0400 Subject: 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. --- Source/cmMakefileLibraryTargetGenerator.cxx | 119 +++++----------------- Source/cmSetTargetPropertiesCommand.h | 7 -- Source/cmTarget.cxx | 48 --------- Source/cmTarget.h | 12 --- Tests/Complex/Library/CMakeLists.txt | 2 +- Tests/ComplexOneConfig/Library/CMakeLists.txt | 2 +- Tests/ComplexRelativePaths/Library/CMakeLists.txt | 2 +- 7 files changed, 31 insertions(+), 161 deletions(-) diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 0e71d50..ec9789f 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -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 libCleanFiles; - if(this->Target->GetPropertyAsBool("CLEAN_DIRECT_OUTPUT")) - { - // 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(targetFullPath.c_str(), + cmLocalGenerator::START_OUTPUT, + cmLocalGenerator::UNCHANGED)); + if(targetNameReal != targetName) + { + 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)); - } - - // 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)); + 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(targetFullPathPDB.c_str(), + cmLocalGenerator::START_OUTPUT, + cmLocalGenerator::UNCHANGED)); #ifdef _WIN32 // There may be a manifest file for this target. Add it to the diff --git a/Source/cmSetTargetPropertiesCommand.h b/Source/cmSetTargetPropertiesCommand.h index 78429d2..05adfcc 100644 --- a/Source/cmSetTargetPropertiesCommand.h +++ b/Source/cmSetTargetPropertiesCommand.h @@ -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 " diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 7acfe7e..1f0464d 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -78,17 +78,6 @@ void cmTarget::DefineProperties(cmake *cm) "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.", "The COMPILE_FLAGS property sets additional compiler flags used " @@ -2724,43 +2713,6 @@ void cmTarget::GetLibraryNames(std::string& name, } //---------------------------------------------------------------------------- -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, std::string& realName, diff --git a/Source/cmTarget.h b/Source/cmTarget.h index e1caaef..e89add1 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -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. */ diff --git a/Tests/Complex/Library/CMakeLists.txt b/Tests/Complex/Library/CMakeLists.txt index 4f2e5a4..d21e959 100644 --- a/Tests/Complex/Library/CMakeLists.txt +++ b/Tests/Complex/Library/CMakeLists.txt @@ -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) # diff --git a/Tests/ComplexOneConfig/Library/CMakeLists.txt b/Tests/ComplexOneConfig/Library/CMakeLists.txt index 4f2e5a4..d21e959 100644 --- a/Tests/ComplexOneConfig/Library/CMakeLists.txt +++ b/Tests/ComplexOneConfig/Library/CMakeLists.txt @@ -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) # diff --git a/Tests/ComplexRelativePaths/Library/CMakeLists.txt b/Tests/ComplexRelativePaths/Library/CMakeLists.txt index 4f2e5a4..d21e959 100644 --- a/Tests/ComplexRelativePaths/Library/CMakeLists.txt +++ b/Tests/ComplexRelativePaths/Library/CMakeLists.txt @@ -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) # -- cgit v0.12