Skip to content
Snippets Groups Projects
Commit 13594c7e authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

GMSHPY_INSTALL_DIRECTORY, ENABLE_GMSHPY_SOURCE_PACKAGE

parent 98dad5ca
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,10 @@ set(SWIG_MODULES
gmshSolver
gmshMesh
)
if (NOT GMSHPY_INSTALL_DIRECTORY)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print (sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_PREFIX}'))" OUTPUT_VARIABLE PYTHON_MODULE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
set(GMSHPY_INSTALL_DIRECTORY ${PYTHON_MODULE_PATH}/gmshpy CACHE STRING "python wrappers installation directory")
endif (NOT GMSHPY_INSTALL_DIRECTORY)
# code backported from CMake git version, see CMake bug 4147
MACRO(SWIG_GET_WRAPPER_DEPENDENCIES swigFile genWrapper language DEST_VARIABLE)
......@@ -60,18 +64,10 @@ MACRO(SWIG_GET_WRAPPER_DEPENDENCIES swigFile genWrapper language DEST_VARIABLE)
ENDIF(NOT ${swig_getdeps_error} EQUAL 0)
ENDMACRO(SWIG_GET_WRAPPER_DEPENDENCIES)
option(ENABLE_PYTHON_LIB_API "Export all C header files needed to build the python library" OFF)
if(ENABLE_PYTHON_LIB_API)
set(GMSH_API ${GMSH_API} Geo/Curvature.h Mesh/Generator.h
Mesh/meshGFaceLloyd.h Numeric/DivideAndConquer.h Post/PViewFactory.h
Solver/linearSystemPETSc.h Fltk/FlGui.h Solver/functionSpace.h
Solver/STensor43.h Solver/sparsityPattern.h Solver/SElement.h
Solver/groupOfElements.h PARENT_SCOPE)
endif(ENABLE_PYTHON_LIB_API)
include(${SWIG_USE_FILE})
include_directories(${PYTHON_INCLUDE_PATH})
option(ENABLE_GMSHPY_SOURCE_PACKAGE "Instead of generating the python bindings for the current python executable, generate a source package that can be used to generate the bindings without requiring the gmsh source code" OFF)
set(GMSH_PYTHON_MODULES_INCLUDE_CODE "")
foreach(module ${SWIG_MODULES})
set_source_files_properties(${module}.i PROPERTIES CPLUSPLUS ON)
......@@ -91,74 +87,92 @@ foreach(module ${SWIG_MODULES})
set(GMSH_PYTHON_MODULES_INCLUDE_CODE
"${GMSH_PYTHON_MODULES_INCLUDE_CODE}from gmshpy.${module} import *\n")
list(APPEND GMSHPY_DEPENDS "${module}PYTHON_wrap.cxx")
if (NOT ENABLE_GMSHPY_SOURCE_PACKAGE)
install(TARGETS ${SWIG_MODULE_${module}_REAL_NAME} DESTINATION ${GMSHPY_INSTALL_DIRECTORY})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${module}.py DESTINATION ${GMSHPY_INSTALL_DIRECTORY})
endif (NOT ENABLE_GMSHPY_SOURCE_PACKAGE)
if(APPLE)
set_target_properties("_${module}" PROPERTIES LINK_FLAGS "-undefined suppress -flat_namespace")
endif(APPLE)
endforeach(module)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in ${CMAKE_CURRENT_BINARY_DIR}/__init__.py.orig)
IF(HAVE_MPI)
# this hack is only required for openmpi compiled with dynamic modules
# unfortunately I do not know how to detect this situation => I always enable it
set(GMSH_PYTHON_OPENMPI_HACK "import ctypes\n")
FOREACH (lib ${MPI_C_LIBRARIES})
IF (${lib} MATCHES ".*libmpi.*")
set(GMSH_PYTHON_OPENMPI_HACK
"${GMSH_PYTHON_OPENMPI_HACK}ctypes.CDLL(\"${lib}\", mode = ctypes.RTLD_GLOBAL)\n")
ENDIF (${lib} MATCHES ".*libmpi.*")
ENDFOREACH (lib)
ENDIF(HAVE_MPI)
if (NOT ENABLE_GMSHPY_SOURCE_PACKAGE)
IF(HAVE_MPI)
# this hack is only required for openmpi compiled with dynamic modules
# unfortunately I do not know how to detect this situation => I always enable it
set(GMSH_PYTHON_OPENMPI_HACK "import ctypes\n")
FOREACH (lib ${MPI_C_LIBRARIES})
IF (${lib} MATCHES ".*libmpi.*")
set(GMSH_PYTHON_OPENMPI_HACK
"${GMSH_PYTHON_OPENMPI_HACK}ctypes.CDLL(\"${lib}\", mode = ctypes.RTLD_GLOBAL)\n")
ENDIF (${lib} MATCHES ".*libmpi.*")
ENDFOREACH (lib)
ENDIF(HAVE_MPI)
endif (NOT ENABLE_GMSHPY_SOURCE_PACKAGE)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in ${CMAKE_CURRENT_BINARY_DIR}/__init__.py)
if (NOT ENABLE_GMSHPY_SOURCE_PACKAGE)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/__init__.py DESTINATION ${GMSHPY_INSTALL_DIRECTORY})
endif (NOT ENABLE_GMSHPY_SOURCE_PACKAGE)
string(REPLACE ";" "\", \"" GMSH_PYTHON_MODULES "${SWIG_MODULES}")
set(GMSH_PYTHON_MODULES "\"${GMSH_PYTHON_MODULES}\"")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
if(ENABLE_GMSHPY_SOURCE_PACKAGE)
set(GMSH_API ${GMSH_API} Geo/Curvature.h Mesh/Generator.h
Mesh/meshGFaceLloyd.h Numeric/DivideAndConquer.h Post/PViewFactory.h
Solver/linearSystemPETSc.h Fltk/FlGui.h Solver/functionSpace.h
Solver/STensor43.h Solver/sparsityPattern.h Solver/SElement.h
Solver/groupOfElements.h PARENT_SCOPE)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/__init__.py.orig DESTINATION gmshpy/src RENAME __init__.py)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/setup.py DESTINATION gmshpy)
foreach(module ${SWIG_MODULES})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${module}PYTHON_wrap.cxx DESTINATION gmshpy/src)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${module}.py DESTINATION gmshpy/src)
install(TARGETS _${module} DESTINATION gmshpy/src)
endforeach(module)
set (GMSH_PYTHON_EXTRA_INCLUDE
Numeric/BasisFactory.h
Numeric/BergotBasis.h
Mesh/CenterlineField.h
Geo/Curvature.h
Common/Options.h
Mesh/directions3D.h
Mesh/DivideAndConquer.h
Mesh/Field.h
Mesh/FieldPython.h
Fltk/FlGui.h
Solver/frameSolver.h
Solver/functionSpace.h
Solver/eigenSolver.h
Mesh/Generator.h
Geo/GeomMeshMatcher.h
Geo/GFaceCompound.h
Geo/gmshLevelset.h
Numeric/jacobiPolynomials.h
Numeric/legendrePolynomials.h
Plugin/Plugin.h
Solver/linearSystemPETSc.h
Mesh/meshGFaceLloyd.h
contrib/HighOrderMeshOptimizer/OptHomRun.h
contrib/HighOrderMeshOptimizer/OptHomElastic.h
contrib/MeshQualityOptimizer/MeshQualityOptimizer.h
Post/PViewAsSimpleFunction.h
Post/PViewDataList.h
Post/PViewFactory.h
Numeric/pyramidalBasis.h
Numeric/FuncSpaceData.h
Solver/SElement.h
Numeric/simpleFunctionPython.h
Solver/STensor33.h
Solver/STensor43.h
)
string(REPLACE ";" "\", \"" GMSH_PYTHON_MODULES "${SWIG_MODULES}")
set(GMSH_PYTHON_MODULES "\"${GMSH_PYTHON_MODULES}\"")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/__init__.py.orig DESTINATION gmshpy/src RENAME __init__.py)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/setup.py DESTINATION gmshpy)
foreach(module ${SWIG_MODULES})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${module}PYTHON_wrap.cxx DESTINATION gmshpy/src)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${module}.py DESTINATION gmshpy/src)
install(TARGETS _${module} DESTINATION gmshpy/src)
endforeach(module)
set (GMSH_PYTHON_EXTRA_INCLUDE
Numeric/BasisFactory.h
Numeric/BergotBasis.h
Mesh/CenterlineField.h
Geo/Curvature.h
Common/Options.h
Mesh/directions3D.h
Mesh/DivideAndConquer.h
Mesh/Field.h
Mesh/FieldPython.h
Fltk/FlGui.h
Solver/frameSolver.h
Solver/functionSpace.h
Solver/eigenSolver.h
Mesh/Generator.h
Geo/GeomMeshMatcher.h
Geo/GFaceCompound.h
Geo/gmshLevelset.h
Numeric/jacobiPolynomials.h
Numeric/legendrePolynomials.h
Plugin/Plugin.h
Solver/linearSystemPETSc.h
Mesh/meshGFaceLloyd.h
contrib/HighOrderMeshOptimizer/OptHomRun.h
contrib/HighOrderMeshOptimizer/OptHomElastic.h
contrib/MeshQualityOptimizer/MeshQualityOptimizer.h
Post/PViewAsSimpleFunction.h
Post/PViewDataList.h
Post/PViewFactory.h
Numeric/pyramidalBasis.h
Numeric/FuncSpaceData.h
Solver/SElement.h
Numeric/simpleFunctionPython.h
Solver/STensor33.h
Solver/STensor43.h
)
foreach (file ${GMSH_PYTHON_EXTRA_INCLUDE})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../${file} DESTINATION gmshpy/extra_include)
endforeach(file)
foreach (file ${GMSH_PYTHON_EXTRA_INCLUDE})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../${file} DESTINATION gmshpy/extra_include)
endforeach(file)
endif(ENABLE_GMSHPY_SOURCE_PACKAGE)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment