From 23c65fd0767519d28bfc1152ec40097832535b67 Mon Sep 17 00:00:00 2001 From: mpa Date: Tue, 5 Nov 2013 12:49:17 +0000 Subject: [PATCH] CMake: improved reloading of dependent CMake targets in Config file to account for COMPONENTS. --- CMakeLists.txt | 4 ++++ SalomeSMESHConfig.cmake.in | 35 +++++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5f40f51b..07278cd49 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -309,6 +309,10 @@ SET(CGNS_ROOT_DIR "${CGNS_ROOT_DIR}") SET(TBB_ROOT_DIR "${TBB_ROOT_DIR}") SET(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include") + +# Build variables that will be expanded when configuring SalomeConfig.cmake: +SALOME_CONFIGURE_PREPARE(CGNS TBB MEDFile) + CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_NAME}Config.cmake.in ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake INSTALL_DESTINATION "${SALOME_INSTALL_CMAKE_LOCAL}" diff --git a/SalomeSMESHConfig.cmake.in b/SalomeSMESHConfig.cmake.in index c4417cb2b..8a36a1cc3 100644 --- a/SalomeSMESHConfig.cmake.in +++ b/SalomeSMESHConfig.cmake.in @@ -78,21 +78,32 @@ ENDIF() # For all prerequisites, load the corresponding targets if the package was used # in CONFIG mode. This ensures dependent projects link correctly # without having to set LD_LIBRARY_PATH: -SET(_PREREQ CGNS TBB MEDFile) -SET(_PREREQ_CONFIG_DIR "@CGNS_DIR@" "@TBB_DIR@" "@MEDFile_DIR@") +SET(_PREREQ @_PREREQ_LIST@) +SET(_PREREQ_CONFIG_DIR @_PREREQ_DIR_LIST@) +SET(_PREREQ_COMPONENTS "@_PREREQ_COMPO_LIST@") LIST(LENGTH _PREREQ_CONFIG_DIR _list_len) -# 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) - ENDIF() -ENDFOREACH() + 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() + ENDFOREACH() +ENDIF() # Installation directories SET(SALOME_INSTALL_BINS "@SALOME_INSTALL_BINS@") -- 2.39.2