From a1b80eb1f929992f499616388d0efd2504ada02a Mon Sep 17 00:00:00 2001 From: Marcos Bento Date: Tue, 14 Nov 2023 18:10:13 +0000 Subject: [PATCH 1/3] Modernize CMakeLists.txt for Python3 --- Pyext/CMakeLists.txt | 98 +++++++++++- Pyext/python2/CMakeLists.txt | 294 ++++++++++++++++------------------ Pyext/python3/CMakeLists.txt | 299 ++++++++++++++++------------------- 3 files changed, 367 insertions(+), 324 deletions(-) diff --git a/Pyext/CMakeLists.txt b/Pyext/CMakeLists.txt index a49060f3d..d66d993fd 100644 --- a/Pyext/CMakeLists.txt +++ b/Pyext/CMakeLists.txt @@ -1,3 +1,13 @@ +# +# Copyright 2023- ECMWF. +# +# This software is licensed under the terms of the Apache Licence version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# In applying this licence, ECMWF does not waive the privileges and immunities +# granted to it by virtue of its status as an intergovernmental organisation +# nor does it submit to any jurisdiction. +# + ### ecflow python bindings # NOTES: # 1/ Building multiple python3 versions not supported, since find_python(..) caches variables, Hack: clear cached variable. @@ -51,13 +61,89 @@ include_directories( ../CSim/src ) + +# ============================================================================== +# source files (paths relative to dirs python2/python3) +# ============================================================================== +set(srcs + # Headers + ../src/BoostPythonUtil.hpp + ../src/ClientDoc.hpp + ../src/DefsDoc.hpp + ../src/Edit.hpp + ../src/GlossaryDoc.hpp + ../src/NodeAttrDoc.hpp + ../src/NodeUtil.hpp + ../src/Trigger.hpp + # Sources + ../src/BoostPythonUtil.cpp + ../src/ClientDoc.cpp + ../src/DefsDoc.cpp + ../src/EcfExt.cpp + ../src/Edit.cpp + ../src/ExportClient.cpp + ../src/ExportCore.cpp + ../src/ExportDefs.cpp + ../src/ExportNode.cpp + ../src/ExportNodeAttr.cpp + ../src/ExportSuiteAndFamily.cpp + ../src/ExportTask.cpp + ../src/GlossaryDoc.cpp + ../src/NodeAttrDoc.cpp + ../src/NodeUtil.cpp + ../src/Trigger.cpp +) + +# ===================================================================== +# tests +# ===================================================================== +set(u_tests + py_u_test_add + py_u_test_collection + py_u_test_cron + py_u_test_defs_constructor + py_u_test_get_attr + py_u_test_manual + py_u_test_late + py_u_test_replace_node + py_u_test_tutorial + py_u_TestAddDelete + py_u_TestAddDeleteFunc + py_u_TestAddNodeFunc + py_u_TestAutoAddExtern + py_u_TestCopy + py_u_TestDefs + py_u_TestDefsCheck + py_u_TestDerivable + py_u_TestEcf + py_u_TestError + py_u_TestFind + py_u_TestFlag + py_u_TestGetAllTasks + py_u_TestJobGeneration + py_u_TestParent + py_u_TestRemove + py_u_TestRepeatArithmetic + py_u_TestSimulator + py_u_TestTraversal + py_u_TestUserManual + py_u_TestWith + py_u_sort +) + +set(s_tests + s_TestClientApi + s_TestPythonChildApi +) + + message( STATUS "====================================================================================================================" ) message( STATUS "PYTHON2" ) message( STATUS "====================================================================================================================" ) if(${CMAKE_VERSION} VERSION_LESS "3.12.0") # We only support python2 extension for cmake less 3.12.0 # cmake 3.12.0 or greater allows multiple boost python libs & hence multiple extensions to be built - # Using -DPYTHON_EXECUTABLE=/usr/local/apps/python3/3.6.5-01/bin/python3 is not suffcient as the wrong(python2) libs are found + # Using -DPYTHON_EXECUTABLE=/usr/local/apps/python3/3.6.5-01/bin/python3 is not sufficient as the wrong(python2) libs are found ecbuild_find_python( VERSION 2.6 REQUIRED ) message( STATUS " PYTHON_FOUND : ${PYTHON_FOUND}" ) message( STATUS " PYTHONINTERP_FOUND : ${PYTHONINTERP_FOUND}" ) @@ -119,10 +205,11 @@ else() # cmake 3.15 # see: https://gitlab.kitware.com/cmake/cmake/issues/19656 # INTERFACE_LIBRARY targets may only have whitelisted properties." - find_package( Boost ${ECFLOW_BOOST_VERSION} COMPONENTS python${Python2_VERSION_MAJOR}${Python2_VERSION_MINOR} ) + set(ECFLOW_BOOST_PYTHON_COMPONENT python${Python2_VERSION_MAJOR}${Python2_VERSION_MINOR}) else() - find_package( Boost ${ECFLOW_BOOST_VERSION} COMPONENTS python ) + set(ECFLOW_BOOST_PYTHON_COMPONENT python) endif() + find_package( Boost ${ECFLOW_BOOST_VERSION} COMPONENTS ${ECFLOW_BOOST_PYTHON_COMPONENT} ) if (Boost_PYTHON_FOUND OR Boost_PYTHON${Python2_VERSION_MAJOR}${Python2_VERSION_MINOR}_FOUND) set(ECF_PYTHON_FOUND "ECF_PYTHON_FOUND") @@ -159,10 +246,11 @@ else() # cmake 3.15 # see: https://gitlab.kitware.com/cmake/cmake/issues/19656 # INTERFACE_LIBRARY targets may only have whitelisted properties. - find_package( Boost ${ECFLOW_BOOST_VERSION} COMPONENTS python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR} ) + set(ECFLOW_BOOST_PYTHON_COMPONENT python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}) else() - find_package( Boost ${ECFLOW_BOOST_VERSION} COMPONENTS python3 ) + set(ECFLOW_BOOST_PYTHON_COMPONENT python3) endif() + find_package( Boost ${ECFLOW_BOOST_VERSION} COMPONENTS ${ECFLOW_BOOST_PYTHON_COMPONENT} ) if (Boost_PYTHON3_FOUND OR Boost_PYTHON${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}_FOUND) if ( Python3_LIBRARIES ) diff --git a/Pyext/python2/CMakeLists.txt b/Pyext/python2/CMakeLists.txt index 89ed92365..f39a352ee 100644 --- a/Pyext/python2/CMakeLists.txt +++ b/Pyext/python2/CMakeLists.txt @@ -1,39 +1,35 @@ -# ===================================================================== -# INCLUDES here is for external includes -# NOINSTALL this stops double install, the one in i.e lib/ecflow.so -# The other install is in python2.7/site-packages/ecflow.so -# if OpenSSL not enabled ${OPENSSL_LIBRARIES}, is empty -file( GLOB srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "../src/*.cpp" "../src/*.hpp" ) -ecbuild_add_library( TARGET ecflow - NOINSTALL - TYPE MODULE - SOURCES ${srcs} - ) -target_include_directories(ecflow PRIVATE ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} ) - - - -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # using regular Clang or AppleClang - # Stop annoying message: - # warning: '_POSIX_C_SOURCE' macro redefined [-Wmacro-redefined] - # warning: '_XOPEN_SOURCE' macro redefined [-Wmacro-redefined] - target_compile_options(ecflow PRIVATE -Wno-macro-redefined) -endif() +# +# Copyright 2023- ECMWF. +# +# This software is licensed under the terms of the Apache Licence version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# In applying this licence, ECMWF does not waive the privileges and immunities +# granted to it by virtue of its status as an intergovernmental organisation +# nor does it submit to any jurisdiction. +# -# This ensures that for debug config, we only link with debug boost libs, for other configs, we link with optimised boost libs -# Currently we only build optimised boost libs -# versions of boost >= 1.67 now tag the python libs, i.e. libboost_python27-mt.a, libboost_python36-mt.so -if ( Boost_MINOR_VERSION GREATER 66 ) - target_link_libraries(ecflow libclient libsimu base node nodeattr core - ${PYTHON_LIBRARIES} ${OPENSSL_LIBRARIES} - ${Boost_PYTHON${Python2_VERSION_MAJOR}${Python2_VERSION_MINOR}_LIBRARY_RELEASE} ) -else() - target_link_libraries(ecflow libclient libsimu base node nodeattr core - ${PYTHON_LIBRARIES} ${OPENSSL_LIBRARIES} - ${Boost_PYTHON_LIBRARY_RELEASE} ) -endif() +ecbuild_add_library( + TARGET + ecflow2 + NOINSTALL + TYPE MODULE + SOURCES + ${srcs} + PUBLIC_LIBS + libclient + libsimu + base + node + nodeattr + core + Python2::Python + Boost::${ECFLOW_BOOST_PYTHON_COMPONENT} + $<$:OpenSSL::SSL> + CXXFLAGS + $<$:-Wno-macro-redefined> +) +target_clangformat(ecflow2) # # Override default behaviour that add RPATHS during install @@ -42,86 +38,55 @@ endif() # had no effect # # by default cmake add prefix 'lib', we don't want this hence disable -set_target_properties(ecflow PROPERTIES - PREFIX "" - INSTALL_RPATH "" - ) - -target_clangformat(ecflow) +# +# To avoid duplicate target names we chose to name the targets: ecflow2/ecflow3. +# however test and user code depend on name 'ecflow', hence we rename the output to 'cflow' +set_target_properties(ecflow3 + PROPERTIES + OUTPUT_NAME "ecflow" + PREFIX "" + INSTALL_RPATH "" +) # ===================================================================== -# tests - -#ecbuild_add_test( TARGET py_u_TestMigrate -# TYPE PYTHON -# ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../migrate/py_u_TestMigrate.py -# ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" ) - -list( APPEND u_tests - py_u_test_add - py_u_test_collection - py_u_test_cron - py_u_test_defs_constructor - py_u_test_get_attr - py_u_test_manual - py_u_test_late - py_u_test_replace_node - py_u_test_tutorial - py_u_TestAddDelete - py_u_TestAddDeleteFunc - py_u_TestAddNodeFunc - py_u_TestAutoAddExtern - py_u_TestCopy - py_u_TestDefs - py_u_TestDefsCheck - py_u_TestDerivable - py_u_TestEcf - py_u_TestError - py_u_TestFind - py_u_TestFlag - py_u_TestGetAllTasks - py_u_TestJobGeneration - py_u_TestParent - py_u_TestRemove - py_u_TestRepeatArithmetic - py_u_TestSimulator - py_u_TestTraversal - py_u_TestUserManual - py_u_TestWith - py_u_sort -) -foreach( test ${u_tests} ) +# tests - ecbuild_add_test( TARGET ${test} - TYPE PYTHON - ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../test/${test}.py - ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - TEST_DEPENDS u_base - ) +foreach( test ${u_tests} ) + ecbuild_add_test( + TARGET + py2_${test} + TYPE PYTHON + ARGS + ${CMAKE_CURRENT_SOURCE_DIR}/../test/${test}.py + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + TEST_DEPENDS + u_base + ) endforeach() if ( ENABLE_ALL_TESTS AND ENABLE_SERVER) - list( APPEND s_tests - py_s_TestClientApi - py_s_TestPythonChildApi - ) - - foreach( test ${s_tests} ) - - ecbuild_add_test( TARGET ${test} - TYPE PYTHON - ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../test/${test}.py - ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - TEST_DEPENDS u_base - ) - endforeach() - - set_property(TEST py_s_TestClientApi APPEND PROPERTY DEPENDS s_test) - set_property(TEST py_s_TestPythonChildApi APPEND PROPERTY DEPENDS py_s_TestClientApi) + + foreach( test ${s_tests} ) + ecbuild_add_test( + TARGET + py2_${test} + TYPE PYTHON + ARGS + ${CMAKE_CURRENT_SOURCE_DIR}/../test/${test}.py + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + TEST_DEPENDS + u_base + ) + endforeach() + + set_property(TEST py2_s_TestClientApi APPEND PROPERTY DEPENDS s_test) + set_property(TEST py2_s_TestPythonChildApi APPEND PROPERTY DEPENDS py_s_TestClientApi) endif() - + # ========================================================================== # install # -DCMAKE_PYTHON_INSTALL_TYPE = [ local | setup | not defined ] @@ -137,58 +102,73 @@ endif() # cd buildir # cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DCOMPONENT=python -P cmake_install.cmake -- make install # ========================================================================== - + if( CMAKE_PYTHON_INSTALL_TYPE MATCHES "local" OR NOT DEFINED CMAKE_PYTHON_INSTALL_TYPE ) - - message(STATUS "python install *LOCAL* +++ lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/ecflow +++++++") - if( NOT INSTALL_PYTHON2_DIR ) - set(PYTHON_SITE "lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages" ) - else() - # Resolve ${VAR} in the value provided - string(CONFIGURE "${INSTALL_PYTHON2_DIR}" PYTHON_SITE) - endif() - set(PYTHON_DEST "${PYTHON_SITE}/ecflow" ) - - install( TARGETS ecflow DESTINATION ${PYTHON_DEST} RENAME ecflow.so COMPONENT python ) - install( FILES ../ecflow/__init__.py DESTINATION ${PYTHON_DEST} COMPONENT python ) - - # Install files that Axel has asked for. - # These are example of what Axel uses as a layer over ecflow api, for operations - install( FILES ../samples/api/ecf.py DESTINATION ${PYTHON_DEST} COMPONENT python ) - install( FILES ../samples/api/sms2ecf.py DESTINATION ${PYTHON_DEST} COMPONENT python ) - + + message(STATUS "python install *LOCAL* +++ lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/ecflow +++++++") + if( NOT INSTALL_PYTHON2_DIR ) + set(PYTHON_SITE "lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages" ) + else() + # Resolve ${VAR} in the value provided + string(CONFIGURE "${INSTALL_PYTHON2_DIR}" PYTHON_SITE) + endif() + set(PYTHON_DEST "${PYTHON_SITE}/ecflow" ) + + install( + TARGETS + ecflow2 + DESTINATION + ${PYTHON_DEST} + RENAME + ecflow.so + COMPONENT + python + ) + install( + FILES + ../ecflow/__init__.py + ../samples/api/ecf.py + ../samples/api/sms2ecf.py + DESTINATION + ${PYTHON_DEST} + COMPONENT + python + ) + else() - message( STATUS "python found, CMAKE_PYTHON_INSTALL_TYPE=${CMAKE_PYTHON_INSTALL_TYPE}") - - # ------------------------------------------------------------------------------------- - # Install using setup.py - # See: http://bloerg.net/2012/11/10/cmake-and-distutils.html - # ------------------------------------------------------------------------------------- - message(STATUS "python install using *setup.py* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") - message(STATUS "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}") - message(STATUS "CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}") - message(STATUS "CMAKE_PYTHON_INSTALL_PREFIX : ${CMAKE_PYTHON_INSTALL_PREFIX}" ) - - set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/../setup.py.in") - set(SETUP_PY "${CMAKE_CURRENT_SOURCE_DIR}/../setup.py") - set(DEPS "${CMAKE_CURRENT_SOURCE_DIR}/../ecflow/__init__.py") - set(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/timestamp") - - configure_file(${SETUP_PY_IN} ${SETUP_PY} ) - - add_custom_command(OUTPUT ${OUTPUT} - COMMAND ${PYTHON} ${SETUP_PY} build - COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT} - DEPENDS ${DEPS}) - add_custom_target(target ALL DEPENDS ${OUTPUT}) - - - install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} build_ext)") - - if( DEFINED CMAKE_PYTHON_INSTALL_PREFIX ) - message(STATUS "custom/*test* python install prefix defined CMAKE_PYTHON_INSTALL_PREFIX=${CMAKE_PYTHON_INSTALL_PREFIX}") - install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install -f --prefix=${CMAKE_PYTHON_INSTALL_PREFIX})") - else() - install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install)") - endif() + + message( STATUS "python found, CMAKE_PYTHON_INSTALL_TYPE=${CMAKE_PYTHON_INSTALL_TYPE}") + + # ------------------------------------------------------------------------------------- + # Install using setup.py + # See: http://bloerg.net/2012/11/10/cmake-and-distutils.html + # ------------------------------------------------------------------------------------- + message(STATUS "python install using *setup.py* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") + message(STATUS "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}") + message(STATUS "CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}") + message(STATUS "CMAKE_PYTHON_INSTALL_PREFIX : ${CMAKE_PYTHON_INSTALL_PREFIX}" ) + + set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/../setup.py.in") + set(SETUP_PY "${CMAKE_CURRENT_SOURCE_DIR}/../setup.py") + set(DEPS "${CMAKE_CURRENT_SOURCE_DIR}/../ecflow/__init__.py") + set(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/timestamp") + + configure_file(${SETUP_PY_IN} ${SETUP_PY} ) + + add_custom_command( + OUTPUT ${OUTPUT} + COMMAND ${PYTHON} ${SETUP_PY} build + COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT} + DEPENDS ${DEPS} + ) + add_custom_target(target ALL DEPENDS ${OUTPUT}) + + install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} build_ext)") + + if( DEFINED CMAKE_PYTHON_INSTALL_PREFIX ) + message(STATUS "custom/*test* python install prefix defined CMAKE_PYTHON_INSTALL_PREFIX=${CMAKE_PYTHON_INSTALL_PREFIX}") + install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install -f --prefix=${CMAKE_PYTHON_INSTALL_PREFIX})") + else() + install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install)") + endif() endif() diff --git a/Pyext/python3/CMakeLists.txt b/Pyext/python3/CMakeLists.txt index 1e150aee9..9ee8021a5 100644 --- a/Pyext/python3/CMakeLists.txt +++ b/Pyext/python3/CMakeLists.txt @@ -1,8 +1,12 @@ -# ===================================================================== -# INCLUDES here is for external includes -# NOINSTALL this stops double install, the one in i.e lib/ecflow.so -# The other install is in python2.7/site-packages/ecflow.so -# if OpenSSL not enabled ${OPENSSL_LIBRARIES}, is empty +# +# Copyright 2023- ECMWF. +# +# This software is licensed under the terms of the Apache Licence version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# In applying this licence, ECMWF does not waive the privileges and immunities +# granted to it by virtue of its status as an intergovernmental organisation +# nor does it submit to any jurisdiction. +# # ENABLE_PYTHON_UNDEF_LOOKUP # on some systems (e.g. conda on macOS) the boost Python libraries seem to be too @@ -12,42 +16,33 @@ # we can make our ecflow shared library more movable bewteen systems if (ENABLE_PYTHON_UNDEF_LOOKUP) - add_link_options(-undefined dynamic_lookup) - set(PY3_LIBRARIES "") -else() - set(PY3_LIBRARIES ${Python3_LIBRARIES}) + add_link_options(-undefined dynamic_lookup) endif() -file( GLOB srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "../src/*.cpp" "../src/*.hpp" ) -ecbuild_add_library( TARGET ecflow3 - NOINSTALL - TYPE MODULE - SOURCES ${srcs} - ) -target_include_directories(ecflow3 PRIVATE ${Boost_INCLUDE_DIRS} ${Python3_INCLUDE_DIRS} ) - - -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # using regular Clang or AppleClang - # Stop annoying message: - # warning: '_POSIX_C_SOURCE' macro redefined [-Wmacro-redefined] - # warning: '_XOPEN_SOURCE' macro redefined [-Wmacro-redefined] - target_compile_options(ecflow3 PRIVATE -Wno-macro-redefined) -endif() +ecbuild_add_library( + TARGET + ecflow3 + NOINSTALL + TYPE MODULE + SOURCES + ${srcs} + PUBLIC_LIBS + libclient + libsimu + base + node + nodeattr + core + Python3::Python + Boost::${ECFLOW_BOOST_PYTHON_COMPONENT} + $<$:OpenSSL::SSL> + CXXFLAGS + $<$:-Wno-macro-redefined> +) -# This ensures that for debug config, we only link with debug boost libs, for other configs, we link with optimised boost libs -# Currently we only build optimised boost libs -# versions of boost >= 1.67 now tag the python libs, i.e. libboost_python27-mt.a, libboost_python36-mt.so -if ( Boost_MINOR_VERSION GREATER 66 ) - target_link_libraries(ecflow3 libclient libsimu base node nodeattr core - ${PY3_LIBRARIES} ${OPENSSL_LIBRARIES} - ${Boost_PYTHON${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}_LIBRARY_RELEASE} ) -else() - target_link_libraries(ecflow3 libclient libsimu base node nodeattr core - ${PY3_LIBRARIES} ${OPENSSL_LIBRARIES} - ${Boost_PYTHON3_LIBRARY_RELEASE} ) -endif() +target_clangformat(ecflow3) +# # Override default behaviour that add RPATHS during install # The only thing that seem to work is set INSTALL_RPATH to "" # Using SKIP_BUILD_RPATH,BUILD_WITH_INSTALL_RPATH,INSTALL_RPATH_USE_LINK_PATH @@ -55,86 +50,51 @@ endif() # # by default cmake add prefix 'lib', we don't want this hence disable # -# To avoid duplicate target names with python2 we chose ecflow3, however test and user code -# depend on name 'ecflow' hence rename using 'OUTPUT_NAME' -set_target_properties(ecflow3 PROPERTIES - OUTPUT_NAME "ecflow" - PREFIX "" - INSTALL_RPATH "" - ) - -target_clangformat(ecflow3) +# To avoid duplicate target names we chose to name the targets: ecflow2/ecflow3. +# however test and user code depend on name 'ecflow', hence we rename the output to 'cflow' +set_target_properties(ecflow3 + PROPERTIES + OUTPUT_NAME "ecflow" + PREFIX "" + INSTALL_RPATH "" +) # ===================================================================== -# tests - -#ecbuild_add_test( TARGET py3_u_TestMigrate -# TYPE PYTHON -# ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../migrate/py_u_TestMigrate.py -# ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" ) - -list( APPEND u_tests - u_test_add - u_test_collection - u_test_cron - u_test_defs_constructor - u_test_get_attr - u_test_manual - u_test_late - u_test_replace_node - u_test_tutorial - u_TestAddDelete - u_TestAddDeleteFunc - u_TestAddNodeFunc - u_TestAutoAddExtern - u_TestCopy - u_TestDefs - u_TestDefsCheck - u_TestDerivable - u_TestEcf - u_TestError - u_TestFind - u_TestFlag - u_TestGetAllTasks - u_TestJobGeneration - u_TestParent - u_TestRemove - u_TestRepeatArithmetic - u_TestSimulator - u_TestTraversal - u_TestUserManual - u_TestWith - u_sort -) -foreach( test ${u_tests} ) +# tests - ecbuild_add_test( TARGET py3_${test} - TYPE PYTHON - ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../test/py_${test}.py - ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - TEST_DEPENDS u_base - ) +foreach( test ${u_tests} ) + ecbuild_add_test( + TARGET + py3_${test} + TYPE PYTHON + ARGS + ${CMAKE_CURRENT_SOURCE_DIR}/../test/${test}.py + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + TEST_DEPENDS + u_base + ) endforeach() if ( ENABLE_ALL_TESTS AND ENABLE_SERVER) - list( APPEND s_tests - s_TestClientApi - s_TestPythonChildApi - ) - - foreach( test ${s_tests} ) - - ecbuild_add_test( TARGET py3_${test} - TYPE PYTHON - ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../test/py_${test}.py - ENVIRONMENT "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" - TEST_DEPENDS u_base - ) - endforeach() - - set_property(TEST py3_s_TestClientApi APPEND PROPERTY DEPENDS s_test) - set_property(TEST py3_s_TestPythonChildApi APPEND PROPERTY DEPENDS py3_s_TestClientApi) + + foreach( test ${s_tests} ) + ecbuild_add_test( + TARGET + py3_${test} + TYPE PYTHON + ARGS + ${CMAKE_CURRENT_SOURCE_DIR}/../test/py_${test}.py + ENVIRONMENT + "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}" + TEST_DEPENDS + u_base + ) + endforeach() + + set_property(TEST py3_s_TestClientApi APPEND PROPERTY DEPENDS s_test) + set_property(TEST py3_s_TestPythonChildApi APPEND PROPERTY DEPENDS py3_s_TestClientApi) endif() @@ -153,58 +113,73 @@ endif() # cd buildir # cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DCOMPONENT=python -P cmake_install.cmake -- make install # ========================================================================== - + if( CMAKE_PYTHON_INSTALL_TYPE MATCHES "local" OR NOT DEFINED CMAKE_PYTHON_INSTALL_TYPE ) - - message(STATUS "python install *LOCAL* +++ lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages/ecflow +++++++") - if( NOT INSTALL_PYTHON3_DIR ) - set(PYTHON_SITE "lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages" ) - else() - # Resolve ${VAR} in the value provided - string(CONFIGURE "${INSTALL_PYTHON3_DIR}" PYTHON_SITE) - endif() - set(PYTHON_DEST "${PYTHON_SITE}/ecflow" ) - - install( TARGETS ecflow3 DESTINATION ${PYTHON_DEST} RENAME ecflow.so COMPONENT python ) - install( FILES ../ecflow/__init__.py DESTINATION ${PYTHON_DEST} COMPONENT python ) - - # Install files that Axel has asked for. - # These are example of what Axel uses as a layer over ecflow api, for operations - install( FILES ../samples/api/ecf.py DESTINATION ${PYTHON_DEST} COMPONENT python ) - install( FILES ../samples/api/sms2ecf.py DESTINATION ${PYTHON_DEST} COMPONENT python ) - + + message(STATUS "python install *LOCAL* +++ lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages/ecflow +++++++") + if( NOT INSTALL_PYTHON3_DIR ) + set(PYTHON_SITE "lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages" ) + else() + # Resolve ${VAR} in the value provided + string(CONFIGURE "${INSTALL_PYTHON3_DIR}" PYTHON_SITE) + endif() + set(PYTHON_DEST "${PYTHON_SITE}/ecflow" ) + + install( + TARGETS + ecflow3 + DESTINATION + ${PYTHON_DEST} + RENAME + ecflow.so + COMPONENT + python + ) + install( + FILES + ../ecflow/__init__.py + ../samples/api/ecf.py + ../samples/api/sms2ecf.py + DESTINATION + ${PYTHON_DEST} + COMPONENT + python + ) + else() - message( STATUS "python found, CMAKE_PYTHON_INSTALL_TYPE=${CMAKE_PYTHON_INSTALL_TYPE}") - - # ------------------------------------------------------------------------------------- - # Install using setup.py - # See: http://bloerg.net/2012/11/10/cmake-and-distutils.html - # ------------------------------------------------------------------------------------- - message(STATUS "python install using *setup.py* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") - message(STATUS "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}") - message(STATUS "CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}") - message(STATUS "CMAKE_PYTHON_INSTALL_PREFIX : ${CMAKE_PYTHON_INSTALL_PREFIX}" ) - - set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/../setup.py.in") - set(SETUP_PY "${CMAKE_CURRENT_SOURCE_DIR}/../setup.py") - set(DEPS "${CMAKE_CURRENT_SOURCE_DIR}/../ecflow/__init__.py") - set(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/timestamp") - - configure_file(${SETUP_PY_IN} ${SETUP_PY} ) - - add_custom_command(OUTPUT ${OUTPUT} - COMMAND ${PYTHON} ${SETUP_PY} build - COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT} - DEPENDS ${DEPS}) - add_custom_target(target ALL DEPENDS ${OUTPUT}) - - - install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} build_ext)") - - if( DEFINED CMAKE_PYTHON_INSTALL_PREFIX ) - message(STATUS "custom/*test* python install prefix defined CMAKE_PYTHON_INSTALL_PREFIX=${CMAKE_PYTHON_INSTALL_PREFIX}") - install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install -f --prefix=${CMAKE_PYTHON_INSTALL_PREFIX})") - else() - install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install)") - endif() + + message( STATUS "python found, CMAKE_PYTHON_INSTALL_TYPE=${CMAKE_PYTHON_INSTALL_TYPE}") + + # ------------------------------------------------------------------------------------- + # Install using setup.py + # See: http://bloerg.net/2012/11/10/cmake-and-distutils.html + # ------------------------------------------------------------------------------------- + message(STATUS "python install using *setup.py* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") + message(STATUS "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}") + message(STATUS "CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}") + message(STATUS "CMAKE_PYTHON_INSTALL_PREFIX : ${CMAKE_PYTHON_INSTALL_PREFIX}" ) + + set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/../setup.py.in") + set(SETUP_PY "${CMAKE_CURRENT_SOURCE_DIR}/../setup.py") + set(DEPS "${CMAKE_CURRENT_SOURCE_DIR}/../ecflow/__init__.py") + set(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/timestamp") + + configure_file(${SETUP_PY_IN} ${SETUP_PY} ) + + add_custom_command( + OUTPUT ${OUTPUT} + COMMAND ${PYTHON} ${SETUP_PY} build + COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT} + DEPENDS ${DEPS} + ) + add_custom_target(target ALL DEPENDS ${OUTPUT}) + + install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} build_ext)") + + if( DEFINED CMAKE_PYTHON_INSTALL_PREFIX ) + message(STATUS "custom/*test* python install prefix defined CMAKE_PYTHON_INSTALL_PREFIX=${CMAKE_PYTHON_INSTALL_PREFIX}") + install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install -f --prefix=${CMAKE_PYTHON_INSTALL_PREFIX})") + else() + install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} install)") + endif() endif() From b555b09c3fa8d14fa57b2bd4fc8a82cc84ede917 Mon Sep 17 00:00:00 2001 From: Marcos Bento Date: Tue, 14 Nov 2023 18:11:10 +0000 Subject: [PATCH 2/3] Modernize CMakeLists.txt for share --- share/CMakeLists.txt | 11 +++- share/ecflow/etc/CMakeLists.txt | 73 ++++++++++++++++---------- share/ecflow/etc/sounds/CMakeLists.txt | 31 ++++++++--- 3 files changed, 81 insertions(+), 34 deletions(-) diff --git a/share/CMakeLists.txt b/share/CMakeLists.txt index a4a5284b2..cd020faf2 100644 --- a/share/CMakeLists.txt +++ b/share/CMakeLists.txt @@ -1,3 +1,12 @@ +# +# Copyright 2023- ECMWF. +# +# This software is licensed under the terms of the Apache Licence version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# In applying this licence, ECMWF does not waive the privileges and immunities +# granted to it by virtue of its status as an intergovernmental organisation +# nor does it submit to any jurisdiction. +# add_subdirectory(ecflow/etc) -add_subdirectory(ecflow/etc/sounds) \ No newline at end of file +add_subdirectory(ecflow/etc/sounds) diff --git a/share/ecflow/etc/CMakeLists.txt b/share/ecflow/etc/CMakeLists.txt index d1d3acc77..a7851b2b2 100644 --- a/share/ecflow/etc/CMakeLists.txt +++ b/share/ecflow/etc/CMakeLists.txt @@ -1,34 +1,53 @@ +# +# Copyright 2023- ECMWF. +# +# This software is licensed under the terms of the Apache Licence version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# In applying this licence, ECMWF does not waive the privileges and immunities +# granted to it by virtue of its status as an intergovernmental organisation +# nor does it submit to any jurisdiction. +# -# the list of files we want to install -set (files ecflowview_menus.json - ecflowview_attribute_conf.json - ecflowview_gui.json - ecflowview_gui_server.json - ecflowview_highlighter.json - ecflowview_icon_conf.json - ecflowview_menu_conf.json - ecflowview_network_conf.json - ecflowview_notification_conf.json - ecflowview_nstate_conf.json - ecflowview_palette.json - ecflowview_panels.json - ecflowview_panel_conf.json - ecflowview_query_conf.json - ecflowview_sstate_conf.json - ecflowview_server_conf.json - ecflowview_view_conf.json - ecflow_ui_test.def - ecflow_ui_test_session_template.json - ecflow_ui_test_server_scripts.tar.gz - shortcuts.txt - viewer.qss) +# the files we want to install +set (files + ecflowview_menus.json + ecflowview_attribute_conf.json + ecflowview_gui.json + ecflowview_gui_server.json + ecflowview_highlighter.json + ecflowview_icon_conf.json + ecflowview_menu_conf.json + ecflowview_network_conf.json + ecflowview_notification_conf.json + ecflowview_nstate_conf.json + ecflowview_palette.json + ecflowview_panels.json + ecflowview_panel_conf.json + ecflowview_query_conf.json + ecflowview_sstate_conf.json + ecflowview_server_conf.json + ecflowview_view_conf.json + ecflow_ui_test.def + ecflow_ui_test_session_template.json + ecflow_ui_test_server_scripts.tar.gz + shortcuts.txt + viewer.qss +) # for each file, copy it into the build directory at build time # and install it into the installation directory at install time (!) foreach( f ${files} ) - configure_file(${f} ${CMAKE_CURRENT_BINARY_DIR} COPYONLY) + configure_file(${f} ${CMAKE_CURRENT_BINARY_DIR} COPYONLY) - install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${f} - DESTINATION share/ecflow/etc - PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ) + install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/${f} + DESTINATION + share/ecflow/etc + PERMISSIONS + OWNER_WRITE + OWNER_READ + GROUP_READ + WORLD_READ + ) endforeach() diff --git a/share/ecflow/etc/sounds/CMakeLists.txt b/share/ecflow/etc/sounds/CMakeLists.txt index d164e3e72..f41e61896 100644 --- a/share/ecflow/etc/sounds/CMakeLists.txt +++ b/share/ecflow/etc/sounds/CMakeLists.txt @@ -1,13 +1,32 @@ +# +# Copyright 2023- ECMWF. +# +# This software is licensed under the terms of the Apache Licence version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# In applying this licence, ECMWF does not waive the privileges and immunities +# granted to it by virtue of its status as an intergovernmental organisation +# nor does it submit to any jurisdiction. +# -# the list of files we want to install -set (files tone.ogg) +# the files we want to install +set (files + tone.ogg +) # for each file, copy it into the build directory at build time # and install it into the installation directory at install time (!) foreach( f ${files} ) - configure_file(${f} ${CMAKE_CURRENT_BINARY_DIR} COPYONLY) + configure_file(${f} ${CMAKE_CURRENT_BINARY_DIR} COPYONLY) - install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${f} - DESTINATION share/ecflow/etc/sounds - PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ) + install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/${f} + DESTINATION + share/ecflow/etc/sounds + PERMISSIONS + OWNER_WRITE + OWNER_READ + GROUP_READ + WORLD_READ + ) endforeach() From a818058dc402f735572be8e8cbf99f0be5c12802 Mon Sep 17 00:00:00 2001 From: Marcos Bento Date: Tue, 14 Nov 2023 18:11:32 +0000 Subject: [PATCH 3/3] Modernize CMakeLists.txt for tools --- tools/CMakeLists.txt | 61 +++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 69db7c249..5dbbfc707 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,8 +1,20 @@ +# +# Copyright 2023- ECMWF. +# +# This software is licensed under the terms of the Apache Licence version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# In applying this licence, ECMWF does not waive the privileges and immunities +# granted to it by virtue of its status as an intergovernmental organisation +# nor does it submit to any jurisdiction. +# # This can be used by submission system. i.e trimurti -ecbuild_add_executable( TARGET ecflow_standalone - SOURCES ecflow_standalone.c - ) +ecbuild_add_executable( + TARGET + ecflow_standalone + SOURCES + ecflow_standalone.c +) # # Configure ecflow_site.sh. This is used in ecflow_start.sh and ecflow_stop.sh @@ -10,23 +22,30 @@ ecbuild_add_executable( TARGET ecflow_standalone # Avoid's hard copy mention of paths specific to ECMWF if( DEFINED SITE_SPECIFIC_SERVER_SCRIPT ) - - macro(install_symlink filepath sympath) - install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${filepath} ${sympath})") - install(CODE "message(\"-- Created symlink: ${sympath} -> ${filepath}\")") - endmacro(install_symlink) - - install_symlink(${SITE_SPECIFIC_SERVER_SCRIPT} ${CMAKE_INSTALL_PREFIX}/bin/ecflow_site.sh ) - + macro(install_symlink filepath sympath) + install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${filepath} ${sympath})") + install(CODE "message(\"-- Created symlink: ${sympath} -> ${filepath}\")") + endmacro(install_symlink) + + install_symlink(${SITE_SPECIFIC_SERVER_SCRIPT} ${CMAKE_INSTALL_PREFIX}/bin/ecflow_site.sh ) endif() -install( FILES - ${CMAKE_SOURCE_DIR}/tools/ecflow_fuse.py - ${CMAKE_SOURCE_DIR}/tools/ecflow_logsvr.pl - ${CMAKE_SOURCE_DIR}/tools/ecflow_start.sh - ${CMAKE_SOURCE_DIR}/tools/ecflow_stop.sh - ${CMAKE_SOURCE_DIR}/tools/ecflow_logserver.sh - DESTINATION bin - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE - COMPONENT binary - ) \ No newline at end of file +install( + FILES + ${CMAKE_SOURCE_DIR}/tools/ecflow_fuse.py + ${CMAKE_SOURCE_DIR}/tools/ecflow_logsvr.pl + ${CMAKE_SOURCE_DIR}/tools/ecflow_start.sh + ${CMAKE_SOURCE_DIR}/tools/ecflow_stop.sh + ${CMAKE_SOURCE_DIR}/tools/ecflow_logserver.sh + DESTINATION bin + PERMISSIONS + OWNER_READ + OWNER_WRITE + OWNER_EXECUTE + GROUP_READ + GROUP_EXECUTE + WORLD_READ + WORLD_EXECUTE + COMPONENT + binary +)