Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conda new toolchain #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the message here is maybe misleading. I guess it should be:
"set this to OFF to not link against python DSO"


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")
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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} "\
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions libsrc/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion libsrc/csg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion libsrc/geom2d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion libsrc/meshing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion libsrc/occ/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
5 changes: 4 additions & 1 deletion libsrc/stlgeom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion libsrc/visualization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion ng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions nglib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)