[cmake] Don't link python libraries in unix-conda environment

Conda links python libs statically to python executable
This commit is contained in:
Matthias Hochsteger 2019-11-26 19:26:18 +00:00 committed by Joachim Schöberl
parent 2afefa2e4d
commit f3d9d3ad67
12 changed files with 70 additions and 27 deletions

View File

@ -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_STUB_FILES "Build stub files for better autocompletion" ON)
option( BUILD_FOR_CONDA "Link python libraries only to executables" OFF)
option( USE_SUPERBUILD "use ccache" ON)
@ -227,7 +228,7 @@ if(WIN32)
add_definitions(-DMSVC_EXPRESS -D_CRT_SECURE_NO_WARNINGS -DHAVE_STRUCT_TIMESPEC)
# build convenience (aka object) libraries in windows)
set(NG_LIB_TYPE OBJECT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /wd4244 /wd4800")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
else(WIN32)
# build shared libraries
set(NG_LIB_TYPE SHARED)
@ -270,9 +271,14 @@ if (USE_GUI)
endif (USE_GUI)
#######################################################################
if(WIN32)
add_library(netgen_python INTERFACE IMPORTED)
else()
add_library(netgen_python INTERFACE)
endif()
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}")
@ -280,8 +286,11 @@ if (USE_PYTHON)
message(FATAL_ERROR "Could NOT find pybind11!")
endif( PYBIND_INCLUDE_DIR )
include_directories(${PYBIND_INCLUDE_DIR})
include_directories(${PYTHON_INCLUDE_DIRS})
target_include_directories(netgen_python INTERFACE ${PYBIND_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS})
if(NOT ${BUILD_FOR_CONDA})
# Don't link python libraries in conda environments
target_link_libraries(netgen_python INTERFACE ${PYTHON_LIBRARIES})
endif()
if(NG_INSTALL_PYBIND)
install(DIRECTORY ${PYBIND_INCLUDE_DIR}/pybind11 DESTINATION ${NG_INSTALL_DIR_INCLUDE} COMPONENT netgen_devel)

View File

