commit bd8f6ecea0663bdd150aa48941cbd47d25874396 Author: Nick Cao Date: Tue Apr 19 13:49:59 2022 +0800 patch cmake file generation for nixpkgs packaging As of qt 6.3.0, installing components into different prefixes is not supported. To workaround that, we move files to their designated in the postInstall hook. However the generated cmake files still have references to the original prefix, and would cause issues when using said components as the dependency of other packages. The purpose of this patch is to closely match the output layout of qt, and rewrite the generated cmake files to point to the corrected pathes. diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 5a33349b19..677a6084d6 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -330,9 +331,21 @@ static void prefixItems(std::string& exportDirs) for (std::string const& e : entries) { exportDirs += sep; sep = ";"; - if (!cmSystemTools::FileIsFullPath(e) && - e.find("${_IMPORT_PREFIX}") == std::string::npos) { - exportDirs += "${_IMPORT_PREFIX}/"; + if (!cmSystemTools::FileIsFullPath(e)) { + if (std::getenv("dev")) { + if (cmHasLiteralPrefix(e, "include") || cmHasLiteralPrefix(e, "./include")) { + exportDirs += std::getenv("dev"); + } else if (cmHasLiteralPrefix(e, "mkspecs") || cmHasLiteralPrefix(e, "./mkspecs")) { + exportDirs += std::getenv("dev"); + } else if (cmHasLiteralPrefix(e, "libexec") || cmHasLiteralPrefix(e, "./libexec")) { + exportDirs += std::getenv("dev"); + } else { + exportDirs += std::getenv("out"); + } + } else { + exportDirs += std::getenv("out"); + } + exportDirs += "/"; } exportDirs += e; } diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index adccdfeece..ba248305bd 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -6,6 +6,7 @@ #include #include #include +#include #include "cmExportSet.h" #include "cmFileSet.h" @@ -266,7 +267,7 @@ void cmExportInstallFileGenerator::LoadConfigFiles(std::ostream& os) void cmExportInstallFileGenerator::ReplaceInstallPrefix(std::string& input) { - cmGeneratorExpression::ReplaceInstallPrefix(input, "${_IMPORT_PREFIX}"); + cmGeneratorExpression::ReplaceInstallPrefix(input, std::getenv("out")); } bool cmExportInstallFileGenerator::GenerateImportFileConfig( @@ -382,9 +383,22 @@ void cmExportInstallFileGenerator::SetImportLocationProperty( // Construct the installed location of the target. std::string dest = itgen->GetDestination(config); std::string value; + if (!cmSystemTools::FileIsFullPath(dest)) { - // The target is installed relative to the installation prefix. - value = "${_IMPORT_PREFIX}/"; + if (std::getenv("dev")) { + if (cmHasLiteralPrefix(dest, "include") || cmHasLiteralPrefix(dest, "./include")) { + value = std::getenv("dev"); + } else if (cmHasLiteralPrefix(dest, "mkspecs") || cmHasLiteralPrefix(dest, "./mkspecs")) { + value = std::getenv("dev"); + } else if (cmHasLiteralPrefix(dest, "libexec") || cmHasLiteralPrefix(dest, "./libexec")) { + value = std::getenv("dev"); + } else { + value = std::getenv("out"); + } + } else { + value = std::getenv("out"); + } + value += "/"; } value += dest; value += "/"; diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index f988e54a19..cc5c7ac9fd 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -192,7 +192,20 @@ static void prefixItems(const std::string& content, std::string& result, sep = ";"; if (!cmSystemTools::FileIsFullPath(e) && cmGeneratorExpression::Find(e) != 0) { - result += prefix; + if (std::getenv("dev")) { + if (cmHasLiteralPrefix(e, "include") || cmHasLiteralPrefix(e, "./include")) { + result += std::getenv("dev"); + } else if (cmHasLiteralPrefix(e, "mkspecs") || cmHasLiteralPrefix(e, "./mkspecs")) { + result += std::getenv("dev"); + } else if (cmHasLiteralPrefix(e, "libexec") || cmHasLiteralPrefix(e, "./libexec")) { + result += std::getenv("dev"); + } else { + result += std::getenv("out"); + } + } else { + result += std::getenv("out"); + } + result += "/"; } result += e; }