From 10b71812e88652602f090a7e2e1bcd5710ff0f51 Mon Sep 17 00:00:00 2001 From: bruneton Date: Tue, 27 Aug 2013 08:45:56 +0000 Subject: [PATCH] CMake: creation of the macros SALOME_UPDATE_FLAG_AND_LOG_PACKAGE() and SALOME_PACKAGE_REPORT(). The two are used to register optional packages and to turn off specific configuration flags when the optional prerequisites is not found. The final setup is printed on screen through SALOME_PACKAGE_REPORT() --- CMakeLists.txt | 18 ++++-- salome_adm/cmake_files/SalomeMacros.cmake | 69 ++++++++++++++++++++++- 2 files changed, 81 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cd3236d6..d40fb2578 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,8 @@ MARK_AS_ADVANCED(SALOME_LIGHT_ONLY SALOME_USE_LIBBATCH SALOME_PACO_PARALLEL SALO # Exception: LibBatch is optional but is loaded first, as it can # give Python, Pthread and SWIG: IF(SALOME_USE_LIBBATCH) - FIND_PACKAGE(SalomeLibBatch REQUIRED) + FIND_PACKAGE(SalomeLibBatch) + SALOME_UPDATE_FLAG_AND_LOG_PACKAGE(LibBatch SALOME_USE_LIBBATCH) ENDIF() FIND_PACKAGE(SalomePython REQUIRED) @@ -104,14 +105,21 @@ IF(SALOME_PACO_PARALLEL) ENDIF() IF(SALOME_BUILD_TESTS) ENABLE_TESTING() - FIND_PACKAGE(SalomeCppUnit REQUIRED) + FIND_PACKAGE(SalomeCppUnit) + SALOME_UPDATE_FLAG_AND_LOG_PACKAGE(CppUnit SALOME_BUILD_TESTS) ENDIF() IF(SALOME_BUILD_DOC) - FIND_PACKAGE(SalomeDoxygen REQUIRED) - FIND_PACKAGE(SalomeGraphviz) # Remains optional even here. - FIND_PACKAGE(SalomeSphinx REQUIRED) + FIND_PACKAGE(SalomeDoxygen) + FIND_PACKAGE(SalomeGraphviz) + FIND_PACKAGE(SalomeSphinx) + SALOME_UPDATE_FLAG_AND_LOG_PACKAGE(Doxygen SALOME_BUILD_DOC) + SALOME_UPDATE_FLAG_AND_LOG_PACKAGE(Graphviz SALOME_BUILD_DOC) + SALOME_UPDATE_FLAG_AND_LOG_PACKAGE(Sphinx SALOME_BUILD_DOC) ENDIF() +# Detection summary: +SALOME_PACKAGE_REPORT() + # Directories # # Directories have to be given after prerequisites (to be able to use diff --git a/salome_adm/cmake_files/SalomeMacros.cmake b/salome_adm/cmake_files/SalomeMacros.cmake index be1631cc9..454bb47e6 100755 --- a/salome_adm/cmake_files/SalomeMacros.cmake +++ b/salome_adm/cmake_files/SalomeMacros.cmake @@ -210,6 +210,73 @@ MACRO(SALOME_CHECK_EQUAL_PATHS varRes path1 path2) # MESSAGE(${${varRes}}) ENDMACRO() +#### +# SALOME_UPDATE_FLAG_AND_LOG_PACKAGE(pkg flag) +# +# Register in global variables the detection status (found or not) of the optional package 'pkg' +# and the configuration flag that should be turned off if it is not found. +# If the package was not found, the macro explicitly turns off the flag. +# The global variables are read again by SALOME_PACKAGE_REPORT to produce a summary report +# of the detection status, and of the modified flags. +MACRO(SALOME_UPDATE_FLAG_AND_LOG_PACKAGE pkg flag) + # Was the package found + STRING(TOUPPER ${pkg} _pkg_UC) + IF(${pkg}_FOUND OR ${_pkg_UC}_FOUND) + SET(_isFound TRUE) + ELSE() + SET(_isFound FALSE) + ENDIF() + + # Is the package already in the list? Then update its status: + LIST(FIND _SALOME_OPTIONAL_PACKAGES_names ${pkg} _result) + IF(NOT ${_result} EQUAL -1) + LIST(REMOVE_AT _SALOME_OPTIONAL_PACKAGES_found ${_result}) + LIST(REMOVE_AT _SALOME_OPTIONAL_PACKAGES_flags ${_result}) + LIST(INSERT _SALOME_OPTIONAL_PACKAGES_found ${_result} ${_isFound}) + LIST(INSERT _SALOME_OPTIONAL_PACKAGES_flags ${_result} ${flag}) + ELSE() + # Otherwise insert it + LIST(APPEND _SALOME_OPTIONAL_PACKAGES_names ${pkg}) + LIST(APPEND _SALOME_OPTIONAL_PACKAGES_found ${_isFound}) + LIST(APPEND _SALOME_OPTIONAL_PACKAGES_flags ${flag}) + ENDIF() + + # If the package was not found, force the cache flag to OFF + IF(NOT isFound) + SET(${flag} OFF) + ENDIF() +ENDMACRO(SALOME_UPDATE_FLAG_AND_LOG_PACKAGE) + +#### +# SALOME_PACKAGE_REPORT() +# +# Print a quick summary of the detection of optional prerequisites. +# +MACRO(SALOME_PACKAGE_REPORT) + MESSAGE(STATUS "") + MESSAGE(STATUS " Optional packages - Detection report ") + MESSAGE(STATUS " ==================================== ") + MESSAGE(STATUS "") + LIST(LENGTH _SALOME_OPTIONAL_PACKAGES_names _list_len) + # Another CMake stupidity - FOREACH(... RANGE r) generates r+1 numbers ... + MATH(EXPR _range "${_list_len}-1") + FOREACH(_idx RANGE ${_range}) + LIST(GET _SALOME_OPTIONAL_PACKAGES_names ${_idx} _pkg_name) + LIST(GET _SALOME_OPTIONAL_PACKAGES_found ${_idx} _pkg_found) + LIST(GET _SALOME_OPTIONAL_PACKAGES_flags ${_idx} _pkg_flag) + IF(_pkg_found) + SET(_found_msg "Found") + SET(_flag_msg "") + ELSE() + SET(_found_msg "NOT Found") + SET(_flag_msg " - ${_pkg_flag} has been switched OFF.") + ENDIF() + + MESSAGE(STATUS " * ${_pkg_name} -> ${_found_msg}${_flag_msg}") + ENDFOREACH() + MESSAGE(STATUS "") + MESSAGE(STATUS "") +ENDMACRO(SALOME_PACKAGE_REPORT) #### # SALOME_FIND_PACKAGE(englobingPackageName standardPackageName modus [onlyTryQuietly]) @@ -259,7 +326,7 @@ MACRO(SALOME_FIND_PACKAGE englobPkg stdPkg mode) STRING(TOLOWER ${stdPkg} _pkg_lc) IF(("${mode}" STREQUAL "NO_MODULE") OR ("${mode}" STREQUAL "CONFIG")) # Hope to find direclty a CMake config file, indicating the SALOME CMake file - # paths (the command already look in places like "share/cmake", etc ... by default) + # paths (the command already looks in places like "share/cmake", etc ... by default) # Note the options NO_CMAKE_BUILDS_PATH, NO_CMAKE_PACKAGE_REGISTRY to avoid (under Windows) # looking into a previous CMake build done via a GUI, or into the Win registry. # NO_CMAKE_SYSTEM_PATH and NO_SYSTEM_ENVIRONMENT_PATH ensure any _system_ files like 'xyz-config.cmake' -- 2.39.2