diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeVersion.cmake | 2 | ||||
-rw-r--r-- | Source/cmDocumentGeneratorExpressions.h | 4 | ||||
-rw-r--r-- | Source/cmExportBuildFileGenerator.cxx | 1 | ||||
-rw-r--r-- | Source/cmExportFileGenerator.cxx | 196 | ||||
-rw-r--r-- | Source/cmExportFileGenerator.h | 2 | ||||
-rw-r--r-- | Source/cmExportInstallFileGenerator.cxx | 23 | ||||
-rw-r--r-- | Source/cmGeneratorExpressionDAGChecker.cxx | 13 | ||||
-rw-r--r-- | Source/cmGeneratorExpressionDAGChecker.h | 3 | ||||
-rw-r--r-- | Source/cmGeneratorExpressionEvaluator.cxx | 122 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 3 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 15 | ||||
-rw-r--r-- | Source/cmPolicies.cxx | 21 | ||||
-rw-r--r-- | Source/cmPolicies.h | 1 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 73 | ||||
-rw-r--r-- | Source/cmTarget.h | 7 | ||||
-rw-r--r-- | Source/cmTargetPropCommandBase.cxx | 12 |
16 files changed, 413 insertions, 85 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 487d456..623b708 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -2,5 +2,5 @@ set(CMake_VERSION_MAJOR 2) set(CMake_VERSION_MINOR 8) set(CMake_VERSION_PATCH 10) -set(CMake_VERSION_TWEAK 20130119) +set(CMake_VERSION_TWEAK 20130123) #set(CMake_VERSION_RC 1) diff --git a/Source/cmDocumentGeneratorExpressions.h b/Source/cmDocumentGeneratorExpressions.h index fa21907..c2bf423 100644 --- a/Source/cmDocumentGeneratorExpressions.h +++ b/Source/cmDocumentGeneratorExpressions.h @@ -50,6 +50,10 @@ " $<TARGET_PROPERTY:tgt,prop> = The value of the property prop\n" \ "on the target tgt. Note that tgt is not added as a dependency of\n" \ "the target this expression is evaluated on.\n" \ + " $<TARGET_POLICY:pol> = '1' if the policy was NEW when " \ + "the 'head' target was created, else '0'. If the policy was not " \ + "set, the warning message for the policy will be emitted. This " \ + "generator expression only works for a subset of policies.\n" \ "Boolean expressions:\n" \ " $<AND:?[,?]...> = '1' if all '?' are '1', else '0'\n" \ " $<OR:?[,?]...> = '0' if all '?' are '0', else '1'\n" \ diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index 61e130d..7147f86 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -74,6 +74,7 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os) properties, missingTargets); this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE", te, properties); + this->PopulateCompatibleInterfaceProperties(te, properties); this->GenerateInterfaceProperties(te, os, properties); } diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 4a7c6f9..ef1fc5f 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -21,6 +21,7 @@ #include "cmTarget.h" #include "cmTargetExport.h" #include "cmVersion.h" +#include "cmComputeLinkInformation.h" #include <cmsys/auto_ptr.hxx> @@ -81,16 +82,16 @@ bool cmExportFileGenerator::GenerateImportFile() // Protect that file against use with older CMake versions. os << "# Generated by CMake " << cmVersion::GetCMakeVersion() << "\n\n"; - os << "IF(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.5)\n" - << " MESSAGE(FATAL_ERROR \"CMake >= 2.6.0 required\")\n" - << "ENDIF(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.5)\n"; + os << "if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.5)\n" + << " message(FATAL_ERROR \"CMake >= 2.6.0 required\")\n" + << "endif()\n"; // Isolate the file policy level. // We use 2.6 here instead of the current version because newer // versions of CMake should be able to export files imported by 2.6 // until the import format changes. - os << "CMAKE_POLICY(PUSH)\n" - << "CMAKE_POLICY(VERSION 2.6)\n"; + os << "cmake_policy(PUSH)\n" + << "cmake_policy(VERSION 2.6)\n"; // Start with the import file header. this->GenerateImportHeaderCode(os); @@ -100,7 +101,7 @@ bool cmExportFileGenerator::GenerateImportFile() // End with the import file footer. this->GenerateImportFooterCode(os); - os << "CMAKE_POLICY(POP)\n"; + os << "cmake_policy(POP)\n"; return result; } @@ -177,6 +178,79 @@ void cmExportFileGenerator::PopulateInterfaceProperty(const char *propName, properties, missingTargets); } + +//---------------------------------------------------------------------------- +void getPropertyContents(cmTarget *tgt, const char *prop, + std::set<std::string> &ifaceProperties) +{ + const char *p = tgt->GetProperty(prop); + if (!p) + { + return; + } + std::vector<std::string> content; + cmSystemTools::ExpandListArgument(p, content); + for (std::vector<std::string>::const_iterator ci = content.begin(); + ci != content.end(); ++ci) + { + ifaceProperties.insert(*ci); + } +} + +//---------------------------------------------------------------------------- +void getCompatibleInterfaceProperties(cmTarget *target, + std::set<std::string> &ifaceProperties, + const char *config) +{ + cmComputeLinkInformation *info = target->GetLinkInformation(config); + + const cmComputeLinkInformation::ItemVector &deps = info->GetItems(); + + for(cmComputeLinkInformation::ItemVector::const_iterator li = + deps.begin(); + li != deps.end(); ++li) + { + if (!li->Target) + { + continue; + } + getPropertyContents(li->Target, + "COMPATIBLE_INTERFACE_BOOL", + ifaceProperties); + } +} + +//---------------------------------------------------------------------------- +void cmExportFileGenerator::PopulateCompatibleInterfaceProperties( + cmTarget *target, + ImportPropertyMap &properties) +{ + this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_BOOL", + target, properties); + + std::set<std::string> ifaceProperties; + + getPropertyContents(target, "COMPATIBLE_INTERFACE_BOOL", ifaceProperties); + + getCompatibleInterfaceProperties(target, ifaceProperties, 0); + + std::vector<std::string> configNames; + target->GetMakefile()->GetConfigurations(configNames); + + for (std::vector<std::string>::const_iterator ci = configNames.begin(); + ci != configNames.end(); ++ci) + { + getCompatibleInterfaceProperties(target, ifaceProperties, ci->c_str()); + } + + for (std::set<std::string>::const_iterator it = ifaceProperties.begin(); + it != ifaceProperties.end(); ++it) + { + this->PopulateInterfaceProperty(("INTERFACE_" + *it).c_str(), + target, properties); + } +} + //---------------------------------------------------------------------------- void cmExportFileGenerator::GenerateInterfaceProperties(cmTarget *target, std::ostream& os, @@ -186,7 +260,7 @@ void cmExportFileGenerator::GenerateInterfaceProperties(cmTarget *target, { std::string targetName = this->Namespace; targetName += target->GetName(); - os << "SET_TARGET_PROPERTIES(" << targetName << " PROPERTIES\n"; + os << "set_target_properties(" << targetName << " PROPERTIES\n"; for(ImportPropertyMap::const_iterator pi = properties.begin(); pi != properties.end(); ++pi) { @@ -536,7 +610,7 @@ void cmExportFileGenerator::GenerateImportHeaderCode(std::ostream& os, void cmExportFileGenerator::GenerateImportFooterCode(std::ostream& os) { os << "# Commands beyond this point should not need to know the version.\n" - << "SET(CMAKE_IMPORT_FILE_VERSION)\n"; + << "set(CMAKE_IMPORT_FILE_VERSION)\n"; } //---------------------------------------------------------------------------- @@ -545,7 +619,7 @@ void cmExportFileGenerator::GenerateImportVersionCode(std::ostream& os) // Store an import file format version. This will let us change the // format later while still allowing old import files to work. os << "# Commands may need to know the format version.\n" - << "SET(CMAKE_IMPORT_FILE_VERSION 1)\n" + << "set(CMAKE_IMPORT_FILE_VERSION 1)\n" << "\n"; } @@ -553,31 +627,31 @@ void cmExportFileGenerator::GenerateImportVersionCode(std::ostream& os) void cmExportFileGenerator::GenerateExpectedTargetsCode(std::ostream& os, const std::string &expectedTargets) { - os << "SET(_targetsDefined)\n" - "SET(_targetsNotDefined)\n" - "SET(_expectedTargets)\n" - "FOREACH(_expectedTarget " << expectedTargets << ")\n" - " LIST(APPEND _expectedTargets ${_expectedTarget})\n" - " IF(NOT TARGET ${_expectedTarget})\n" - " LIST(APPEND _targetsNotDefined ${_expectedTarget})\n" - " ENDIF(NOT TARGET ${_expectedTarget})\n" - " IF(TARGET ${_expectedTarget})\n" - " LIST(APPEND _targetsDefined ${_expectedTarget})\n" - " ENDIF(TARGET ${_expectedTarget})\n" - "ENDFOREACH(_expectedTarget)\n" - "IF(\"${_targetsDefined}\" STREQUAL \"${_expectedTargets}\")\n" - " SET(CMAKE_IMPORT_FILE_VERSION)\n" - " CMAKE_POLICY(POP)\n" - " RETURN()\n" - "ENDIF(\"${_targetsDefined}\" STREQUAL \"${_expectedTargets}\")\n" - "IF(NOT \"${_targetsDefined}\" STREQUAL \"\")\n" - " MESSAGE(FATAL_ERROR \"Some (but not all) targets in this export " + os << "set(_targetsDefined)\n" + "set(_targetsNotDefined)\n" + "set(_expectedTargets)\n" + "foreach(_expectedTarget " << expectedTargets << ")\n" + " list(APPEND _expectedTargets ${_expectedTarget})\n" + " if(NOT TARGET ${_expectedTarget})\n" + " list(APPEND _targetsNotDefined ${_expectedTarget})\n" + " endif()\n" + " if(TARGET ${_expectedTarget})\n" + " list(APPEND _targetsDefined ${_expectedTarget})\n" + " endif()\n" + "endforeach()\n" + "if(\"${_targetsDefined}\" STREQUAL \"${_expectedTargets}\")\n" + " set(CMAKE_IMPORT_FILE_VERSION)\n" + " cmake_policy(POP)\n" + " return()\n" + "endif()\n" + "if(NOT \"${_targetsDefined}\" STREQUAL \"\")\n" + " message(FATAL_ERROR \"Some (but not all) targets in this export " "set were already defined.\\nTargets Defined: ${_targetsDefined}\\n" "Targets not yet defined: ${_targetsNotDefined}\\n\")\n" - "ENDIF(NOT \"${_targetsDefined}\" STREQUAL \"\")\n" - "UNSET(_targetsDefined)\n" - "UNSET(_targetsNotDefined)\n" - "UNSET(_expectedTargets)\n" + "endif()\n" + "unset(_targetsDefined)\n" + "unset(_targetsNotDefined)\n" + "unset(_expectedTargets)\n" "\n\n"; } //---------------------------------------------------------------------------- @@ -594,16 +668,16 @@ cmExportFileGenerator switch(target->GetType()) { case cmTarget::EXECUTABLE: - os << "ADD_EXECUTABLE(" << targetName << " IMPORTED)\n"; + os << "add_executable(" << targetName << " IMPORTED)\n"; break; case cmTarget::STATIC_LIBRARY: - os << "ADD_LIBRARY(" << targetName << " STATIC IMPORTED)\n"; + os << "add_library(" << targetName << " STATIC IMPORTED)\n"; break; case cmTarget::SHARED_LIBRARY: - os << "ADD_LIBRARY(" << targetName << " SHARED IMPORTED)\n"; + os << "add_library(" << targetName << " SHARED IMPORTED)\n"; break; case cmTarget::MODULE_LIBRARY: - os << "ADD_LIBRARY(" << targetName << " MODULE IMPORTED)\n"; + os << "add_library(" << targetName << " MODULE IMPORTED)\n"; break; default: // should never happen break; @@ -612,27 +686,27 @@ cmExportFileGenerator // Mark the imported executable if it has exports. if(target->IsExecutableWithExports()) { - os << "SET_PROPERTY(TARGET " << targetName + os << "set_property(TARGET " << targetName << " PROPERTY ENABLE_EXPORTS 1)\n"; } // Mark the imported library if it is a framework. if(target->IsFrameworkOnApple()) { - os << "SET_PROPERTY(TARGET " << targetName + os << "set_property(TARGET " << targetName << " PROPERTY FRAMEWORK 1)\n"; } // Mark the imported executable if it is an application bundle. if(target->IsAppBundleOnApple()) { - os << "SET_PROPERTY(TARGET " << targetName + os << "set_property(TARGET " << targetName << " PROPERTY MACOSX_BUNDLE 1)\n"; } if (target->IsCFBundleOnApple()) { - os << "SET_PROPERTY(TARGET " << targetName + os << "set_property(TARGET " << targetName << " PROPERTY BUNDLE 1)\n"; } os << "\n"; @@ -652,7 +726,7 @@ cmExportFileGenerator // Set the import properties. os << "# Import target \"" << targetName << "\" for configuration \"" << config << "\"\n"; - os << "SET_PROPERTY(TARGET " << targetName + os << "set_property(TARGET " << targetName << " APPEND PROPERTY IMPORTED_CONFIGURATIONS "; if(config && *config) { @@ -663,7 +737,7 @@ cmExportFileGenerator os << "NOCONFIG"; } os << ")\n"; - os << "SET_TARGET_PROPERTIES(" << targetName << " PROPERTIES\n"; + os << "set_target_properties(" << targetName << " PROPERTIES\n"; for(ImportPropertyMap::const_iterator pi = properties.begin(); pi != properties.end(); ++pi) { @@ -689,17 +763,17 @@ void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os, { if (emitted.insert(missingTargets[i]).second) { - os << "IF(NOT TARGET \"" << missingTargets[i] << "\" )\n" - << " IF(CMAKE_FIND_PACKAGE_NAME)\n" - << " SET( ${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)\n" - << " SET( ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE " + os << "if(NOT TARGET \"" << missingTargets[i] << "\" )\n" + << " if(CMAKE_FIND_PACKAGE_NAME)\n" + << " set( ${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)\n" + << " set( ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE " << "\"Required imported target \\\"" << missingTargets[i] << "\\\" not found ! \")\n" - << " ELSE()\n" - << " MESSAGE(FATAL_ERROR \"Required imported target \\\"" + << " else()\n" + << " message(FATAL_ERROR \"Required imported target \\\"" << missingTargets[i] << "\\\" not found ! \")\n" - << " ENDIF()\n" - << "ENDIF()\n"; + << " endif()\n" + << "endif()\n"; } } os << "\n"; @@ -718,10 +792,10 @@ cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os) // on SUSE with a mysql pkg-config file, which claimed everything is fine, // but the development package was not installed.). os << "# Loop over all imported files and verify that they actually exist\n" - "FOREACH(target ${_IMPORT_CHECK_TARGETS} )\n" - " FOREACH(file ${_IMPORT_CHECK_FILES_FOR_${target}} )\n" - " IF(NOT EXISTS \"${file}\" )\n" - " MESSAGE(FATAL_ERROR \"The imported target \\\"${target}\\\"" + "foreach(target ${_IMPORT_CHECK_TARGETS} )\n" + " foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} )\n" + " if(NOT EXISTS \"${file}\" )\n" + " message(FATAL_ERROR \"The imported target \\\"${target}\\\"" " references the file\n" " \\\"${file}\\\"\n" "but this file does not exist. Possible reasons include:\n" @@ -731,11 +805,11 @@ cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os) " \\\"${CMAKE_CURRENT_LIST_FILE}\\\"\n" "but not all the files it references.\n" "\")\n" - " ENDIF()\n" - " ENDFOREACH()\n" - " UNSET(_IMPORT_CHECK_FILES_FOR_${target})\n" - "ENDFOREACH()\n" - "UNSET(_IMPORT_CHECK_TARGETS)\n" + " endif()\n" + " endforeach()\n" + " unset(_IMPORT_CHECK_FILES_FOR_${target})\n" + "endforeach()\n" + "unset(_IMPORT_CHECK_TARGETS)\n" "\n"; } @@ -751,8 +825,8 @@ cmExportFileGenerator std::string targetName = this->Namespace; targetName += target->GetName(); - os << "LIST(APPEND _IMPORT_CHECK_TARGETS " << targetName << " )\n" - "LIST(APPEND _IMPORT_CHECK_FILES_FOR_" << targetName << " "; + os << "list(APPEND _IMPORT_CHECK_TARGETS " << targetName << " )\n" + "list(APPEND _IMPORT_CHECK_FILES_FOR_" << targetName << " "; for(std::set<std::string>::const_iterator li = importedLocations.begin(); li != importedLocations.end(); diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h index eb3f3c3..b39df0f 100644 --- a/Source/cmExportFileGenerator.h +++ b/Source/cmExportFileGenerator.h @@ -103,6 +103,8 @@ protected: std::vector<std::string> &missingTargets); void PopulateInterfaceProperty(const char *propName, cmTarget *target, ImportPropertyMap &properties); + void PopulateCompatibleInterfaceProperties(cmTarget *target, + ImportPropertyMap &properties); void GenerateInterfaceProperties(cmTarget *target, std::ostream& os, const ImportPropertyMap &properties); diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index 965f63d..a35f5cf 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -57,7 +57,7 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) else { cmOStringStream e; - e << "INSTALL(EXPORT \"" + e << "install(EXPORT \"" << this->IEGen->GetExportSet()->GetName() << "\" ...) " << "includes target \"" << te->Target->GetName() << "\" more than once in the export set."; @@ -91,6 +91,7 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) properties, missingTargets); this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE", te, properties); + this->PopulateCompatibleInterfaceProperties(te, properties); this->GenerateInterfaceProperties(te, os, properties); } @@ -98,12 +99,12 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) // Now load per-configuration properties for them. os << "# Load information for each installed configuration.\n" - << "GET_FILENAME_COMPONENT(_DIR \"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n" - << "FILE(GLOB CONFIG_FILES \"${_DIR}/" + << "get_filename_component(_DIR \"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n" + << "file(GLOB CONFIG_FILES \"${_DIR}/" << this->GetConfigImportFileGlob() << "\")\n" - << "FOREACH(f ${CONFIG_FILES})\n" - << " INCLUDE(${f})\n" - << "ENDFOREACH(f)\n" + << "foreach(f ${CONFIG_FILES})\n" + << " include(${f})\n" + << "endforeach()\n" << "\n"; this->GenerateImportedFileCheckLoop(os); @@ -193,12 +194,12 @@ cmExportInstallFileGenerator { std::string dest = installDest; os << "# Compute the installation prefix relative to this file.\n" - << "GET_FILENAME_COMPONENT(_IMPORT_PREFIX " + << "get_filename_component(_IMPORT_PREFIX " << "\"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n"; while(!dest.empty()) { os << - "GET_FILENAME_COMPONENT(_IMPORT_PREFIX \"${_IMPORT_PREFIX}\" PATH)\n"; + "get_filename_component(_IMPORT_PREFIX \"${_IMPORT_PREFIX}\" PATH)\n"; dest = cmSystemTools::GetFilenamePath(dest); } os << "\n"; @@ -257,7 +258,7 @@ cmExportInstallFileGenerator if(!this->ImportPrefix.empty()) { os << "# Cleanup temporary variables.\n" - << "SET(_IMPORT_PREFIX)\n" + << "set(_IMPORT_PREFIX)\n" << "\n"; } } @@ -427,7 +428,7 @@ cmExportInstallFileGenerator { const char* installDest = this->IEGen->GetDestination(); cmOStringStream e; - e << "INSTALL(EXPORT \"" + e << "install(EXPORT \"" << this->IEGen->GetExportSet()->GetName() << "\") given absolute " << "DESTINATION \"" << installDest << "\" but the export " @@ -445,7 +446,7 @@ cmExportInstallFileGenerator int occurrences) { cmOStringStream e; - e << "INSTALL(EXPORT \"" + e << "install(EXPORT \"" << this->IEGen->GetExportSet()->GetName() << "\" ...) " << "includes target \"" << depender->GetName() diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx index 2e5b5ae..057f4c3 100644 --- a/Source/cmGeneratorExpressionDAGChecker.cxx +++ b/Source/cmGeneratorExpressionDAGChecker.cxx @@ -106,3 +106,16 @@ cmGeneratorExpressionDAGChecker::checkGraph() const } return DAG; } + +//---------------------------------------------------------------------------- +bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries() +{ + const cmGeneratorExpressionDAGChecker *top = this; + const cmGeneratorExpressionDAGChecker *parent = this->Parent; + while (parent) + { + parent = parent->Parent; + top = parent; + } + return top->Property == "LINK_LIBRARIES"; +} diff --git a/Source/cmGeneratorExpressionDAGChecker.h b/Source/cmGeneratorExpressionDAGChecker.h index 48f26ed..3169291 100644 --- a/Source/cmGeneratorExpressionDAGChecker.h +++ b/Source/cmGeneratorExpressionDAGChecker.h @@ -35,6 +35,9 @@ struct cmGeneratorExpressionDAGChecker void reportError(cmGeneratorExpressionContext *context, const std::string &expr); + + bool EvaluatingLinkLibraries(); + private: Result checkGraph() const; diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index 8e40815a..c468c39 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -442,6 +442,27 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode const char *prop = target->GetProperty(propertyName.c_str()); if (!prop) { + if (target->IsImported()) + { + return std::string(); + } + if (dagCheckerParent && dagCheckerParent->EvaluatingLinkLibraries()) + { + return std::string(); + } + if (propertyName == "POSITION_INDEPENDENT_CODE") + { + return target->GetLinkInterfaceDependentBoolProperty( + "POSITION_INDEPENDENT_CODE", context->Config) ? "1" : "0"; + } + if (target->IsLinkInterfaceDependentBoolProperty(propertyName, + context->Config)) + { + return target->GetLinkInterfaceDependentBoolProperty( + propertyName, + context->Config) ? "1" : "0"; + } + return std::string(); } @@ -488,6 +509,105 @@ static const struct TargetNameNode : public cmGeneratorExpressionNode } targetNameNode; //---------------------------------------------------------------------------- +static const char* targetPolicyWhitelist[] = { + "CMP0003" + , "CMP0004" + , "CMP0008" + , "CMP0020" +}; + +cmPolicies::PolicyStatus statusForTarget(cmTarget *tgt, const char *policy) +{ +#define RETURN_POLICY(POLICY) \ + if (strcmp(policy, #POLICY) == 0) \ + { \ + return tgt->GetPolicyStatus ## POLICY (); \ + } \ + + RETURN_POLICY(CMP0003) + RETURN_POLICY(CMP0004) + RETURN_POLICY(CMP0008) + RETURN_POLICY(CMP0020) + +#undef RETURN_POLICY + + assert("!Unreachable code. Not a valid policy"); + return cmPolicies::WARN; +} + +cmPolicies::PolicyID policyForString(const char *policy_id) +{ +#define RETURN_POLICY_ID(POLICY_ID) \ + if (strcmp(policy_id, #POLICY_ID) == 0) \ + { \ + return cmPolicies:: POLICY_ID; \ + } \ + + RETURN_POLICY_ID(CMP0003) + RETURN_POLICY_ID(CMP0004) + RETURN_POLICY_ID(CMP0008) + RETURN_POLICY_ID(CMP0020) + +#undef RETURN_POLICY_ID + + assert("!Unreachable code. Not a valid policy"); + return cmPolicies::CMP0002; +} + +//---------------------------------------------------------------------------- +static const struct TargetPolicyNode : public cmGeneratorExpressionNode +{ + TargetPolicyNode() {} + + virtual int NumExpectedParameters() const { return 1; } + + std::string Evaluate(const std::vector<std::string> ¶meters, + cmGeneratorExpressionContext *context , + const GeneratorExpressionContent *content, + cmGeneratorExpressionDAGChecker *) const + { + if (!context->HeadTarget) + { + reportError(context, content->GetOriginalExpression(), + "$<TARGET_POLICY:prop> may only be used with targets. It may not " + "be used with add_custom_command."); + return std::string(); + } + for (size_t i = 0; + i < (sizeof(targetPolicyWhitelist) / + sizeof(*targetPolicyWhitelist)); + ++i) + { + const char *policy = targetPolicyWhitelist[i]; + if (parameters.front() == policy) + { + cmMakefile *mf = context->HeadTarget->GetMakefile(); + switch(statusForTarget(context->HeadTarget, policy)) + { + case cmPolicies::WARN: + mf->IssueMessage(cmake::AUTHOR_WARNING, + mf->GetPolicies()-> + GetPolicyWarning(policyForString(policy))); + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::OLD: + return "0"; + case cmPolicies::NEW: + return "1"; + } + } + } + reportError(context, content->GetOriginalExpression(), + "$<TARGET_POLICY:prop> may only be used with a limited number of " + "policies. Currently it may be used with policies CMP0003, CMP0004, " + "CMP0008 and CMP0020." + ); + return std::string(); + } + +} targetPolicyNode; + +//---------------------------------------------------------------------------- template<bool linker, bool soname> struct TargetFilesystemArtifactResultCreator { @@ -714,6 +834,8 @@ cmGeneratorExpressionNode* GetNode(const std::string &identifier) return &targetPropertyNode; else if (identifier == "TARGET_NAME") return &targetNameNode; + else if (identifier == "TARGET_POLICY") + return &targetPolicyNode; else if (identifier == "BUILD_INTERFACE") return &buildInterfaceNode; else if (identifier == "INSTALL_INTERFACE") diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index f28bd6c..f7eff21 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1064,7 +1064,8 @@ void cmGlobalGenerator::CreateAutomocTargets() if(target.GetType() == cmTarget::EXECUTABLE || target.GetType() == cmTarget::STATIC_LIBRARY || target.GetType() == cmTarget::SHARED_LIBRARY || - target.GetType() == cmTarget::MODULE_LIBRARY) + target.GetType() == cmTarget::MODULE_LIBRARY || + target.GetType() == cmTarget::OBJECT_LIBRARY) { if(target.GetPropertyAsBool("AUTOMOC") && !target.IsImported()) { diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 2cfe4da..0681ce5 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1367,16 +1367,18 @@ void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases, } //---------------------------------------------------------------------------- -// This function removes each occurence of the flag and returns the last one +// This function removes each occurrence of the flag and returns the last one // (i.e., the dominant flag in GCC) std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag, std::string& flags) { std::string retFlag; - std::string::size_type pos = flags.rfind(flag); + std::string::size_type lastOccurancePos = flags.rfind(flag); bool saved = false; - while(pos != flags.npos) + while(lastOccurancePos != flags.npos) { + //increment pos, we use lastOccurancePos to reduce search space on next inc + std::string::size_type pos = lastOccurancePos; if(pos == 0 || flags[pos-1]==' ') { while(pos < flags.size() && flags[pos] != ' ') @@ -1388,9 +1390,12 @@ std::string cmGlobalXCodeGenerator::ExtractFlag(const char* flag, flags[pos] = ' '; pos++; } - } saved = true; - pos = flags.rfind(flag); + } + //decrement lastOccurancePos while making sure we don't loop around + //and become a very large positive number since size_type is unsigned + lastOccurancePos = lastOccurancePos == 0 ? 0 : lastOccurancePos-1; + lastOccurancePos = flags.rfind(flag,lastOccurancePos); } return retFlag; } diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index eb7d666..831e92e 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -508,6 +508,27 @@ cmPolicies::cmPolicies() "for strict compatibility. " "The NEW behavior for this policy is to leave the values untouched.", 2,8,11,0, cmPolicies::WARN); + + this->DefinePolicy( + CMP0020, "CMP0020", + "Automatically link Qt executables to qtmain target on Windows.", + "CMake 2.8.10 and lower required users of Qt to always specify a link " + "dependency to the qtmain.lib static library manually on Windows. CMake " + "2.8.11 gained the ability to evaluate generator expressions while " + "determining the link dependencies from IMPORTED targets. This allows " + "CMake itself to automatically link executables which link to Qt to the " + "qtmain.lib library when using IMPORTED Qt targets. For applications " + "already linking to qtmain.lib, this should have little impact. For " + "applications which supply their own alternative WinMain implementation " + "and for applications which use the QAxServer library, this automatic " + "linking will need to be disabled as per the documentation." + "\n" + "The OLD behavior for this policy is not to link executables to " + "qtmain.lib automatically when they link to the QtCore IMPORTED" + "target. " + "The NEW behavior for this policy is to link executables to " + "qtmain.lib automatically when they link to QtCore IMPORTED target.", + 2,8,11,0, cmPolicies::WARN); } cmPolicies::~cmPolicies() diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index d7d945c..c11af07 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -69,6 +69,7 @@ public: /// POSITION_INDEPENDENT_CODE property and *_COMPILE_OPTIONS_PI{E,C} /// instead. CMP0019, ///< No variable re-expansion in include and link info + CMP0020, ///< Automatically link Qt executables to qtmain target /** \brief Always the last entry. * diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 6c9ed1b..2b912f3 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -145,6 +145,7 @@ cmTarget::cmTarget() this->PolicyStatusCMP0003 = cmPolicies::WARN; this->PolicyStatusCMP0004 = cmPolicies::WARN; this->PolicyStatusCMP0008 = cmPolicies::WARN; + this->PolicyStatusCMP0020 = cmPolicies::WARN; this->LinkLibrariesAnalyzed = false; this->HaveInstallRule = false; this->DLLPlatform = false; @@ -1500,6 +1501,8 @@ void cmTarget::SetMakefile(cmMakefile* mf) this->Makefile->GetPolicyStatus(cmPolicies::CMP0004); this->PolicyStatusCMP0008 = this->Makefile->GetPolicyStatus(cmPolicies::CMP0008); + this->PolicyStatusCMP0020 = + this->Makefile->GetPolicyStatus(cmPolicies::CMP0020); } //---------------------------------------------------------------------------- @@ -1521,6 +1524,13 @@ void cmTarget::ClearLinkMaps() this->Internal->LinkImplMap.clear(); this->Internal->LinkInterfaceMap.clear(); this->Internal->LinkClosureMap.clear(); + for (cmTargetLinkInformationMap::const_iterator it + = this->LinkInformation.begin(); + it != this->LinkInformation.end(); ++it) + { + delete it->second; + } + this->LinkInformation.clear(); } //---------------------------------------------------------------------------- @@ -2270,8 +2280,9 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf, cmTarget *tgt = this->Makefile->FindTargetToUse(lib); const bool isNonImportedTarget = tgt && !tgt->IsImported(); - std::string libName = isNonImportedTarget ? targetNameGenex(lib) - : std::string(lib); + const std::string libName = (isNonImportedTarget && llt != GENERAL) + ? targetNameGenex(lib) + : std::string(lib); this->AppendProperty("LINK_LIBRARIES", this->GetDebugGeneratorExpressions(libName, llt).c_str()); @@ -4540,6 +4551,7 @@ bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p, "INTERFACE_" << p << " property requirement\nof " "dependency \"" << li->Target->GetName() << "\".\n"; cmSystemTools::Error(e.str().c_str()); + break; } else { @@ -4566,6 +4578,7 @@ bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p, "INTERFACE_" << p << " property on\ndependency \"" << li->Target->GetName() << "\" is in conflict.\n"; cmSystemTools::Error(e.str().c_str()); + break; } else { @@ -4593,6 +4606,7 @@ bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p, "of " << p << " already determined\nfor \"" << this->GetName() << "\".\n"; cmSystemTools::Error(e.str().c_str()); + break; } else { @@ -4617,6 +4631,53 @@ bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p, } //---------------------------------------------------------------------------- +bool isLinkDependentProperty(cmTarget *tgt, const std::string &p, + const char *interfaceProperty, + const char *config) +{ + cmComputeLinkInformation *info = tgt->GetLinkInformation(config); + + const cmComputeLinkInformation::ItemVector &deps = info->GetItems(); + + for(cmComputeLinkInformation::ItemVector::const_iterator li = + deps.begin(); + li != deps.end(); ++li) + { + if (!li->Target) + { + continue; + } + const char *prop = li->Target->GetProperty(interfaceProperty); + if (!prop) + { + continue; + } + + std::vector<std::string> props; + cmSystemTools::ExpandListArgument(prop, props); + + for(std::vector<std::string>::iterator pi = props.begin(); + pi != props.end(); ++pi) + { + if (*pi == p) + { + return true; + } + } + } + + return false; +} + +//---------------------------------------------------------------------------- +bool cmTarget::IsLinkInterfaceDependentBoolProperty(const std::string &p, + const char *config) +{ + return isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_BOOL", + config); +} + +//---------------------------------------------------------------------------- void cmTarget::GetLanguages(std::set<cmStdString>& languages) const { for(std::vector<cmSourceFile*>::const_iterator @@ -5429,14 +5490,14 @@ cmTarget::GetLinkInformation(const char* config, cmTarget *head) info = 0; } + // Store the information for this configuration. + cmTargetLinkInformationMap::value_type entry(key, info); + i = this->LinkInformation.insert(entry).first; + if (info) { this->CheckPropertyCompatibility(info, config); } - - // Store the information for this configuration. - cmTargetLinkInformationMap::value_type entry(key, info); - i = this->LinkInformation.insert(entry).first; } return i->second; } diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 47ec528..9909bae 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -102,6 +102,10 @@ public: cmPolicies::PolicyStatus GetPolicyStatusCMP0008() const { return this->PolicyStatusCMP0008; } + /** Get the status of policy CMP0020 when the target was created. */ + cmPolicies::PolicyStatus GetPolicyStatusCMP0020() const + { return this->PolicyStatusCMP0020; } + /** * Get the list of the custom commands for this target */ @@ -495,6 +499,8 @@ public: void GetLinkDependentTargetsForProperty(const std::string &p, std::set<std::string> &targets); bool IsNullImpliedByLinkLibraries(const std::string &p); + bool IsLinkInterfaceDependentBoolProperty(const std::string &p, + const char *config); void AddLinkDependentTargetsForProperties( const std::map<cmStdString, cmStdString> &map); @@ -657,6 +663,7 @@ private: cmPolicies::PolicyStatus PolicyStatusCMP0003; cmPolicies::PolicyStatus PolicyStatusCMP0004; cmPolicies::PolicyStatus PolicyStatusCMP0008; + cmPolicies::PolicyStatus PolicyStatusCMP0020; // Internal representation details. friend class cmTargetInternals; diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx index 69aaf17..7f15dcb 100644 --- a/Source/cmTargetPropCommandBase.cxx +++ b/Source/cmTargetPropCommandBase.cxx @@ -66,6 +66,14 @@ bool cmTargetPropCommandBase } //---------------------------------------------------------------------------- +static bool isGeneratorExpression(const std::string &lib) +{ + const std::string::size_type openpos = lib.find("$<"); + return (openpos != std::string::npos) + && (lib.find(">", openpos) != std::string::npos); +} + +//---------------------------------------------------------------------------- bool cmTargetPropCommandBase ::ProcessContentArgs(std::vector<std::string> const& args, unsigned int &argIndex, bool prepend) @@ -105,6 +113,10 @@ bool cmTargetPropCommandBase content += sep + "$<TARGET_PROPERTY:" + args[i] + ",INTERFACE_" + this->Property + ">"; } + else if(isGeneratorExpression(args[i])) + { + content += sep + args[i]; + } else if (!this->HandleNonTargetArg(content, sep, args[i], args[0])) { return false; |