diff --git a/CMakeLists.txt b/CMakeLists.txt index bf7980e30..e9b528ea1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,20 +28,22 @@ option( ENABLE_CPP_CORE_GUIDELINES_CHECK "Enable cpp core guideline checks on ng 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) set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_modules") -if(APPLE) +if(APPLE AND NOT BUILD_WITH_CONDA) set(INSTALL_DIR_DEFAULT /Applications/Netgen.app) -else(APPLE) +else(APPLE AND NOT BUILD_WITH_CONDA) if(WIN32) set(INSTALL_DIR_DEFAULT "C:/netgen") else(WIN32) set(INSTALL_DIR_DEFAULT /opt/netgen) endif(WIN32) -endif(APPLE) +endif(APPLE AND NOT BUILD_WITH_CONDA) if(INSTALL_DIR) message(WARNING "INSTALL_DIR is deprecated, use CMAKE_INSTALL_PREFIX instead") @@ -123,13 +125,18 @@ if(USE_PYTHON) find_package(PythonInterp 3 REQUIRED) find_package(PythonLibs 3 REQUIRED) - execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1,0,''))" OUTPUT_VARIABLE PYTHON_PACKAGES_INSTALL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) + if(BUILD_WITH_CONDA) + execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" OUTPUT_VARIABLE PYTHON_PACKAGES_INSTALL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) + else(BUILD_WITH_CONDA) + execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1,0,''))" OUTPUT_VARIABLE PYTHON_PACKAGES_INSTALL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) + endif(BUILD_WITH_CONDA) + file(TO_CMAKE_PATH ${PYTHON_PACKAGES_INSTALL_DIR} PYTHON_PACKAGES_INSTALL_DIR) endif(USE_PYTHON) set(NG_INSTALL_SUFFIX netgen CACHE STRING "Suffix appended to install directories (project name)") -if(APPLE) +if(APPLE AND NOT BUILD_WITH_CONDA) set(NG_INSTALL_DIR_BIN_DEFAULT Contents/MacOS) set(NG_INSTALL_DIR_LIB_DEFAULT Contents/MacOS) set(NG_INSTALL_DIR_CMAKE_DEFAULT Contents/Resources/CMake) @@ -138,7 +145,7 @@ if(APPLE) set(NG_INSTALL_DIR_INCLUDE_DEFAULT Contents/Resources/include) set(NG_RPATH_TOKEN "@loader_path") -else(APPLE) +else(APPLE AND NOT BUILD_WITH_CONDA) set(NG_INSTALL_DIR_BIN_DEFAULT bin) set(NG_INSTALL_DIR_LIB_DEFAULT lib) if(WIN32) @@ -151,7 +158,7 @@ else(APPLE) set(NG_INSTALL_DIR_INCLUDE_DEFAULT include) set(NG_RPATH_TOKEN "\$ORIGIN") -endif(APPLE) +endif(APPLE AND NOT BUILD_WITH_CONDA) set(NG_INSTALL_DIR_PYTHON ${NG_INSTALL_DIR_PYTHON_DEFAULT} CACHE STRING "Install directory for Python files") set(NG_INSTALL_DIR_BIN ${NG_INSTALL_DIR_BIN_DEFAULT} CACHE STRING "Install directory for executables") @@ -267,21 +274,26 @@ endif (USE_GUI) ####################################################################### if (USE_PYTHON) - add_subdirectory(external_dependencies/pybind11) add_definitions(-DNG_PYTHON) - find_path(PYBIND_INCLUDE_DIR pybind11/pybind11.h HINTS ${PYTHON_INCLUDE_DIR}) - if( PYBIND_INCLUDE_DIR ) - message(STATUS "Found Pybind11: ${PYBIND_INCLUDE_DIR}") - else( PYBIND_INCLUDE_DIR ) - message(FATAL_ERROR "Could NOT find pybind11!") - endif( PYBIND_INCLUDE_DIR ) + if(BUILD_WITH_CONDA) + find_package(pybind11 REQUIRED) + set(PYBIND_INCLUDE_DIR PYBIND11_INCLUDE_DIR) + else(BUILD_WITH_CONDA) + add_subdirectory(external_dependencies/pybind11) + find_path(PYBIND_INCLUDE_DIR pybind11/pybind11.h HINTS ${PYTHON_INCLUDE_DIR}) + if( PYBIND_INCLUDE_DIR ) + message(STATUS "Found Pybind11: ${PYBIND_INCLUDE_DIR}") + else( PYBIND_INCLUDE_DIR ) + message(FATAL_ERROR "Could NOT find pybind11!") + endif( PYBIND_INCLUDE_DIR ) + endif(BUILD_WITH_CONDA) include_directories(${PYBIND_INCLUDE_DIR}) include_directories(${PYTHON_INCLUDE_DIRS}) if(NG_INSTALL_PYBIND) - install(DIRECTORY ${PYBIND_INCLUDE_DIR}/pybind11 DESTINATION ${NG_INSTALL_DIR_INCLUDE} COMPONENT netgen_devel) - install(FILES ${PYBIND_INCLUDE_DIR}/../LICENSE DESTINATION ${NG_INSTALL_DIR_INCLUDE}/pybind11 COMPONENT netgen_devel) + install(DIRECTORY ${PYBIND_INCLUDE_DIR}/pybind11 DESTINATION ${NG_INSTALL_DIR_INCLUDE} COMPONENT netgen_devel) + install(FILES ${PYBIND_INCLUDE_DIR}/../LICENSE DESTINATION ${NG_INSTALL_DIR_INCLUDE}/pybind11 COMPONENT netgen_devel) endif(NG_INSTALL_PYBIND) endif (USE_PYTHON) @@ -428,7 +440,7 @@ if(UNIX) endif(temp) endif(UNIX) -if(APPLE) +if(APPLE AND NOT BUILD_WITH_CONDA) # create some auxiliary files set(mac_startup ${CMAKE_CURRENT_BINARY_DIR}/startup.sh) file(WRITE ${mac_startup} "\ @@ -473,7 +485,7 @@ open -a /Applications/Utilities/Terminal.app $Netgen_MACOS/startup.sh install(FILES ${mac_plist} DESTINATION ${NG_INSTALL_DIR_BIN}/../) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/netgen.icns DESTINATION ${NG_INSTALL_DIR_RES}/../ RENAME Netgen.icns) -endif(APPLE) +endif(APPLE AND NOT BUILD_WITH_CONDA) if(NOT APPLE) include(CPack) diff --git a/libsrc/core/CMakeLists.txt b/libsrc/core/CMakeLists.txt index 46a2230b3..03b791598 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 eaf7dffc1..ab42006aa 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 43c619a0e..58297e698 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 12fe70ae4..c1e2b8890 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 1f093ad84..55c1bdb9b 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 8925c828f..b615bfbdb 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 4288862c7..5584178fd 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 2705aecf1..41c980407 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 7253230ab..116fc2264 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)