diff options
41 files changed, 1037 insertions, 218 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index c71ba21..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 20130111) +set(CMake_VERSION_TWEAK 20130123) #set(CMake_VERSION_RC 1) diff --git a/Source/cmDocumentGeneratorExpressions.h b/Source/cmDocumentGeneratorExpressions.h index b8889ac..fa21907 100644 --- a/Source/cmDocumentGeneratorExpressions.h +++ b/Source/cmDocumentGeneratorExpressions.h @@ -37,6 +37,7 @@ "target in the same buildsystem. Expands to the empty string " \ "otherwise.\n" \ " $<TARGET_FILE:tgt> = main file (.exe, .so.1.2, .a)\n" \ + " $<TARGET_DEFINED:tgt> = '1' if tgt is a target, else '0'\n" \ " $<TARGET_LINKER_FILE:tgt> = file used to link (.a, .lib, .so)\n" \ " $<TARGET_SONAME_FILE:tgt> = file with soname (.so.3)\n" \ "where \"tgt\" is the name of a target. " \ diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index 9533319..61e130d 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -62,6 +62,8 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os) cmTarget* te = *tei; this->GenerateImportTargetCode(os, te); + te->AppendBuildInterfaceIncludes(); + ImportPropertyMap properties; this->PopulateInterfaceProperty("INTERFACE_INCLUDE_DIRECTORIES", te, @@ -70,20 +72,22 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os) this->PopulateInterfaceProperty("INTERFACE_COMPILE_DEFINITIONS", te, cmGeneratorExpression::BuildInterface, properties, missingTargets); + this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE", + te, properties); this->GenerateInterfaceProperties(te, os, properties); } - this->GenerateMissingTargetsCheckCode(os, missingTargets); - // Generate import file content for each configuration. for(std::vector<std::string>::const_iterator ci = this->Configurations.begin(); ci != this->Configurations.end(); ++ci) { - this->GenerateImportConfig(os, ci->c_str()); + this->GenerateImportConfig(os, ci->c_str(), missingTargets); } + this->GenerateMissingTargetsCheckCode(os, missingTargets); + return true; } @@ -91,7 +95,8 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os) void cmExportBuildFileGenerator ::GenerateImportTargetsConfig(std::ostream& os, - const char* config, std::string const& suffix) + const char* config, std::string const& suffix, + std::vector<std::string> &missingTargets) { for(std::vector<cmTarget*>::const_iterator tei = this->Exports->begin(); @@ -104,9 +109,12 @@ cmExportBuildFileGenerator if(!properties.empty()) { // Get the rest of the target details. - std::vector<std::string> missingTargets; this->SetImportDetailProperties(config, suffix, target, properties, missingTargets); + this->SetImportLinkInterface(config, suffix, + cmGeneratorExpression::BuildInterface, + target, properties, missingTargets); + // TOOD: PUBLIC_HEADER_LOCATION // This should wait until the build feature propagation stuff @@ -115,7 +123,6 @@ cmExportBuildFileGenerator // properties); // Generate code in the export file. - this->GenerateMissingTargetsCheckCode(os, missingTargets); this->GenerateImportPropertyCode(os, config, target, properties); } } diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h index 726537b..5e1be16 100644 --- a/Source/cmExportBuildFileGenerator.h +++ b/Source/cmExportBuildFileGenerator.h @@ -44,7 +44,8 @@ protected: virtual bool GenerateMainFile(std::ostream& os); virtual void GenerateImportTargetsConfig(std::ostream& os, const char* config, - std::string const& suffix); + std::string const& suffix, + std::vector<std::string> &missingTargets); virtual void HandleMissingTarget(std::string& link_libs, std::vector<std::string>& missingTargets, cmMakefile* mf, diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 90c0c41..4a7c6f9 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -107,7 +107,8 @@ bool cmExportFileGenerator::GenerateImportFile() //---------------------------------------------------------------------------- void cmExportFileGenerator::GenerateImportConfig(std::ostream& os, - const char* config) + const char* config, + std::vector<std::string> &missingTargets) { // Construct the property configuration suffix. std::string suffix = "_"; @@ -121,7 +122,19 @@ void cmExportFileGenerator::GenerateImportConfig(std::ostream& os, } // Generate the per-config target information. - this->GenerateImportTargetsConfig(os, config, suffix); + this->GenerateImportTargetsConfig(os, config, suffix, missingTargets); +} + +//---------------------------------------------------------------------------- +void cmExportFileGenerator::PopulateInterfaceProperty(const char *propName, + cmTarget *target, + ImportPropertyMap &properties) +{ + const char *input = target->GetProperty(propName); + if (input) + { + properties[propName] = input; + } } //---------------------------------------------------------------------------- @@ -184,10 +197,90 @@ void cmExportFileGenerator::GenerateInterfaceProperties(cmTarget *target, } //---------------------------------------------------------------------------- +bool +cmExportFileGenerator::AddTargetNamespace(std::string &input, + cmTarget* target, + std::vector<std::string> &missingTargets) +{ + cmMakefile *mf = target->GetMakefile(); + + cmTarget *tgt = mf->FindTargetToUse(input.c_str()); + if (!tgt) + { + return false; + } + + if(tgt->IsImported()) + { + return true; + } + if(this->ExportedTargets.find(tgt) != this->ExportedTargets.end()) + { + input = this->Namespace + input; + } + else + { + std::string namespacedTarget; + this->HandleMissingTarget(namespacedTarget, missingTargets, + mf, target, tgt); + if (!namespacedTarget.empty()) + { + input = namespacedTarget; + } + } + return true; +} + +//---------------------------------------------------------------------------- +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); +} + +//---------------------------------------------------------------------------- void cmExportFileGenerator::ResolveTargetsInGeneratorExpressions( std::string &input, cmTarget* target, + std::vector<std::string> &missingTargets, + FreeTargetsReplace replace) +{ + if (replace == NoReplaceFreeTargets) + { + this->ResolveTargetsInGeneratorExpression(input, target, missingTargets); + return; + } + std::vector<std::string> parts; + cmGeneratorExpression::Split(input, parts); + + std::string sep; + input = ""; + for(std::vector<std::string>::iterator li = parts.begin(); + li != parts.end(); ++li) + { + if (!isGeneratorExpression(*li)) + { + this->AddTargetNamespace(*li, target, missingTargets); + } + else + { + this->ResolveTargetsInGeneratorExpression( + *li, + target, + missingTargets); + } + input += sep + *li; + sep = ";"; + } +} + +//---------------------------------------------------------------------------- +void +cmExportFileGenerator::ResolveTargetsInGeneratorExpression( + std::string &input, + cmTarget* target, std::vector<std::string> &missingTargets) { std::string::size_type pos = 0; @@ -212,45 +305,17 @@ cmExportFileGenerator::ResolveTargetsInGeneratorExpressions( continue; } - const std::string targetName = input.substr(nameStartPos, + std::string targetName = input.substr(nameStartPos, commaPos - nameStartPos); - pos = nameStartPos; // We're not going to replace the entire expression, - // but only the target parameter. - if (cmTarget *tgt = mf->FindTargetToUse(targetName.c_str())) - { - if(tgt->IsImported()) - { - pos += targetName.size(); - } - else if(this->ExportedTargets.find(tgt) != this->ExportedTargets.end()) - { - input.replace(pos, targetName.size(), - this->Namespace + targetName); - pos += this->Namespace.size() + targetName.size(); - } - else - { - std::string namespacedTarget; - this->HandleMissingTarget(namespacedTarget, missingTargets, - mf, target, tgt); - if (!namespacedTarget.empty()) - { - input.replace(pos, targetName.size(), namespacedTarget); - pos += namespacedTarget.size(); - } - } - } - else + if (!this->AddTargetNamespace(targetName, target, missingTargets)) { errorString = "$<TARGET_PROPERTY:" + targetName + ",prop> requires " "its first parameter to be a reachable target."; - } - lastPos = pos; - if (!errorString.empty()) - { break; } + input.replace(nameStartPos, commaPos - nameStartPos, targetName); + lastPos = pos + targetName.size(); } if (!errorString.empty()) { @@ -267,51 +332,24 @@ cmExportFileGenerator::ResolveTargetsInGeneratorExpressions( if (endPos == input.npos) { errorString = "$<TARGET_NAME:...> expression incomplete"; + break; } - const std::string targetName = input.substr(nameStartPos, + std::string targetName = input.substr(nameStartPos, endPos - nameStartPos); - if(targetName.find("$<", lastPos) != input.npos) + if(targetName.find("$<") != input.npos) { errorString = "$<TARGET_NAME:...> requires its parameter to be a " "literal."; + break; } - if (cmTarget *tgt = mf->FindTargetToUse(targetName.c_str())) - { - if(tgt->IsImported()) - { - input.replace(pos, sizeof("$<TARGET_NAME:") + targetName.size(), - targetName); - pos += sizeof("$<TARGET_NAME:") + targetName.size(); - } - else if(this->ExportedTargets.find(tgt) != this->ExportedTargets.end()) - { - input.replace(pos, sizeof("$<TARGET_NAME:") + targetName.size(), - this->Namespace + targetName); - pos += sizeof("$<TARGET_NAME:") + targetName.size(); - } - else - { - std::string namespacedTarget; - this->HandleMissingTarget(namespacedTarget, missingTargets, - mf, target, tgt); - if (!namespacedTarget.empty()) - { - input.replace(pos, sizeof("$<TARGET_NAME:") + targetName.size(), - namespacedTarget); - pos += sizeof("$<TARGET_NAME:") + targetName.size(); - } - } - } - else + if (!this->AddTargetNamespace(targetName, target, missingTargets)) { errorString = "$<TARGET_NAME:...> requires its parameter to be a " "reachable target."; - } - lastPos = pos; - if (!errorString.empty()) - { break; } + input.replace(pos, endPos - pos + 1, targetName); + lastPos = endPos; } if (!errorString.empty()) { @@ -322,6 +360,64 @@ cmExportFileGenerator::ResolveTargetsInGeneratorExpressions( //---------------------------------------------------------------------------- void cmExportFileGenerator +::SetImportLinkInterface(const char* config, std::string const& suffix, + cmGeneratorExpression::PreprocessContext preprocessRule, + cmTarget* target, ImportPropertyMap& properties, + std::vector<std::string>& missingTargets) +{ + // Add the transitive link dependencies for this configuration. + cmTarget::LinkInterface const* iface = target->GetLinkInterface(config, + target); + if (!iface) + { + return; + } + + if (iface->ImplementationIsInterface) + { + this->SetImportLinkProperty(suffix, target, + "IMPORTED_LINK_INTERFACE_LIBRARIES", + iface->Libraries, properties, missingTargets); + return; + } + + const char *propContent; + + if (const char *prop_suffixed = target->GetProperty( + ("LINK_INTERFACE_LIBRARIES" + suffix).c_str())) + { + propContent = prop_suffixed; + } + else if (const char *prop = target->GetProperty( + "LINK_INTERFACE_LIBRARIES")) + { + propContent = prop; + } + else + { + return; + } + + if (!*propContent) + { + properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = ""; + return; + } + + std::string prepro = cmGeneratorExpression::Preprocess(propContent, + preprocessRule); + if (!prepro.empty()) + { + this->ResolveTargetsInGeneratorExpressions(prepro, target, + missingTargets, + ReplaceFreeTargets); + properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = prepro; + } +} + +//---------------------------------------------------------------------------- +void +cmExportFileGenerator ::SetImportDetailProperties(const char* config, std::string const& suffix, cmTarget* target, ImportPropertyMap& properties, std::vector<std::string>& missingTargets @@ -363,9 +459,7 @@ cmExportFileGenerator this->SetImportLinkProperty(suffix, target, "IMPORTED_LINK_INTERFACE_LANGUAGES", iface->Languages, properties, missingTargets); - this->SetImportLinkProperty(suffix, target, - "IMPORTED_LINK_INTERFACE_LIBRARIES", - iface->Libraries, properties, missingTargets); + this->SetImportLinkProperty(suffix, target, "IMPORTED_LINK_DEPENDENT_LIBRARIES", iface->SharedDeps, properties, missingTargets); @@ -397,9 +491,6 @@ cmExportFileGenerator return; } - // Get the makefile in which to lookup target information. - cmMakefile* mf = target->GetMakefile(); - // Construct the property value. std::string link_libs; const char* sep = ""; @@ -410,33 +501,9 @@ cmExportFileGenerator link_libs += sep; sep = ";"; - // Append this entry. - if(cmTarget* tgt = mf->FindTargetToUse(li->c_str())) - { - // This is a target. - if(tgt->IsImported()) - { - // The target is imported (and therefore is not in the - // export). Append the raw name. - link_libs += *li; - } - else if(this->ExportedTargets.find(tgt) != this->ExportedTargets.end()) - { - // The target is in the export. Append it with the export - // namespace. - link_libs += this->Namespace; - link_libs += *li; - } - else - { - this->HandleMissingTarget(link_libs, missingTargets, mf, target, tgt); - } - } - else - { - // Append the raw name. - link_libs += *li; - } + std::string temp = *li; + this->AddTargetNamespace(temp, target, missingTargets); + link_libs += temp; } // Store the property. @@ -611,21 +678,29 @@ cmExportFileGenerator void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os, const std::vector<std::string>& missingTargets) { + if (missingTargets.empty()) + { + return; + } os << "# Make sure the targets which have been exported in some other \n" "# export set exist.\n"; + std::set<std::string> emitted; for(unsigned int i=0; i<missingTargets.size(); ++i) { - 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 \\\"" - << missingTargets[i] << "\\\" not found ! \")\n" - << " ENDIF()\n" - << "ENDIF()\n"; + 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 " + << "\"Required imported target \\\"" << missingTargets[i] + << "\\\" not found ! \")\n" + << " ELSE()\n" + << " MESSAGE(FATAL_ERROR \"Required imported target \\\"" + << missingTargets[i] << "\\\" not found ! \")\n" + << " ENDIF()\n" + << "ENDIF()\n"; + } } os << "\n"; } diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h index 7c58ad8..eb3f3c3 100644 --- a/Source/cmExportFileGenerator.h +++ b/Source/cmExportFileGenerator.h @@ -47,7 +47,8 @@ protected: // Generate per-configuration target information to the given output // stream. - void GenerateImportConfig(std::ostream& os, const char* config); + void GenerateImportConfig(std::ostream& os, const char* config, + std::vector<std::string> &missingTargets); // Methods to implement export file code generation. void GenerateImportHeaderCode(std::ostream& os, const char* config = 0); @@ -85,7 +86,8 @@ protected: /** Each subclass knows where the target files are located. */ virtual void GenerateImportTargetsConfig(std::ostream& os, const char* config, - std::string const& suffix) = 0; + std::string const& suffix, + std::vector<std::string> &missingTargets) = 0; /** Each subclass knows how to deal with a target that is missing from an * export set. */ @@ -99,12 +101,25 @@ protected: cmGeneratorExpression::PreprocessContext, ImportPropertyMap &properties, std::vector<std::string> &missingTargets); + void PopulateInterfaceProperty(const char *propName, cmTarget *target, + ImportPropertyMap &properties); void GenerateInterfaceProperties(cmTarget *target, std::ostream& os, const ImportPropertyMap &properties); + void SetImportLinkInterface(const char* config, std::string const& suffix, + cmGeneratorExpression::PreprocessContext preprocessRule, + cmTarget* target, ImportPropertyMap& properties, + std::vector<std::string>& missingTargets); + + enum FreeTargetsReplace { + ReplaceFreeTargets, + NoReplaceFreeTargets + }; + void ResolveTargetsInGeneratorExpressions(std::string &input, - cmTarget* target, - std::vector<std::string> &missingTargets); + cmTarget* target, + std::vector<std::string> &missingTargets, + FreeTargetsReplace replace = NoReplaceFreeTargets); // The namespace in which the exports are placed in the generated file. std::string Namespace; @@ -128,6 +143,13 @@ private: cmGeneratorExpression::PreprocessContext, ImportPropertyMap &properties, std::vector<std::string> &missingTargets); + + bool AddTargetNamespace(std::string &input, cmTarget* target, + std::vector<std::string> &missingTargets); + + void ResolveTargetsInGeneratorExpression(std::string &input, + cmTarget* target, + std::vector<std::string> &missingTargets); }; #endif diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index bc953c9..965f63d 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -89,11 +89,12 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) te, cmGeneratorExpression::InstallInterface, properties, missingTargets); + this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE", + te, properties); this->GenerateInterfaceProperties(te, os, properties); } - this->GenerateMissingTargetsCheckCode(os, missingTargets); // Now load per-configuration properties for them. os << "# Load information for each installed configuration.\n" @@ -105,23 +106,29 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) << "ENDFOREACH(f)\n" << "\n"; + this->GenerateImportedFileCheckLoop(os); + // Generate an import file for each configuration. bool result = true; for(std::vector<std::string>::const_iterator ci = this->Configurations.begin(); ci != this->Configurations.end(); ++ci) { - if(!this->GenerateImportFileConfig(ci->c_str())) + if(!this->GenerateImportFileConfig(ci->c_str(), missingTargets)) { result = false; } } + + this->GenerateMissingTargetsCheckCode(os, missingTargets); + return result; } //---------------------------------------------------------------------------- bool -cmExportInstallFileGenerator::GenerateImportFileConfig(const char* config) +cmExportInstallFileGenerator::GenerateImportFileConfig(const char* config, + std::vector<std::string> &missingTargets) { // Skip configurations not enabled for this export. if(!this->IEGen->InstallsForConfig(config)) @@ -161,7 +168,7 @@ cmExportInstallFileGenerator::GenerateImportFileConfig(const char* config) this->GenerateImportHeaderCode(os, config); // Generate the per-config target information. - this->GenerateImportConfig(os, config); + this->GenerateImportConfig(os, config, missingTargets); // End with the import file footer. this->GenerateImportFooterCode(os); @@ -176,7 +183,8 @@ cmExportInstallFileGenerator::GenerateImportFileConfig(const char* config) void cmExportInstallFileGenerator ::GenerateImportTargetsConfig(std::ostream& os, - const char* config, std::string const& suffix) + const char* config, std::string const& suffix, + std::vector<std::string> &missingTargets) { // Add code to compute the installation prefix relative to the // import file location. @@ -225,10 +233,13 @@ cmExportInstallFileGenerator if(!properties.empty()) { // Get the rest of the target details. - std::vector<std::string> missingTargets; this->SetImportDetailProperties(config, suffix, te->Target, properties, missingTargets); + this->SetImportLinkInterface(config, suffix, + cmGeneratorExpression::InstallInterface, + te->Target, properties, missingTargets); + // TOOD: PUBLIC_HEADER_LOCATION // This should wait until the build feature propagation stuff // is done. Then this can be a propagated include directory. @@ -236,15 +247,12 @@ cmExportInstallFileGenerator // properties); // Generate code in the export file. - this->GenerateMissingTargetsCheckCode(os, missingTargets); this->GenerateImportPropertyCode(os, config, te->Target, properties); this->GenerateImportedFileChecksCode(os, te->Target, properties, importedLocations); } } - this->GenerateImportedFileCheckLoop(os); - // Cleanup the import prefix variable. if(!this->ImportPrefix.empty()) { diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h index e719ecc..e187749 100644 --- a/Source/cmExportInstallFileGenerator.h +++ b/Source/cmExportInstallFileGenerator.h @@ -56,7 +56,8 @@ protected: virtual bool GenerateMainFile(std::ostream& os); virtual void GenerateImportTargetsConfig(std::ostream& os, const char* config, - std::string const& suffix); + std::string const& suffix, + std::vector<std::string> &missingTargets); virtual void HandleMissingTarget(std::string& link_libs, std::vector<std::string>& missingTargets, cmMakefile* mf, @@ -72,7 +73,8 @@ protected: /** Generate a per-configuration file for the targets. */ - bool GenerateImportFileConfig(const char* config); + bool GenerateImportFileConfig(const char* config, + std::vector<std::string> &missingTargets); /** Fill in properties indicating installed file locations. */ void SetImportLocationProperty(const char* config, diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index 4063697..78ae8f2 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -148,6 +148,38 @@ cmCompiledGeneratorExpression::~cmCompiledGeneratorExpression() } //---------------------------------------------------------------------------- +static std::string stripEmptyListElements(const std::string &input) +{ + std::string result; + + const char *c = input.c_str(); + bool skipSemiColons = true; + for ( ; *c; ++c) + { + if(c[0] == ';') + { + if(skipSemiColons) + { + continue; + } + skipSemiColons = true; + } + else + { + skipSemiColons = false; + } + result += *c; + } + + if (!result.empty() && *(result.end() - 1) == ';') + { + result.resize(result.size() - 1); + } + + return result; +} + +//---------------------------------------------------------------------------- static std::string stripAllGeneratorExpressions(const std::string &input) { std::string result; @@ -186,7 +218,7 @@ static std::string stripAllGeneratorExpressions(const std::string &input) lastPos = pos; } result += input.substr(lastPos); - return result; + return stripEmptyListElements(result); } //---------------------------------------------------------------------------- @@ -247,7 +279,68 @@ static std::string stripExportInterface(const std::string &input, } result += input.substr(lastPos); - return result; + return stripEmptyListElements(result); +} + +//---------------------------------------------------------------------------- +void cmGeneratorExpression::Split(const std::string &input, + std::vector<std::string> &output) +{ + std::string::size_type pos = 0; + std::string::size_type lastPos = pos; + while((pos = input.find("$<", lastPos)) != input.npos) + { + std::string part = input.substr(lastPos, pos - lastPos); + std::string preGenex; + if (!part.empty()) + { + std::string::size_type startPos = input.rfind(";", pos); + if (startPos != pos - 1 && startPos >= lastPos) + { + part = input.substr(lastPos, startPos - lastPos); + preGenex = input.substr(startPos + 1, pos - startPos - 1); + } + cmSystemTools::ExpandListArgument(part.c_str(), output); + } + pos += 2; + int nestingLevel = 1; + const char *c = input.c_str() + pos; + const char * const cStart = c; + for ( ; *c; ++c) + { + if(c[0] == '$' && c[1] == '<') + { + ++nestingLevel; + ++c; + continue; + } + if(c[0] == '>') + { + --nestingLevel; + if (nestingLevel == 0) + { + break; + } + } + } + for ( ; *c; ++c) + { + // Capture the part after the genex and before the next ';' + if(c[0] == ';') + { + --c; + break; + } + } + const std::string::size_type traversed = (c - cStart) + 1; + output.push_back(preGenex + "$<" + input.substr(pos, traversed)); + pos += traversed; + lastPos = pos; + } + if (lastPos < input.size()) + { + cmSystemTools::ExpandListArgument(input.substr(lastPos), output); + } } //---------------------------------------------------------------------------- diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h index b58dde5..8f1aef6 100644 --- a/Source/cmGeneratorExpression.h +++ b/Source/cmGeneratorExpression.h @@ -59,6 +59,9 @@ public: static std::string Preprocess(const std::string &input, PreprocessContext context); + static void Split(const std::string &input, + std::vector<std::string> &output); + private: cmGeneratorExpression(const cmGeneratorExpression &); void operator=(const cmGeneratorExpression &); diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index f4e4131..8e40815a 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -289,6 +289,22 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode } configurationTestNode; +static const struct TargetDefinedNode : public cmGeneratorExpressionNode +{ + TargetDefinedNode() {} + + virtual int NumExpectedParameters() const { return 1; } + + std::string Evaluate(const std::vector<std::string> ¶meters, + cmGeneratorExpressionContext *context, + const GeneratorExpressionContent *, + cmGeneratorExpressionDAGChecker *) const + { + return context->Makefile->FindTargetToUse(parameters.front().c_str()) + ? "1" : "0"; + } +} targetDefinedNode; + //---------------------------------------------------------------------------- static const char* targetPropertyTransitiveWhitelist[] = { "INTERFACE_INCLUDE_DIRECTORIES" @@ -702,6 +718,8 @@ cmGeneratorExpressionNode* GetNode(const std::string &identifier) return &buildInterfaceNode; else if (identifier == "INSTALL_INTERFACE") return &installInterfaceNode; + else if (identifier == "TARGET_DEFINED") + return &targetDefinedNode; return 0; } diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index b431705..8cd648b 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -941,19 +941,7 @@ void cmGlobalGenerator::Generate() for ( tit = targets->begin(); tit != targets->end(); ++ tit ) { - if (mf->IsOn("CMAKE_BUILD_INTERFACE_INCLUDES")) - { - const char *binDir = mf->GetStartOutputDirectory(); - const char *srcDir = mf->GetStartDirectory(); - const std::string dirs = std::string(binDir ? binDir : "") - + std::string(binDir ? ";" : "") - + std::string(srcDir ? srcDir : ""); - if (!dirs.empty()) - { - tit->second.AppendProperty("INTERFACE_INCLUDE_DIRECTORIES", - ("$<BUILD_INTERFACE:" + dirs + ">").c_str()); - } - } + tit->second.AppendBuildInterfaceIncludes(); } } diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 2cfb1bf..815da40 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -150,6 +150,7 @@ cmTarget::cmTarget() this->DLLPlatform = false; this->IsApple = false; this->IsImportedTarget = false; + this->BuildInterfaceIncludesAppended = false; } //---------------------------------------------------------------------------- @@ -892,6 +893,19 @@ void cmTarget::DefineProperties(cmake *cm) "requirement for their INTERFACE_POSITION_INDEPENDENT_CODE property."); cm->DefineProperty + ("COMPATIBLE_INTERFACE_BOOL", cmProperty::TARGET, + "Properties which must be compatible with their link interface", + "The COMPATIBLE_INTERFACE_BOOL property may contain a list of properties" + "for this target which must be consistent when evaluated as a boolean " + "in the INTERFACE of all linked dependencies. For example, if a " + "property \"FOO\" appears in the list, then the \"INTERFACE_FOO\" " + "property content in all dependencies must be consistent with each " + "other, and with the \"FOO\" property in this target. " + "Consistency in this sense has the meaning that if the property is set," + "then it must have the same boolean value as all others, and if the " + "property is not set, then it is ignored."); + + cm->DefineProperty ("POST_INSTALL_SCRIPT", cmProperty::TARGET, "Deprecated install support.", "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the " @@ -2233,6 +2247,14 @@ static std::string targetNameGenex(const char *lib) } //---------------------------------------------------------------------------- +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); +} + +//---------------------------------------------------------------------------- void cmTarget::AddLinkLibrary(cmMakefile& mf, const char *target, const char* lib, LinkLibraryType llt) @@ -2254,6 +2276,11 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf, llt).c_str()); } + if (isGeneratorExpression(lib)) + { + return; + } + cmTarget::LibraryID tmp; tmp.first = lib; tmp.second = llt; @@ -2655,6 +2682,30 @@ void cmTarget::AppendProperty(const char* prop, const char* value, } //---------------------------------------------------------------------------- +void cmTarget::AppendBuildInterfaceIncludes() +{ + if (this->BuildInterfaceIncludesAppended) + { + return; + } + this->BuildInterfaceIncludesAppended = true; + + if (this->Makefile->IsOn("CMAKE_BUILD_INTERFACE_INCLUDES")) + { + const char *binDir = this->Makefile->GetStartOutputDirectory(); + const char *srcDir = this->Makefile->GetStartDirectory(); + const std::string dirs = std::string(binDir ? binDir : "") + + std::string(binDir ? ";" : "") + + std::string(srcDir ? srcDir : ""); + if (!dirs.empty()) + { + this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES", + ("$<BUILD_INTERFACE:" + dirs + ">").c_str()); + } + } +} + +//---------------------------------------------------------------------------- void cmTarget::InsertInclude(const cmMakefileIncludeDirectoriesEntry &entry, bool before) { @@ -4896,16 +4947,30 @@ void cmTarget::ComputeImportInfo(std::string const& desired_config, { std::string linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES"; linkProp += suffix; - if(const char* config_libs = this->GetProperty(linkProp.c_str())) + + const char *propertyLibs = this->GetProperty(linkProp.c_str()); + + if(!propertyLibs) { - cmSystemTools::ExpandListArgument(config_libs, - info.LinkInterface.Libraries); + linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES"; + propertyLibs = this->GetProperty(linkProp.c_str()); } - else if(const char* libs = - this->GetProperty("IMPORTED_LINK_INTERFACE_LIBRARIES")) + if(propertyLibs) { - cmSystemTools::ExpandListArgument(libs, - info.LinkInterface.Libraries); + cmListFileBacktrace lfbt; + cmGeneratorExpression ge(lfbt); + + cmGeneratorExpressionDAGChecker dagChecker(lfbt, + this->GetName(), + linkProp, 0, 0); + cmSystemTools::ExpandListArgument(ge.Parse(propertyLibs) + ->Evaluate(this->Makefile, + desired_config.c_str(), + false, + headTarget, + this, + &dagChecker), + info.LinkInterface.Libraries); } } @@ -5019,18 +5084,20 @@ bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface, // An explicit list of interface libraries may be set for shared // libraries and executables that export symbols. const char* explicitLibraries = 0; + std::string linkIfaceProp; if(this->GetType() == cmTarget::SHARED_LIBRARY || this->IsExecutableWithExports()) { // Lookup the per-configuration property. - std::string propName = "LINK_INTERFACE_LIBRARIES"; - propName += suffix; - explicitLibraries = this->GetProperty(propName.c_str()); + linkIfaceProp = "LINK_INTERFACE_LIBRARIES"; + linkIfaceProp += suffix; + explicitLibraries = this->GetProperty(linkIfaceProp.c_str()); // If not set, try the generic property. if(!explicitLibraries) { - explicitLibraries = this->GetProperty("LINK_INTERFACE_LIBRARIES"); + linkIfaceProp = "LINK_INTERFACE_LIBRARIES"; + explicitLibraries = this->GetProperty(linkIfaceProp.c_str()); } } @@ -5048,7 +5115,16 @@ bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface, if(explicitLibraries) { // The interface libraries have been explicitly set. - cmSystemTools::ExpandListArgument(explicitLibraries, iface.Libraries); + cmListFileBacktrace lfbt; + cmGeneratorExpression ge(lfbt); + cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(), + linkIfaceProp, 0, 0); + cmSystemTools::ExpandListArgument(ge.Parse(explicitLibraries)->Evaluate( + this->Makefile, + config, + false, + headTarget, + this, &dagChecker), iface.Libraries); if(this->GetType() == cmTarget::SHARED_LIBRARY) { @@ -5091,6 +5167,7 @@ bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface, // The link implementation is the default link interface. LinkImplementation const* impl = this->GetLinkImplementation(config, headTarget); + iface.ImplementationIsInterface = true; iface.Libraries = impl->Libraries; iface.WrongConfigLibraries = impl->WrongConfigLibraries; if(this->GetType() == cmTarget::STATIC_LIBRARY) @@ -5273,6 +5350,58 @@ std::string cmTarget::CheckCMP0004(std::string const& item) } //---------------------------------------------------------------------------- +void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info, + const char* config) +{ + const cmComputeLinkInformation::ItemVector &deps = info->GetItems(); + + std::set<cmStdString> emitted; + + for(cmComputeLinkInformation::ItemVector::const_iterator li = + deps.begin(); + li != deps.end(); ++li) + { + if (!li->Target) + { + continue; + } + const char *prop = li->Target->GetProperty("COMPATIBLE_INTERFACE_BOOL"); + 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 (this->Makefile->GetCMakeInstance() + ->GetIsPropertyDefined(pi->c_str(), + cmProperty::TARGET)) + { + cmOStringStream e; + e << "Target \"" << li->Target->GetName() << "\" has property \"" + << *pi << "\" listed in its COMPATIBLE_INTERFACE_BOOL property. " + "This is not allowed. Only user-defined properties may appear " + "listed in the COMPATIBLE_INTERFACE_BOOL property."; + this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + return; + } + if(emitted.insert(*pi).second) + { + this->GetLinkInterfaceDependentBoolProperty(*pi, config); + if (cmSystemTools::GetErrorOccuredFlag()) + { + return; + } + } + } + } +} + +//---------------------------------------------------------------------------- cmComputeLinkInformation* cmTarget::GetLinkInformation(const char* config, cmTarget *head) { @@ -5293,6 +5422,11 @@ cmTarget::GetLinkInformation(const char* config, cmTarget *head) info = 0; } + if (info) + { + this->CheckPropertyCompatibility(info, config); + } + // Store the information for this configuration. cmTargetLinkInformationMap::value_type entry(key, info); i = this->LinkInformation.insert(entry).first; diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 1188a6a..69a00c1 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -258,7 +258,9 @@ public: // Needed only for OLD behavior of CMP0003. std::vector<std::string> WrongConfigLibraries; - LinkInterface(): Multiplicity(0) {} + bool ImplementationIsInterface; + + LinkInterface(): Multiplicity(0), ImplementationIsInterface(false) {} }; /** Get the link interface for the given configuration. Returns 0 @@ -488,6 +490,8 @@ public: void InsertInclude(const cmMakefileIncludeDirectoriesEntry &entry, bool before = false); + void AppendBuildInterfaceIncludes(); + void GetLinkDependentTargetsForProperty(const std::string &p, std::set<std::string> &targets); bool IsNullImpliedByLinkLibraries(const std::string &p); @@ -609,6 +613,7 @@ private: mutable std::map<cmStdString, std::set<std::string> > LinkDependentProperties; mutable std::set<std::string> LinkImplicitNullProperties; + bool BuildInterfaceIncludesAppended; // Cache target output paths for each configuration. struct OutputInfo; @@ -624,6 +629,8 @@ private: cmTarget *head); cmTargetLinkInformationMap LinkInformation; + void CheckPropertyCompatibility(cmComputeLinkInformation *info, + const char* config); bool ComputeLinkInterface(const char* config, LinkInterface& iface, cmTarget *head); diff --git a/Source/cmTargetCompileDefinitionsCommand.h b/Source/cmTargetCompileDefinitionsCommand.h index 707610e..4b066b7a 100644 --- a/Source/cmTargetCompileDefinitionsCommand.h +++ b/Source/cmTargetCompileDefinitionsCommand.h @@ -69,6 +69,9 @@ public: "INTERFACE_COMPILE_DEFINITIONS from. " "Repeated calls for the same <target> append items in the order called." "\n" + "Arguments to target_compile_definitions may use \"generator " + "expressions\" with the syntax \"$<...>\". " + CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS ; } diff --git a/Source/cmTargetIncludeDirectoriesCommand.h b/Source/cmTargetIncludeDirectoriesCommand.h index c1957d6..90e039c 100644 --- a/Source/cmTargetIncludeDirectoriesCommand.h +++ b/Source/cmTargetIncludeDirectoriesCommand.h @@ -73,6 +73,9 @@ public: "directories must be absolute paths, not relative paths. " "Repeated calls for the same <target> append items in the order called." "\n" + "Arguments to target_include_directories may use \"generator " + "expressions\" with the syntax \"$<...>\". " + CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS ; } diff --git a/Source/cmTargetLinkLibrariesCommand.h b/Source/cmTargetLinkLibrariesCommand.h index 8e5823c..34fe54c 100644 --- a/Source/cmTargetLinkLibrariesCommand.h +++ b/Source/cmTargetLinkLibrariesCommand.h @@ -13,6 +13,7 @@ #define cmTargetLinkLibrariesCommand_h #include "cmCommand.h" +#include "cmDocumentGeneratorExpressions.h" /** \class cmTargetLinkLibrariesCommand * \brief Specify a list of libraries to link into executables. @@ -141,6 +142,12 @@ public: "However, if two archives are really so interdependent they should " "probably be combined into a single archive." ")" + "\n" + "Arguments to target_link_libraries may use \"generator expressions\" " + "with the syntax \"$<...>\". Note however, that generator expressions " + "will not be used in OLD handling of CMP0003 or CMP0004." + "\n" + CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS ; } diff --git a/Source/cmTargetPropCommandBase.h b/Source/cmTargetPropCommandBase.h index 90e3bbb..e757f9d 100644 --- a/Source/cmTargetPropCommandBase.h +++ b/Source/cmTargetPropCommandBase.h @@ -14,6 +14,7 @@ #define cmTargetPropCommandBase_h #include "cmCommand.h" +#include "cmDocumentGeneratorExpressions.h" class cmTarget; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index a44c825..2eecfba 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -3299,6 +3299,12 @@ int cmake::ExecuteLinkScript(std::vector<std::string>& args) int result = 0; while(result == 0 && cmSystemTools::GetLineFromStream(fin, command)) { + // Skip empty command lines. + if(command.find_first_not_of(" \t") == command.npos) + { + continue; + } + // Setup this command line. const char* cmd[2] = {command.c_str(), 0}; cmsysProcess_SetCommand(cp, cmd); @@ -3552,6 +3558,13 @@ void cmake::DefineProperty(const char *name, cmProperty::ScopeType scope, chained); } +bool cmake::GetIsPropertyDefined(const char *name, + cmProperty::ScopeType scope) +{ + return this->PropertyDefinitions[scope].find(name) != + this->PropertyDefinitions[scope].end(); +} + cmPropertyDefinition *cmake ::GetPropertyDefinition(const char *name, cmProperty::ScopeType scope) diff --git a/Source/cmake.h b/Source/cmake.h index e5aa076..f6fe0d6 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -341,6 +341,8 @@ class cmake bool chain = false, const char *variableGroup = 0); + bool GetIsPropertyDefined(const char *name, cmProperty::ScopeType scope); + // get property definition cmPropertyDefinition *GetPropertyDefinition (const char *name, cmProperty::ScopeType scope); diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt index 6bfcab0..124b8ac 100644 --- a/Source/kwsys/CMakeLists.txt +++ b/Source/kwsys/CMakeLists.txt @@ -574,6 +574,8 @@ IF(KWSYS_USE_SystemTools) ENDIF() IF(KWSYS_USE_SystemInformation) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS SIZEOF_VOID_P=${CMAKE_SIZEOF_VOID_P}) IF(NOT CYGWIN) INCLUDE(CheckIncludeFiles) CHECK_INCLUDE_FILES("sys/types.h;ifaddrs.h" KWSYS_SYS_HAS_IFADDRS_H) @@ -603,6 +605,13 @@ IF(KWSYS_USE_SystemInformation) COMPILE_DEFINITIONS KWSYS_SYS_HAS_MPCTL_H=1) ENDIF() ENDIF() + IF(CMAKE_SYSTEM MATCHES "BSD") + CHECK_INCLUDE_FILES("machine/cpu.h" KWSYS_SYS_HAS_MACHINE_CPU_H) + IF(KWSYS_SYS_HAS_MACHINE_CPU_H) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_SYS_HAS_MACHINE_CPU_H=1) + ENDIF() + ENDIF() IF(KWSYS_LFS_AVAILABLE AND NOT KWSYS_LFS_DISABLE) SET(KWSYS_PLATFORM_CXX_TEST_DEFINES -DKWSYS_HAS_LFS=1) ENDIF() @@ -631,6 +640,20 @@ IF(KWSYS_USE_SystemInformation) SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY COMPILE_DEFINITIONS KWSYS_CXX_HAS__ATOI64=1) ENDIF() + IF(BORLAND) + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BORLAND_ASM + "Checking whether Borland CXX compiler supports assembler instructions" DIRECT) + IF(KWSYS_CXX_HAS_BORLAND_ASM) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_CXX_HAS_BORLAND_ASM=1) + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BORLAND_ASM_CPUID + "Checking whether Borland CXX compiler supports CPUID assembler instruction" DIRECT) + IF(KWSYS_CXX_HAS_BORLAND_ASM_CPUID) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_CXX_HAS_BORLAND_ASM_CPUID=1) + ENDIF() + ENDIF() + ENDIF() IF(KWSYS_USE___INT64) SET_PROPERTY(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY COMPILE_DEFINITIONS KWSYS_USE___INT64=1) diff --git a/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c index 83838af..2db1254 100644 --- a/Source/kwsys/ProcessUNIX.c +++ b/Source/kwsys/ProcessUNIX.c @@ -418,9 +418,10 @@ int kwsysProcess_AddCommand(kwsysProcess* cp, char const* const* command) parse it. */ newCommands[cp->NumberOfCommands] = kwsysSystem_Parse_CommandForUnix(*command, 0); - if(!newCommands[cp->NumberOfCommands]) + if(!newCommands[cp->NumberOfCommands] || + !newCommands[cp->NumberOfCommands][0]) { - /* Out of memory. */ + /* Out of memory or no command parsed. */ free(newCommands); return 0; } diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx index 0460b29..b20d724 100644 --- a/Source/kwsys/SystemInformation.cxx +++ b/Source/kwsys/SystemInformation.cxx @@ -91,6 +91,10 @@ typedef int siginfo_t; # include <sys/sysctl.h> #endif +#if defined(KWSYS_SYS_HAS_MACHINE_CPU_H) +# include <machine/cpu.h> +#endif + #if defined(__DragonFly__) # include <sys/sysctl.h> #endif @@ -198,7 +202,7 @@ typedef struct rlimit ResourceLimitType; #define USE_CPUID_INTRINSICS 0 #endif -#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS +#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS || defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID) # define USE_CPUID 1 #else # define USE_CPUID 0 @@ -220,6 +224,7 @@ static bool call_cpuid(int select, int result[4]) return true; #else int tmp[4]; +#if defined(_MSC_VER) // Use SEH to determine CPUID presence __try { _asm { @@ -258,7 +263,24 @@ static bool call_cpuid(int select, int result[4]) return false; } - memcpy(result, tmp, sizeof(tmp)); + memcpy(result, tmp, sizeof(tmp)); +#elif defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID) + unsigned int a, b, c, d; + __asm { + mov EAX, select; + cpuid + mov a, EAX; + mov b, EBX; + mov c, ECX; + mov d, EDX; + } + + result[0] = a; + result[1] = b; + result[2] = c; + result[3] = d; +#endif + // The cpuid instruction succeeded. return true; #endif @@ -428,7 +450,7 @@ protected: int CPUCount(); unsigned char LogicalCPUPerPhysicalCPU(); unsigned char GetAPICId(); - unsigned int IsHyperThreadingSupported(); + bool IsHyperThreadingSupported(); static LongLong GetCyclesDifference(DELAY_FUNC, unsigned int); // For Linux and Cygwin, /proc/cpuinfo formats are slightly different @@ -452,7 +474,8 @@ protected: kwsys_stl::string SysCtlBuffer; // For Solaris - bool QuerySolarisInfo(); + bool QuerySolarisMemory(); + bool QuerySolarisProcessor(); kwsys_stl::string ParseValueFromKStat(const char* arguments); kwsys_stl::string RunProcess(kwsys_stl::vector<const char*> args); @@ -477,9 +500,11 @@ protected: //For AIX bool QueryAIXMemory(); + bool QueryProcessorBySysconf(); bool QueryProcessor(); // Evaluate the memory information. + bool QueryMemoryBySysconf(); bool QueryMemory(); size_t TotalVirtualMemory; size_t AvailableVirtualMemory; @@ -1283,7 +1308,7 @@ void SystemInformationImplementation::RunCPUCheck() #elif defined(__APPLE__) this->ParseSysCtl(); #elif defined (__SVR4) && defined (__sun) - this->QuerySolarisInfo(); + this->QuerySolarisProcessor(); #elif defined(__HAIKU__) this->QueryHaikuInfo(); #elif defined(__QNX__) @@ -1309,7 +1334,7 @@ void SystemInformationImplementation::RunMemoryCheck() #if defined(__APPLE__) this->ParseSysCtl(); #elif defined (__SVR4) && defined (__sun) - this->QuerySolarisInfo(); + this->QuerySolarisMemory(); #elif defined(__HAIKU__) this->QueryHaikuInfo(); #elif defined(__QNX__) @@ -3012,7 +3037,7 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile() return true; } -bool SystemInformationImplementation::QueryProcessor() +bool SystemInformationImplementation::QueryProcessorBySysconf() { #if defined(_SC_NPROC_ONLN) && !defined(_SC_NPROCESSORS_ONLN) // IRIX names this slightly different @@ -3026,7 +3051,7 @@ bool SystemInformationImplementation::QueryProcessor() return false; } - this->NumberOfPhysicalCPU = c; + this->NumberOfPhysicalCPU = static_cast<unsigned int>(c); this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU; return true; @@ -3035,6 +3060,11 @@ bool SystemInformationImplementation::QueryProcessor() #endif } +bool SystemInformationImplementation::QueryProcessor() +{ + return this->QueryProcessorBySysconf(); +} + /** Get total system RAM in units of KiB. */ @@ -3555,8 +3585,7 @@ bool SystemInformationImplementation::QueryAIXMemory() #endif } -/** Query for the memory status */ -bool SystemInformationImplementation::QueryMemory() +bool SystemInformationImplementation::QueryMemoryBySysconf() { #if defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE) // Assume the mmap() granularity as returned by _SC_PAGESIZE is also @@ -3593,6 +3622,12 @@ bool SystemInformationImplementation::QueryMemory() #endif } +/** Query for the memory status */ +bool SystemInformationImplementation::QueryMemory() +{ + return this->QueryMemoryBySysconf(); +} + /** */ size_t SystemInformationImplementation::GetTotalVirtualMemory() { @@ -3725,8 +3760,13 @@ unsigned char SystemInformationImplementation::LogicalCPUPerPhysicalCPU(void) /** Works only for windows */ -unsigned int SystemInformationImplementation::IsHyperThreadingSupported() +bool SystemInformationImplementation::IsHyperThreadingSupported() { + if (this->Features.ExtendedFeatures.SupportsHyperthreading) + { + return true; + } + #if USE_CPUID int Regs[4] = { 0, 0, 0, 0 }, VendorId[4] = { 0, 0, 0, 0 }; @@ -3744,13 +3784,15 @@ unsigned int SystemInformationImplementation::IsHyperThreadingSupported() if (((Regs[0] & FAMILY_ID) == PENTIUM4_ID) || (Regs[0] & EXT_FAMILY_ID)) { - if (VendorId[1] == 'uneG') + if (VendorId[1] == 0x756e6547) // 'uneG' { - if (VendorId[3] == 'Ieni') + if (VendorId[3] == 0x49656e69) // 'Ieni' { - if (VendorId[2] == 'letn') + if (VendorId[2] == 0x6c65746e) // 'letn' { - return(Regs[3] & HT_BIT); // Genuine Intel with hyper-Threading technology + // Genuine Intel with hyper-Threading technology + this->Features.ExtendedFeatures.SupportsHyperthreading = ((Regs[3] & HT_BIT) != 0); + return this->Features.ExtendedFeatures.SupportsHyperthreading; } } } @@ -4000,6 +4042,81 @@ bool SystemInformationImplementation::ParseSysCtl() len = sizeof(value); err = sysctlbyname("machdep.cpu.model", &value, &len, NULL, 0); this->ChipID.Model = static_cast< int >( value ); + + // Chip Stepping + len = sizeof(value); + value = 0; + err = sysctlbyname("machdep.cpu.stepping", &value, &len, NULL, 0); + if (!err) + { + this->ChipID.Revision = static_cast< int >( value ); + } + + // feature string + char *buf = 0; + size_t allocSize = 128; + + err = 0; + len = 0; + + // sysctlbyname() will return with err==0 && len==0 if the buffer is too small + while (err == 0 && len == 0) + { + delete[] buf; + allocSize *= 2; + buf = new char[allocSize]; + if (!buf) + { + break; + } + buf[0] = ' '; + len = allocSize - 2; // keep space for leading and trailing space + err = sysctlbyname("machdep.cpu.features", buf + 1, &len, NULL, 0); + } + if (!err && buf && len) + { + // now we can match every flags as space + flag + space + buf[len + 1] = ' '; + kwsys_stl::string cpuflags(buf, len + 2); + + if ((cpuflags.find(" FPU ")!=kwsys_stl::string::npos)) + { + this->Features.HasFPU = true; + } + if ((cpuflags.find(" TSC ")!=kwsys_stl::string::npos)) + { + this->Features.HasTSC = true; + } + if ((cpuflags.find(" MMX ")!=kwsys_stl::string::npos)) + { + this->Features.HasMMX = true; + } + if ((cpuflags.find(" SSE ")!=kwsys_stl::string::npos)) + { + this->Features.HasSSE = true; + } + if ((cpuflags.find(" SSE2 ")!=kwsys_stl::string::npos)) + { + this->Features.HasSSE2 = true; + } + if ((cpuflags.find(" APIC ")!=kwsys_stl::string::npos)) + { + this->Features.HasAPIC = true; + } + if ((cpuflags.find(" CMOV ")!=kwsys_stl::string::npos)) + { + this->Features.HasCMOV = true; + } + if ((cpuflags.find(" MTRR ")!=kwsys_stl::string::npos)) + { + this->Features.HasMTRR = true; + } + if ((cpuflags.find(" ACPI ")!=kwsys_stl::string::npos)) + { + this->Features.HasACPI = true; + } + } + delete[] buf; } // brand string @@ -4059,13 +4176,12 @@ kwsys_stl::string SystemInformationImplementation::RunProcess(kwsys_stl::vector< char* data = NULL; int length; double timeout = 255; + int pipe; // pipe id as returned by kwsysProcess_WaitForData() - while(kwsysProcess_WaitForData(gp,&data,&length,&timeout)) // wait for 1s + while( ( pipe = kwsysProcess_WaitForData(gp,&data,&length,&timeout), + (pipe == kwsysProcess_Pipe_STDOUT || pipe == kwsysProcess_Pipe_STDERR) ) ) // wait for 1s { - for(int i=0;i<length;i++) - { - buffer += data[i]; - } + buffer.append(data, length); } kwsysProcess_WaitForExit(gp, 0); @@ -4173,16 +4289,40 @@ kwsys_stl::string SystemInformationImplementation::ParseValueFromKStat(const cha return value; } - /** Querying for system information from Solaris */ -bool SystemInformationImplementation::QuerySolarisInfo() +bool SystemInformationImplementation::QuerySolarisMemory() { - // Parse values - this->NumberOfPhysicalCPU = static_cast<unsigned int>( - atoi(this->ParseValueFromKStat("-n syste_misc -s ncpus").c_str())); - this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU; - this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = 1; +#if defined (__SVR4) && defined (__sun) + // Solaris allows querying this value by sysconf, but if this is + // a 32 bit process on a 64 bit host the returned memory will be + // limited to 4GiB. So if this is a 32 bit process or if the sysconf + // method fails use the kstat interface. +#if SIZEOF_VOID_P == 8 + if (this->QueryMemoryBySysconf()) + { + return true; + } +#endif + + char* tail; + unsigned long totalMemory = + strtoul(this->ParseValueFromKStat("-s physmem").c_str(),&tail,0); + this->TotalPhysicalMemory = totalMemory/128; + + return true; +#else + return false; +#endif +} +bool SystemInformationImplementation::QuerySolarisProcessor() +{ + if (!this->QueryProcessorBySysconf()) + { + return false; + } + + // Parse values this->CPUSpeedInMHz = static_cast<float>(atoi(this->ParseValueFromKStat("-s clock_MHz").c_str())); // Chip family @@ -4199,20 +4339,6 @@ bool SystemInformationImplementation::QuerySolarisInfo() this->FindManufacturer(); } - // Cache size - this->Features.L1CacheSize = 0; - this->Features.L2CacheSize = 0; - - char* tail; - unsigned long totalMemory = - strtoul(this->ParseValueFromKStat("-s physmem").c_str(),&tail,0); - this->TotalPhysicalMemory = totalMemory/128; - - // Undefined values (for now at least) - this->TotalVirtualMemory = 0; - this->AvailablePhysicalMemory = 0; - this->AvailableVirtualMemory = 0; - return true; } @@ -4424,6 +4550,45 @@ bool SystemInformationImplementation::QueryBSDProcessor() this->CPUSpeedInMHz = (float) k; #endif +#if defined(CPU_SSE) + ctrl[0] = CTL_MACHDEP; + ctrl[1] = CPU_SSE; + + if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0) + { + return false; + } + + this->Features.HasSSE = (k > 0); +#endif + +#if defined(CPU_SSE2) + ctrl[0] = CTL_MACHDEP; + ctrl[1] = CPU_SSE2; + + if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0) + { + return false; + } + + this->Features.HasSSE2 = (k > 0); +#endif + +#if defined(CPU_CPUVENDOR) + ctrl[0] = CTL_MACHDEP; + ctrl[1] = CPU_CPUVENDOR; + char vbuf[25]; + ::memset(vbuf, 0, sizeof(vbuf)); + sz = sizeof(vbuf) - 1; + if (sysctl(ctrl, 2, vbuf, &sz, NULL, 0) != 0) + { + return false; + } + + this->ChipID.Vendor = vbuf; + this->FindManufacturer(); +#endif + return true; #else return false; diff --git a/Source/kwsys/kwsysPlatformTestsCXX.cxx b/Source/kwsys/kwsysPlatformTestsCXX.cxx index ae58703..48976c4 100644 --- a/Source/kwsys/kwsysPlatformTestsCXX.cxx +++ b/Source/kwsys/kwsysPlatformTestsCXX.cxx @@ -580,3 +580,30 @@ int main() } } #endif + +#ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM +int main() +{ + int a = 1; + __asm { + xor EBX, EBX; + mov a, EBX; + } + + return a; +} +#endif + +#ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM_CPUID +int main() +{ + int a = 0; + __asm { + xor EAX, EAX; + cpuid; + mov a, EAX; + } + + return a; +} +#endif diff --git a/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt b/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt index 84a23ef..a37c597 100644 --- a/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt +++ b/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt @@ -23,4 +23,6 @@ add_executable(consumer target_compile_definitions(consumer PRIVATE target_compile_definitions importedlib + $<$<TARGET_DEFINED:notdefined>:SHOULD_NOT_BE_DEFINED> + $<$<TARGET_DEFINED:importedlib>:SHOULD_BE_DEFINED> ) diff --git a/Tests/CMakeCommands/target_compile_definitions/consumer.cpp b/Tests/CMakeCommands/target_compile_definitions/consumer.cpp index e3788dd..1ef657d 100644 --- a/Tests/CMakeCommands/target_compile_definitions/consumer.cpp +++ b/Tests/CMakeCommands/target_compile_definitions/consumer.cpp @@ -15,4 +15,12 @@ #error Expected MY_IMPORTEDINTERFACE_DEFINE #endif +#ifdef SHOULD_NOT_BE_DEFINED +#error Unexpected SHOULD_NOT_BE_DEFINED +#endif + +#ifndef SHOULD_BE_DEFINED +#error Expected SHOULD_BE_DEFINED +#endif + int main() { return 0; } diff --git a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt index 746d30c..1551c50 100644 --- a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt +++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt @@ -80,3 +80,13 @@ assert_property(targetA LINK_INTERFACE_LIBRARIES "") add_library(depIfaceOnly SHARED EXCLUDE_FROM_ALL depIfaceOnly.cpp) generate_export_header(depIfaceOnly) set_property(TARGET depB APPEND PROPERTY LINK_INTERFACE_LIBRARIES depIfaceOnly) + +add_library(depD SHARED depD.cpp) +generate_export_header(depD) +set_property(TARGET depD APPEND PROPERTY + LINK_INTERFACE_LIBRARIES + $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:depA> +) + +add_executable(targetB targetB.cpp) +target_link_libraries(targetB depD) diff --git a/Tests/CMakeCommands/target_link_libraries/depD.cpp b/Tests/CMakeCommands/target_link_libraries/depD.cpp new file mode 100644 index 0000000..b02c76c --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/depD.cpp @@ -0,0 +1,13 @@ + +#include "depD.h" + +int DepD::foo() +{ + return 0; +} + +DepA DepD::getA() +{ + DepA a; + return a; +} diff --git a/Tests/CMakeCommands/target_link_libraries/depD.h b/Tests/CMakeCommands/target_link_libraries/depD.h new file mode 100644 index 0000000..d24ff5f --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/depD.h @@ -0,0 +1,11 @@ + +#include "depd_export.h" + +#include "depA.h" + +struct DEPD_EXPORT DepD +{ + int foo(); + + DepA getA(); +}; diff --git a/Tests/CMakeCommands/target_link_libraries/targetB.cpp b/Tests/CMakeCommands/target_link_libraries/targetB.cpp new file mode 100644 index 0000000..063d63a --- /dev/null +++ b/Tests/CMakeCommands/target_link_libraries/targetB.cpp @@ -0,0 +1,10 @@ + +#include "depD.h" + +int main(int argc, char **argv) +{ + DepD d; + DepA a = d.getA(); + + return d.foo() + a.foo(); +} diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt index 569845a..dd615d1 100644 --- a/Tests/ExportImport/Export/CMakeLists.txt +++ b/Tests/ExportImport/Export/CMakeLists.txt @@ -158,6 +158,40 @@ set_property(TARGET testLibRequired APPEND PROPERTY $<INSTALL_INTERFACE:InstallOnly_DEFINE> ) +include(GenerateExportHeader) + +add_library(testSharedLibRequired SHARED testSharedLibRequired.cpp) +generate_export_header(testSharedLibRequired) +set_property(TARGET testSharedLibRequired + PROPERTY + INTERFACE_POSITION_INDEPENDENT_CODE ON +) +set_property(TARGET testSharedLibRequired APPEND PROPERTY + INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}" +) +set_property(TARGET testSharedLibRequired APPEND PROPERTY + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}" +) + +add_library(testSharedLibDepends SHARED testSharedLibDepends.cpp) +set_property(TARGET testSharedLibDepends APPEND PROPERTY + INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}" +) +generate_export_header(testSharedLibDepends) + +set_property(TARGET testSharedLibDepends APPEND PROPERTY + INTERFACE_INCLUDE_DIRECTORIES + $<TARGET_PROPERTY:testSharedLibRequired,INTERFACE_INCLUDE_DIRECTORIES> +) +set_property(TARGET testSharedLibDepends APPEND PROPERTY + LINK_INTERFACE_LIBRARIES + $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:$<TARGET_NAME:testSharedLibRequired>> +) + +# LINK_PRIVATE because the LINK_INTERFACE_LIBRARIES is specified above. +target_link_libraries(testSharedLibDepends LINK_PRIVATE testSharedLibRequired) + install(TARGETS testLibRequired testLibIncludeRequired1 testLibIncludeRequired2 @@ -165,10 +199,11 @@ install(TARGETS testLibRequired testLibIncludeRequired4 testLibIncludeRequired5 testLibIncludeRequired6 + testSharedLibRequired EXPORT RequiredExp DESTINATION lib ) install(EXPORT RequiredExp NAMESPACE Req:: FILE testLibRequiredConfig.cmake DESTINATION lib/cmake/testLibRequired) -install(TARGETS testLibDepends EXPORT DependsExp DESTINATION lib ) +install(TARGETS testLibDepends testSharedLibDepends EXPORT DependsExp DESTINATION lib ) install(EXPORT DependsExp FILE testLibDependsConfig.cmake DESTINATION lib/cmake/testLibDepends) @@ -216,9 +251,12 @@ if(WIN32) install(TARGETS testLib5 RUNTIME DESTINATION bin) endif() +add_subdirectory(sublib) # For CMAKE_BUILD_INTERFACE_INCLUDES test. + # Export from build tree. export(TARGETS testExe1 testLib1 testLib2 testLib3 - testExe2libImp testLib3Imp testLib3ImpDep + testExe2libImp testLib3Imp testLib3ImpDep subdirlib + testSharedLibRequired testSharedLibDepends NAMESPACE bld_ FILE ExportBuildTree.cmake ) diff --git a/Tests/ExportImport/Export/sublib/CMakeLists.txt b/Tests/ExportImport/Export/sublib/CMakeLists.txt new file mode 100644 index 0000000..2d11040 --- /dev/null +++ b/Tests/ExportImport/Export/sublib/CMakeLists.txt @@ -0,0 +1,6 @@ + +set(CMAKE_BUILD_INTERFACE_INCLUDES ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +add_library(subdirlib SHARED subdir.cpp) +generate_export_header(subdirlib) diff --git a/Tests/ExportImport/Export/sublib/subdir.cpp b/Tests/ExportImport/Export/sublib/subdir.cpp new file mode 100644 index 0000000..35b0743 --- /dev/null +++ b/Tests/ExportImport/Export/sublib/subdir.cpp @@ -0,0 +1,7 @@ + +#include "subdir.h" + +int SubDirObject::foo() +{ + return 0; +} diff --git a/Tests/ExportImport/Export/sublib/subdir.h b/Tests/ExportImport/Export/sublib/subdir.h new file mode 100644 index 0000000..3a4b73d --- /dev/null +++ b/Tests/ExportImport/Export/sublib/subdir.h @@ -0,0 +1,12 @@ + +#ifndef SUBDIR_H +#define SUBDIR_H + +#include "subdirlib_export.h" + +struct SUBDIRLIB_EXPORT SubDirObject +{ + int foo(); +}; + +#endif diff --git a/Tests/ExportImport/Export/testSharedLibDepends.cpp b/Tests/ExportImport/Export/testSharedLibDepends.cpp new file mode 100644 index 0000000..e279207 --- /dev/null +++ b/Tests/ExportImport/Export/testSharedLibDepends.cpp @@ -0,0 +1,8 @@ + +#include "testSharedLibDepends.h" + +int TestSharedLibDepends::foo() +{ + TestSharedLibRequired req; + return req.foo(); +} diff --git a/Tests/ExportImport/Export/testSharedLibDepends.h b/Tests/ExportImport/Export/testSharedLibDepends.h new file mode 100644 index 0000000..b93143a --- /dev/null +++ b/Tests/ExportImport/Export/testSharedLibDepends.h @@ -0,0 +1,14 @@ + +#ifndef TESTSHAREDLIBDEPENDS_H +#define TESTSHAREDLIBDEPENDS_H + +#include "testsharedlibdepends_export.h" + +#include "testSharedLibRequired.h" + +struct TESTSHAREDLIBDEPENDS_EXPORT TestSharedLibDepends +{ + int foo(); +}; + +#endif diff --git a/Tests/ExportImport/Export/testSharedLibRequired.cpp b/Tests/ExportImport/Export/testSharedLibRequired.cpp new file mode 100644 index 0000000..1ac34aa --- /dev/null +++ b/Tests/ExportImport/Export/testSharedLibRequired.cpp @@ -0,0 +1,7 @@ + +#include "testSharedLibRequired.h" + +int TestSharedLibRequired::foo() +{ + return 0; +} diff --git a/Tests/ExportImport/Export/testSharedLibRequired.h b/Tests/ExportImport/Export/testSharedLibRequired.h new file mode 100644 index 0000000..edaddd4 --- /dev/null +++ b/Tests/ExportImport/Export/testSharedLibRequired.h @@ -0,0 +1,12 @@ + +#ifndef TESTSHAREDLIBREQUIRED_H +#define TESTSHAREDLIBREQUIRED_H + +#include "testsharedlibrequired_export.h" + +struct TESTSHAREDLIBREQUIRED_EXPORT TestSharedLibRequired +{ + int foo(); +}; + +#endif diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt index b77562e..4812e7e 100644 --- a/Tests/ExportImport/Import/A/CMakeLists.txt +++ b/Tests/ExportImport/Import/A/CMakeLists.txt @@ -157,13 +157,41 @@ endif() # Test that dependent imported targets have usable # INTERFACE_COMPILE_DEFINITIONS and INTERFACE_INCLUDE_DIRECTORIES -add_library(deps_iface deps_iface.cpp) -target_link_libraries(deps_iface testLibsDepends) -set_property(TARGET deps_iface APPEND PROPERTY - COMPILE_DEFINITIONS - $<TARGET_PROPERTY:testLibDepends,INTERFACE_COMPILE_DEFINITIONS> -) -set_property(TARGET deps_iface APPEND PROPERTY - INCLUDE_DIRECTORIES - $<TARGET_PROPERTY:testLibDepends,INTERFACE_INCLUDE_DIRECTORIES> +add_executable(deps_iface deps_iface.c) +target_link_libraries(deps_iface testLibDepends) +target_include_directories(deps_iface PRIVATE testLibDepends) +target_compile_definitions(deps_iface PRIVATE testLibDepends) + +add_executable(deps_shared_iface deps_shared_iface.cpp) +target_link_libraries(deps_shared_iface testSharedLibDepends) +target_include_directories(deps_shared_iface PRIVATE testSharedLibDepends) +target_compile_definitions(deps_shared_iface PRIVATE testSharedLibDepends) + +if (APPLE OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag(-fPIE run_pic_test) +else() + if (CMAKE_CXX_COMPILER_ID MATCHES "PGI" + OR CMAKE_CXX_COMPILER_ID MATCHES "PathScale" + OR CMAKE_SYSTEM_NAME MATCHES "IRIX64" + OR CMAKE_CXX_COMPILER_ID MATCHES "Intel") + set(run_pic_test 0) + else() + set(run_pic_test 1) + endif() +endif() + +if (run_pic_test) + target_compile_definitions(deps_shared_iface PRIVATE CHECK_PIC_WORKS) +endif() + +#----------------------------------------------------------------------------- +# Test that targets imported from the build tree have their dependencies +# evaluated correctly. The above already tests the same for the install tree. + +add_executable(deps_shared_iface2 deps_shared_iface.cpp) +target_link_libraries(deps_shared_iface2 bld_testSharedLibDepends bld_subdirlib) +target_include_directories(deps_shared_iface2 PRIVATE bld_testSharedLibDepends bld_subdirlib) +target_compile_definitions(deps_shared_iface2 + PRIVATE bld_testSharedLibDepends TEST_SUBDIR_LIB ) diff --git a/Tests/ExportImport/Import/A/deps_iface.cpp b/Tests/ExportImport/Import/A/deps_iface.c index 7190b92..e73ca26 100644 --- a/Tests/ExportImport/Import/A/deps_iface.cpp +++ b/Tests/ExportImport/Import/A/deps_iface.c @@ -18,7 +18,7 @@ extern int testLibDepends(void); -int main(int,char **) +int main() { return testLibDepends(); } diff --git a/Tests/ExportImport/Import/A/deps_shared_iface.cpp b/Tests/ExportImport/Import/A/deps_shared_iface.cpp new file mode 100644 index 0000000..43f832a --- /dev/null +++ b/Tests/ExportImport/Import/A/deps_shared_iface.cpp @@ -0,0 +1,29 @@ + + +#include "testSharedLibDepends.h" + +#ifdef CHECK_PIC_WORKS +#if defined(__ELF__) && !defined(__PIC__) && !defined(__PIE__) +#error Expected by INTERFACE_POSITION_INDEPENDENT_CODE property of dependency +#endif +#endif + +#ifdef TEST_SUBDIR_LIB +#include "subdir.h" +#endif + +int main(int,char **) +{ + TestSharedLibDepends dep; + TestSharedLibRequired req; + +#ifdef TEST_SUBDIR_LIB + SubDirObject sdo; +#endif + + return dep.foo() + req.foo() +#ifdef TEST_SUBDIR_LIB + + sdo.foo() +#endif + ; +} |