Diagnostics: Add CMD_INSTALL_ABSOLUTE_DIR for all install types

The original addition of CMD_INSTALL_ABSOLUTE_DIR by commit
39a56136a3 (Diagnostic: Add warn or error on absolute install paths,
2026-03-25) didn't cover all install signatures. Add checks to cover
those install types that weren't covered by the original commit.
This commit is contained in:
Robert Maynard
2026-06-05 13:10:12 -04:00
parent f9fe9884ac
commit ef3681667f
24 changed files with 178 additions and 13 deletions
+29 -8
View File
@@ -301,6 +301,18 @@ bool AddBundleExecutable(Helper& helper,
return true;
}
void CheckAbsoluteDestination(Helper& helper, std::string const& destination)
{
// Check for an absolute destination.
if (cmGeneratorExpression::Find(destination) == std::string::npos &&
cmSystemTools::FileIsFullPath(destination)) {
helper.Makefile->IssueDiagnostic(
cmDiagnostics::CMD_INSTALL_ABSOLUTE_DESTINATION,
cmStrCat("INSTALL command given absolute DESTINATION path:\n ",
destination));
}
}
bool HandleScriptMode(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
@@ -1911,14 +1923,8 @@ bool HandleDirectoryMode(std::vector<std::string> const& args,
cmInstallGenerator::MessageLevel message =
cmInstallGenerator::SelectMessageLevel(helper.Makefile, messageNever);
// Check for an absolute destination.
if (cmGeneratorExpression::Find(*destination) == std::string::npos &&
cmSystemTools::FileIsFullPath(*destination)) {
helper.Makefile->IssueDiagnostic(
cmDiagnostics::CMD_INSTALL_ABSOLUTE_DESTINATION,
cmStrCat("INSTALL command given absolute DESTINATION path:\n ",
*destination));
}
// Check for CMD_INSTALL_ABSOLUTE_DESTINATION diagnostics.
CheckAbsoluteDestination(helper, *destination);
// Create the directory install generator.
helper.Makefile->AddInstallGenerator(
@@ -1974,6 +1980,9 @@ bool HandleExportAndroidMKMode(std::vector<std::string> const& args,
return false;
}
// Check for CMD_INSTALL_ABSOLUTE_DESTINATION diagnostics.
CheckAbsoluteDestination(helper, ica.GetDestination());
// Check the file name.
std::string fname = filename;
if (fname.find_first_of(":/\\") != std::string::npos) {
@@ -2142,6 +2151,9 @@ bool HandleMappedPackageInfo(
}
}
// Check for CMD_INSTALL_ABSOLUTE_DESTINATION diagnostics.
CheckAbsoluteDestination(helper, dest);
if (arguments.Appendix.empty()) {
// Get additional export information from variables.
GetExportArgumentFromVariable( // BR
@@ -2296,6 +2308,9 @@ bool HandleExportMode(std::vector<std::string> const& args,
}
#endif
// Check for CMD_INSTALL_ABSOLUTE_DESTINATION diagnostics.
CheckAbsoluteDestination(helper, ica.GetDestination());
// Create the export install generator.
helper.Makefile->AddInstallGenerator(
cm::make_unique<cmInstallCMakeConfigExportGenerator>(
@@ -2356,6 +2371,9 @@ bool HandlePackageInfoMode(std::vector<std::string> const& args,
}
}
// Check for CMD_INSTALL_ABSOLUTE_DESTINATION diagnostics.
CheckAbsoluteDestination(helper, dest);
cmExportSet& exportSet =
helper.Makefile->GetGlobalGenerator()->GetExportSets()[exportName];
@@ -2555,6 +2573,9 @@ bool HandleSbomMode(std::vector<std::string> const& args,
}
}
// Check for CMD_INSTALL_ABSOLUTE_DESTINATION diagnostics.
CheckAbsoluteDestination(helper, dest);
cmGlobalGenerator* gg = helper.Makefile->GetGlobalGenerator();
std::string const fpath =
+5 -2
View File
@@ -50,6 +50,7 @@ std::string cmInstallCxxModuleBmiGenerator::GetScriptLocation(
if (config.empty()) {
configName = "noconfig";
}
return cmStrCat(this->Target->GetCMFSupportDirectory(),
"/install-cxx-module-bmi-", configName, ".cmake");
}
@@ -57,8 +58,10 @@ std::string cmInstallCxxModuleBmiGenerator::GetScriptLocation(
std::string cmInstallCxxModuleBmiGenerator::GetDestination(
std::string const& config) const
{
return cmGeneratorExpression::Evaluate(this->Destination,
this->LocalGenerator, config);
std::string dest = cmGeneratorExpression::Evaluate(
this->Destination, this->LocalGenerator, config);
this->CheckAbsoluteDestination(dest, this->LocalGenerator);
return dest;
}
void cmInstallCxxModuleBmiGenerator::GenerateScriptForConfig(
@@ -60,8 +60,10 @@ bool cmInstallImportedRuntimeArtifactsGenerator::Compute(cmLocalGenerator* lg)
std::string cmInstallImportedRuntimeArtifactsGenerator::GetDestination(
std::string const& config) const
{
return cmGeneratorExpression::Evaluate(
std::string dest = cmGeneratorExpression::Evaluate(
this->Destination, this->Target->GetLocalGenerator(), config);
this->CheckAbsoluteDestination(dest, this->Target->GetLocalGenerator());
return dest;
}
void cmInstallImportedRuntimeArtifactsGenerator::GenerateScriptForConfig(
@@ -269,6 +269,8 @@ void cmInstallRuntimeDependencySetGenerator::GenerateStripFixup(
std::string cmInstallRuntimeDependencySetGenerator::GetDestination(
std::string const& config) const
{
return cmGeneratorExpression::Evaluate(this->Destination,
this->LocalGenerator, config);
std::string dest = cmGeneratorExpression::Evaluate(
this->Destination, this->LocalGenerator, config);
this->CheckAbsoluteDestination(dest, this->LocalGenerator);
return dest;
}
@@ -0,0 +1 @@
1
@@ -0,0 +1,10 @@
CMake Error \(install-absolute-destination\) at InstallBMIAbsDir\.cmake:[0-9]+ \(install\):
INSTALL command given absolute DESTINATION path:
/lib/bmi
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
This error is for project developers\. Use -Wno-error=author or
-Wno-error=install-absolute-destination to suppress it\.
CMake Generate step failed\. Build files cannot be regenerated correctly\.$
@@ -0,0 +1,32 @@
set(CMAKE_INTERMEDIATE_DIR_STRATEGY FULL CACHE STRING "" FORCE)
enable_language(CXX)
add_library(install-bmi SHARED)
target_sources(install-bmi
PUBLIC
FILE_SET CXX_MODULES
BASE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}"
FILES
sources/importable.cxx)
target_compile_features(install-bmi PUBLIC cxx_std_20)
cmake_diagnostic(SET CMD_INSTALL_ABSOLUTE_DESTINATION FATAL_ERROR)
install(TARGETS install-bmi
CXX_MODULES_BMI
DESTINATION "/lib/bmi"
COMPONENT "bmi")
install(TARGETS install-bmi
CXX_MODULES_BMI
DESTINATION "/lib/bmi"
EXCLUDE_FROM_ALL
COMPONENT "bmi-optional")
install(TARGETS install-bmi
CXX_MODULES_BMI
DESTINATION "/lib/bmi"
CONFIGURATIONS Debug
COMPONENT "bmi-only-debug")
@@ -117,6 +117,9 @@ endif ()
run_cmake(InstallBMI)
run_cmake(InstallBMIGenericArgs)
run_cmake(InstallBMIIgnore)
if(NOT RunCMake_GENERATOR MATCHES "^Visual Studio ")
run_cmake(InstallBMIAbsDir)
endif()
run_cmake(ExportBuildCxxModules)
run_cmake(ExportBuildCxxModulesTargets)
@@ -0,0 +1,6 @@
export module importable;
export int from_import()
{
return 0;
}
@@ -0,0 +1,8 @@
CMake Warning \(install-absolute-destination\) at EXPORT-AbsoluteDest-warn\.cmake:[0-9]+ \(install\):
INSTALL command given absolute DESTINATION path:
/absolute/path
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
This warning is for project developers\. Use -Wno-author or
-Wno-install-absolute-destination to suppress it\.
@@ -0,0 +1,4 @@
enable_language(C)
add_library(mylib STATIC empty.c)
install(TARGETS mylib EXPORT myexp DESTINATION lib)
install(EXPORT myexp DESTINATION /absolute/path)
@@ -0,0 +1,8 @@
CMake Warning \(install-absolute-destination\) at EXPORT_ANDROID_MK-AbsoluteDest-warn\.cmake:[0-9]+ \(install\):
INSTALL command given absolute DESTINATION path:
/absolute/path
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
This warning is for project developers\. Use -Wno-author or
-Wno-install-absolute-destination to suppress it\.
@@ -0,0 +1,4 @@
enable_language(C)
add_library(mylib STATIC empty.c)
install(TARGETS mylib EXPORT myexp DESTINATION lib)
install(EXPORT_ANDROID_MK myexp DESTINATION /absolute/path)
@@ -0,0 +1,8 @@
CMake Warning \(install-absolute-destination\) at IMPORTED_RUNTIME_ARTIFACTS-AbsoluteDest-warn\.cmake:[0-9]+ \(install\):
INSTALL command given absolute DESTINATION path:
/absolute/path
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
This warning is for project developers\. Use -Wno-author or
-Wno-install-absolute-destination to suppress it\.
@@ -0,0 +1,4 @@
enable_language(C)
add_executable(myexe IMPORTED)
set_target_properties(myexe PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/myexe")
install(IMPORTED_RUNTIME_ARTIFACTS myexe RUNTIME DESTINATION /absolute/path)
@@ -0,0 +1,8 @@
CMake Error \(install-absolute-destination\) at PACKAGE_INFO-AbsoluteDest-error\.cmake:[0-9]+ \(install\):
INSTALL command given absolute DESTINATION path:
/absolute/path
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
This error is for project developers\. Use -Wno-error=author or
-Wno-error=install-absolute-destination to suppress it\.
@@ -0,0 +1,5 @@
enable_language(C)
project(PACKAGE_INFO-AbsoluteDest-error LANGUAGES C VERSION 1.0)
add_library(mylib STATIC empty.c)
install(TARGETS mylib EXPORT myexp DESTINATION lib)
install(PACKAGE_INFO mypkg EXPORT myexp DESTINATION /absolute/path)
@@ -0,0 +1,8 @@
CMake Warning \(install-absolute-destination\) at RUNTIME_DEPENDENCY_SET-AbsoluteDest-warn\.cmake:[0-9]+ \(install\):
INSTALL command given absolute DESTINATION path:
/absolute/path
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
This warning is for project developers\. Use -Wno-author or
-Wno-install-absolute-destination to suppress it\.
@@ -0,0 +1,4 @@
install(RUNTIME_DEPENDENCY_SET deps
LIBRARY DESTINATION /absolute/path
RUNTIME DESTINATION /absolute/path
)
+10
View File
@@ -90,6 +90,16 @@ run_cmake_with_options(TARGETS-AbsoluteDest-warn -Winstall-absolute-destination)
run_cmake(TARGETS-AbsoluteDest-archive-error)
run_cmake(TARGETS-AbsoluteDest-library-error)
run_cmake(TARGETS-AbsoluteDest-runtime-error)
run_cmake_with_options(EXPORT-AbsoluteDest-warn -Winstall-absolute-destination)
run_cmake_with_options(EXPORT_ANDROID_MK-AbsoluteDest-warn -Winstall-absolute-destination)
run_cmake_with_options(PACKAGE_INFO-AbsoluteDest-error -Werror=install-absolute-destination)
run_cmake_with_options(SBOM-AbsoluteDest-warn
-Winstall-absolute-destination
-DCMAKE_EXPERIMENTAL_GENERATE_SBOM=2d856d6d-53e8-488b-a17f-d486d2cac317)
run_cmake_with_options(IMPORTED_RUNTIME_ARTIFACTS-AbsoluteDest-warn -Winstall-absolute-destination)
if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$")
run_cmake_with_options(RUNTIME_DEPENDENCY_SET-AbsoluteDest-warn -Winstall-absolute-destination)
endif()
run_cmake(EXPORT-Component)
run_cmake(EXPORT-FindDependencyExportGate)
run_cmake(EXPORT-OldIFace)
@@ -0,0 +1,8 @@
CMake Warning \(install-absolute-destination\) at SBOM-AbsoluteDest-warn\.cmake:[0-9]+ \(install\):
INSTALL command given absolute DESTINATION path:
/absolute/path
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
This warning is for project developers\. Use -Wno-author or
-Wno-install-absolute-destination to suppress it\.
@@ -0,0 +1,5 @@
enable_language(C)
project(SBOM-AbsoluteDest-warn LANGUAGES C VERSION 1.0)
add_library(mylib STATIC empty.c)
install(TARGETS mylib EXPORT myexp DESTINATION lib)
install(SBOM mysbom EXPORTS myexp FORMAT "spdx-3.0+json" DESTINATION /absolute/path)
View File