# Copyright (C) 2013-2015 CEA/DEN, EDF R&D, OPEN CASCADE # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # ### # SALOME_CHECK_EQUAL_PATHS(result path1 path2) # Check if two paths are identical, resolving links. If the paths do not exist a simple # text comparison is performed. # result is a boolean. ### MACRO(SALOME_CHECK_EQUAL_PATHS varRes path1 path2) SET("${varRes}" OFF) IF(EXISTS "${path1}") GET_FILENAME_COMPONENT(_tmp1 "${path1}" REALPATH) ELSE() SET(_tmp1 "${path1}") ENDIF() IF(EXISTS "${path2}") GET_FILENAME_COMPONENT(_tmp2 "${path2}" REALPATH) ELSE() SET(_tmp2 "${path2}") ENDIF() IF("${_tmp1}" STREQUAL "${_tmp2}") SET("${varRes}" ON) ENDIF() # MESSAGE(${${varRes}}) ENDMACRO() #### # SALOME_FIND_PACKAGE(englobingPackageName standardPackageName modus [onlyTryQuietly]) # # example: SALOME_FIND_PACKAGE(SalomeVTK VTK CONFIG) # # Encapsulate the call to the standard FIND_PACKAGE(standardPackageName) passing all the options # given when calling the command FIND_PACKAGE(SimanIOXyz). Those options are stored implicitly in # CMake variables: Xyz_FIND_QUIETLY, Xyz_FIND_REQUIRED, etc ... # # If a list of components was specified when invoking the initial FIND_PACKAGE(SimanIOXyz ...) this is # also handled properly. # # Modus is either MODULE or CONFIG (cf standard FIND_PACKAGE() documentation). # The last argument is optional and if set to TRUE will force the search to be OPTIONAL and QUIET. # If the package is looked for in CONFIG mode, the standard system paths are skipped. If you still want a # system installation to be found in this mode, you have to set the ROOT_DIR variable explicitly to /usr (for # example). # # This macro is to be called from within the FindSimanIOXyz.cmake files (where Xyz is some package to be detected). # #### MACRO(SALOME_FIND_PACKAGE englobPkg stdPkg mode) SET(_OPT_ARG ${ARGV3}) # Only bother if the package was not already found: # Some old packages use the lower case version - standard should be to always use # upper case: STRING(TOUPPER ${stdPkg} stdPkgUC) IF(NOT (${stdPkg}_FOUND OR ${stdPkgUC}_FOUND)) IF(${englobPkg}_FIND_QUIETLY OR _OPT_ARG) SET(_tmp_quiet "QUIET") ELSE() SET(_tmp_quiet) ENDIF() IF(${englobPkg}_FIND_REQUIRED AND NOT _OPT_ARG) SET(_tmp_req "REQUIRED") ELSE() SET(_tmp_req) ENDIF() IF(${englobPkg}_FIND_VERSION_EXACT) SET(_tmp_exact "EXACT") ELSE() SET(_tmp_exact) ENDIF() # Call the CMake FIND_PACKAGE() command: 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 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' # don't get loaded (typically Boost). To force their loading, set the XYZ_ROOT_DIR variable to '/usr'. # See documentation of FIND_PACKAGE() for full details. # Do we need to call the signature using components? IF(${englobPkg}_FIND_COMPONENTS) FIND_PACKAGE(${stdPkg} ${${englobPkg}_FIND_VERSION} ${_tmp_exact} NO_MODULE ${_tmp_quiet} ${_tmp_req} COMPONENTS ${${englobPkg}_FIND_COMPONENTS} NO_CMAKE_BUILDS_PATH NO_CMAKE_PACKAGE_REGISTRY NO_CMAKE_SYSTEM_PACKAGE_REGISTRY NO_CMAKE_SYSTEM_PATH NO_SYSTEM_ENVIRONMENT_PATH) ELSE() FIND_PACKAGE(${stdPkg} ${${englobPkg}_FIND_VERSION} ${_tmp_exact} NO_MODULE ${_tmp_quiet} ${_tmp_req} NO_CMAKE_BUILDS_PATH NO_CMAKE_PACKAGE_REGISTRY NO_CMAKE_SYSTEM_PACKAGE_REGISTRY NO_CMAKE_SYSTEM_PATH NO_SYSTEM_ENVIRONMENT_PATH) ENDIF() MARK_AS_ADVANCED(${stdPkg}_DIR) ELSEIF("${mode}" STREQUAL "MODULE") # Do we need to call the signature using components? IF(${englobPkg}_FIND_COMPONENTS) FIND_PACKAGE(${stdPkg} ${${englobPkg}_FIND_VERSION} ${_tmp_exact} MODULE ${_tmp_quiet} ${_tmp_req} COMPONENTS ${${englobPkg}_FIND_COMPONENTS}) ELSE() FIND_PACKAGE(${stdPkg} ${${englobPkg}_FIND_VERSION} ${_tmp_exact} MODULE ${_tmp_quiet} ${_tmp_req}) ENDIF() ELSE() MESSAGE(FATAL_ERROR "Invalid mode argument in the call to the macro SALOME_FIND_PACKAGE. Should be CONFIG or MODULE.") ENDIF() ENDIF() ENDMACRO() #################################################################### # SALOME_FIND_PACKAGE_DETECT_CONFLICTS(pkg referenceVariable upCount) # pkg : name of the system package to be detected # referenceVariable: variable containing a path that can be browsed up to # retrieve the package root directory (xxx_ROOT_DIR) # upCount : number of times we have to go up from the path # to obtain the package root directory. # # For example: SALOME_FIND_PACKAGE_DETECT_CONFLICTS(SWIG SWIG_EXECUTABLE 2) # # Generic detection (and conflict check) procedure for package XYZ: # 1. Load a potential env variable XYZ_ROOT_DIR as a default choice for the cache entry XYZ_ROOT_DIR # If empty, load a potential XYZ_ROOT_DIR_EXP as default value (path exposed by another package depending # directly on XYZ) # 2. Invoke FIND_PACKAGE() in this order: # * in CONFIG mode first (if possible): priority is given to a potential # "XYZ-config.cmake" file # * then switch to the standard MODULE mode, appending on CMAKE_PREFIX_PATH # the above XYZ_ROOT_DIR variable # 3. Extract the path actually found into a temp variable _XYZ_TMP_DIR # 4. Warn if XYZ_ROOT_DIR is set and doesn't match what was found (e.g. when CMake found the system installation # instead of what is pointed to by XYZ_ROOT_DIR - happens when a typo in the content of XYZ_ROOT_DIR). # 5. Conflict detection: # * check the temp variable against a potentially existing XYZ_ROOT_DIR_EXP # 6. Finally expose what was *actually* found in XYZ_ROOT_DIR. # 7. Specific stuff: for example exposing a prerequisite of XYZ to the rest of the world for future # conflict detection. This is added after the call to the macro by the callee. # MACRO(SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS pkg referenceVariable upCount) ## ## 0. Initialization ## # Package name, upper case STRING(TOUPPER ${pkg} pkg_UC) ## ## 1. Load environment or any previously detected root dir for the package ## IF(DEFINED ENV{${pkg_UC}_ROOT_DIR}) FILE(TO_CMAKE_PATH "$ENV{${pkg_UC}_ROOT_DIR}" _${pkg_UC}_ROOT_DIR_ENV) SET(_dflt_value "${_${pkg_UC}_ROOT_DIR_ENV}") ELSE() # will be blank if no package was previously loaded: SET(_dflt_value "${${pkg_UC}_ROOT_DIR_EXP}") ENDIF() # Detect if the variable has been set on the command line or elsewhere: IF(DEFINED ${pkg_UC}_ROOT_DIR) SET(_var_already_there TRUE) ELSE() SET(_var_already_there FALSE) ENDIF() # Make cache entry SET(${pkg_UC}_ROOT_DIR "${_dflt_value}" CACHE PATH "Path to ${pkg_UC} directory") ## ## 2. Find package - try CONFIG mode first (i.e. looking for XYZ-config.cmake) ## # Override the variable - don't append to it, as it would give precedence # to what was stored there before! SET(CMAKE_PREFIX_PATH "${${pkg_UC}_ROOT_DIR}") # Try find_package in config mode. This has the priority, but is # performed QUIET and not REQUIRED: SALOME_FIND_PACKAGE("Salome${pkg}" ${pkg} NO_MODULE TRUE) IF (${pkg_UC}_FOUND OR ${pkg}_FOUND) MESSAGE(STATUS "Found ${pkg} in CONFIG mode!") ENDIF() # Otherwise try the standard way (module mode, with the standard CMake Find*** macro): # We do it quietly to produce our own error message, except if we are in debug mode: IF(SALOME_CMAKE_DEBUG) SALOME_FIND_PACKAGE("Salome${pkg}" ${pkg} MODULE FALSE) ELSE() SALOME_FIND_PACKAGE("Salome${pkg}" ${pkg} MODULE TRUE) ENDIF() # Set the "FOUND" variable for the SALOME wrapper: IF(${pkg_UC}_FOUND OR ${pkg}_FOUND) SET(SALOME${pkg_UC}_FOUND TRUE) ELSE() SET(SALOME${pkg_UC}_FOUND FALSE) IF(NOT Salome${pkg}_FIND_QUIETLY) IF(Salome${pkg}_FIND_REQUIRED) MESSAGE(FATAL_ERROR "Package ${pkg} couldn't be found - did you set the corresponing root dir correctly? " "It currently contains ${pkg_UC}_ROOT_DIR=${${pkg_UC}_ROOT_DIR} " "Append -DSALOME_CMAKE_DEBUG=ON on the command line if you want to see the original CMake error.") ELSE() MESSAGE(WARNING "Package ${pkg} couldn't be found - did you set the corresponing root dir correctly? " "It currently contains ${pkg_UC}_ROOT_DIR=${${pkg_UC}_ROOT_DIR} " "Append -DSALOME_CMAKE_DEBUG=ON on the command line if you want to see the original CMake error.") ENDIF() ENDIF() ENDIF() IF (${pkg_UC}_FOUND OR ${pkg}_FOUND) ## 3. Set the root dir which was finally retained by going up "upDir" times ## from the given reference path. The variable "referenceVariable" may be a list. ## In this case we take its first element. # First test if the variable exists, warn otherwise: IF(NOT DEFINED ${referenceVariable}) MESSAGE(WARNING "${pkg}: the reference variable '${referenceVariable}' used when calling the macro " "SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS() is not defined.") ENDIF() LIST(LENGTH ${referenceVariable} _tmp_len) IF(_tmp_len) LIST(GET ${referenceVariable} 0 _tmp_ROOT_DIR) ELSE() # Note the double de-reference of "referenceVariable": SET(_tmp_ROOT_DIR "${${referenceVariable}}") ENDIF() IF(${upCount}) FOREACH(_unused RANGE 1 ${upCount}) GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${_tmp_ROOT_DIR}" PATH) ENDFOREACH() ENDIF() ## ## 4. Warn if CMake found something not located under ENV(XYZ_ROOT_DIR) ## IF(DEFINED ENV{${pkg_UC}_ROOT_DIR}) SALOME_CHECK_EQUAL_PATHS(_res "${_tmp_ROOT_DIR}" "${_${pkg_UC}_ROOT_DIR_ENV}") IF(NOT _res) MESSAGE(WARNING "${pkg} was found, but not at the path given by the " "environment ${pkg_UC}_ROOT_DIR! Is the variable correctly set? " "The two paths are: ${_tmp_ROOT_DIR} and: ${_${pkg_UC}_ROOT_DIR_ENV}") ELSE() MESSAGE(STATUS "${pkg} found directory matches what was specified in the ${pkg_UC}_ROOT_DIR variable, all good!") ENDIF() ELSE() IF(NOT _var_already_there) MESSAGE(STATUS "Variable ${pkg_UC}_ROOT_DIR was not explicitly defined. " "An installation was found anyway: ${_tmp_ROOT_DIR}") ENDIF() ENDIF() ## ## 5. Conflict detection ## From another prerequisite using the package: ## IF(${pkg_UC}_ROOT_DIR_EXP) SALOME_CHECK_EQUAL_PATHS(_res "${_tmp_ROOT_DIR}" "${${pkg_UC}_ROOT_DIR_EXP}") IF(NOT _res) MESSAGE(WARNING "Warning: ${pkg}: detected version conflicts with a previously found ${pkg}!" " The two paths are " ${_tmp_ROOT_DIR} " vs " ${${pkg_UC}_ROOT_DIR_EXP}) ELSE() MESSAGE(STATUS "${pkg} directory matches what was previously exposed by another prereq, all good!") ENDIF() ENDIF() ## ## 6. Save the detected installation ## SET(${pkg_UC}_ROOT_DIR "${_tmp_ROOT_DIR}") ELSE() MESSAGE(STATUS "${pkg} was not found.") ENDIF() SET(Salome${pkg}_FOUND "${pkg}_FOUND") ENDMACRO(SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS)