diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 8ca9a66cd1..8b0f64e23b 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -367,7 +367,8 @@ void cmExportFileGenerator::PopulateSourcesInterface( void cmExportFileGenerator::PopulateIncludeDirectoriesInterface( cmGeneratorTarget const* target, cmGeneratorExpression::PreprocessContext preprocessRule, - ImportPropertyMap& properties, std::vector& missingTargets) + ImportPropertyMap& properties, std::vector& missingTargets, + cmTargetExport const& te) { assert(preprocessRule == cmGeneratorExpression::InstallInterface); @@ -377,7 +378,7 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface( cmGeneratorExpression ge; std::string dirs = cmGeneratorExpression::Preprocess( - cmJoin(target->Target->GetInstallIncludeDirectoriesEntries(), ";"), + cmJoin(target->Target->GetInstallIncludeDirectoriesEntries(te), ";"), preprocessRule, true); this->ReplaceInstallPrefix(dirs); std::unique_ptr cge = ge.Parse(dirs); diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h index 24e048bca2..29a6a986a8 100644 --- a/Source/cmExportFileGenerator.h +++ b/Source/cmExportFileGenerator.h @@ -16,6 +16,7 @@ #include "cmVersionConfig.h" class cmGeneratorTarget; +class cmTargetExport; #define STRINGIFY_HELPER(X) #X #define STRINGIFY(X) STRINGIFY_HELPER(X) @@ -146,7 +147,8 @@ protected: void PopulateIncludeDirectoriesInterface( cmGeneratorTarget const* target, cmGeneratorExpression::PreprocessContext preprocessRule, - ImportPropertyMap& properties, std::vector& missingTargets); + ImportPropertyMap& properties, std::vector& missingTargets, + cmTargetExport const& te); void PopulateSourcesInterface( cmGeneratorTarget const* target, cmGeneratorExpression::PreprocessContext preprocessRule, diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index e9ac8752fe..4a3c565bce 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -86,7 +86,8 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) ImportPropertyMap properties; this->PopulateIncludeDirectoriesInterface( - gt, cmGeneratorExpression::InstallInterface, properties, missingTargets); + gt, cmGeneratorExpression::InstallInterface, properties, missingTargets, + *te); this->PopulateSourcesInterface(gt, cmGeneratorExpression::InstallInterface, properties, missingTargets); this->PopulateInterfaceProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", gt, diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index eaf88f64a0..92e3bb5fb4 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -683,7 +683,7 @@ bool HandleTargetsMode(std::vector const& args, te->RuntimeGenerator = runtimeGenerator.get(); te->ObjectsGenerator = objectGenerator.get(); target.AddInstallIncludeDirectories( - cmMakeRange(includesArgs.GetIncludeDirs())); + *te, cmMakeRange(includesArgs.GetIncludeDirs())); te->NamelinkOnly = namelinkOnly; helper.Makefile->GetGlobalGenerator() ->GetExportSets()[exports] diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 97d60cf030..45e23d384d 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -191,7 +191,8 @@ public: cmTarget::LinkLibraryVectorType OriginalLinkLibraries; std::map> LanguageStandardProperties; std::vector> IncludeDirectoriesEntries; - std::vector InstallIncludeDirectoriesEntries; + std::map> + InstallIncludeDirectoriesEntries; std::vector> CompileOptionsEntries; std::vector> CompileFeaturesEntries; std::vector> CompileDefinitionsEntries; @@ -1054,15 +1055,18 @@ std::set const& cmTarget::GetSystemIncludeDirectories() const return this->impl->SystemIncludeDirectories; } -void cmTarget::AddInstallIncludeDirectories(cmStringRange const& incs) +void cmTarget::AddInstallIncludeDirectories(cmTargetExport const& te, + cmStringRange const& incs) { - std::copy(incs.begin(), incs.end(), - std::back_inserter(this->impl->InstallIncludeDirectoriesEntries)); + std::copy( + incs.begin(), incs.end(), + std::back_inserter(this->impl->InstallIncludeDirectoriesEntries[&te])); } -cmStringRange cmTarget::GetInstallIncludeDirectoriesEntries() const +cmStringRange cmTarget::GetInstallIncludeDirectoriesEntries( + cmTargetExport const& te) const { - return cmMakeRange(this->impl->InstallIncludeDirectoriesEntries); + return cmMakeRange(this->impl->InstallIncludeDirectoriesEntries[&te]); } cmBTStringRange cmTarget::GetIncludeDirectoriesEntries() const diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 3cf69429cf..95aa4d3505 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -26,6 +26,7 @@ class cmMakefile; class cmMessenger; class cmPropertyMap; class cmSourceFile; +class cmTargetExport; class cmTargetInternals; /** \class cmTarget @@ -232,8 +233,10 @@ public: void AddSystemIncludeDirectories(std::set const& incs); std::set const& GetSystemIncludeDirectories() const; - void AddInstallIncludeDirectories(cmStringRange const& incs); - cmStringRange GetInstallIncludeDirectoriesEntries() const; + void AddInstallIncludeDirectories(cmTargetExport const& te, + cmStringRange const& incs); + cmStringRange GetInstallIncludeDirectoriesEntries( + cmTargetExport const& te) const; BTs const* GetLanguageStandardProperty( const std::string& propertyName) const; diff --git a/Tests/RunCMake/install/EXPORT-TargetTwice-check.cmake b/Tests/RunCMake/install/EXPORT-TargetTwice-check.cmake new file mode 100644 index 0000000000..97677cad48 --- /dev/null +++ b/Tests/RunCMake/install/EXPORT-TargetTwice-check.cmake @@ -0,0 +1,19 @@ +set(pkg1_cmake "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/Export/pkg1/pkg1.cmake") +file(STRINGS "${pkg1_cmake}" pkg1_includes REGEX INTERFACE_INCLUDE_DIRECTORIES) +set(pkg1_expect [[INTERFACE_INCLUDE_DIRECTORIES "\${_IMPORT_PREFIX}/pkg1/inc"]]) +if(NOT pkg1_includes MATCHES "${pkg1_expect}") + set(RunCMake_TEST_FAILED "pkg1 has unexpected INTERFACE_INCLUDE_DIRECTORIES line: + ${pkg1_includes} +It does not match: + ${pkg1_expect}") +endif() + +set(pkg2_cmake "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/Export/pkg2/pkg2.cmake") +file(STRINGS "${pkg2_cmake}" pkg2_includes REGEX INTERFACE_INCLUDE_DIRECTORIES) +set(pkg2_expect [[INTERFACE_INCLUDE_DIRECTORIES "\${_IMPORT_PREFIX}/pkg2/inc"]]) +if(NOT pkg2_includes MATCHES "${pkg2_expect}") + set(RunCMake_TEST_FAILED "pkg2 has unexpected INTERFACE_INCLUDE_DIRECTORIES line: + ${pkg2_includes} +It does not match: + ${pkg2_expect}") +endif() diff --git a/Tests/RunCMake/install/EXPORT-TargetTwice-pkg1.txt b/Tests/RunCMake/install/EXPORT-TargetTwice-pkg1.txt new file mode 100644 index 0000000000..592f79c688 --- /dev/null +++ b/Tests/RunCMake/install/EXPORT-TargetTwice-pkg1.txt @@ -0,0 +1,5 @@ +.+ +set_target_properties\(pkg1::foo PROPERTIES +.+INTERFACE_INCLUDE_DIRECTORIES "\${_IMPORT_PREFIX}/pkg1/inc" +\) +.+ diff --git a/Tests/RunCMake/install/EXPORT-TargetTwice-pkg2.txt b/Tests/RunCMake/install/EXPORT-TargetTwice-pkg2.txt new file mode 100644 index 0000000000..ebfc43e344 --- /dev/null +++ b/Tests/RunCMake/install/EXPORT-TargetTwice-pkg2.txt @@ -0,0 +1,5 @@ +.+ +set_target_properties\(pkg2::foo PROPERTIES +.+INTERFACE_INCLUDE_DIRECTORIES "\${_IMPORT_PREFIX}/pkg2/inc" +\) +.+ diff --git a/Tests/RunCMake/install/EXPORT-TargetTwice.cmake b/Tests/RunCMake/install/EXPORT-TargetTwice.cmake new file mode 100644 index 0000000000..cac4ff2adc --- /dev/null +++ b/Tests/RunCMake/install/EXPORT-TargetTwice.cmake @@ -0,0 +1,17 @@ +enable_language(C) + +add_library(foo STATIC empty.c) + +install(TARGETS foo + EXPORT pkg1 + ARCHIVE DESTINATION pkg1/lib + INCLUDES DESTINATION pkg1/inc + ) +install(EXPORT pkg1 DESTINATION pkg1) + +install(TARGETS foo + EXPORT pkg2 + ARCHIVE DESTINATION pkg2/lib + INCLUDES DESTINATION pkg2/inc + ) +install(EXPORT pkg2 DESTINATION pkg2) diff --git a/Tests/RunCMake/install/RunCMakeTest.cmake b/Tests/RunCMake/install/RunCMakeTest.cmake index f79a3ea745..7c12d4a315 100644 --- a/Tests/RunCMake/install/RunCMakeTest.cmake +++ b/Tests/RunCMake/install/RunCMakeTest.cmake @@ -82,6 +82,7 @@ run_cmake(EXPORT-OldIFace) run_cmake(EXPORT-UnknownExport) run_cmake(EXPORT-NamelinkOnly) run_cmake(EXPORT-SeparateNamelink) +run_cmake(EXPORT-TargetTwice) run_cmake(CMP0062-OLD) run_cmake(CMP0062-NEW) run_cmake(CMP0062-WARN)