@ -14,6 +14,7 @@ get_filename_component(NETGEN_RESOURCE_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_RESOURCE
set(NETGEN_SOURCE_DIR "@PROJECT_SOURCE_DIR@")
set(NETGEN_BUILD_FOR_CONDA "@BUILD_FOR_CONDA@")
set(NETGEN_CHECK_RANGE "@CHECK_RANGE@")
set(NETGEN_INCLUDE_DIRS "${NETGEN_INCLUDE_DIR}/include;${NETGEN_INCLUDE_DIR}")
set(NETGEN_CMAKE_THREAD_LIBS_INIT "@CMAKE_THREAD_LIBS_INIT@")

View File

@ -151,6 +151,7 @@ set_vars( NETGEN_CMAKE_ARGS
DEBUG_LOG
CHECK_RANGE
BUILD_STUB_FILES
BUILD_FOR_CONDA
)
# propagate all variables set on the command line using cmake -DFOO=BAR

View File

@ -20,6 +20,7 @@ endif()
if(USE_PYTHON)
target_sources(ngcore PRIVATE python_ngcore.cpp)
target_compile_definitions(ngcore PUBLIC NETGEN_PYTHON NG_PYTHON)
endif(USE_PYTHON)
target_compile_definitions(ngcore PRIVATE NGCORE_EXPORTS)
@ -52,12 +53,7 @@ endif(USE_SPDLOG)
install(TARGETS ngcore DESTINATION ${NG_INSTALL_DIR} COMPONENT netgen)
if(USE_PYTHON)
target_compile_definitions(ngcore PUBLIC NETGEN_PYTHON)
target_include_directories(ngcore PRIVATE ${PYTHON_INCLUDE_DIRS})
target_link_libraries(ngcore PRIVATE ${PYTHON_LIBRARIES})
endif(USE_PYTHON)
target_link_libraries(ngcore PUBLIC netgen_mpi PRIVATE ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(ngcore PUBLIC netgen_mpi PRIVATE netgen_python ${CMAKE_THREAD_LIBS_INIT})
install(FILES ngcore.hpp archive.hpp type_traits.hpp version.hpp ngcore_api.hpp logging.hpp
exception.hpp symboltable.hpp paje_trace.hpp utils.hpp profiler.hpp mpi_wrapper.hpp
@ -71,7 +67,7 @@ endif(ENABLE_CPP_CORE_GUIDELINES_CHECK)
if(USE_PYTHON)
pybind11_add_module(pyngcore SHARED python_ngcore_export.cpp)
target_link_libraries(pyngcore PUBLIC ngcore ${PYTHON_LIBRARIES})
target_link_libraries(pyngcore PUBLIC ngcore netgen_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)

View File

@ -1,6 +1,36 @@
#ifndef NETGEN_CORE_NGCORE_API_HPP
#define NETGEN_CORE_NGCORE_API_HPP
#ifdef WIN32
// This function or variable may be unsafe. Consider using _ftime64_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
#pragma warning(disable:4244)
#pragma warning(disable:4996)
// multiple inheritance via dominance
#pragma warning(disable:4250)
// needs to have dll-interface to be used by clients of class
#pragma warning(disable:4251)
// size_t to int conversion:
#pragma warning(disable:4267)
// non dll-interface class 'std::exception' used as base for dll-interface class
#pragma warning(disable:4275)
// C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#pragma warning(disable:4290)
// no suitable definition provided for explicit template instantiation request
#pragma warning(disable:4661)
// bool-int conversion
#pragma warning(disable:4800)
#endif // WIN32
#ifdef WIN32
#define NGCORE_API_EXPORT __declspec(dllexport)
#define NGCORE_API_IMPORT __declspec(dllimport)

View File

@ -11,7 +11,7 @@ if(APPLE)
set_target_properties( csg PROPERTIES SUFFIX ".so")
endif(APPLE)
target_link_libraries(csg PUBLIC mesh PRIVATE ${PYTHON_LIBRARIES})
target_link_libraries(csg PUBLIC mesh PRIVATE netgen_python)
if(NOT WIN32)
install( TARGETS csg ${NG_INSTALL_DIR})
endif(NOT WIN32)
@ -20,8 +20,9 @@ target_link_libraries(csg PUBLIC ngcore)
if(USE_GUI)
add_library(csgvis ${NG_LIB_TYPE} vscsg.cpp )
target_link_libraries(csgvis PRIVATE netgen_python PUBLIC ngcore)
if(NOT WIN32)
target_link_libraries(csgvis csg visual)
target_link_libraries(csgvis PUBLIC csg visual)
if(APPLE)
set_target_properties( csgvis PROPERTIES SUFFIX ".so")
endif(APPLE)

View File

@ -4,7 +4,7 @@ if(APPLE)
set_target_properties( geom2d PROPERTIES SUFFIX ".so")
endif(APPLE)
target_link_libraries(geom2d PUBLIC ngcore mesh PRIVATE ${PYTHON_LIBRARIES})
target_link_libraries(geom2d PUBLIC ngcore mesh PRIVATE netgen_python)
if(NOT WIN32)
install( TARGETS geom2d ${NG_INSTALL_DIR})
endif(NOT WIN32)

View File

@ -23,7 +23,7 @@ endif(APPLE)
target_link_libraries( mesh PUBLIC ngcore PRIVATE gprim la gen )
target_link_libraries( mesh PRIVATE netgen_metis ${ZLIB_LIBRARIES} ${PYTHON_LIBRARIES} )
target_link_libraries( mesh PRIVATE netgen_metis netgen_python ${ZLIB_LIBRARIES} )
if(NOT WIN32)
install( TARGETS mesh ${NG_INSTALL_DIR})
endif(NOT WIN32)

View File

@ -8,10 +8,10 @@ if(USE_GUI)
add_library(occvis ${NG_LIB_TYPE} vsocc.cpp)
endif(USE_GUI)
target_link_libraries(occ PUBLIC ngcore)
target_link_libraries(occ PUBLIC ngcore PRIVATE netgen_python)
if(NOT WIN32)
target_link_libraries( occ PRIVATE ${OCC_LIBRARIES} ${PYTHON_LIBRARIES})
target_link_libraries( occ PRIVATE ${OCC_LIBRARIES} )
if(USE_OCC AND APPLE)
# Link AppKit in case OCE was built as static libraries
find_library(AppKit AppKit)

View File

@ -4,18 +4,17 @@ add_library(stl ${NG_LIB_TYPE}
)
if(NOT WIN32)
target_link_libraries( stl PUBLIC mesh PRIVATE ${PYTHON_LIBRARIES})
target_link_libraries( stl PUBLIC mesh )
install( TARGETS stl ${NG_INSTALL_DIR})
endif(NOT WIN32)
target_link_libraries( stl PUBLIC ngcore )
target_link_libraries( stl PUBLIC ngcore PRIVATE netgen_python )
if(USE_GUI)
add_library(stlvis ${NG_LIB_TYPE}
vsstl.cpp
)
add_library(stlvis ${NG_LIB_TYPE} vsstl.cpp)
target_link_libraries(stlvis PRIVATE netgen_python PUBLIC ngcore)
if(NOT WIN32)
target_link_libraries( stlvis stl )
target_link_libraries( stlvis PUBLIC stl )
install( TARGETS stlvis ${NG_INSTALL_DIR})
endif(NOT WIN32)
endif(USE_GUI)

View File

@ -9,7 +9,7 @@ endif(USE_GUI)
add_library(visual ${NG_LIB_TYPE} ${LIB_VISUAL_SOURCES})
target_link_libraries( visual PUBLIC ngcore PRIVATE ${PYTHON_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} )
target_link_libraries( visual PUBLIC ngcore PRIVATE netgen_python ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} )
install( TARGETS visual ${NG_INSTALL_DIR})
install(FILES

View File

@ -30,7 +30,7 @@ if(USE_GUI)
target_link_libraries( gui PRIVATE ${TCL_LIBRARY} ${TK_LIBRARY})
endif(NOT APPLE)
target_link_libraries( netgen nglib gui ${MPI_mpi_LIBRARY} ${MPI_CXX_LIBRARIES} ${LIBTOGL} ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_Xmu_LIB} ${X11_X11_LIB} ${OCC_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${PYTHON_LIBRARIES})
target_link_libraries( netgen nglib gui netgen_python ${MPI_mpi_LIBRARY} ${MPI_CXX_LIBRARIES} ${LIBTOGL} ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_Xmu_LIB} ${X11_X11_LIB} ${OCC_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY})
if(NOT WIN32)
target_link_libraries( netgen mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis )
@ -46,13 +46,19 @@ if(USE_GUI)
if(WIN32)
set_target_properties( gui PROPERTIES OUTPUT_NAME libgui )
endif(WIN32)
target_link_libraries( gui PRIVATE ${PYTHON_LIBRARIES})
target_link_libraries( gui PRIVATE netgen_python )
endif(USE_GUI)
if(USE_PYTHON)
if(${BUILD_FOR_CONDA} AND UNIX AND NOT APPLE)
target_link_libraries( netgen -Wl,--no-as-needed ${PYTHON_LIBRARIES})
else()
target_link_libraries( netgen ${PYTHON_LIBRARIES})
endif()
add_library(ngpy SHARED netgenpy.cpp)
target_link_libraries( ngpy PUBLIC nglib PRIVATE ${PYTHON_LIBRARIES})
target_link_libraries( ngpy PUBLIC nglib PRIVATE netgen_python )
if(APPLE)
set_target_properties( ngpy PROPERTIES SUFFIX ".so")
elseif(WIN32)