From f61845fa4da624706218785368f3c43ad3b9ea7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20=C5=81ukawski?= Date: Sun, 10 Jun 2018 19:27:21 +0200 Subject: [PATCH] [skip ci] Handle OPTIONAL_COMPONENTS in find_package(YARP) 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. --- cmake/template/YARPConfig.cmake.in | 37 +++++++++++++----------------- doc/release/v3_0_1.md | 1 + 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/cmake/template/YARPConfig.cmake.in b/cmake/template/YARPConfig.cmake.in index 14060c0a3dd..84e50630d76 100644 --- a/cmake/template/YARPConfig.cmake.in +++ b/cmake/template/YARPConfig.cmake.in @@ -7,7 +7,6 @@ -include(CMakeFindDependencyMacro) include(CMakeDependentOption) @@ -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 diff --git a/doc/release/v3_0_1.md b/doc/release/v3_0_1.md index bc224c3b964..2aa692a6679 100644 --- a/doc/release/v3_0_1.md +++ b/doc/release/v3_0_1.md @@ -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