Skip to content

Commit

Permalink
Handle OPTIONAL_COMPONENTS in find_package(YARP)
Browse files Browse the repository at this point in the history
There is no way to make this work with `find_dependency()` since it
passes caller's REQUIRED to the underlying `find_package()` call.
That is, no error should be raised if an optional component was not
found while issuing a `find_package(YARP REQUIRED ...)` command.
  • Loading branch information
PeterBowman committed Jun 13, 2018
1 parent 1d6675c commit 19a87ba
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
44 changes: 20 additions & 24 deletions cmake/template/YARPConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@



include(CMakeFindDependencyMacro)
include(CMakeDependentOption)


Expand Down Expand Up @@ -116,17 +115,14 @@ set(YARP_QML2_IMPORT_DIR_FULL "@PACKAGE_YARP_QML2_IMPORT_DIR@")
# Used by YarpIDL.cmake
set(YARP_IDL_BINARY_HINT "@PACKAGE_YARP_IDL_BINARY_HINT@")

# FIXME Remove this check when CMake 3.9 or later is required
# This is used later and in YARPTargetsStatic.cmake
if (CMAKE_VERSION VERSION_LESS 3.9)
set(_YARP_FIND_PARTS_REQUIRED)
if (YARP_FIND_REQUIRED)
set(_YARP_FIND_PARTS_REQUIRED REQUIRED)
endif()
set(_YARP_FIND_PARTS_QUIET)
if (YARP_FIND_QUIETLY)
set(_YARP_FIND_PARTS_QUIET QUIET)
endif()
# This is used later and in YARPTargetsStatic.cmake
set(_YARP_FIND_PARTS_REQUIRED)
if (YARP_FIND_REQUIRED)
set(_YARP_FIND_PARTS_REQUIRED REQUIRED)
endif()
set(_YARP_FIND_PARTS_QUIET)
if (YARP_FIND_QUIETLY)
set(_YARP_FIND_PARTS_QUIET QUIET)
endif()

# Include YARPTargets.cmake file (that includes for now, targets without a
Expand All @@ -149,19 +145,19 @@ endif()
# Find all requested components
set(YARP_LIBRARIES YARP::YARP_init)
foreach(_yarp_module ${YARP_FIND_COMPONENTS})
# FIXME Remove this check when CMake 3.9 or later is required
if (CMAKE_VERSION VERSION_LESS 3.9)
find_package(YARP_${_yarp_module}
${_YARP_FIND_PARTS_QUIET}
${_YARP_FIND_PARTS_REQUIRED}
HINTS "${YARP_CMAKECONFIG_DIR}"
NO_DEFAULT_PATH)
else()
find_dependency(YARP_${_yarp_module}
HINTS "${YARP_CMAKECONFIG_DIR}"
NO_DEFAULT_PATH)
set(_YARP_FIND_PART_${_yarp_module}_REQUIRED)
# Only propagate REQUIRED if module was not passed to OPTIONAL_COMPONENTS
if(YARP_FIND_REQUIRED_${_yarp_module})
set(_YARP_FIND_PART_${_yarp_module}_REQUIRED ${_YARP_FIND_PARTS_REQUIRED})
endif()
find_package(YARP_${_yarp_module}
${_YARP_FIND_PARTS_QUIET}
${_YARP_FIND_PART_${_yarp_module}_REQUIRED}
HINTS "${YARP_CMAKECONFIG_DIR}"
NO_DEFAULT_PATH)
if(YARP_${_yarp_module}_FOUND)
list(APPEND YARP_LIBRARIES YARP::YARP_${_yarp_module})
endif()
list(APPEND YARP_LIBRARIES YARP::YARP_${_yarp_module})
endforeach()

# Ensure that all requested modules are available
Expand Down
21 changes: 10 additions & 11 deletions cmake/template/YARPTargetsStatic.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,17 @@ list(APPEND CMAKE_MODULE_PATH ${YARP_MODULE_PATH})
# Properly find the dependencies. This will force to include all the
# dependencies also for packages in other exports
foreach(_target ${_targets})
# FIXME Remove this check when CMake 3.9 or later is required
if (CMAKE_VERSION VERSION_LESS 3.9)
find_package(${_target}
${_YARP_FIND_PARTS_QUIET}
${_YARP_FIND_PARTS_REQUIRED}
HINTS "${YARP_CMAKECONFIG_DIR}"
NO_DEFAULT_PATH)
else()
find_dependency(${_target}
HINTS "${YARP_CMAKECONFIG_DIR}"
NO_DEFAULT_PATH)
string(REGEX REPLACE "^YARP_" "" _target "${_target}")
set(_YARP_FIND_PART_${_target}_REQUIRED)
# Only propagate REQUIRED if module was not passed to OPTIONAL_COMPONENTS
if(YARP_FIND_REQUIRED_${_target})
set(_YARP_FIND_PART_${_target}_REQUIRED ${_YARP_FIND_PARTS_REQUIRED})
endif()
find_package(YARP_${_target}
${_YARP_FIND_PARTS_QUIET}
${_YARP_FIND_PART_${_target}_REQUIRED}
HINTS "${YARP_CMAKECONFIG_DIR}"
NO_DEFAULT_PATH)
endforeach()

# Restore the original situation
Expand Down
4 changes: 4 additions & 0 deletions doc/release/v3_1_0.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ A (partial) list of bug fixed and issues resolved in this release can be found
New Features
------------

### Build System

* Added support for `OPTIONAL_COMPONENTS` in `find_package(YARP)` calls.

### Devices

#### imuBosch_BNO055
Expand Down

0 comments on commit 19a87ba

Please sign in to comment.