From 15cdeae1d9cfec90cdb0c55370db6cc36df77d75 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Fri, 22 Jul 2016 14:13:29 -0500 Subject: [PATCH] CMake: Add a component DEAL_II_COMPONENT_PYTHON_BINDINGS --- cmake/modules/FindBOOST.cmake | 8 ++- cmake/setup_cached_variables.cmake | 7 +++ contrib/python-bindings/CMakeLists.txt | 74 ++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 contrib/python-bindings/CMakeLists.txt diff --git a/cmake/modules/FindBOOST.cmake b/cmake/modules/FindBOOST.cmake index 83b6f8c221..b8a08bf3b3 100644 --- a/cmake/modules/FindBOOST.cmake +++ b/cmake/modules/FindBOOST.cmake @@ -43,7 +43,13 @@ ENDIF() # temporarily disable ${CMAKE_SOURCE_DIR}/cmake/modules for module lookup LIST(REMOVE_ITEM CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules/) -FIND_PACKAGE(Boost 1.54 COMPONENTS iostreams serialization system thread) +SET(_boost_python "") +IF(DEAL_II_COMPONENT_PYTHON_BINDINGS) + SET(_boost_python "python") +ENDIF() +FIND_PACKAGE(Boost 1.54 COMPONENTS + iostreams serialization system thread ${_boost_python} + ) LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules/) # diff --git a/cmake/setup_cached_variables.cmake b/cmake/setup_cached_variables.cmake index 3bbd7c1e0b..94ea7a0a9b 100644 --- a/cmake/setup_cached_variables.cmake +++ b/cmake/setup_cached_variables.cmake @@ -25,6 +25,7 @@ # DEAL_II_COMPONENT_DOCUMENTATION # DEAL_II_COMPONENT_EXAMPLES # DEAL_II_COMPONENT_PACKAGE +# DEAL_II_COMPONENT_PYTHON_BINDINGS # DEAL_II_FORCE_AUTODETECTION # # Options regarding compilation and linking: @@ -91,6 +92,12 @@ OPTION(DEAL_II_COMPONENT_PACKAGE ) LIST(APPEND DEAL_II_COMPONENTS PACKAGE) +OPTION(DEAL_II_COMPONENT_PYTHON_BINDINGS + "Enable configuration and installation of the python bindings. This adds a COMPONENT \"PYTHON_BINDINGS\" to the build system." + OFF + ) +LIST(APPEND DEAL_II_COMPONENTS PYTHON_BINDINGS) + OPTION(DEAL_II_ALLOW_AUTODETECTION "Allow to automatically set up features by setting all undefined DEAL_II_WITH_* variables to ON or OFF" ON diff --git a/contrib/python-bindings/CMakeLists.txt b/contrib/python-bindings/CMakeLists.txt new file mode 100644 index 0000000000..b490eee0cc --- /dev/null +++ b/contrib/python-bindings/CMakeLists.txt @@ -0,0 +1,74 @@ +## --------------------------------------------------------------------- +## +## Copyright (C) 2016 by the deal.II authors +## +## This file is part of the deal.II library. +## +## The deal.II library is free software; you can use it, redistribute +## it, and/or modify it under the terms of the GNU Lesser General +## Public License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## The full text of the license can be found in the file LICENSE at +## the top level of the deal.II distribution. +## +## --------------------------------------------------------------------- + +FIND_LIBRARY(Boost_PYTHON_LIBRARY boost_python PATH ${Boost_LIBRARY_DIRS} NO_DEFAULT_PATH) +INCLUDE(FindPythonLibs) +INCLUDE(FindPythonInterp) +INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) +INCLUDE_DIRECTORIES( + ${CMAKE_BINARY_DIR}/include/ + ${CMAKE_SOURCE_DIR}/include/ + ${DEAL_II_BUNDLED_INCLUDE_DIRS} + ${DEAL_II_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/contrib/python-bindings/include/ + ) +INCLUDE_DIRECTORIES(SYSTEM ${PYTHON_INCLUDE_DIRS}) + +SET(_src + wrappers.cc + export_cell_accessor.cc + export_point.cc + export_triangulation.cc + cell_accessor_wrapper.cc + point_wrapper.cc + triangulation_wrapper.cc + ) + +PYTHON_ADD_MODULE(PyDealII ${_src}) + +SET(PYTHON_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages) + +TARGET_LINK_LIBRARIES(PyDealII deal_II.g) +TARGET_LINK_LIBRARIES(PyDealII ${Boost_PYTHON_LIBRARY}) +TARGET_LINK_LIBRARIES(PyDealII ${PYTHON_LIBRARIES}) + +SET_TARGET_PROPERTIES(PyDealII PROPERTIES + CXX_STANDARD 11 + ) + +INSTALL(TARGETS PyDealII DESTINATION ${PYTHON_INSTALL_PREFIX}/pydealii) + +SET(PYTHON_SOURCES + __init__.py + ) + +FOREACH(PYTHON_SOURCE ${PYTHON_SOURCES}) + ADD_CUSTOM_COMMAND( + OUTPUT ${CMAKE_BINARY_DIR}/python/pydealii/${PYTHON_SOURCE} + DEPENDS ${CMAKE_SOURCE_DIR}/contrib/python-bindings/source/${PYTHON_SOURCE} + COMMAND ${CMAKE_COMMAND} + ARGS -E copy ${CMAKE_SOURCE_DIR}/contrib/python-bindings/source/${PYTHON_SOURCE} ${CMAKE_BINARY_DIR}/python/pydealii/${PYTHON_SOURCE} + COMMENT "Copying ${PYTHON_SOURCE}" + ) + ADD_CUSTOM_TARGET( + ${PYTHON_SOURCE} ALL + DEPENDS ${CMAKE_BINARY_DIR}/python/pydealii/${PYTHON_SOURCE} + ) +ENDFOREACH() +INSTALL( + DIRECTORY ${CMAKE_BINARY_DIR}/python/pydealii + DESTINATION ${PYTHON_INSTALL_PREFIX} + FILES_MATCHING PATTERN "*.py" + ) -- 2.39.5