diff --git a/Help/release/dev/CMAKE_INSTALL_DEFAULT_COMPONENT_NAME-project-name-placeholder.rst b/Help/release/dev/CMAKE_INSTALL_DEFAULT_COMPONENT_NAME-project-name-placeholder.rst new file mode 100644 index 0000000000..37dc6264b5 --- /dev/null +++ b/Help/release/dev/CMAKE_INSTALL_DEFAULT_COMPONENT_NAME-project-name-placeholder.rst @@ -0,0 +1,7 @@ +CMAKE_INSTALL_DEFAULT_COMPONENT_NAME-project-name-placeholder +------------------------------------------------------------- + +* :variable:`CMAKE_INSTALL_DEFAULT_COMPONENT_NAME` gained support for a + special ```` placeholder value. It tells each + :command:`install` invocation to take a default component name + from the current :variable:`PROJECT_NAME` variable value. diff --git a/Help/variable/CMAKE_INSTALL_DEFAULT_COMPONENT_NAME.rst b/Help/variable/CMAKE_INSTALL_DEFAULT_COMPONENT_NAME.rst index 57160f1d9a..15ec0cdf82 100644 --- a/Help/variable/CMAKE_INSTALL_DEFAULT_COMPONENT_NAME.rst +++ b/Help/variable/CMAKE_INSTALL_DEFAULT_COMPONENT_NAME.rst @@ -7,3 +7,13 @@ If an :command:`install` command is used without the ``COMPONENT`` argument, these files will be grouped into a default component. The name of this default install component will be taken from this variable. It defaults to ``Unspecified``. + +There is a special component name: + +```` + .. versionadded:: 4.4 + + This literal placeholder will expand to the contents of the + :variable:`PROJECT_NAME` variable when the :command:`install` command is + evaluated. If no :command:`project` command has been called it defaults to + ``Unspecified``. diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 12d67cfb61..1783e18339 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -95,6 +95,14 @@ public: { this->DefaultComponentName = this->Makefile->GetSafeDefinition( "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"); + if (this->DefaultComponentName == "") { + cmValue projectName = this->Makefile->GetDefinition("PROJECT_NAME"); + if (!projectName->empty()) { + this->DefaultComponentName = projectName; + } else { + this->DefaultComponentName = "Unspecified"; + } + } if (this->DefaultComponentName.empty()) { this->DefaultComponentName = "Unspecified"; } diff --git a/Tests/RunCMake/install/RunCMakeTest.cmake b/Tests/RunCMake/install/RunCMakeTest.cmake index fcd1cd503e..ff8e812fba 100644 --- a/Tests/RunCMake/install/RunCMakeTest.cmake +++ b/Tests/RunCMake/install/RunCMakeTest.cmake @@ -215,6 +215,8 @@ if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$") unset(RunCMake_TEST_OPTIONS) run_cmake(TARGETS-RUNTIME_DEPENDENCY_SET-RUNTIME_DEPENDENCIES-conflict) run_cmake(RuntimeDependencies-COMPONENTS) + run_cmake(RuntimeDependencies-Default-COMPONENT-Name) + run_cmake(RuntimeDependencies-ProjectName-Placeholder-COMPONENT-Name) else() run_cmake(TARGETS-RUNTIME_DEPENDENCIES-unsupported) run_cmake(TARGETS-RUNTIME_DEPENDENCY_SET-unsupported) diff --git a/Tests/RunCMake/install/RuntimeDependencies-Default-COMPONENT-Name.cmake b/Tests/RunCMake/install/RuntimeDependencies-Default-COMPONENT-Name.cmake new file mode 100644 index 0000000000..47e8f36800 --- /dev/null +++ b/Tests/RunCMake/install/RuntimeDependencies-Default-COMPONENT-Name.cmake @@ -0,0 +1,21 @@ +enable_language(C) + +function(check_components value) + get_cmake_property(comp COMPONENTS) + if(NOT comp STREQUAL value) + message(FATAL_ERROR "Expected value of COMPONENTS:\n ${value}\nActual value of COMPONENTS:\n ${comp}") + endif() +endfunction() + +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + add_library(tgt MODULE obj1.c) +else() + add_executable(tgt main.c) +endif() + +set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "default_name") +install(TARGETS tgt + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ) +check_components("default_name") diff --git a/Tests/RunCMake/install/RuntimeDependencies-ProjectName-Placeholder-COMPONENT-Name.cmake b/Tests/RunCMake/install/RuntimeDependencies-ProjectName-Placeholder-COMPONENT-Name.cmake new file mode 100644 index 0000000000..6701bcc71d --- /dev/null +++ b/Tests/RunCMake/install/RuntimeDependencies-ProjectName-Placeholder-COMPONENT-Name.cmake @@ -0,0 +1,28 @@ +enable_language(C) + +function(check_components value) + get_cmake_property(comp COMPONENTS) + if(NOT comp STREQUAL value) + message(FATAL_ERROR "Expected value of COMPONENTS:\n ${value}\nActual value of COMPONENTS:\n ${comp}") + endif() +endfunction() + +project(hello_world) +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + add_library(tgt MODULE obj1.c) + add_library(tgt2 MODULE obj1.c) +else() + add_executable(tgt main.c) + add_executable(tgt2 main.c) +endif() + +set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "") +install(TARGETS tgt + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ) +install(TARGETS tgt2 + RUNTIME DESTINATION bin COMPONENT "other" + LIBRARY DESTINATION lib COMPONENT "other" + ) +check_components("hello_world;other")