CMake: improved reloading of dependent CMake targets in Config file to

account for COMPONENTS.
This commit is contained in:
mpa 2013-11-05 12:41:48 +00:00
parent 06ff3ece88
commit a8b09e8ac8
2 changed files with 27 additions and 13 deletions

View File

@ -272,6 +272,10 @@ SET(VTK_ROOT_DIR "${VTK_ROOT_DIR}")
SET(OPENCV_ROOT_DIR "${OPENCV_ROOT_DIR}") SET(OPENCV_ROOT_DIR "${OPENCV_ROOT_DIR}")
SET(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include") SET(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include")
# Build variables that will be expanded when configuring Salome<MODULE>Config.cmake:
SALOME_CONFIGURE_PREPARE(OpenCV CAS VTK)
CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_NAME}Config.cmake.in CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_NAME}Config.cmake.in
${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION "${SALOME_INSTALL_CMAKE_LOCAL}" INSTALL_DESTINATION "${SALOME_INSTALL_CMAKE_LOCAL}"

View File

@ -77,22 +77,32 @@ ENDIF()
# For all prerequisites, load the corresponding targets if the package was used # For all prerequisites, load the corresponding targets if the package was used
# in CONFIG mode. This ensures dependent projects link correctly # in CONFIG mode. This ensures dependent projects link correctly
# without having to set LD_LIBRARY_PATH: # without having to set LD_LIBRARY_PATH:
SET(_PREREQ @_PREREQ_LIST@)
SET(_PREREQ OpenCV CAS VTK) SET(_PREREQ_CONFIG_DIR @_PREREQ_DIR_LIST@)
SET(_PREREQ_CONFIG_DIR "@OpenCV_DIR@" "@CAS_DIR@" "@VTK_DIR@") SET(_PREREQ_COMPONENTS "@_PREREQ_COMPO_LIST@")
LIST(LENGTH _PREREQ_CONFIG_DIR _list_len) LIST(LENGTH _PREREQ_CONFIG_DIR _list_len)
IF(NOT _list_len EQUAL 0)
# Another CMake stupidity - FOREACH(... RANGE r) generates r+1 numbers ... # Another CMake stupidity - FOREACH(... RANGE r) generates r+1 numbers ...
MATH(EXPR _range "${_list_len}-1") MATH(EXPR _range "${_list_len}-1")
FOREACH(_p RANGE ${_range}) FOREACH(_p RANGE ${_range})
LIST(GET _PREREQ ${_p} _pkg ) LIST(GET _PREREQ ${_p} _pkg )
LIST(GET _PREREQ_CONFIG_DIR ${_p} _pkg_dir) LIST(GET _PREREQ_CONFIG_DIR ${_p} _pkg_dir)
IF(_pkg_dir) LIST(GET _PREREQ_COMPONENTS ${_p} _pkg_compo)
MESSAGE(STATUS "===> Reloading targets from ${_pkg} ...") MESSAGE(STATUS "===> Reloading targets from ${_pkg} ...")
IF(NOT _pkg_compo)
FIND_PACKAGE(${_pkg} REQUIRED NO_MODULE FIND_PACKAGE(${_pkg} REQUIRED NO_MODULE
PATHS "${_pkg_dir}" PATHS "${_pkg_dir}"
NO_DEFAULT_PATH) NO_DEFAULT_PATH)
ELSE()
STRING(REPLACE "," ";" _compo_lst "${_pkg_compo}")
MESSAGE(STATUS "===> (components: ${_pkg_compo})")
FIND_PACKAGE(${_pkg} REQUIRED NO_MODULE
COMPONENTS ${_compo_lst}
PATHS "${_pkg_dir}"
NO_DEFAULT_PATH)
ENDIF() ENDIF()
ENDFOREACH() ENDFOREACH()
ENDIF()
# Installation directories # Installation directories
SET(SALOME_INSTALL_BINS "@SALOME_INSTALL_BINS@") SET(SALOME_INSTALL_BINS "@SALOME_INSTALL_BINS@")