-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
85 lines (69 loc) · 3.32 KB
/
CMakeLists.txt
File metadata and controls
85 lines (69 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
project(Plugin VERSION 1.0)
set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/config.h.in
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/initModule.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/PythonEnvironment.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/SceneLoaderPY3.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/SpellingSuggestionHelper.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/DataCache.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/DataHelper.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/LinkPath.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/PythonFactory.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Prefab.h
)
set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/initModule.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/PythonEnvironment.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/SceneLoaderPY3.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/DataCache.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/DataHelper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/LinkPath.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/PythonFactory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Prefab.cpp
)
find_package(pybind11 CONFIG REQUIRED)
sofa_find_package(Sofa.Simulation.Graph REQUIRED)
add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
add_library(SofaPython3::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_compile_definitions(${PROJECT_NAME} PRIVATE "-DSOFA_BUILD_SOFAPYTHON3")
target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Simulation.Graph)
# The public linking with pybind lead to have a link with libpython which
# propagates in the python module .so. On macOS, this extra link with libpython
# lead to segv when importing the python module in versions of python that don't
# have a dynamic link with libpython (such as the one provided by conda which is linked
# statically), but works fine with versions that have such link.
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
target_link_libraries(${PROJECT_NAME} PRIVATE pybind11::pybind11 pybind11::python_link_helper)
else()
target_link_libraries(${PROJECT_NAME} PUBLIC pybind11::embed)
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME SofaPython3)
if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
# Sized deallocaion is not enabled by default under clang after c++14
target_compile_options(${PROJECT_NAME} PUBLIC "-fsized-deallocation")
endif ()
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
# dlopen() is used on Linux for a workaround (see PythonEnvironnement.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE dl)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL Windows )
# https://github.com/boostorg/system/issues/32
target_compile_definitions(${PROJECT_NAME} PUBLIC "-DHAVE_SNPRINTF")
endif()
set_target_properties(
${PROJECT_NAME}
PROPERTIES
CXX_VISIBILITY_PRESET "hidden"
CUDA_VISIBILITY_PRESET "hidden"
)
target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>")
sofa_create_component_in_package_with_targets(
COMPONENT_NAME ${PROJECT_NAME}
COMPONENT_VERSION ${SofaPython3_VERSION}
PACKAGE_NAME SofaPython3
TARGETS ${PROJECT_NAME} AUTO_SET_TARGET_PROPERTIES
INCLUDE_SOURCE_DIR "src"
INCLUDE_INSTALL_DIR "."
OPTIMIZE_BUILD_DIR FALSE
RELOCATABLE "../../plugins"
)