From b279f2b43180b6c55dd3361c2380f7ed3c998109 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 13 Jan 2013 09:39:29 +0100 Subject: Strip consecutive semicolons when preprocessing genex strings. --- Source/cmGeneratorExpression.cxx | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index d306dee..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,7 @@ static std::string stripExportInterface(const std::string &input, } result += input.substr(lastPos); - return result; + return stripEmptyListElements(result); } //---------------------------------------------------------------------------- -- cgit v0.12 From f623d37a9558336af208a4fb5db232b28b56cb82 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 13 Jan 2013 09:42:07 +0100 Subject: Don't write a comment in the export file without the code. --- Source/cmExportFileGenerator.cxx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 94e24c7..91de200 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -665,6 +665,10 @@ cmExportFileGenerator void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os, const std::vector& missingTargets) { + if (missingTargets.empty()) + { + return; + } os << "# Make sure the targets which have been exported in some other \n" "# export set exist.\n"; for(unsigned int i=0; i Date: Sun, 13 Jan 2013 09:42:47 +0100 Subject: Only generate one check per missing target. --- Source/cmExportFileGenerator.cxx | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 91de200..a2d6961 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -671,19 +671,23 @@ void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os, } os << "# Make sure the targets which have been exported in some other \n" "# export set exist.\n"; + std::set emitted; for(unsigned int i=0; i Date: Sun, 13 Jan 2013 09:44:52 +0100 Subject: Move the exported check for dependencies of targets Check only once, in the Config.cmake file, instead of once in each Config-.cmake file. --- Source/cmExportBuildFileGenerator.cxx | 11 +++++------ Source/cmExportBuildFileGenerator.h | 3 ++- Source/cmExportFileGenerator.cxx | 5 +++-- Source/cmExportFileGenerator.h | 6 ++++-- Source/cmExportInstallFileGenerator.cxx | 16 +++++++++------- Source/cmExportInstallFileGenerator.h | 6 ++++-- 6 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index 29f6743..ad61803 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -74,16 +74,16 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os) this->GenerateInterfaceProperties(te, os, properties); } - this->GenerateMissingTargetsCheckCode(os, missingTargets); - // Generate import file content for each configuration. for(std::vector::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 +91,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 &missingTargets) { for(std::vector::const_iterator tei = this->Exports->begin(); @@ -104,7 +105,6 @@ cmExportBuildFileGenerator if(!properties.empty()) { // Get the rest of the target details. - std::vector missingTargets; this->SetImportDetailProperties(config, suffix, target, properties, missingTargets); this->SetImportLinkInterface(config, suffix, @@ -119,7 +119,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 &missingTargets); virtual void HandleMissingTarget(std::string& link_libs, std::vector& missingTargets, cmMakefile* mf, diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index a2d6961..fc78eeb 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 &missingTargets) { // Construct the property configuration suffix. std::string suffix = "_"; @@ -121,7 +122,7 @@ void cmExportFileGenerator::GenerateImportConfig(std::ostream& os, } // Generate the per-config target information. - this->GenerateImportTargetsConfig(os, config, suffix); + this->GenerateImportTargetsConfig(os, config, suffix, missingTargets); } //---------------------------------------------------------------------------- diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h index 4d97a63..8620dd1 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 &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 &missingTargets) = 0; /** Each subclass knows how to deal with a target that is missing from an * export set. */ diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index 68881a1..bffa2b6 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -93,7 +93,6 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) this->GenerateInterfaceProperties(te, os, properties); } - this->GenerateMissingTargetsCheckCode(os, missingTargets); // Now load per-configuration properties for them. os << "# Load information for each installed configuration.\n" @@ -111,17 +110,21 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) 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 &missingTargets) { // Skip configurations not enabled for this export. if(!this->IEGen->InstallsForConfig(config)) @@ -161,7 +164,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 +179,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 &missingTargets) { // Add code to compute the installation prefix relative to the // import file location. @@ -225,7 +229,6 @@ cmExportInstallFileGenerator if(!properties.empty()) { // Get the rest of the target details. - std::vector missingTargets; this->SetImportDetailProperties(config, suffix, te->Target, properties, missingTargets); @@ -240,7 +243,6 @@ 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); 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 &missingTargets); virtual void HandleMissingTarget(std::string& link_libs, std::vector& 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 &missingTargets); /** Fill in properties indicating installed file locations. */ void SetImportLocationProperty(const char* config, -- cgit v0.12 From 6c828f9126453d27c45e1ca6113602fe9df8cbe2 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 13 Jan 2013 09:48:45 +0100 Subject: Move the exported check for file existence. Check only once, in the Config.cmake file, instead of once in each Config-.cmake file. --- Source/cmExportInstallFileGenerator.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index bffa2b6..7eed5ab 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -104,6 +104,8 @@ 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::const_iterator @@ -249,8 +251,6 @@ cmExportInstallFileGenerator } } - this->GenerateImportedFileCheckLoop(os); - // Cleanup the import prefix variable. if(!this->ImportPrefix.empty()) { -- cgit v0.12 From 1d47cd94f3748d287f676f3847d42f3674062dcd Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 12 Jan 2013 00:00:42 +0100 Subject: Add a test for the interfaces in targets exported from the build tree. --- Tests/ExportImport/Export/CMakeLists.txt | 1 + Tests/ExportImport/Import/A/CMakeLists.txt | 29 +++++++++++++---------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt index 779d889..4f6ccd6 100644 --- a/Tests/ExportImport/Export/CMakeLists.txt +++ b/Tests/ExportImport/Export/CMakeLists.txt @@ -250,6 +250,7 @@ endif() # Export from build tree. export(TARGETS testExe1 testLib1 testLib2 testLib3 testExe2libImp testLib3Imp testLib3ImpDep + testSharedLibRequired testSharedLibDepends NAMESPACE bld_ FILE ExportBuildTree.cmake ) diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt index abb2ab0..6a2e54c 100644 --- a/Tests/ExportImport/Import/A/CMakeLists.txt +++ b/Tests/ExportImport/Import/A/CMakeLists.txt @@ -159,22 +159,19 @@ endif() add_executable(deps_iface deps_iface.c) target_link_libraries(deps_iface testLibDepends) -set_property(TARGET deps_iface APPEND PROPERTY - COMPILE_DEFINITIONS - $ -) -set_property(TARGET deps_iface APPEND PROPERTY - INCLUDE_DIRECTORIES - $ -) +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) -set_property(TARGET deps_shared_iface APPEND PROPERTY - COMPILE_DEFINITIONS - $ -) -set_property(TARGET deps_shared_iface APPEND PROPERTY - INCLUDE_DIRECTORIES - $ -) +target_include_directories(deps_shared_iface PRIVATE testSharedLibDepends) +target_compile_definitions(deps_shared_iface PRIVATE testSharedLibDepends) + +#----------------------------------------------------------------------------- +# 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) +target_include_directories(deps_shared_iface2 PRIVATE bld_testSharedLibDepends) +target_compile_definitions(deps_shared_iface2 PRIVATE bld_testSharedLibDepends) -- cgit v0.12 From 4ee872cb99f49ac5a95768da454f3313ba87182f Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 12 Jan 2013 12:11:29 +0100 Subject: Make the BUILD_INTERFACE of export()ed targets work. The existing BUILD_INTERFACE code is executed at generate time, which is too late for export(). --- Source/cmExportBuildFileGenerator.cxx | 2 ++ Source/cmGlobalGenerator.cxx | 14 +------------ Source/cmTarget.cxx | 25 +++++++++++++++++++++++ Source/cmTarget.h | 3 +++ Tests/ExportImport/Export/CMakeLists.txt | 4 +++- Tests/ExportImport/Export/sublib/CMakeLists.txt | 6 ++++++ Tests/ExportImport/Export/sublib/subdir.cpp | 7 +++++++ Tests/ExportImport/Export/sublib/subdir.h | 12 +++++++++++ Tests/ExportImport/Import/A/CMakeLists.txt | 8 +++++--- Tests/ExportImport/Import/A/deps_shared_iface.cpp | 14 ++++++++++++- 10 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 Tests/ExportImport/Export/sublib/CMakeLists.txt create mode 100644 Tests/ExportImport/Export/sublib/subdir.cpp create mode 100644 Tests/ExportImport/Export/sublib/subdir.h diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index ad61803..36c53dc 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, diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index d030aa7..d2baf53 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", - ("$").c_str()); - } - } + tit->second.AppendBuildInterfaceIncludes(); } } diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 9b50b8e..cf01f9f 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; } //---------------------------------------------------------------------------- @@ -2655,6 +2656,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", + ("$").c_str()); + } + } +} + +//---------------------------------------------------------------------------- void cmTarget::InsertInclude(const cmMakefileIncludeDirectoriesEntry &entry, bool before) { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index b4d053d..48dde0a 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -490,6 +490,8 @@ public: void InsertInclude(const cmMakefileIncludeDirectoriesEntry &entry, bool before = false); + void AppendBuildInterfaceIncludes(); + void GetLinkDependentTargetsForProperty(const std::string &p, std::set &targets); bool IsNullImpliedByLinkLibraries(const std::string &p); @@ -611,6 +613,7 @@ private: mutable std::map > LinkDependentProperties; mutable std::set LinkImplicitNullProperties; + bool BuildInterfaceIncludesAppended; // Cache target output paths for each configuration. struct OutputInfo; diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt index 4f6ccd6..e92dcd8 100644 --- a/Tests/ExportImport/Export/CMakeLists.txt +++ b/Tests/ExportImport/Export/CMakeLists.txt @@ -247,9 +247,11 @@ 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/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt index 6a2e54c..72d11b6 100644 --- a/Tests/ExportImport/Import/A/CMakeLists.txt +++ b/Tests/ExportImport/Import/A/CMakeLists.txt @@ -172,6 +172,8 @@ target_compile_definitions(deps_shared_iface PRIVATE testSharedLibDepends) # 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) -target_include_directories(deps_shared_iface2 PRIVATE bld_testSharedLibDepends) -target_compile_definitions(deps_shared_iface2 PRIVATE bld_testSharedLibDepends) +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_shared_iface.cpp b/Tests/ExportImport/Import/A/deps_shared_iface.cpp index 4f7eb23..14aac0a 100644 --- a/Tests/ExportImport/Import/A/deps_shared_iface.cpp +++ b/Tests/ExportImport/Import/A/deps_shared_iface.cpp @@ -2,10 +2,22 @@ #include "testSharedLibDepends.h" +#ifdef TEST_SUBDIR_LIB +#include "subdir.h" +#endif + int main(int,char **) { TestSharedLibDepends dep; TestSharedLibRequired req; - return dep.foo() + req.foo(); +#ifdef TEST_SUBDIR_LIB + SubDirObject sdo; +#endif + + return dep.foo() + req.foo() +#ifdef TEST_SUBDIR_LIB + + sdo.foo() +#endif + ; } -- cgit v0.12 From 522bdac14963acf7c147f5518ea51382b042bf96 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 12 Jan 2013 12:13:19 +0100 Subject: Export the INTERFACE_PIC property. --- Source/cmExportBuildFileGenerator.cxx | 2 ++ Source/cmExportFileGenerator.cxx | 12 ++++++++++++ Source/cmExportFileGenerator.h | 2 ++ Source/cmExportInstallFileGenerator.cxx | 2 ++ Tests/ExportImport/Export/CMakeLists.txt | 4 ++++ Tests/ExportImport/Import/A/CMakeLists.txt | 18 ++++++++++++++++++ Tests/ExportImport/Import/A/deps_shared_iface.cpp | 6 ++++++ 7 files changed, 46 insertions(+) diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index 36c53dc..61e130d 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -72,6 +72,8 @@ 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); } diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index fc78eeb..4a7c6f9 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -127,6 +127,18 @@ void cmExportFileGenerator::GenerateImportConfig(std::ostream& os, //---------------------------------------------------------------------------- void cmExportFileGenerator::PopulateInterfaceProperty(const char *propName, + cmTarget *target, + ImportPropertyMap &properties) +{ + const char *input = target->GetProperty(propName); + if (input) + { + properties[propName] = input; + } +} + +//---------------------------------------------------------------------------- +void cmExportFileGenerator::PopulateInterfaceProperty(const char *propName, const char *outputName, cmTarget *target, cmGeneratorExpression::PreprocessContext preprocessRule, diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h index 8620dd1..eb3f3c3 100644 --- a/Source/cmExportFileGenerator.h +++ b/Source/cmExportFileGenerator.h @@ -101,6 +101,8 @@ protected: cmGeneratorExpression::PreprocessContext, ImportPropertyMap &properties, std::vector &missingTargets); + void PopulateInterfaceProperty(const char *propName, 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 7eed5ab..965f63d 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -89,6 +89,8 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) te, cmGeneratorExpression::InstallInterface, properties, missingTargets); + this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE", + te, properties); this->GenerateInterfaceProperties(te, os, properties); } diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt index e92dcd8..fd7a1a6 100644 --- a/Tests/ExportImport/Export/CMakeLists.txt +++ b/Tests/ExportImport/Export/CMakeLists.txt @@ -162,6 +162,10 @@ 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}" ) diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt index 72d11b6..4812e7e 100644 --- a/Tests/ExportImport/Import/A/CMakeLists.txt +++ b/Tests/ExportImport/Import/A/CMakeLists.txt @@ -167,6 +167,24 @@ 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. diff --git a/Tests/ExportImport/Import/A/deps_shared_iface.cpp b/Tests/ExportImport/Import/A/deps_shared_iface.cpp index 14aac0a..43f832a 100644 --- a/Tests/ExportImport/Import/A/deps_shared_iface.cpp +++ b/Tests/ExportImport/Import/A/deps_shared_iface.cpp @@ -2,6 +2,12 @@ #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 -- cgit v0.12 From 1d74ba21f6ee70936191c94448c88fd10eb1e81c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 12 Jan 2013 12:13:44 +0100 Subject: Test evaluation target via export for generator expressions --- Tests/ExportImport/Export/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt index fd7a1a6..dd615d1 100644 --- a/Tests/ExportImport/Export/CMakeLists.txt +++ b/Tests/ExportImport/Export/CMakeLists.txt @@ -186,7 +186,7 @@ set_property(TARGET testSharedLibDepends APPEND PROPERTY ) set_property(TARGET testSharedLibDepends APPEND PROPERTY LINK_INTERFACE_LIBRARIES - $<1:$> + $<$,EXECUTABLE>:$> ) # LINK_PRIVATE because the LINK_INTERFACE_LIBRARIES is specified above. -- cgit v0.12