From: abn Date: Mon, 18 May 2015 14:31:31 +0000 (+0200) Subject: 0022778: [CEA 1298] Python file compilation should be done at build time, not install... X-Git-Tag: V7_7_0a1~22^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5b2ab12f1ba8db6ac67c37e2f9340683bc981c53;p=modules%2Fmed.git 0022778: [CEA 1298] Python file compilation should be done at build time, not install time - Synchronisation of adm file with KERNEL (see log there) + removal of obsolete INSTALL_AND_COMPILE... CMake macro. --- diff --git a/adm_local_without_kernel/cmake_files/SalomeMacros.cmake b/adm_local_without_kernel/cmake_files/SalomeMacros.cmake index a7cf6304c..557a5a548 100755 --- a/adm_local_without_kernel/cmake_files/SalomeMacros.cmake +++ b/adm_local_without_kernel/cmake_files/SalomeMacros.cmake @@ -109,59 +109,59 @@ MACRO(SALOME_INSTALL_SCRIPTS file_list path) IF(NOT SALOME_INSTALL_SCRIPTS_DEF_PERMS) SET(PERMS ${PERMS} OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE) ENDIF(NOT SALOME_INSTALL_SCRIPTS_DEF_PERMS) + SET(_all_pyc) + SET(_all_pyo) + SET(_all_subdirs) FOREACH(file ${file_list}) SET(PREFIX "") + SET(_source_prefix "") GET_FILENAME_COMPONENT(file_name ${file} NAME) IF(NOT IS_ABSOLUTE ${file}) IF(SALOME_INSTALL_SCRIPTS_WORKING_DIRECTORY) SET(PREFIX "${SALOME_INSTALL_SCRIPTS_WORKING_DIRECTORY}/") ENDIF(SALOME_INSTALL_SCRIPTS_WORKING_DIRECTORY) + SET(_source_prefix "${CMAKE_CURRENT_SOURCE_DIR}/") ENDIF(NOT IS_ABSOLUTE ${file}) INSTALL(FILES ${PREFIX}${file} DESTINATION ${path} PERMISSIONS ${PERMS}) GET_FILENAME_COMPONENT(ext ${file} EXT) - IF(ext STREQUAL .py) - # FILE TIMESTAMP command appears in cmake-2.8.11 - IF(${CMAKE_VERSION} VERSION_LESS "2.8.11") - INSTALL(CODE "MESSAGE(STATUS \"py compiling ${CMAKE_INSTALL_PREFIX}/${path}/${file_name}\")") - INSTALL(CODE "SET(CMD \"import py_compile ; py_compile.compile('${CMAKE_INSTALL_PREFIX}/${path}/${file_name}')\")") - INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c \"\${CMD}\")") - INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -O -c \"\${CMD}\")") - ELSE(${CMAKE_VERSION} VERSION_LESS "2.8.11") - GET_FILENAME_COMPONENT(file_we ${file_name} NAME_WE) - INSTALL(CODE "SET(CMD \"import py_compile ; py_compile.compile('${CMAKE_INSTALL_PREFIX}/${path}/${file_name}')\")") - INSTALL(CODE "FILE(TIMESTAMP \"${CMAKE_INSTALL_PREFIX}/${path}/${file_name}\" py_time)") - INSTALL(CODE "IF(EXISTS \"${CMAKE_INSTALL_PREFIX}/${path}/${file_we}.pyc\") \n FILE(TIMESTAMP \"${CMAKE_INSTALL_PREFIX}/${path}/${file_we}.pyc\" pyc_time) \n ELSE()\n SET(pyc_time 0) \n ENDIF() ") - INSTALL(CODE "IF(EXISTS \"${CMAKE_INSTALL_PREFIX}/${path}/${file_we}.pyo\") \n FILE(TIMESTAMP \"${CMAKE_INSTALL_PREFIX}/${path}/${file_we}.pyo\" pyo_time) \n ELSE()\n SET(pyo_time 0) \n ENDIF() ") - #INSTALL(CODE "MESSAGE(STATUS \"\${py_time} \${pyc_time} \")") - INSTALL(CODE "STRING(COMPARE LESS \${pyc_time} \${py_time} to_install_pyc)") - INSTALL(CODE "STRING(COMPARE LESS \${pyo_time} \${py_time} to_install_pyo)") - INSTALL(CODE "IF (\${to_install_pyc} OR \${to_install_pyo}) \n MESSAGE(STATUS \"py compiling ${CMAKE_INSTALL_PREFIX}/${path}/${file_name}\") \n ENDIF()") - INSTALL(CODE "IF (\${to_install_pyc}) \n EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c \"\${CMD}\") \n ENDIF()") - INSTALL(CODE "IF (\${to_install_pyo}) \n EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -O -c \"\${CMD}\") \n ENDIF()") - ENDIF(${CMAKE_VERSION} VERSION_LESS "2.8.11") + GET_FILENAME_COMPONENT(we_ext ${file} NAME_WE) + GET_FILENAME_COMPONENT(single_dir ${CMAKE_CURRENT_SOURCE_DIR} NAME_WE) + IF(ext STREQUAL .py) + # Generate and install the pyc and pyo + # [ABN] Important: we avoid references or usage of CMAKE_INSTALL_PREFIX which is not correctly set + # when using CPack. + SET(_pyc_file "${CMAKE_CURRENT_BINARY_DIR}/${we_ext}.pyc") + SET(_pyo_file "${CMAKE_CURRENT_BINARY_DIR}/${we_ext}.pyo") + LIST(APPEND _all_pyc ${_pyc_file}) + LIST(APPEND _all_pyo ${_pyo_file}) + ADD_CUSTOM_COMMAND( + OUTPUT ${_pyc_file} + COMMAND ${PYTHON_EXECUTABLE} -c "import py_compile ; py_compile.compile('${_source_prefix}${file}', '${_pyc_file}' )" + DEPENDS ${PREFIX}${file} + VERBATIM + ) + ADD_CUSTOM_COMMAND( + OUTPUT ${_pyo_file} + COMMAND ${PYTHON_EXECUTABLE} -O -c "import py_compile ; py_compile.compile('${_source_prefix}${file}', '${_pyo_file}' )" + DEPENDS ${PREFIX}${file} + VERBATIM + ) + # Install the .pyo and the .pyc + INSTALL(FILES ${_pyc_file} DESTINATION ${path} PERMISSIONS ${PERMS}) + INSTALL(FILES ${_pyo_file} DESTINATION ${path} PERMISSIONS ${PERMS}) ENDIF(ext STREQUAL .py) ENDFOREACH(file ${file_list}) + # Generate only one target for all requested Python script compilation. + # Make sure that the target name is unique too. + IF(_all_pyc) + SET(_cnt 0) + WHILE(TARGET "PYCOMPILE_${single_dir}_${_cnt}") + MATH(EXPR _cnt ${_cnt}+1) + ENDWHILE() + ADD_CUSTOM_TARGET("PYCOMPILE_${single_dir}_${_cnt}" ALL DEPENDS ${_all_pyc} ${_all_pyo}) + ENDIF() ENDMACRO(SALOME_INSTALL_SCRIPTS) -#---------------------------------------------------------------------------- -# SALOME_INSTALL_SCRIPTS is a macro useful for installing executable scripts. -# ARGUMENTS: -# PYFILE2COMPINST: IN : list of python files to be installed. -# PYFILELOC: IN : full pathname for installing. -# Permissions of installed files: OWNER_WRITE, OWNER_READ, GROUP_READ, and WORLD_READ -#---------------------------------------------------------------------------- -MACRO(INSTALL_AND_COMPILE_PYTHON_FILE PYFILE2COMPINST PYFILELOC) - INSTALL(CODE "SET(PYTHON_FILE ${f})") - FOREACH(input ${PYFILE2COMPINST}) - GET_FILENAME_COMPONENT(inputname ${input} NAME) - INSTALL(FILES ${input} DESTINATION ${CMAKE_INSTALL_PREFIX}/${PYFILELOC}) - INSTALL(CODE "MESSAGE(STATUS \"py compiling ${CMAKE_INSTALL_PREFIX}/${PYFILELOC}/${inputname}\")") - INSTALL(CODE "SET(CMD \"import py_compile ; py_compile.compile('${CMAKE_INSTALL_PREFIX}/${PYFILELOC}/${inputname}')\")") - INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c \"\${CMD}\")") - INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -O -c \"\${CMD}\")") - ENDFOREACH(input ${PYFILE2COMPINST}) -ENDMACRO(INSTALL_AND_COMPILE_PYTHON_FILE PYFILE2COMPINST PYFILELOC) - #---------------------------------------------------------------------------- # SALOME_CONFIGURE_FILE is a macro useful for copying a file to another location # and modify its contents. diff --git a/src/MEDCalculator/Swig/CMakeLists.txt b/src/MEDCalculator/Swig/CMakeLists.txt index b0c7c2353..817839313 100644 --- a/src/MEDCalculator/Swig/CMakeLists.txt +++ b/src/MEDCalculator/Swig/CMakeLists.txt @@ -60,4 +60,4 @@ FILE(GLOB medcalculatorspython_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx") INSTALL(FILES ${medcalculatorspython_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS}) INSTALL(TARGETS _MEDCalculator DESTINATION ${SALOME_INSTALL_PYTHON}) INSTALL(FILES MEDCalculator.i MEDCalculatorTypemaps.i DESTINATION ${SALOME_INSTALL_HEADERS}) -INSTALL_AND_COMPILE_PYTHON_FILE(${CMAKE_CURRENT_BINARY_DIR}/MEDCalculator.py ${SALOME_INSTALL_PYTHON}) +SALOME_INSTALL_SCRIPTS(${CMAKE_CURRENT_BINARY_DIR}/MEDCalculator.py ${SALOME_INSTALL_PYTHON}) diff --git a/src/MEDCouplingCorba_Swig/CMakeLists.txt b/src/MEDCouplingCorba_Swig/CMakeLists.txt index b5d7f1e9a..7bac79b2a 100644 --- a/src/MEDCouplingCorba_Swig/CMakeLists.txt +++ b/src/MEDCouplingCorba_Swig/CMakeLists.txt @@ -59,4 +59,4 @@ ENDIF(WIN32) INSTALL(TARGETS _MEDCouplingCorba DESTINATION ${SALOME_INSTALL_PYTHON}) INSTALL(FILES MEDCouplingCorba.i MEDCouplingCorbaTypemaps.i DESTINATION ${SALOME_INSTALL_HEADERS}) SET(PYFILES_TO_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/MEDCouplingCorba.py) -INSTALL_AND_COMPILE_PYTHON_FILE("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_PYTHON}) +SALOME_INSTALL_SCRIPTS("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_PYTHON}) diff --git a/src/MEDCouplingCorba_Swig/Client/CMakeLists.txt b/src/MEDCouplingCorba_Swig/Client/CMakeLists.txt index 526d240e1..8e3466516 100644 --- a/src/MEDCouplingCorba_Swig/Client/CMakeLists.txt +++ b/src/MEDCouplingCorba_Swig/Client/CMakeLists.txt @@ -48,4 +48,4 @@ ENDIF(WIN32) INSTALL(TARGETS _MEDCouplingClient DESTINATION ${SALOME_INSTALL_PYTHON}) INSTALL(FILES MEDCouplingClient.i DESTINATION ${SALOME_INSTALL_HEADERS}) SET(PYFILES_TO_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/MEDCouplingClient.py) -INSTALL_AND_COMPILE_PYTHON_FILE("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_PYTHON}) +SALOME_INSTALL_SCRIPTS("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_PYTHON}) diff --git a/src/MEDCoupling_Swig/CMakeLists.txt b/src/MEDCoupling_Swig/CMakeLists.txt index edb7d4a00..4d218def5 100644 --- a/src/MEDCoupling_Swig/CMakeLists.txt +++ b/src/MEDCoupling_Swig/CMakeLists.txt @@ -72,7 +72,7 @@ ENDIF(WIN32) INSTALL(TARGETS ${SWIG_MODULE_MEDCoupling_REAL_NAME} ${SWIG_MODULE_MEDCouplingRemapper_REAL_NAME} DESTINATION ${SALOME_INSTALL_PYTHON}) SET(PYFILES_TO_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/MEDCoupling.py ${CMAKE_CURRENT_BINARY_DIR}/MEDCouplingRemapper.py) -INSTALL_AND_COMPILE_PYTHON_FILE("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_PYTHON}) +SALOME_INSTALL_SCRIPTS("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_PYTHON}) INSTALL(FILES MEDCoupling.i MEDCouplingCommon.i MEDCouplingRefCountObject.i MEDCouplingMemArray.i MEDCouplingFieldDiscretization.i MEDCouplingTimeDiscretization.i MEDCouplingFinalize.i MEDCouplingRemapper.i MEDCouplingTypemaps.i MEDCouplingDataArrayTypemaps.i DESTINATION ${SALOME_INSTALL_HEADERS}) INSTALL(FILES MEDCouplingBasicsTest.py MEDCouplingRemapperTest.py MEDCouplingDataForTest.py MEDCouplingNumPyTest.py MEDCouplingPickleTest.py DESTINATION ${SALOME_INSTALL_SCRIPT_PYTHON}) diff --git a/src/MEDLoader/Swig/CMakeLists.txt b/src/MEDLoader/Swig/CMakeLists.txt index c6673cdd1..4fcecf52d 100644 --- a/src/MEDLoader/Swig/CMakeLists.txt +++ b/src/MEDLoader/Swig/CMakeLists.txt @@ -61,7 +61,7 @@ INSTALL(TARGETS _MEDLoader DESTINATION ${SALOME_INSTALL_PYTHON}) INSTALL(FILES MEDLoader.i MEDLoaderTypemaps.i MEDLoaderCommon.i DESTINATION ${SALOME_INSTALL_HEADERS}) SET(PYFILES_TO_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/MEDLoader.py) -INSTALL_AND_COMPILE_PYTHON_FILE("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_PYTHON}) +SALOME_INSTALL_SCRIPTS("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_PYTHON}) INSTALL(FILES MEDLoaderDataForTest.py MEDLoaderTest.py MEDLoaderTest2.py MEDLoaderTest3.py MEDLoaderTest4.py SauvLoaderTest.py MEDLoaderExamplesTest.py MEDLoaderCouplingTrainingSession.py CaseIO.py CaseReader.py CaseWriter.py VTKReader.py MEDLoaderSplitter.py medutilities.py DESTINATION ${SALOME_INSTALL_SCRIPT_SCRIPTS}) INSTALL(FILES med2sauv PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ DESTINATION ${SALOME_INSTALL_BINS} ) diff --git a/src/MEDOP/tui/xmedpy/CMakeLists.txt b/src/MEDOP/tui/xmedpy/CMakeLists.txt index 667465203..bbc6e70c4 100644 --- a/src/MEDOP/tui/xmedpy/CMakeLists.txt +++ b/src/MEDOP/tui/xmedpy/CMakeLists.txt @@ -32,7 +32,7 @@ SET(PYFILES_TO_INSTALL properties.py ) -INSTALL_AND_COMPILE_PYTHON_FILE("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_PYTHON}/xmed) +SALOME_INSTALL_SCRIPTS("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_PYTHON}/xmed) SET(TEST_SCRIPTS_XMED tests/test_xmed_fieldOperations.py diff --git a/src/MEDPartitioner_Swig/CMakeLists.txt b/src/MEDPartitioner_Swig/CMakeLists.txt index 5245aab2c..f203e7295 100644 --- a/src/MEDPartitioner_Swig/CMakeLists.txt +++ b/src/MEDPartitioner_Swig/CMakeLists.txt @@ -56,7 +56,7 @@ ENDIF(WIN32) INSTALL(TARGETS ${SWIG_MODULE_MEDPartitioner_REAL_NAME} DESTINATION ${SALOME_INSTALL_PYTHON}) SET(PYFILES_TO_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/MEDPartitioner.py) -INSTALL_AND_COMPILE_PYTHON_FILE("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_SCRIPT_PYTHON}) +SALOME_INSTALL_SCRIPTS("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_SCRIPT_PYTHON}) INSTALL(FILES MEDPartitioner.i MEDPartitionerCommon.i DESTINATION ${SALOME_INSTALL_HEADERS}) INSTALL(FILES MEDPartitionerTest.py DESTINATION ${SALOME_INSTALL_SCRIPT_PYTHON}) diff --git a/src/ParaMEDMEM_Swig/CMakeLists.txt b/src/ParaMEDMEM_Swig/CMakeLists.txt index 23b9b5d90..48266ae3b 100644 --- a/src/ParaMEDMEM_Swig/CMakeLists.txt +++ b/src/ParaMEDMEM_Swig/CMakeLists.txt @@ -58,5 +58,5 @@ SET_SOURCE_FILES_PROPERTIES(ParaMEDMEM.i PROPERTIES SWIG_DEFINITIONS "-shadow") INSTALL(TARGETS _ParaMEDMEM DESTINATION ${SALOME_INSTALL_PYTHON}) INSTALL(FILES ParaMEDMEM.i DESTINATION ${SALOME_INSTALL_HEADERS}) -INSTALL_AND_COMPILE_PYTHON_FILE(${CMAKE_CURRENT_BINARY_DIR}/ParaMEDMEM.py ${SALOME_INSTALL_SCRIPT_PYTHON}) +SALOME_INSTALL_SCRIPTS(${CMAKE_CURRENT_BINARY_DIR}/ParaMEDMEM.py ${SALOME_INSTALL_SCRIPT_PYTHON}) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/ParaMEDMEM.py test_InterpKernelDEC.py test_NonCoincidentDEC.py test_StructuredCoincidentDEC.py DESTINATION ${SALOME_INSTALL_SCRIPT_PYTHON}) \ No newline at end of file diff --git a/src/RENUMBER_Swig/CMakeLists.txt b/src/RENUMBER_Swig/CMakeLists.txt index 98007acb4..c4c5943d1 100644 --- a/src/RENUMBER_Swig/CMakeLists.txt +++ b/src/RENUMBER_Swig/CMakeLists.txt @@ -60,7 +60,7 @@ ENDIF(WIN32) INSTALL(TARGETS ${SWIG_MODULE_MEDRenumber_REAL_NAME} DESTINATION ${SALOME_INSTALL_PYTHON}) SET(PYFILES_TO_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/MEDRenumber.py) -INSTALL_AND_COMPILE_PYTHON_FILE("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_SCRIPT_PYTHON}) +SALOME_INSTALL_SCRIPTS("${PYFILES_TO_INSTALL}" ${SALOME_INSTALL_SCRIPT_PYTHON}) INSTALL(FILES MEDRenumber.i MEDRenumberCommon.i DESTINATION ${SALOME_INSTALL_HEADERS}) INSTALL(FILES MEDRenumberTest.py DESTINATION ${SALOME_INSTALL_SCRIPT_PYTHON})