# MESSAGE(${${varRes}})
ENDMACRO()
+####
+# SALOME_LOG_OPTIONAL_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 to avoid detection of the package.
+# The global variables are read again by SALOME_PACKAGE_REPORT_AND_CHECK to produce
+# a summary report of the detection status and stops the process if necessary.
+MACRO(SALOME_LOG_OPTIONAL_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()
+
+ENDMACRO(SALOME_LOG_OPTIONAL_PACKAGE)
+
+####
+# SALOME_JUSTIFY_STRING()
+#
+# Justifies the string specified as an argument to the given length
+# adding required number of spaces to the end. Does noting if input
+# string is longer as required length.
+# Puts the result to the output variable.
+#
+# USAGE: SALOME_JUSTIFY_STRING(input length result)
+#
+# ARGUMENTS:
+# input [in] input string
+# length [in] required length of resulting string
+# result [out] name of variable where the result string is put to
+#
+MACRO(SALOME_JUSTIFY_STRING input length result)
+ SET(${result} ${input})
+ STRING(LENGTH ${input} _input_length)
+ MATH(EXPR _nb_spaces "${length}-${_input_length}-1")
+ IF (_nb_spaces GREATER 0)
+ FOREACH(_idx RANGE ${_nb_spaces})
+ SET(${result} "${${result}} ")
+ ENDFOREACH()
+ ENDIF()
+ENDMACRO(SALOME_JUSTIFY_STRING)
+
+####
+# SALOME_PACKAGE_REPORT_AND_CHECK()
+#
+# Print a quick summary of the detection of optional prerequisites.
+# If a package was not found, the configuration is stopped. The summary also indicates
+# which flag should be turned off to skip the detection of the package.
+#
+# If optional JUSTIFY argument is specified, names of packages
+# are left-justified to the given length; default value is 10.
+#
+# USAGE: SALOME_PACKAGE_REPORT_AND_CHECK([JUSTIFY length])
+#
+MACRO(SALOME_PACKAGE_REPORT_AND_CHECK)
+ SET(_will_fail OFF)
+ PARSE_ARGUMENTS(SALOME_PACKAGE_REPORT "JUSTIFY" "" ${ARGN})
+ IF(SALOME_PACKAGE_REPORT_JUSTIFY)
+ SET(_length ${SALOME_PACKAGE_REPORT_JUSTIFY})
+ ELSE()
+ SET(_length 23)
+ ENDIF()
+ MESSAGE(STATUS "")
+ MESSAGE(STATUS " Optional packages - Detection report ")
+ MESSAGE(STATUS " ==================================== ")
+ MESSAGE(STATUS "")
+ IF(DEFINED _SALOME_OPTIONAL_PACKAGES_names)
+ 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)
+ SALOME_JUSTIFY_STRING(${_pkg_name} ${_length} _pkg_name)
+ IF(_pkg_found)
+ SET(_found_msg "Found")
+ SET(_flag_msg "")
+ ELSE()
+ SET(_will_fail ON)
+ SET(_found_msg "NOT Found")
+ SET(_flag_msg " - ${_pkg_flag} can be switched OFF to skip this prerequisite.")
+ ENDIF()
+
+ MESSAGE(STATUS " * ${_pkg_name} -> ${_found_msg}${_flag_msg}")
+ ENDFOREACH()
+ ENDIF(DEFINED _SALOME_OPTIONAL_PACKAGES_names)
+ MESSAGE(STATUS "")
+ MESSAGE(STATUS "")
+
+ # Failure if some packages were missing:
+ IF(_will_fail)
+ MESSAGE(FATAL_ERROR "Some required prerequisites have NOT been found. Take a look at the report above to fix this.")
+ ENDIF()
+ENDMACRO(SALOME_PACKAGE_REPORT_AND_CHECK)
####
# SALOME_FIND_PACKAGE(englobingPackageName standardPackageName modus [onlyTryQuietly])
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'
ENDIF()
# Otherwise try the standard way (module mode, with the standard CMake Find*** macro):
- # We do it quietly to produce our own error message:
- SALOME_FIND_PACKAGE("Salome${pkg}" ${pkg} MODULE TRUE)
+ # 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)
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}")
+ "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}")
+ "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()
## 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 and is not empty:
- IF((NOT DEFINED ${referenceVariable}) OR ("${${referenceVariable}}" STREQUAL ""))
+ # 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() does not exist or is empty.")
+ "SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS() is not defined.")
ENDIF()
LIST(LENGTH ${referenceVariable} _tmp_len)
# Note the double de-reference of "referenceVariable":
SET(_tmp_ROOT_DIR "${${referenceVariable}}")
ENDIF()
- IF(${upCount})
- MATH(EXPR _rge "${upCount}-1")
- FOREACH(_unused RANGE ${_rge})
+ IF(${upCount})
+ FOREACH(_unused RANGE 1 ${upCount})
GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${_tmp_ROOT_DIR}" PATH)
ENDFOREACH()
ENDIF()
SET(HDF5_LIBRARIES ${HDF5_LIBRARIES} ${MPI_LIBRARIES})
ENDMACRO(SALOME_ADD_MPI_TO_HDF5)
+####################################################################
+# SALOME_TOHEXA()
+# Convert a number (smaller than 16) into hexadecimal representation
+# with a leading 0.
+MACRO(SALOME_TOHEXA num result)
+ SET(_hexa_map a b c d e f)
+ IF(${num} LESS 10)
+ SET(${result} "0${num}")
+ ELSE()
+ MATH(EXPR _res "${num}-10" )
+ LIST(GET _hexa_map ${_res} _out)
+ SET(${result} "0${_out}")
+ ENDIF()
+ENDMACRO(SALOME_TOHEXA)
+
####################################################################
# SALOME_XVERSION()
#
MACRO(SALOME_XVERSION pkg)
STRING(TOUPPER ${pkg} _pkg_UC)
IF(${_pkg_UC}_VERSION)
- EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import sys; t=sys.argv[-1].split(\".\") ; t[:]=(int(elt) for elt in t) ; sys.stdout.write(\"0x%02x%02x%02x\"%tuple(t))" ${${_pkg_UC}_VERSION}
- OUTPUT_VARIABLE ${_pkg_UC}_XVERSION)
+ SET(_major)
+ SET(_minor)
+ SET(_patch)
+ SALOME_TOHEXA(${${_pkg_UC}_MAJOR_VERSION} _major)
+ SALOME_TOHEXA(${${_pkg_UC}_MINOR_VERSION} _minor)
+ SALOME_TOHEXA(${${_pkg_UC}_PATCH_VERSION} _patch)
+ SET(${_pkg_UC}_XVERSION "0x${_major}${_minor}${_patch}")
ENDIF()
ENDMACRO(SALOME_XVERSION)
+
+
+#########################################################################
+# SALOME_ACCUMULATE_HEADERS()
+#
+# This macro is called in the various FindSalomeXYZ.cmake modules to accumulate
+# internally the list of include headers to be saved for future export.
+# The full set of include is saved in a variable called
+# _${PROJECT_NAME}_EXTRA_HEADERS
+#
+MACRO(SALOME_ACCUMULATE_HEADERS lst)
+ FOREACH(l IN LISTS ${lst})
+ LIST(FIND _${PROJECT_NAME}_EXTRA_HEADERS "${l}" _res)
+ IF(_res EQUAL "-1")
+ IF(NOT "${l}" STREQUAL "/usr/include")
+ LIST(APPEND _${PROJECT_NAME}_EXTRA_HEADERS "${l}")
+ ENDIF()
+ ENDIF()
+ ENDFOREACH()
+ENDMACRO(SALOME_ACCUMULATE_HEADERS)
+
+#########################################################################
+# SALOME_ACCUMULATE_ENVIRONMENT()
+#
+# USAGE: SALOME_ACCUMULATE_ENVIRONMENT(envvar value [value ...])
+#
+# ARGUMENTS:
+# envvar [in] environment variable name, e.g. PATH
+# value [in] value(s) to be added to environment variable
+#
+# This macro is called in the various FindSalomeXYZ.cmake modules to
+# accumulate environment variables, to be used later to run some command
+# in proper environment.
+#
+# 1. Each envrironment variable is stored in specific CMake variable
+# _${PROJECT_NAME}_EXTRA_ENV_<var>, where <var> is name of variable.
+# 2. Full list of environment variable names is stored in CMake variable
+# _${PROJECT_NAME}_EXTRA_ENV.
+#
+# Notes:
+# - The arguments list can include optional CHECK or NOCHECK keywords:
+# * For all arguments following CHECK keyword the macro perform an
+# additional check (see below); this is the default mode, it is suitable
+# for path variables (PATH, LD_LIBRARY_PATH, etc).
+# * For all arguments following NOCHECK keyword, no additional check is
+# performed.
+# Checking an argument means that we check:
+# - That the path actually exists
+# - That this is not a standard system path (starting with "/usr"); this avoids
+# polluting LD_LIBRARY_PATH or PATH with things like "/usr/lib64" ...
+#
+MACRO(SALOME_ACCUMULATE_ENVIRONMENT envvar)
+ SET(_is_check ON)
+ FOREACH(_item ${ARGN})
+ IF(${_item} STREQUAL "NOCHECK")
+ SET(_is_check OFF)
+ ELSEIF(${_item} STREQUAL "CHECK")
+ SET(_is_check ON)
+ ELSE()
+ IF(_is_check)
+ IF(NOT IS_DIRECTORY ${_item})
+ IF(TARGET ${_item})
+ GET_TARGET_PROPERTY(_item ${_item} LOCATION)
+ ENDIF()
+ GET_FILENAME_COMPONENT(_item ${_item} PATH)
+ ENDIF()
+ IF(EXISTS ${_item})
+ STRING(REGEX MATCH "^(/usr|/lib|/bin)" _usr_find ${_item})
+ LIST(FIND _${PROJECT_NAME}_EXTRA_ENV_${envvar} ${_item} _res)
+ IF(NOT _usr_find AND _res EQUAL -1)
+ LIST(APPEND _${PROJECT_NAME}_EXTRA_ENV_${envvar} ${_item})
+ ENDIF()
+ ENDIF()
+ ELSE(_is_check)
+ LIST(FIND _${PROJECT_NAME}_EXTRA_ENV_${envvar} ${_item} _res)
+ IF( _res EQUAL -1)
+ LIST(APPEND _${PROJECT_NAME}_EXTRA_ENV_${envvar} ${_item})
+ ENDIF()
+ ENDIF(_is_check)
+ ENDIF()
+ ENDFOREACH()
+
+ LIST(FIND _${PROJECT_NAME}_EXTRA_ENV ${envvar} _res)
+ IF(_res EQUAL -1)
+ LIST(APPEND _${PROJECT_NAME}_EXTRA_ENV ${envvar})
+ ENDIF()
+ SET(_${PROJECT_NAME}_EXTRA_ENV_FULL "SET\(${PROJECT_NAME}_EXTRA_ENV ${_${PROJECT_NAME}_EXTRA_ENV}\)")
+ FOREACH(_res ${_${PROJECT_NAME}_EXTRA_ENV})
+ SET(_${PROJECT_NAME}_EXTRA_ENV_FULL "${_${PROJECT_NAME}_EXTRA_ENV_FULL}\nSET\(${PROJECT_NAME}_EXTRA_ENV_${_res} ${_${PROJECT_NAME}_EXTRA_ENV_${_res}}\)")
+ ENDFOREACH()
+ENDMACRO(SALOME_ACCUMULATE_ENVIRONMENT)
+
+#########################################################################
+# SALOME_GENERATE_ENVIRONMENT_SCRIPT()
+#
+# USAGE: SALOME_GENERATE_ENVIRONMENT_SCRIPT(output script cmd opts)
+#
+# ARGUMENTS:
+# output [out] output command, e.g. for creation of target.
+# script [in] output environement script name
+# cmd [in] input command, e.g. sphinx or python command.
+# opts [in] options for input command (cmd).
+#
+# This macro is called when it's necessary to use given environment to run some command.
+# Macro generates environement script using previously created variables
+# _${PROJECT_NAME}_EXTRA_ENV_<var>, where <var> is name of variable and
+# _${PROJECT_NAME}_EXTRA_ENV (see marco SALOME_ACCUMULATE_ENVIRONMENT);
+# and puts generated command in proper environment into <output> argument.
+#
+# Notes:
+# - If <script> is specified as relative path, it is computed from the current build
+# directory.
+#
+MACRO(SALOME_GENERATE_ENVIRONMENT_SCRIPT output script cmd opts)
+ IF(IS_ABSOLUTE ${script})
+ SET(_script ${script})
+ ELSE()
+ SET(_script ${CMAKE_CURRENT_BINARY_DIR}/${script})
+ ENDIF()
+
+ SET(_env)
+ FOREACH(_item ${_${PROJECT_NAME}_EXTRA_ENV})
+ FOREACH(_val ${_${PROJECT_NAME}_EXTRA_ENV_${_item}})
+ IF(WIN32)
+ IF(${_item} STREQUAL "LD_LIBRARY_PATH")
+ SET(_item PATH)
+ ENDIF()
+ STRING(REPLACE "/" "\\" _env "${_env} @SET ${_item}=${_val};%${_item}%\n")
+ SET(_ext "bat")
+ SET(_call_cmd "call")
+ ELSE(WIN32)
+ SET(_env "${_env} export ${_item}=${_val}:\${${_item}}\n")
+ SET(_ext "sh")
+ SET(_call_cmd ".")
+ ENDIF(WIN32)
+ ENDFOREACH()
+ ENDFOREACH()
+
+ SET(_script ${_script}.${_ext})
+ FILE(WRITE ${_script} "${_env}")
+
+ SET(${output} ${_call_cmd} ${_script} && ${cmd} ${opts})
+
+ENDMACRO(SALOME_GENERATE_ENVIRONMENT_SCRIPT)
+
+#########################################################################
+# SALOME_GENERATE_TESTS_ENVIRONMENT()
+#
+# USAGE: SALOME_GENERATE_TESTS_ENVIRONMENT(output)
+#
+# ARGUMENTS:
+# output [out] output environement variable.
+#
+# This macro generates <output> variable to use given environment to run some tests.
+# Macro generates environement variable using previously created variables
+# _${PROJECT_NAME}_EXTRA_ENV_<var>, where <var> is name of variable and
+# _${PROJECT_NAME}_EXTRA_ENV (see marco SALOME_ACCUMULATE_ENVIRONMENT);
+# and puts this variable into <output> argument.
+#
+MACRO(SALOME_GENERATE_TESTS_ENVIRONMENT output)
+ SET(_env)
+ FOREACH(_item ${_${PROJECT_NAME}_EXTRA_ENV})
+ FOREACH(_val ${_${PROJECT_NAME}_EXTRA_ENV_${_item}})
+ IF(WIN32)
+ SET(_env "${_val};${_env}")
+ ELSE()
+ SET(_env "${_val}:${_env}")
+ ENDIF()
+ ENDFOREACH()
+ SET(_env " ${_item}=${_env}")
+ ENDFOREACH()
+ SET(${output} ${_env})
+ENDMACRO(SALOME_GENERATE_TESTS_ENVIRONMENT)
+
+#########################################################################
+# SALOME_APPEND_LIST_OF_LIST()
+#
+# USAGE: SALOME_APPEND_LIST_OF_LIST(result element_list)
+#
+# Build a list of lists. The element_list is first parsed to convert it
+# from
+# a;b;c;d;e
+# to
+# a,b,c,d,e
+#
+# It is then added to the big list 'result'. Hence 'result' looks like:
+# a,b,c,d,e;f,g,h; ...
+#
+MACRO(SALOME_APPEND_LIST_OF_LIST result element_list)
+ SET(_tmp_res)
+ STRING(REPLACE ";" "," _tmp_res "${${element_list}}")
+ SET(${result} "${${result}};${_tmp_res}") # LIST(APPEND ...) doesn't handle well empty elements!?
+ENDMACRO(SALOME_APPEND_LIST_OF_LIST)
+
+#########################################################################
+# SALOME_CONFIGURE_PREPARE()
+#
+# USAGE: SALOME_CONFIGURE_PREPARE(pkg1 pkg2 ...)
+#
+# Prepare the variable that will be used to configure the file Salome<MODULE>Config.cmake,
+# namely:
+# - _PREREQ_LIST : the list of level 1 external prerequisites
+# - _PREREQ_DIR_LIST : their corresponding CMake directories (i.e. where the CMake configuration
+# file for this package can be found, if there is any!)
+# - _PREREQ_COMPO_LIST: the list of components requested when this package was invoked
+#
+# All this information is built from the package_list, the list of level 1 packages for this module.
+# Only the packages found in CONFIG mode are retained.
+#
+MACRO(SALOME_CONFIGURE_PREPARE)
+ SET(_tmp_prereq "${ARGV}")
+ SET(_PREREQ_LIST)
+ SET(_PREREQ_DIR_LIST)
+ SET(_PREREQ_COMPO_LIST)
+ FOREACH(_prereq IN LISTS _tmp_prereq)
+ IF(${_prereq}_DIR)
+ SET(_PREREQ_LIST "${_PREREQ_LIST} ${_prereq}")
+ SET(_PREREQ_DIR_LIST "${_PREREQ_DIR_LIST} \"${${_prereq}_DIR}\"")
+ SALOME_APPEND_LIST_OF_LIST(_PREREQ_COMPO_LIST Salome${_prereq}_COMPONENTS)
+ ENDIF()
+ ENDFOREACH()
+ENDMACRO(SALOME_CONFIGURE_PREPARE)