diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index f520816c9a..0cc6d49d8c 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -339,6 +339,8 @@ add_library( cmInstallAndroidMKExportGenerator.h cmInstallCMakeConfigExportGenerator.cxx cmInstallCMakeConfigExportGenerator.h + cmInstallDirs.cxx + cmInstallDirs.h cmInstallGenerator.h cmInstallGenerator.cxx cmInstallGetRuntimeDependenciesGenerator.h diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 1d37546a51..4e6e652de5 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -31,6 +31,7 @@ #include "cmInstallCommandArguments.h" #include "cmInstallCxxModuleBmiGenerator.h" #include "cmInstallDirectoryGenerator.h" +#include "cmInstallDirs.h" #include "cmInstallFileSetGenerator.h" #include "cmInstallFilesGenerator.h" #include "cmInstallGenerator.h" @@ -108,12 +109,8 @@ public: std::vector const& relFiles, std::vector& absFiles); - std::string GetDestination(cmInstallCommandArguments const* args, - std::string const& varName, - std::string const& guess) const; std::string GetRuntimeDestination( cmInstallCommandArguments const* args) const; - std::string GetSbinDestination(cmInstallCommandArguments const* args) const; std::string GetArchiveDestination( cmInstallCommandArguments const* args) const; std::string GetLibraryDestination( @@ -122,24 +119,6 @@ public: cmInstallCommandArguments const* args) const; std::string GetIncludeDestination( cmInstallCommandArguments const* args) const; - std::string GetSysconfDestination( - cmInstallCommandArguments const* args) const; - std::string GetSharedStateDestination( - cmInstallCommandArguments const* args) const; - std::string GetLocalStateDestination( - cmInstallCommandArguments const* args) const; - std::string GetRunStateDestination( - cmInstallCommandArguments const* args) const; - std::string GetDataRootDestination( - cmInstallCommandArguments const* args) const; - std::string GetDataDestination(cmInstallCommandArguments const* args) const; - std::string GetInfoDestination(cmInstallCommandArguments const* args) const; - std::string GetLocaleDestination( - cmInstallCommandArguments const* args) const; - std::string GetManDestination(cmInstallCommandArguments const* args) const; - std::string GetDocDestination(cmInstallCommandArguments const* args) const; - std::string GetProgramExecutablesDestination( - cmInstallCommandArguments const* args) const; std::string GetDestinationForType(cmInstallCommandArguments const* args, std::string const& type) const; @@ -2626,42 +2605,31 @@ bool Helper::MakeFilesFullPath(char const* modeName, return true; } -std::string Helper::GetDestination(cmInstallCommandArguments const* args, - std::string const& varName, - std::string const& guess) const +std::string Helper::GetRuntimeDestination( + cmInstallCommandArguments const* args) const { if (args && !args->GetDestination().empty()) { return args->GetDestination(); } - std::string val = this->Makefile->GetSafeDefinition(varName); - if (!val.empty()) { - return val; - } - return guess; -} - -std::string Helper::GetRuntimeDestination( - cmInstallCommandArguments const* args) const -{ - return this->GetDestination(args, "CMAKE_INSTALL_BINDIR", "bin"); -} - -std::string Helper::GetSbinDestination( - cmInstallCommandArguments const* args) const -{ - return this->GetDestination(args, "CMAKE_INSTALL_SBINDIR", "sbin"); + return cm::InstallDirs::GetRuntimeDirectory(this->Makefile); } std::string Helper::GetArchiveDestination( cmInstallCommandArguments const* args) const { - return this->GetDestination(args, "CMAKE_INSTALL_LIBDIR", "lib"); + if (args && !args->GetDestination().empty()) { + return args->GetDestination(); + } + return cm::InstallDirs::GetArchiveDirectory(this->Makefile); } std::string Helper::GetLibraryDestination( cmInstallCommandArguments const* args) const { - return this->GetDestination(args, "CMAKE_INSTALL_LIBDIR", "lib"); + if (args && !args->GetDestination().empty()) { + return args->GetDestination(); + } + return cm::InstallDirs::GetLibraryDirectory(this->Makefile); } std::string Helper::GetCxxModulesBmiDestination( @@ -2676,81 +2644,10 @@ std::string Helper::GetCxxModulesBmiDestination( std::string Helper::GetIncludeDestination( cmInstallCommandArguments const* args) const { - return this->GetDestination(args, "CMAKE_INSTALL_INCLUDEDIR", "include"); -} - -std::string Helper::GetSysconfDestination( - cmInstallCommandArguments const* args) const -{ - return this->GetDestination(args, "CMAKE_INSTALL_SYSCONFDIR", "etc"); -} - -std::string Helper::GetSharedStateDestination( - cmInstallCommandArguments const* args) const -{ - return this->GetDestination(args, "CMAKE_INSTALL_SHAREDSTATEDIR", "com"); -} - -std::string Helper::GetLocalStateDestination( - cmInstallCommandArguments const* args) const -{ - return this->GetDestination(args, "CMAKE_INSTALL_LOCALSTATEDIR", "var"); -} - -std::string Helper::GetRunStateDestination( - cmInstallCommandArguments const* args) const -{ - return this->GetDestination(args, "CMAKE_INSTALL_RUNSTATEDIR", - this->GetLocalStateDestination(nullptr) + - "/run"); -} - -std::string Helper::GetDataRootDestination( - cmInstallCommandArguments const* args) const -{ - return this->GetDestination(args, "CMAKE_INSTALL_DATAROOTDIR", "share"); -} - -std::string Helper::GetDataDestination( - cmInstallCommandArguments const* args) const -{ - return this->GetDestination(args, "CMAKE_INSTALL_DATADIR", - this->GetDataRootDestination(nullptr)); -} - -std::string Helper::GetInfoDestination( - cmInstallCommandArguments const* args) const -{ - return this->GetDestination(args, "CMAKE_INSTALL_INFODIR", - this->GetDataRootDestination(nullptr) + "/info"); -} - -std::string Helper::GetLocaleDestination( - cmInstallCommandArguments const* args) const -{ - return this->GetDestination(args, "CMAKE_INSTALL_LOCALEDIR", - this->GetDataRootDestination(nullptr) + - "/locale"); -} - -std::string Helper::GetManDestination( - cmInstallCommandArguments const* args) const -{ - return this->GetDestination(args, "CMAKE_INSTALL_MANDIR", - this->GetDataRootDestination(nullptr) + "/man"); -} - -std::string Helper::GetDocDestination( - cmInstallCommandArguments const* args) const -{ - return this->GetDestination(args, "CMAKE_INSTALL_DOCDIR", - this->GetDataRootDestination(nullptr) + "/doc"); -} - -std::string Helper::GetProgramExecutablesDestination( - cmInstallCommandArguments const* args) const -{ - return this->GetDestination(args, "CMAKE_INSTALL_LIBEXECDIR", "libexec"); + if (args && !args->GetDestination().empty()) { + return args->GetDestination(); + } + return cm::InstallDirs::GetIncludeDirectory(this->Makefile); } std::string Helper::GetDestinationForType( @@ -2759,49 +2656,7 @@ std::string Helper::GetDestinationForType( if (args && !args->GetDestination().empty()) { return args->GetDestination(); } - if (type == "BIN") { - return this->GetRuntimeDestination(nullptr); - } - if (type == "SBIN") { - return this->GetSbinDestination(nullptr); - } - if (type == "SYSCONF") { - return this->GetSysconfDestination(nullptr); - } - if (type == "SHAREDSTATE") { - return this->GetSharedStateDestination(nullptr); - } - if (type == "LOCALSTATE") { - return this->GetLocalStateDestination(nullptr); - } - if (type == "RUNSTATE") { - return this->GetRunStateDestination(nullptr); - } - if (type == "LIB") { - return this->GetLibraryDestination(nullptr); - } - if (type == "INCLUDE") { - return this->GetIncludeDestination(nullptr); - } - if (type == "DATA") { - return this->GetDataDestination(nullptr); - } - if (type == "INFO") { - return this->GetInfoDestination(nullptr); - } - if (type == "LOCALE") { - return this->GetLocaleDestination(nullptr); - } - if (type == "MAN") { - return this->GetManDestination(nullptr); - } - if (type == "DOC") { - return this->GetDocDestination(nullptr); - } - if (type == "LIBEXEC") { - return this->GetProgramExecutablesDestination(nullptr); - } - return ""; + return cm::InstallDirs::GetDirectoryForType(this->Makefile, type); } } // namespace diff --git a/Source/cmInstallDirs.cxx b/Source/cmInstallDirs.cxx new file mode 100644 index 0000000000..0c17bc213c --- /dev/null +++ b/Source/cmInstallDirs.cxx @@ -0,0 +1,160 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file LICENSE.rst or https://cmake.org/licensing for details. */ +#include "cmInstallDirs.h" + +#include + +#include "cmMakefile.h" +#include "cmStringAlgorithms.h" +#include "cmValue.h" + +namespace { +std::string GetDirectory(cmMakefile const* makefile, + std::string const& varName, std::string const& guess) +{ + cmValue value = makefile->GetDefinition(varName); + if (!value.IsEmpty()) { + return value; + } + return guess; +} +} // namespace + +namespace cm { +namespace InstallDirs { +std::string GetRuntimeDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_BINDIR", "bin"); +} + +std::string GetSbinDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_SBINDIR", "sbin"); +} + +std::string GetArchiveDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_LIBDIR", "lib"); +} + +std::string GetLibraryDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_LIBDIR", "lib"); +} + +std::string GetIncludeDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_INCLUDEDIR", "include"); +} + +std::string GetSysconfDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_SYSCONFDIR", "etc"); +} + +std::string GetSharedStateDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_SHAREDSTATEDIR", "com"); +} + +std::string GetLocalStateDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_LOCALSTATEDIR", "var"); +} + +std::string GetRunStateDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_RUNSTATEDIR", + cmStrCat(GetLocalStateDirectory(makefile), "/run")); +} + +std::string GetDataRootDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_DATAROOTDIR", "share"); +} + +std::string GetDataDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_DATADIR", + GetDataRootDirectory(makefile)); +} + +std::string GetInfoDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_INFODIR", + cmStrCat(GetDataRootDirectory(makefile), "/info")); +} + +std::string GetLocaleDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_LOCALEDIR", + cmStrCat(GetDataRootDirectory(makefile), "/locale")); +} + +std::string GetManDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_MANDIR", + cmStrCat(GetDataRootDirectory(makefile), "/man")); +} + +std::string GetDocDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_DOCDIR", + cmStrCat(GetDataRootDirectory(makefile), "/doc")); +} + +std::string GetLibExecDirectory(cmMakefile const* makefile) +{ + return GetDirectory(makefile, "CMAKE_INSTALL_LIBEXECDIR", "libexec"); +} + +std::string GetDirectoryForType(cmMakefile const* makefile, + cm::string_view type) +{ + if (type == "BIN"_s) { + return GetRuntimeDirectory(makefile); + } + if (type == "SBIN"_s) { + return GetSbinDirectory(makefile); + } + if (type == "SYSCONF"_s) { + return GetSysconfDirectory(makefile); + } + if (type == "SHAREDSTATE"_s) { + return GetSharedStateDirectory(makefile); + } + if (type == "LOCALSTATE"_s) { + return GetLocalStateDirectory(makefile); + } + if (type == "RUNSTATE"_s) { + return GetRunStateDirectory(makefile); + } + if (type == "LIB"_s) { + return GetLibraryDirectory(makefile); + } + if (type == "INCLUDE"_s) { + return GetIncludeDirectory(makefile); + } + if (type == "DATA"_s) { + return GetDataDirectory(makefile); + } + if (type == "INFO"_s) { + return GetInfoDirectory(makefile); + } + if (type == "LOCALE"_s) { + return GetLocaleDirectory(makefile); + } + if (type == "MAN"_s) { + return GetManDirectory(makefile); + } + if (type == "DOC"_s) { + return GetDocDirectory(makefile); + } + if (type == "LIBEXEC"_s) { + return GetLibExecDirectory(makefile); + } + return std::string{}; +} + +} // namespace InstallDirs +} // namespace cm diff --git a/Source/cmInstallDirs.h b/Source/cmInstallDirs.h new file mode 100644 index 0000000000..73cc564639 --- /dev/null +++ b/Source/cmInstallDirs.h @@ -0,0 +1,34 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file LICENSE.rst or https://cmake.org/licensing for details. */ + +#pragma once + +#include + +#include + +class cmMakefile; + +namespace cm { + +namespace InstallDirs { +std::string GetRuntimeDirectory(cmMakefile const*); +std::string GetSbinDirectory(cmMakefile const*); +std::string GetArchiveDirectory(cmMakefile const*); +std::string GetLibraryDirectory(cmMakefile const*); +std::string GetIncludeDirectory(cmMakefile const*); +std::string GetSysconfDirectory(cmMakefile const*); +std::string GetSharedStateDirectory(cmMakefile const*); +std::string GetLocalStateDirectory(cmMakefile const*); +std::string GetRunStateDirectory(cmMakefile const*); +std::string GetDataRootDirectory(cmMakefile const*); +std::string GetDataDirectory(cmMakefile const*); +std::string GetInfoDirectory(cmMakefile const*); +std::string GetLocaleDirectory(cmMakefile const*); +std::string GetManDirectory(cmMakefile const*); +std::string GetDocDirectory(cmMakefile const*); +std::string GetLibExecDirectory(cmMakefile const*); + +std::string GetDirectoryForType(cmMakefile const*, cm::string_view type); +} +} diff --git a/bootstrap b/bootstrap index 48c6491dbf..6623b8c685 100755 --- a/bootstrap +++ b/bootstrap @@ -427,6 +427,7 @@ CMAKE_CXX_SOURCES="\ cmInstallGenerator \ cmInstallGetRuntimeDependenciesGenerator \ cmInstallImportedRuntimeArtifactsGenerator \ + cmInstallDirs \ cmInstallRuntimeDependencySet \ cmInstallRuntimeDependencySetGenerator \ cmInstallScriptGenerator \