ros-industrial / ros_industrial_cmake_boilerplate

Other
16 stars 14 forks source link

Auto generation of `*-config.cmake` files for simple cases #59

Closed jdlangs closed 2 years ago

jdlangs commented 2 years ago

This expands the configure_package macro to let users not have to worry about creating the template config file for the most basic cases. For example, using the new macro invocation in opw_kinematics:

configure_package(
  DEFAULT_TEMPLATE
  NAMESPACE opw_kinematics
  TARGETS ${PROJECT_NAME}
  DEPENDENCIES Eigen3
)

generates this file:

#########################################################################
# 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 opw_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(opw_kinematics_FOUND ON)
set_and_check(opw_kinematics_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include")
set_and_check(opw_kinematics_LIBRARY_DIRS "${PACKAGE_PREFIX_DIR}/lib")

# Dependencies
include(CMakeFindDependencyMacro)
find_dependency(Eigen3)

# Targets
include("${CMAKE_CURRENT_LIST_DIR}/opw_kinematics-targets.cmake")

I'm sure there's some subtle stuff that could go wrong here so a close look/review would be greatly appreciated.

Levi-Armstrong commented 2 years ago

I will review tomorrow, but does it support component dependencies?

jdlangs commented 2 years ago

No, just plain calls to find_dependency right now. Is there a natural syntax that could be used in configure_package to indicate the components?

jdlangs commented 2 years ago

I think everything is ready here now for a final check.

Levi-Armstrong commented 2 years ago

@jdlangs Thanks for the contribution.