diff --git a/CMakeLists.txt b/CMakeLists.txt index 4869a4a8..f8937c0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ option( USE_SPDLOG "Enable spd log logging" OFF) option( DEBUG_LOG "Enable more debug output (may increase computation time) - only works with USE_SPDLOG=ON" OFF) option( CHECK_RANGE "Check array range access, automatically enabled if built in debug mode" OFF) option( BUILD_WITH_CONDA "set this to on if the library is compiled with conda-buid" OFF) +option( DYNAMIC_LINK_PYTHON "set this to OFF for static linking to python" ON) option( USE_SUPERBUILD "use ccache" ON) diff --git a/libsrc/core/CMakeLists.txt b/libsrc/core/CMakeLists.txt index 46a2230b..03b79159 100644 --- a/libsrc/core/CMakeLists.txt +++ b/libsrc/core/CMakeLists.txt @@ -28,8 +28,9 @@ install(TARGETS ngcore DESTINATION ${NG_INSTALL_DIR} COMPONENT netgen) if(USE_PYTHON) target_compile_definitions(ngcore PUBLIC NETGEN_PYTHON) - target_include_directories(ngcore PUBLIC ${PYTHON_INCLUDE_DIRS}) - target_link_libraries(ngcore PUBLIC ${PYTHON_LIBRARIES}) + if(DYNAMIC_LINK_PYTHON) + target_include_directories(ngcore PUBLIC ${PYTHON_INCLUDE_DIRS}) + endif(DYNAMIC_LINK_PYTHON) endif(USE_PYTHON) install(FILES ngcore.hpp archive.hpp type_traits.hpp version.hpp ngcore_api.hpp logging.hpp @@ -42,7 +43,9 @@ endif(ENABLE_CPP_CORE_GUIDELINES_CHECK) if(USE_PYTHON) pybind11_add_module(pyngcore SHARED python_ngcore.cpp) - target_link_libraries(pyngcore PUBLIC ngcore ${PYTHON_LIBRARIES}) + if(DYNAMIC_LINK_PYTHON) + target_link_libraries(pyngcore PUBLIC ngcore ${PYTHON_LIBRARIES}) + endif(DYNAMIC_LINK_PYTHON) set_target_properties(pyngcore PROPERTIES INSTALL_RPATH "${NG_RPATH_TOKEN}/${NETGEN_PYTHON_RPATH}") install(TARGETS pyngcore DESTINATION ${NG_INSTALL_DIR_PYTHON} COMPONENT netgen) endif(USE_PYTHON) diff --git a/libsrc/csg/CMakeLists.txt b/libsrc/csg/CMakeLists.txt index eaf7dffc..ab42006a 100644 --- a/libsrc/csg/CMakeLists.txt +++ b/libsrc/csg/CMakeLists.txt @@ -11,7 +11,10 @@ if(APPLE) set_target_properties( csg PROPERTIES SUFFIX ".so") endif(APPLE) -target_link_libraries(csg PUBLIC mesh ${PYTHON_LIBRARIES}) +target_link_libraries(csg PUBLIC mesh) + if(DYNAMIC_LINK_PYTHON) + target_link_libraries(csg PUBLIC ${PYTHON_LIBRARIES}) + endif(DYNAMIC_LINK_PYTHON) install( TARGETS csg ${NG_INSTALL_DIR}) target_link_libraries(csg PUBLIC ngcore) diff --git a/libsrc/geom2d/CMakeLists.txt b/libsrc/geom2d/CMakeLists.txt index 43c619a0..58297e69 100644 --- a/libsrc/geom2d/CMakeLists.txt +++ b/libsrc/geom2d/CMakeLists.txt @@ -4,7 +4,10 @@ if(APPLE) set_target_properties( geom2d PROPERTIES SUFFIX ".so") endif(APPLE) -target_link_libraries(geom2d mesh ${PYTHON_LIBRARIES}) +target_link_libraries(geom2d mesh) +if(DYNAMIC_LINK_PYTHON) + target_link_libraries(geom2d ${PYTHON_LIBRARIES}) +endif(DYNAMIC_LINK_PYTHON) install( TARGETS geom2d ${NG_INSTALL_DIR}) target_link_libraries(geom2d ngcore) diff --git a/libsrc/meshing/CMakeLists.txt b/libsrc/meshing/CMakeLists.txt index 12fe70ae..c1e2b889 100644 --- a/libsrc/meshing/CMakeLists.txt +++ b/libsrc/meshing/CMakeLists.txt @@ -22,8 +22,11 @@ if(APPLE) endif(APPLE) target_link_libraries( mesh PUBLIC ngcore PRIVATE gprim la gen ) +target_link_libraries( mesh PUBLIC ${ZLIB_LIBRARIES} ${MPI_CXX_LIBRARIES} ${METIS_LIBRARY}) +if(DYNAMIC_LINK_PYTHON) + target_link_libraries(mesh PUBLIC ${PYTHON_LIBRARIES}) +endif(DYNAMIC_LINK_PYTHON) -target_link_libraries( mesh PUBLIC ${ZLIB_LIBRARIES} ${MPI_CXX_LIBRARIES} ${PYTHON_LIBRARIES} ${METIS_LIBRARY}) install( TARGETS mesh ${NG_INSTALL_DIR}) install(FILES diff --git a/libsrc/occ/CMakeLists.txt b/libsrc/occ/CMakeLists.txt index 1f093ad8..55c1bdb9 100644 --- a/libsrc/occ/CMakeLists.txt +++ b/libsrc/occ/CMakeLists.txt @@ -11,7 +11,10 @@ endif(USE_GUI) target_link_libraries(occ PUBLIC ngcore) if(NOT WIN32) - target_link_libraries( occ PUBLIC ${OCC_LIBRARIES} ${PYTHON_LIBRARIES}) + target_link_libraries( occ PUBLIC ${OCC_LIBRARIES}) + if(DYNAMIC_LINK_PYTHON) + target_link_libraries(occ PUBLIC ${PYTHON_LIBRARIES}) + endif(DYNAMIC_LINK_PYTHON) install( TARGETS occ ${NG_INSTALL_DIR}) if (USE_GUI) target_link_libraries( occvis PUBLIC occ ) diff --git a/libsrc/stlgeom/CMakeLists.txt b/libsrc/stlgeom/CMakeLists.txt index 8925c828..b615bfbd 100644 --- a/libsrc/stlgeom/CMakeLists.txt +++ b/libsrc/stlgeom/CMakeLists.txt @@ -4,7 +4,10 @@ add_library(stl ${NG_LIB_TYPE} ) if(NOT WIN32) - target_link_libraries( stl mesh ${PYTHON_LIBRARIES}) + target_link_libraries( stl mesh ) + if(DYNAMIC_LINK_PYTHON) + target_link_libraries( stl ${PYTHON_LIBRARIES}) + endif(DYNAMIC_LINK_PYTHON) install( TARGETS stl ${NG_INSTALL_DIR}) endif(NOT WIN32) diff --git a/libsrc/visualization/CMakeLists.txt b/libsrc/visualization/CMakeLists.txt index 4288862c..5584178f 100644 --- a/libsrc/visualization/CMakeLists.txt +++ b/libsrc/visualization/CMakeLists.txt @@ -9,7 +9,10 @@ endif(USE_GUI) add_library(visual ${NG_LIB_TYPE} ${LIB_VISUAL_SOURCES}) -target_link_libraries( visual ngcore ${PYTHON_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ) +target_link_libraries( visual ngcore ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ) +if(DYNAMIC_LINK_PYTHON) + target_link_libraries( visual ${PYTHON_LIBRARIES}) +endif(DYNAMIC_LINK_PYTHON) install( TARGETS visual ${NG_INSTALL_DIR}) install(FILES diff --git a/ng/CMakeLists.txt b/ng/CMakeLists.txt index 2705aecf..41c98040 100644 --- a/ng/CMakeLists.txt +++ b/ng/CMakeLists.txt @@ -51,7 +51,10 @@ endif(USE_GUI) if(USE_PYTHON) add_library(ngpy SHARED netgenpy.cpp) - target_link_libraries( ngpy PUBLIC nglib PRIVATE ${PYTHON_LIBRARIES}) + target_link_libraries( ngpy PUBLIC nglib) + if(DYNAMIC_LINK_PYTHON) + target_link_libraries(ngpy PRIVATE ${PYTHON_LIBRARIES}) + endif(DYNAMIC_LINK_PYTHON) if(APPLE) set_target_properties( ngpy PROPERTIES SUFFIX ".so") elseif(WIN32) diff --git a/nglib/CMakeLists.txt b/nglib/CMakeLists.txt index 7253230a..116fc226 100644 --- a/nglib/CMakeLists.txt +++ b/nglib/CMakeLists.txt @@ -38,9 +38,9 @@ if(USE_OCC AND NOT WIN32) target_link_libraries(nglib PUBLIC occ) endif(USE_OCC AND NOT WIN32) -if(USE_PYTHON) +if(USE_PYTHON AND DYNAMIC_LINK_PYTHON) target_link_libraries(nglib PRIVATE ${PYTHON_LIBRARIES}) -endif(USE_PYTHON) +endif(USE_PYTHON AND DYNAMIC_LINK_PYTHON) install(TARGETS nglib ${NG_INSTALL_DIR}) install(FILES nglib.h DESTINATION ${NG_INSTALL_DIR_INCLUDE} COMPONENT netgen_devel)