mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
Merge topic 'install-default-component-from-project'
accabeb272 install: Add option to use project name as default component
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11811
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
CMAKE_INSTALL_DEFAULT_COMPONENT_NAME-project-name-placeholder
|
||||
-------------------------------------------------------------
|
||||
|
||||
* :variable:`CMAKE_INSTALL_DEFAULT_COMPONENT_NAME` gained support for a
|
||||
special ``<PROJECT_NAME>`` placeholder value. It tells each
|
||||
:command:`install` invocation to take a default component name
|
||||
from the current :variable:`PROJECT_NAME` variable value.
|
||||
@@ -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:
|
||||
|
||||
``<PROJECT_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``.
|
||||
|
||||
@@ -95,6 +95,14 @@ public:
|
||||
{
|
||||
this->DefaultComponentName = this->Makefile->GetSafeDefinition(
|
||||
"CMAKE_INSTALL_DEFAULT_COMPONENT_NAME");
|
||||
if (this->DefaultComponentName == "<PROJECT_NAME>") {
|
||||
cmValue projectName = this->Makefile->GetDefinition("PROJECT_NAME");
|
||||
if (!projectName->empty()) {
|
||||
this->DefaultComponentName = projectName;
|
||||
} else {
|
||||
this->DefaultComponentName = "Unspecified";
|
||||
}
|
||||
}
|
||||
if (this->DefaultComponentName.empty()) {
|
||||
this->DefaultComponentName = "Unspecified";
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
+28
@@ -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 "<PROJECT_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")
|
||||
Reference in New Issue
Block a user