Skip to content

Commit

Permalink
Merge pull request #715 from jorisv/topic/install_component
Browse files Browse the repository at this point in the history
forward COMPONENT parametert in install instruction
  • Loading branch information
jorisv authored Nov 20, 2024
2 parents 5bed33b + f662ae2 commit f1f95f9
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 14 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
./idl.cmake
./idlrtc.cmake
./install-data.cmake
./install-helpers.cmake
./julia.cmake
./kineo.cmake
./lapack.cmake
Expand All @@ -101,6 +102,8 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
./openrtm.cmake
./oscheck.cmake
./package-config.cmake
./package.xml
./pixi.py
./pkg-config.cmake
./pkg-config.pc.cmake
./portability.cmake
Expand All @@ -114,7 +117,6 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
./release.cmake
./relpath.cmake
./ros.cmake
./ros2.cmake
./sdformat.cmake
./setup.cfg
./shared-library.cmake
Expand Down
48 changes: 38 additions & 10 deletions header.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,16 @@ function(
EXPORT_SYMBOL
)
generate_configuration_header_v2(
INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include
HEADER_DIR ${HEADER_DIR}
FILENAME ${FILENAME}
LIBRARY_NAME ${LIBRARY_NAME}
EXPORT_SYMBOL ${EXPORT_SYMBOL}
INCLUDE_DIR
${CMAKE_CURRENT_BINARY_DIR}/include
HEADER_DIR
${HEADER_DIR}
FILENAME
${FILENAME}
LIBRARY_NAME
${LIBRARY_NAME}
EXPORT_SYMBOL
${EXPORT_SYMBOL}
)
endfunction(GENERATE_CONFIGURATION_HEADER)

Expand Down Expand Up @@ -271,19 +276,41 @@ endfunction(GENERATE_CONFIGURATION_HEADER_V2)
macro(_SETUP_PROJECT_HEADER_FINALIZE)
# If the header list is set, install it.
if(DEFINED ${PROJECT_NAME}_HEADERS)
foreach(FILE ${${PROJECT_NAME}_HEADERS})
header_install(${FILE})
endforeach(FILE)
header_install(${${PROJECT_NAME}_HEADERS})
endif(DEFINED ${PROJECT_NAME}_HEADERS)
endmacro(_SETUP_PROJECT_HEADER_FINALIZE)

# .rst: .. ifmode:: internal
#
# .. command:: HEADER_INSTALL (FILES)
# ~~~
# .. command:: HEADER_INSTALL (COMPONENT <component> <files>...)
# ~~~
#
# Install a list of headers.
#
macro(HEADER_INSTALL FILES)
# :param component: Component to forward to install command.
#
# :param files: Files to install.
macro(HEADER_INSTALL)
set(options)
set(oneValueArgs COMPONENT)
set(multiValueArgs)
cmake_parse_arguments(
ARGS
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)

if(ARGS_COMPONENT)
set(_COMPONENT_NAME ${ARGS_COMPONENT})
else()
set(_COMPONENT_NAME ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
endif()

set(FILES ${ARGS_UNPARSED_ARGUMENTS})

foreach(FILE ${FILES})
get_filename_component(DIR "${FILE}" PATH)
string(REGEX REPLACE "${CMAKE_BINARY_DIR}" "" DIR "${DIR}")
Expand All @@ -293,6 +320,7 @@ macro(HEADER_INSTALL FILES)
FILES ${FILE}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${DIR}"
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE
COMPONENT ${_COMPONENT_NAME}
)
endforeach()
endmacro()
49 changes: 49 additions & 0 deletions install-helpers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright (C) 2024 INRIA.
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.

# .rst:
# ~~~
# .. command:: ADD_INSTALL_TARGET (
# NAME <name>
# COMPONENT <component>)
# ~~~
#
# This function add a custom target named install-<name> that will run cmake
# install for a specific <component>.
#
# :param name: Target name suffix (install-<name>).
#
# :param component: component to install.
function(ADD_INSTALL_TARGET)
set(options)
set(oneValueArgs NAME COMPONENT)
set(multiValueArgs)
cmake_parse_arguments(
ARGS
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
set(target_name install-${ARGS_NAME})
set(component ${ARGS_COMPONENT})

add_custom_target(
${target_name}
COMMAND
${CMAKE_COMMAND} -DCOMPONENT=${component} -P
${PROJECT_BINARY_DIR}/cmake_install.cmake
)
endfunction()
63 changes: 60 additions & 3 deletions python-helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,82 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.

# .rst: .. command:: PYTHON_INSTALL(MODULE FILE DEST)
# .rst:
#
# ~~~
# .. command:: PYTHON_INSTALL(<module> <file> <dest> COMPONENT <component>)
# ~~~
#
# Compile and install a Python file.
#
# :param module: Python module name.
#
# :param file: Python file name.
#
# :param file: Installation directory.
#
# :param component: Component to forward to install command.
macro(PYTHON_INSTALL MODULE FILE DEST)
set(options)
set(oneValueArgs COMPONENT)
set(multiValueArgs)
cmake_parse_arguments(
ARGS
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)

if(ARGS_COMPONENT)
set(_COMPONENT_NAME ${ARGS_COMPONENT})
else()
set(_COMPONENT_NAME ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
endif()

python_build("${MODULE}" "${FILE}")

install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/${MODULE}/${FILE}"
DESTINATION "${DEST}/${MODULE}"
COMPONENT ${_COMPONENT_NAME}
)
endmacro()

# .rst: .. command:: PYTHON_INSTALL_ON_SITE (MODULE FILE)
# .rst:
#
# ~~~
# .. command:: PYTHON_INSTALL_ON_SITE (<module> <file> COMPONENT <component>)
# ~~~
#
# Compile and install a Python file in :cmake:variable:`PYTHON_SITELIB`.
#
# :param module: Python module name.
#
# :param file: Python file name.
#
# :param component: Component to forward to install command.
macro(PYTHON_INSTALL_ON_SITE MODULE FILE)
python_install("${MODULE}" "${FILE}" ${PYTHON_SITELIB})
set(options)
set(oneValueArgs COMPONENT)
set(multiValueArgs)
cmake_parse_arguments(
ARGS
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)

if(ARGS_COMPONENT)
set(_COMPONENT_NAME ${ARGS_COMPONENT})
else()
set(_COMPONENT_NAME ${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
endif()

python_install("${MODULE}" "${FILE}" ${PYTHON_SITELIB} COMPONENT
${_COMPONENT_NAME}
)
endmacro()

# PYTHON_BUILD_GET_TARGET(TARGET)
Expand Down

0 comments on commit f1f95f9

Please sign in to comment.