-# Another CMake stupidity - FOREACH(... RANGE r) generates r+1 numbers ...
-MATH(EXPR _range "${_list_len}-1")
-FOREACH(_p RANGE ${_range})
- LIST(GET _PREREQ ${_p} _pkg )
- LIST(GET _PREREQ_CONFIG_DIR ${_p} _pkg_dir)
- IF(_pkg_dir)
- MESSAGE(STATUS "===> Reloading targets from ${_pkg} ...")
- FIND_PACKAGE(${_pkg} REQUIRED NO_MODULE
+IF(NOT _list_len EQUAL 0)
+ # Another CMake stupidity - FOREACH(... RANGE r) generates r+1 numbers ...
+ MATH(EXPR _range "${_list_len}-1")
+ FOREACH(_p RANGE ${_range})
+ LIST(GET _PREREQ ${_p} _pkg )
+ LIST(GET _PREREQ_CONFIG_DIR ${_p} _pkg_dir)
+ LIST(GET _PREREQ_COMPONENTS ${_p} _pkg_compo)
+ MESSAGE(STATUS "===> Reloading targets from ${_pkg} ...")
+ IF(NOT _pkg_compo)
+ FIND_PACKAGE(${_pkg} REQUIRED NO_MODULE
+ PATHS "${_pkg_dir}"
+ NO_DEFAULT_PATH)
+ ELSE()
+ STRING(REPLACE "," ";" _compo_lst "${_pkg_compo}")
+ MESSAGE(STATUS "===> (components: ${_pkg_compo})")
+ FIND_PACKAGE(${_pkg} REQUIRED NO_MODULE
+ COMPONENTS ${_compo_lst}