From 60fab8a6e08a014bc66b2347b4d1037ad52164c7 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 15 Apr 2022 13:33:31 -0400 Subject: cmInstallCommand: tweak error message Not all filesets need to be installed; just those that are visible on the target's interface. Clarify the error message. --- Source/cmInstallCommand.cxx | 6 +++--- .../target_sources/FileSetInstallMissingSetsInterface-stderr.txt | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 8ce7ed1..bb08215 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -741,9 +741,9 @@ bool HandleTargetsMode(std::vector const& args, [=](const cmInstallCommandFileSetArguments& fileSetArg) -> bool { return fileSetArg.GetFileSet() == name; }); })) { - status.SetError(cmStrCat( - "TARGETS target ", target.GetName(), - " is exported but not all of its file sets are installed")); + status.SetError(cmStrCat("TARGETS target ", target.GetName(), + " is exported but not all of its interface " + "file sets are installed")); return false; } diff --git a/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-stderr.txt b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-stderr.txt index 694f227..8b06ebd 100644 --- a/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-stderr.txt +++ b/Tests/RunCMake/target_sources/FileSetInstallMissingSetsInterface-stderr.txt @@ -1,5 +1,5 @@ ^CMake Error at FileSetInstallMissingSetsInterface\.cmake:[0-9]+ \(install\): - install TARGETS target lib1 is exported but not all of its file sets are - installed + install TARGETS target lib1 is exported but not all of its interface file + sets are installed Call Stack \(most recent call first\): CMakeLists\.txt:[0-9]+ \(include\)$ -- cgit v0.12 From 9ee47188c0822932574ce48c31fea18a87165566 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 15 Apr 2022 15:45:54 -0400 Subject: cmExportBuildFileGenerator: handle genex-wrapped source paths Previously a fileset with `$<$:some_file>` would show up as-is (with escaping) in the build directory export. Instead, evaluate all fileset entries as generator expressions and list them as they are similar to the installation information. --- Source/cmExportBuildFileGenerator.cxx | 93 +++++++++++++++++++++-- Tests/RunCMake/target_sources/FileSetImport.cmake | 56 +++++++++++--- 2 files changed, 130 insertions(+), 19 deletions(-) diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index a47f1e5..2773b3b 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmExportBuildFileGenerator.h" +#include #include #include #include @@ -15,7 +16,6 @@ #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" -#include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" @@ -362,16 +362,93 @@ std::string cmExportBuildFileGenerator::InstallNameDir( return install_name_dir; } +namespace { +bool EntryIsContextSensitive( + const std::unique_ptr& cge) +{ + return cge->GetHadContextSensitiveCondition(); +} +} + std::string cmExportBuildFileGenerator::GetFileSetDirectories( - cmGeneratorTarget* /*gte*/, cmFileSet* fileSet, cmTargetExport* /*te*/) + cmGeneratorTarget* gte, cmFileSet* fileSet, cmTargetExport* /*te*/) { - return cmOutputConverter::EscapeForCMake( - cmJoin(fileSet->GetDirectoryEntries(), ";")); + std::vector resultVector; + + auto configs = + gte->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); + auto directoryEntries = fileSet->CompileDirectoryEntries(); + + for (auto const& config : configs) { + auto directories = fileSet->EvaluateDirectoryEntries( + directoryEntries, gte->LocalGenerator, config, gte); + + bool const contextSensitive = + std::any_of(directoryEntries.begin(), directoryEntries.end(), + EntryIsContextSensitive); + + for (auto const& directory : directories) { + auto dest = cmOutputConverter::EscapeForCMake( + directory, cmOutputConverter::WrapQuotes::NoWrap); + + if (contextSensitive && configs.size() != 1) { + resultVector.push_back( + cmStrCat("\"$<$:", dest, ">\"")); + } else { + resultVector.push_back(cmStrCat('"', dest, '"')); + break; + } + } + } + + return cmJoin(resultVector, " "); } -std::string cmExportBuildFileGenerator::GetFileSetFiles( - cmGeneratorTarget* /*gte*/, cmFileSet* fileSet, cmTargetExport* /*te*/) +std::string cmExportBuildFileGenerator::GetFileSetFiles(cmGeneratorTarget* gte, + cmFileSet* fileSet, + cmTargetExport* /*te*/) { - return cmOutputConverter::EscapeForCMake( - cmJoin(fileSet->GetFileEntries(), ";")); + std::vector resultVector; + + auto configs = + gte->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); + + auto fileEntries = fileSet->CompileFileEntries(); + auto directoryEntries = fileSet->CompileDirectoryEntries(); + + for (auto const& config : configs) { + auto directories = fileSet->EvaluateDirectoryEntries( + directoryEntries, gte->LocalGenerator, config, gte); + + std::map> files; + for (auto const& entry : fileEntries) { + fileSet->EvaluateFileEntry(directories, files, entry, + gte->LocalGenerator, config, gte); + } + + bool const contextSensitive = + std::any_of(directoryEntries.begin(), directoryEntries.end(), + EntryIsContextSensitive) || + std::any_of(fileEntries.begin(), fileEntries.end(), + EntryIsContextSensitive); + + for (auto const& it : files) { + for (auto const& filename : it.second) { + auto escapedFile = cmOutputConverter::EscapeForCMake( + filename, cmOutputConverter::WrapQuotes::NoWrap); + if (contextSensitive && configs.size() != 1) { + resultVector.push_back( + cmStrCat("\"$<$:", escapedFile, ">\"")); + } else { + resultVector.push_back(cmStrCat('"', escapedFile, '"')); + } + } + } + + if (!(contextSensitive && configs.size() != 1)) { + break; + } + } + + return cmJoin(resultVector, " "); } diff --git a/Tests/RunCMake/target_sources/FileSetImport.cmake b/Tests/RunCMake/target_sources/FileSetImport.cmake index 7e790c7..8ef8e7d 100644 --- a/Tests/RunCMake/target_sources/FileSetImport.cmake +++ b/Tests/RunCMake/target_sources/FileSetImport.cmake @@ -19,20 +19,54 @@ include("${export_build_dir}/install/lib/cmake/export.cmake") assert_prop_eq(export::lib1 HEADER_SETS "") assert_prop_eq(export::lib1 INTERFACE_HEADER_SETS "HEADERS;b;c;d;dir3;e;f;g") assert_prop_eq(export::lib1 HEADER_SET "${CMAKE_CURRENT_SOURCE_DIR}/error.c") -assert_prop_eq(export::lib1 HEADER_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") +if (_multi_config) + assert_prop_eq(export::lib1 HEADER_DIRS "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}") +else () + assert_prop_eq(export::lib1 HEADER_DIRS "${CMAKE_CURRENT_SOURCE_DIR}") +endif () assert_prop_eq(export::lib1 HEADER_SET_b "${CMAKE_CURRENT_SOURCE_DIR}/h2.h") -assert_prop_eq(export::lib1 HEADER_DIRS_b "${CMAKE_CURRENT_SOURCE_DIR}") -assert_prop_eq(export::lib1 HEADER_SET_c "$<1:dir/dir.h>") -assert_prop_eq(export::lib1 HEADER_DIRS_c "$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>") -assert_prop_eq(export::lib1 HEADER_SET_d "${CMAKE_CURRENT_SOURCE_DIR}/$,debug,release>/empty.h") -assert_prop_eq(export::lib1 HEADER_DIRS_d "${CMAKE_CURRENT_SOURCE_DIR}") -assert_prop_eq(export::lib1 HEADER_SET_e "${CMAKE_CURRENT_SOURCE_DIR}/$,debug,release>/empty2.h") -assert_prop_eq(export::lib1 HEADER_DIRS_e "${CMAKE_CURRENT_SOURCE_DIR}/$,debug,release>") +if (_multi_config) + assert_prop_eq(export::lib1 HEADER_DIRS_b "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}") +else () + assert_prop_eq(export::lib1 HEADER_DIRS_b "${CMAKE_CURRENT_SOURCE_DIR}") +endif () +assert_prop_eq(export::lib1 HEADER_SET_c "${CMAKE_CURRENT_SOURCE_DIR}/dir/dir.h") +if (_multi_config) + assert_prop_eq(export::lib1 HEADER_DIRS_c "${CMAKE_CURRENT_SOURCE_DIR}/dir;${CMAKE_CURRENT_SOURCE_DIR}/dir") +else () + assert_prop_eq(export::lib1 HEADER_DIRS_c "${CMAKE_CURRENT_SOURCE_DIR}/dir") +endif () +if (_multi_config) + assert_prop_eq(export::lib1 HEADER_SET_d "$<$:${CMAKE_CURRENT_SOURCE_DIR}/debug/empty.h>;$<$:${CMAKE_CURRENT_SOURCE_DIR}/release/empty.h>") + assert_prop_eq(export::lib1 HEADER_DIRS_d "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}") +else () + assert_prop_eq(export::lib1 HEADER_SET_d "${CMAKE_CURRENT_SOURCE_DIR}/debug/empty.h") + assert_prop_eq(export::lib1 HEADER_DIRS_d "${CMAKE_CURRENT_SOURCE_DIR}") +endif () +if (_multi_config) + assert_prop_eq(export::lib1 HEADER_SET_e "$<$:${CMAKE_CURRENT_SOURCE_DIR}/debug/empty2.h>;$<$:${CMAKE_CURRENT_SOURCE_DIR}/release/empty2.h>") + assert_prop_eq(export::lib1 HEADER_DIRS_e "$<$:${CMAKE_CURRENT_SOURCE_DIR}/debug>;$<$:${CMAKE_CURRENT_SOURCE_DIR}/release>") +else () + assert_prop_eq(export::lib1 HEADER_SET_e "${CMAKE_CURRENT_SOURCE_DIR}/debug/empty2.h") + assert_prop_eq(export::lib1 HEADER_DIRS_e "${CMAKE_CURRENT_SOURCE_DIR}/debug") +endif () assert_prop_eq(export::lib1 HEADER_SET_f "${CMAKE_CURRENT_SOURCE_DIR}/empty3.h") -assert_prop_eq(export::lib1 HEADER_DIRS_f "${CMAKE_CURRENT_SOURCE_DIR}") +if (_multi_config) + assert_prop_eq(export::lib1 HEADER_DIRS_f "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}") +else () + assert_prop_eq(export::lib1 HEADER_DIRS_f "${CMAKE_CURRENT_SOURCE_DIR}") +endif () assert_prop_eq(export::lib1 HEADER_SET_g "${CMAKE_CURRENT_SOURCE_DIR}/dir1/file1.h;${CMAKE_CURRENT_SOURCE_DIR}/dir2/file2.h") -assert_prop_eq(export::lib1 HEADER_DIRS_g "${CMAKE_CURRENT_SOURCE_DIR}/dir1;${CMAKE_CURRENT_SOURCE_DIR}/dir2") -assert_prop_eq(export::lib1 INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR};$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/$,debug,release>;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/dir1;${CMAKE_CURRENT_SOURCE_DIR}/dir2;${CMAKE_CURRENT_SOURCE_DIR}/dir3;$;$;$>;$;$,debug,release>>;$;$;$;$") +if (_multi_config) + assert_prop_eq(export::lib1 HEADER_DIRS_g "${CMAKE_CURRENT_SOURCE_DIR}/dir1;${CMAKE_CURRENT_SOURCE_DIR}/dir1") +else () + assert_prop_eq(export::lib1 HEADER_DIRS_g "${CMAKE_CURRENT_SOURCE_DIR}/dir1") +endif () +if (_multi_config) + assert_prop_eq(export::lib1 INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR};$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/$,debug,release>;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/dir1;${CMAKE_CURRENT_SOURCE_DIR}/dir2;${CMAKE_CURRENT_SOURCE_DIR}/dir3;$;$;$;$;$;$;$;$;$:${CMAKE_CURRENT_SOURCE_DIR}/debug>>;$:${CMAKE_CURRENT_SOURCE_DIR}/release>>;$;$;$;$;$;$") +else () + assert_prop_eq(export::lib1 INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR};$<1:${CMAKE_CURRENT_SOURCE_DIR}/dir>;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/$,debug,release>;${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/dir1;${CMAKE_CURRENT_SOURCE_DIR}/dir2;${CMAKE_CURRENT_SOURCE_DIR}/dir3;$;$;$;$;$;$;$;$") +endif () assert_prop_eq(install::lib1 HEADER_SETS "") assert_prop_eq(install::lib1 INTERFACE_HEADER_SETS "HEADERS;b;c;d;dir3;e;f;g") -- cgit v0.12