From 1f347ed63db8209e0fc883a4f748a85e1f5a8c2d Mon Sep 17 00:00:00 2001 From: mpa Date: Tue, 14 Jul 2015 14:50:50 +0300 Subject: [PATCH] This is alternative solution for improvement "0023066: [CEA 1509] CMake - Installation of a SALOME module should be movable". For usage, these changes must be implemented for all Salome modules. --- CMakeLists.txt | 13 +- salome_adm/cmake_files/FindSalomeKERNEL.cmake | 5 + salome_adm/cmake_files/SalomeMacros.cmake | 155 +++++++++++------- 3 files changed, 107 insertions(+), 66 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 403a93299..f4583e16d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,10 +175,10 @@ MARK_AS_ADVANCED(SALOME_INSTALL_PYTHON SALOME_INSTALL_PYTHON_SHARED SALOME_KERNE MARK_AS_ADVANCED(SALOME_INSTALL_AMCONFIG SALOME_INSTALL_AMCONFIG_LOCAL) # Accumulate environment variables for KERNEL module -SALOME_ACCUMULATE_ENVIRONMENT(PYTHONPATH NOCHECK ${CMAKE_INSTALL_PREFIX}/${SALOME_INSTALL_BINS} - ${CMAKE_INSTALL_PREFIX}/${SALOME_INSTALL_PYTHON} - ${CMAKE_INSTALL_PREFIX}/${SALOME_INSTALL_PYTHON_SHARED}) -SALOME_ACCUMULATE_ENVIRONMENT(LD_LIBRARY_PATH NOCHECK ${CMAKE_INSTALL_PREFIX}/${SALOME_INSTALL_LIBS}) +INSERT_INTO_MAP(${PROJECT_NAME}_OWN_ENV PYTHONPATH ${CMAKE_INSTALL_PREFIX}/${SALOME_INSTALL_BINS} + ${CMAKE_INSTALL_PREFIX}/${SALOME_INSTALL_PYTHON} + ${CMAKE_INSTALL_PREFIX}/${SALOME_INSTALL_PYTHON_SHARED}) +INSERT_INTO_MAP(${PROJECT_NAME}_OWN_ENV LD_LIBRARY_PATH ${CMAKE_INSTALL_PREFIX}/${SALOME_INSTALL_LIBS}) # For salome test SET(KERNEL_TEST_DIR ${SALOME_INSTALL_SCRIPT_SCRIPTS}/test) @@ -322,3 +322,8 @@ INSTALL(FILES # Install the export set for use with the install-tree INSTALL(EXPORT ${PROJECT_NAME}TargetGroup DESTINATION "${SALOME_INSTALL_CMAKE}" FILE ${PROJECT_NAME}Targets.cmake) + +SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env) +MESSAGE("tests_env = ${tests_env}") + +SALOME_GENERATE_ENVIRONMENT_SCRIPT(plugins_cmd env_script "${PYTHON_EXECUTABLE}" "${plugins_cmd_options}") diff --git a/salome_adm/cmake_files/FindSalomeKERNEL.cmake b/salome_adm/cmake_files/FindSalomeKERNEL.cmake index d10728533..16f5f3c6d 100644 --- a/salome_adm/cmake_files/FindSalomeKERNEL.cmake +++ b/salome_adm/cmake_files/FindSalomeKERNEL.cmake @@ -51,6 +51,11 @@ ENDIF() FOREACH(_res ${SalomeKERNEL_EXTRA_ENV}) SALOME_ACCUMULATE_ENVIRONMENT(${_res} "${SalomeKERNEL_EXTRA_ENV_${_res}}") ENDFOREACH() +# Accumulate own environment variables +SALOME_ACCUMULATE_ENVIRONMENT(PYTHONPATH ${CMAKE_PREFIX_PATH}/${SALOME_INSTALL_BINS} + ${CMAKE_PREFIX_PATH}/${SALOME_INSTALL_PYTHON} + ${CMAKE_PREFIX_PATH}/${SALOME_INSTALL_PYTHON_SHARED}) +SALOME_ACCUMULATE_ENVIRONMENT(LD_LIBRARY_PATH ${CMAKE_PREFIX_PATH}/${SALOME_INSTALL_LIBS}) #---------------------------------------------------------------------------- # KERNEL_WITH_CORBA is a macro useful for determining whether a KERNEL module diff --git a/salome_adm/cmake_files/SalomeMacros.cmake b/salome_adm/cmake_files/SalomeMacros.cmake index 7ed262265..07040086f 100644 --- a/salome_adm/cmake_files/SalomeMacros.cmake +++ b/salome_adm/cmake_files/SalomeMacros.cmake @@ -793,16 +793,19 @@ MACRO(SALOME_GENERATE_ENVIRONMENT_SCRIPT output script cmd opts) 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") - ELSE(WIN32) - SET(_env "${_env} export ${_item}=${_val}:\${${_item}}\n") - ENDIF(WIN32) + SET(_env_vars ${PROJECT_NAME}_OWN_ENV _${PROJECT_NAME}_EXTRA_ENV) + FOREACH(_list ${_env_vars}) + FOREACH(_item ${${_list}}) + FOREACH(_val ${${_list}_${_item}}) + IF(WIN32) + IF(${_item} STREQUAL "LD_LIBRARY_PATH") + SET(_item PATH) + ENDIF() + STRING(REPLACE "/" "\\" _env "${_env} @SET ${_item}=${_val};%${_item}%\n") + ELSE(WIN32) + SET(_env "${_env} export ${_item}=${_val}:\${${_item}}\n") + ENDIF(WIN32) + ENDFOREACH() ENDFOREACH() ENDFOREACH() @@ -828,61 +831,66 @@ ENDMACRO(SALOME_GENERATE_ENVIRONMENT_SCRIPT) # and puts this variable into argument. # MACRO(SALOME_GENERATE_TESTS_ENVIRONMENT output) - SET(_env) - SET(_WIN_LD_LIBRARY OFF) - FOREACH(_item ${_${PROJECT_NAME}_EXTRA_ENV}) - IF(${_item} STREQUAL "LD_LIBRARY_PATH") - SET(_WIN_LD_LIBRARY ON) - ENDIF() - SET(_env_${_item}) - FOREACH(_val ${_${PROJECT_NAME}_EXTRA_ENV_${_item}}) - IF(WIN32) - STRING(REPLACE "/" "\\" _val "${_val}") - SET(_env_${_item} "${_val};${_env_${_item}}") - ELSE() - SET(_env_${_item} "${_val}:${_env_${_item}}") - ENDIF() - ENDFOREACH() - ENDFOREACH() - - IF(_WIN_LD_LIBRARY AND WIN32) - SET(_env_PATH "${_env_PATH}$ENV{LD_LIBRARY_PATH};${_env_LD_LIBRARY_PATH}") - ENDIF() - - IF(WIN32) - SET(sep ",") - ELSE() - SET(sep ";") - ENDIF() + SET(_env) + SET(_WIN_LD_LIBRARY OFF) + SET(_env_vars ${PROJECT_NAME}_OWN_ENV _${PROJECT_NAME}_EXTRA_ENV) + FOREACH(_list ${_env_vars}) + FOREACH(_item ${${_list}}) + IF(${_item} STREQUAL "LD_LIBRARY_PATH") + SET(_WIN_LD_LIBRARY ON) + ENDIF() + SET(_env_${_list}_${_item}) + FOREACH(_val ${${_list}_${_item}}) + IF(WIN32) + STRING(REPLACE "/" "\\" _val "${_val}") + SET(_env_${_list}_${_item} "${_val};${_env_${_list}_${_item}}") + ELSE() + SET(_env_${_list}_${_item} "${_val}:${_env_${_list}_${_item}}") + ENDIF() + ENDFOREACH() + ENDFOREACH() + ENDFOREACH() + + IF(_WIN_LD_LIBRARY AND WIN32) + SET(_env_PATH "${_env_PATH}$ENV{LD_LIBRARY_PATH};${_env_LD_LIBRARY_PATH}") + ENDIF() + + IF(WIN32) + SET(sep ",") + ELSE() + SET(sep ";") + ENDIF() - FOREACH(_item ${_${PROJECT_NAME}_EXTRA_ENV}) - IF(WIN32) - IF(NOT ${_item} STREQUAL "LD_LIBRARY_PATH") - SET(_env "${_item}=$ENV{${_item}};${_env_${_item}}${sep}${_env}") - ENDIF() - ELSE() - STRING(REPLACE ";" ":" _iii "$ENV{${_item}}") - SET(_env "${_item}=${_iii}:${_env_${_item}}${sep}${_env}") - ENDIF() - ENDFOREACH() - - # Get module name as substring of "Salome" - STRING(REGEX MATCH "^Salome" _is_salome_project ${PROJECT_NAME}) - IF(_is_salome_project) - STRING(SUBSTRING "${PROJECT_NAME}" 6 -1 PRNAME) - ELSE() - SET(PRNAME ${PROJECT_NAME}) - ENDIF() - SET(_env "${PRNAME}_ROOT_DIR=${CMAKE_INSTALL_PREFIX}${sep}${_env}") + FOREACH(_list ${_env_vars}) + FOREACH(_item ${${_list}}) + IF(WIN32) + IF(NOT ${_item} STREQUAL "LD_LIBRARY_PATH") + SET(_env "${_item}=$ENV{${_item}};${_env_${_list}_${_item}}${sep}${_env}") + ENDIF() + ELSE() + STRING(REPLACE ";" ":" _iii "$ENV{${_item}}") + SET(_env "${_item}=${_iii}:${_env_${_list}_${_item}}${sep}${_env}") + ENDIF() + ENDFOREACH() + ENDFOREACH() + + # Get module name as substring of "Salome" + STRING(REGEX MATCH "^Salome" _is_salome_project ${PROJECT_NAME}) + IF(_is_salome_project) + STRING(SUBSTRING "${PROJECT_NAME}" 6 -1 PRNAME) + ELSE() + SET(PRNAME ${PROJECT_NAME}) + ENDIF() + SET(_env "${PRNAME}_ROOT_DIR=${CMAKE_INSTALL_PREFIX}${sep}${_env}") - # Creating follow string for Windows environement: - # "VAR1_ENV=1\;2\;3\;...\;...\;...;VAR2_ENV=1\;2\;3\;...\;...\;...;VAR3_ENV=1\;2\;3\;...\;...\;...;..." - IF(WIN32) - STRING(REGEX REPLACE "\\\\*;" "\\\\;" _env "${_env}") - STRING(REGEX REPLACE "\\\\*;*," ";" _env "${_env}") - ENDIF() + # Creating follow string for Windows environement: + # "VAR1_ENV=1\;2\;3\;...\;...\;...;VAR2_ENV=1\;2\;3\;...\;...\;...;VAR3_ENV=1\;2\;3\;...\;...\;...;..." + IF(WIN32) + STRING(REGEX REPLACE "\\\\*;" "\\\\;" _env "${_env}") + STRING(REGEX REPLACE "\\\\*;*," ";" _env "${_env}") + ENDIF() - SET(${output} "${_env}") + SET(${output} "${_env}") ENDMACRO(SALOME_GENERATE_TESTS_ENVIRONMENT) @@ -942,3 +950,26 @@ MACRO(SALOME_CONFIGURE_PREPARE) ENDIF() ENDFOREACH() ENDMACRO(SALOME_CONFIGURE_PREPARE) + +######################################################################### +# INSERT_INTO_MAP() +# +# USAGE: INSERT_INTO_MAP(name key values) +# +# ARGUMENTS: +# name [in] input name of map +# key [in] input key of map +# values [in] input list of key values +# +# This macro emulates the creation of map [key]->[value] +# +MACRO(INSERT_INTO_MAP name key) + FOREACH(_value ${ARGN}) + LIST(APPEND ${name}_${key} "${_value}") + ENDFOREACH() + + LIST(FIND ${key} ${name} _res) + IF(_res EQUAL -1) + LIST(APPEND ${name} ${key}) + ENDIF() +ENDMACRO(INSERT_INTO_MAP) -- 2.39.2