Skip to content
Snippets Groups Projects
Commit 7487b849 authored by Santiago Ospina De Los Ríos's avatar Santiago Ospina De Los Ríos
Browse files

Make consistent use of Python targets and variables in CMake

parent 9ef03b4b
Branches
Tags
1 merge request!1412Make consistent use of Python targets and variables in CMake
Pipeline #72804 passed with warnings
Pipeline: Dune Nightly Test

#72809

    Pipeline: Dune Nightly Test

    #72808

      ......@@ -78,15 +78,12 @@ function(dune_add_pybind11_module)
      # force '.so' as library suffix on macOS due to a problem in Python
      # https://stackoverflow.com/questions/2488016/how-to-make-python-load-dylib-on-osx
      # and add -undefined dynamic_lookup flag to linker
      # https://pybind11.readthedocs.io/en/stable/compiling.html#building-manually
      if (APPLE)
      set_target_properties(${PYBIND11_MODULE_NAME} PROPERTIES SUFFIX ".so")
      target_link_options(${PYBIND11_MODULE_NAME} PRIVATE -undefined dynamic_lookup)
      endif()
      target_compile_definitions(${PYBIND11_MODULE_NAME} PRIVATE ${PYBIND11_MODULE_COMPILE_DEFINITIONS})
      target_link_libraries(${PYBIND11_MODULE_NAME} PUBLIC Dune::Common)
      target_link_libraries(${PYBIND11_MODULE_NAME} PUBLIC Dune::Common Python3::Module)
      dune_target_enable_all_packages(${PYBIND11_MODULE_NAME})
      if(PYBIND11_MODULE_EXCLUDE_FROM_ALL)
      ......
      ......@@ -105,7 +105,7 @@ if(Python3_Interpreter_FOUND)
      ##### Python bindings specific part begin ################
      # first we test if all requirements are satisfied, if not, Python bindings are
      # disabled and the user gets an informative message explaining why
      if((DUNE_ENABLE_PYTHONBINDINGS) AND (NOT Python3_INCLUDE_DIRS))
      if((DUNE_ENABLE_PYTHONBINDINGS) AND (NOT ${Python3_Development.Module_FOUND}))
      message(STATUS "Python bindings disabled")
      message(NOTICE
      " ----------------------------------------------------------------------------------------\n"
      ......
      ......@@ -516,7 +516,8 @@ function(dune_python_configure_package)
      # Add a custom target that globally installs this package if requested
      if (NOT PYPKGCONF_INSTALL_TARGET)
      string(REPLACE "/" "_" PYPKGCONF_INSTALL_TARGET "install_python_${CMAKE_CURRENT_SOURCE_DIR}_${PYPKGCONF_PATH}")
      string(MD5 path_hash "${PYCONFBIND_FULLPATH}")
      set(PYPKGCONF_INSTALL_TARGET "install_python_${path_hash}")
      endif()
      # TODO this creates an egg-info folder in the source directory
      ......@@ -631,11 +632,12 @@ function(dune_python_configure_bindings)
      message(FATAL_ERROR "dune_python_configure_bindings: ${PYCONFBIND_FULLPATH} does not exists")
      endif()
      string(MD5 path_hash "${PYCONFBIND_FULLPATH}")
      dune_python_configure_package(
      PATH ${PYCONFBIND_FULLPATH}
      ADDITIONAL_PIP_PARAMS ${PYCONFBIND_ADDITIONAL_PIP_PARAMS}
      RESULT PYTHON_PACKAGE_FAILED
      INSTALL_TARGET install_python_package_${PYCONFBIND_PACKAGENAME}
      INSTALL_TARGET install_python_package_${path_hash}
      )
      # we could actually add metadata even if the configuration of the venv
      ......@@ -648,7 +650,7 @@ function(dune_python_configure_bindings)
      dune_link_dune_py(
      PATH ${CMAKE_CURRENT_BINARY_DIR}/${PYCONFBIND_PATH}
      PACKAGENAME ${PYCONFBIND_PACKAGENAME}
      INSTALL_TARGET install_python_package_${PYCONFBIND_PACKAGENAME}
      INSTALL_TARGET install_python_package_${path_hash}
      CMAKE_METADATA_FLAGS ${PYCONFBIND_CMAKE_METADATA_FLAGS}
      )
      else()
      ......
      ......@@ -242,7 +242,8 @@ if(DUNE_PYTHON_USE_VENV)
      endif()
      # Also store the virtual env interpreter directly
      set(DUNE_PYTHON_VIRTUALENV_EXECUTABLE ${DUNE_PYTHON_VIRTUALENV_PATH}/bin/python)
      set(DUNE_PYTHON_VIRTUALENV_EXECUTABLE ${DUNE_PYTHON_VIRTUALENV_PATH}/bin/python
      CACHE INTERNAL "Python virtual environment executable used by Dune")
      # Write a symlink for activation of the environment into all the
      # build directories of the Dune stack
      ......@@ -312,7 +313,7 @@ if(DUNE_PYTHON_USE_VENV)
      endif()
      # if pip was not found before then we can set it here since it was now found
      set(DUNE_PYTHON_pip_FOUND ON)
      set(DUNE_PYTHON_pip_FOUND ON CACHE INTERNAL "Whether dune has found python pip")
      # install setuptools into the venv (needed to find dependencies later on)
      dune_execute_process(COMMAND ${DUNE_PYTHON_VIRTUALENV_EXECUTABLE} -m pip install
      ......
      ......@@ -14,18 +14,20 @@ dune_python_add_test(NAME tuplevectortest
      LABELS quick
      )
      dune_add_test(SOURCES test_embed1.cc
      LINK_LIBRARIES ${DUNE_LIBS} ${Python3_LIBRARIES}
      LABELS quick
      COMMAND ${CMAKE_BINARY_DIR}/run-in-dune-env
      CMD_ARGS $<TARGET_FILE:test_embed1>
      )
      target_compile_definitions(test_embed1 PRIVATE PYTHON_INTERPRETER=L"${DUNE_PYTHON_VIRTUALENV_EXECUTABLE}")
      if(TARGET Python3::Python)
      dune_add_test(SOURCES test_embed1.cc
      LINK_LIBRARIES ${DUNE_LIBS} Python3::Python
      LABELS quick
      COMMAND ${CMAKE_BINARY_DIR}/run-in-dune-env
      CMD_ARGS $<TARGET_FILE:test_embed1>
      )
      target_compile_definitions(test_embed1 PRIVATE PYTHON_INTERPRETER=L"${DUNE_PYTHON_VIRTUALENV_EXECUTABLE}")
      dune_add_test(SOURCES test_embed2.cc
      LINK_LIBRARIES ${DUNE_LIBS} ${Python3_LIBRARIES}
      LABELS quick
      COMMAND ${CMAKE_BINARY_DIR}/run-in-dune-env
      CMD_ARGS $<TARGET_FILE:test_embed2>
      )
      target_compile_definitions(test_embed2 PRIVATE PYTHON_INTERPRETER=L"${DUNE_PYTHON_VIRTUALENV_EXECUTABLE}")
      dune_add_test(SOURCES test_embed2.cc
      LINK_LIBRARIES ${DUNE_LIBS} Python3::Python
      LABELS quick
      COMMAND ${CMAKE_BINARY_DIR}/run-in-dune-env
      CMD_ARGS $<TARGET_FILE:test_embed2>
      )
      target_compile_definitions(test_embed2 PRIVATE PYTHON_INTERPRETER=L"${DUNE_PYTHON_VIRTUALENV_EXECUTABLE}")
      endif()
      0% Loading or .
      You are about to add 0 people to the discussion. Proceed with caution.
      Please register or to comment