ros-industrial / ros_industrial_cmake_boilerplate

Other
16 stars 14 forks source link

Add find_package component support #82

Closed Levi-Armstrong closed 1 year ago

Levi-Armstrong commented 1 year ago
marip8 commented 1 year ago

Looks fine to me for the most part, but I don't really understand how to make CMake components. Does this affect CPack and debian generation?

Levi-Armstrong commented 1 year ago

Looks fine to me for the most part, but I don't really understand how to make CMake components. Does this affect CPack and debian generation?

I would take a look at the tesseract PR where I leverage the new features for generating components

Instead of having a single tesseract_kinematics-config.cmake file with everything switching things off and on with build options leveraging the components feature you get a separate component config where the tesseract_kinematics-config.cmake looks like this.

# Default *-config.cmake file created by ros-industrial-cmake-boilerplate

####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was tesseract_kinematics-config.cmake.in                            ########

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)

macro(set_and_check _var _file)
  set(${_var} "${_file}")
  if(NOT EXISTS "${_file}")
    message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  endif()
endmacro()

####################################################################################

set(tesseract_kinematics_FOUND ON)

# Components
set(supported_components core ikfast kdl opw ur)
if (NOT tesseract_kinematics_FIND_COMPONENTS)
  foreach(component ${supported_components})
    include(${CMAKE_CURRENT_LIST_DIR}/${component}-config.cmake)
  endforeach()
else()
  foreach(component ${tesseract_kinematics_FIND_COMPONENTS})
    if(NOT component IN_LIST supported_components)
      set(tesseract_kinematics_${component}_FOUND OFF)
      set(tesseract_kinematics_${component}_NOT_FOUND_MESSAGE "Unsupported component")
      if (tesseract_kinematics_FIND_REQUIRED_${component})
        message(FATAL_ERROR "Failed to find required component ${component} for package tesseract_kinematics")
      endif()
    else()
      include(${CMAKE_CURRENT_LIST_DIR}/${component}-config.cmake)
    endif()
  endforeach()
endif()

# Extra configuration files
include("${CMAKE_CURRENT_LIST_DIR}/tesseract_kinematics-extras.cmake")

image

Levi-Armstrong commented 1 year ago

This should not affect the cpack debain generation, but I think we should be able to create a separate debian for each component to avoid having one which installs all components.