Skip to content

Commit

Permalink
[skip ci] 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 15, 2018
1 parent f23f86b commit f61845f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
37 changes: 16 additions & 21 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 @@ -144,27 +143,23 @@ 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)
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()
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_PARTS_REQUIRED AND YARP_FIND_REQUIRED_${_yarp_module})
set(_YARP_FIND_PART_${_yarp_module}_REQUIRED REQUIRED)
endif()
set(_YARP_FIND_PARTS_QUIET)
if(YARP_FIND_QUIETLY)
set(_YARP_FIND_PARTS_QUIET QUIET)
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()

# Restore the original value of the variable
Expand Down
1 change: 1 addition & 0 deletions doc/release/v3_0_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Bug Fixes
be used instead).
* Deprecation warnings when calling find_package(YARP) more than once are no
longer printed.
* Added missing support for `OPTIONAL_COMPONENTS` in `find_package(YARP)` calls.


### Libraries
Expand Down

0 comments on commit f61845f

Please sign in to comment.