-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
181 lines (163 loc) · 4.96 KB
/
CMakeLists.txt
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
cmake_minimum_required(VERSION 2.8)
project(dartpy)
if(NOT DARTPY_PYTHON_VERSION)
set(DARTPY_PYTHON_VERSION 3.4 CACHE STRING "Choose the target Python version (e.g., 3.4, 2.7)" FORCE)
endif()
# TODO: This should be set by DART.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-deprecated -Wno-deprecated-declarations")
find_package(PythonInterp ${DARTPY_PYTHON_VERSION} REQUIRED)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
"from distutils.sysconfig import get_python_lib;\
print(get_python_lib(plat_specific=True, prefix=''))"
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Find boost with python components. The name of python component varies
# depending on the platform, boost version, and python version.
if(APPLE)
find_package(Boost REQUIRED
COMPONENTS
python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR} thread
)
else() # LINUX assumed
if(${PYTHON_VERSION_MAJOR} EQUAL 3)
find_package(Boost
COMPONENTS
python-py${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR} thread
)
if(NOT Boost_FOUND)
find_package(Boost REQUIRED COMPONENTS python3 thread)
endif()
else() # Python 2 assumed
find_package(Boost REQUIRED COMPONENTS python thread)
endif()
endif()
find_package(DART 6.6.1 REQUIRED
COMPONENTS
collision-bullet
# collision-ode
optimizer-nlopt
planning
utils-urdf
gui-osg
CONFIG
)
# Check if DART is built with octomap so that it supports VoxelGridShape
include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_DEFINITIONS "")
set(CMAKE_REQUIRED_FLAGS "-std=c++11")
set(CMAKE_REQUIRED_INCLUDES ${DART_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${DART_LIBRARIES})
check_cxx_source_compiles(
"
#include <dart/dart.hpp>
int main()
{
auto voxel = new dart::dynamics::VoxelGridShape();
delete voxel;
return 0;
}
"
DART_HAS_VOXELGRIDSHAPE
)
find_package(PythonLibs ${DARTPY_PYTHON_VERSION} REQUIRED)
find_package(chimera QUIET)
include_directories(SYSTEM
${Boost_INCLUDE_DIRS}
${DART_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
)
# Check whether the CXX compiler and boost::python support get_pointer for
# std::shared_ptr<T> references.
include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES
${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
)
set(CMAKE_REQUIRED_LIBRARIES
${Boost_LIBRARIES}
${PYTHON_LIBRARIES}
)
check_cxx_source_compiles(
"
#include <memory>
#include <boost/python.hpp>
int main() { std::shared_ptr<int> ptr; int *p = boost::get_pointer(ptr); }
"
DARTPY_HAS_STD_SHARED_GET_POINTER
)
unset(CMAKE_REQUIRED_INCLUDES)
unset(CMAKE_REQUIRED_LIBRARIES)
# Generate a header file for the DARTPY_HAS_STD_SHARED_GET_POINTER flag.
configure_file("cmake/config.h.in"
"include/dartpy/config.h"
)
include_directories(
"include"
"${CMAKE_CURRENT_BINARY_DIR}/include"
)
# If chimera is available on this system, create a target to build bindings.
if(DART_HAS_VOXELGRIDSHAPE)
set(CHIMERA_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/chimera/chimera.yml")
else()
set(CHIMERA_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/chimera/chimera_without_voxel.yml")
endif()
if(chimera_FOUND)
add_chimera_binding(TARGET "${PROJECT_NAME}_CHIMERA"
MODULE "${PROJECT_NAME}"
CONFIGURATION "${CHIMERA_CONFIG}"
SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/chimera/chimera.cpp"
DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/src/generated"
DEBUG EXCLUDE_FROM_ALL
)
target_link_libraries("${PROJECT_NAME}_CHIMERA"
${Boost_LIBRARIES}
${DART_LIBRARIES}
${PYTHON_LIBRARIES}
)
add_custom_target(binding DEPENDS "${PROJECT_NAME}_CHIMERA_REBUILD")
else()
add_custom_target(binding
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --red "ERROR: Cannot generate bindings without \\'chimera\\' installed."
COMMAND false
)
endif()
# Create a target to build generated bindings.
set(SOURCES_TXT "${CMAKE_CURRENT_SOURCE_DIR}/src/generated/sources.txt")
if(EXISTS "${SOURCES_TXT}")
file(STRINGS "${SOURCES_TXT}" SOURCES_GENERATED_RELATIVE NO_HEX_CONVERSION)
set(SOURCES_GENERATED)
foreach(relative_path ${SOURCES_GENERATED_RELATIVE})
list(APPEND SOURCES_GENERATED "${CMAKE_CURRENT_SOURCE_DIR}/src/generated/${relative_path}")
endforeach()
add_library("${PROJECT_NAME}" MODULE
${SOURCES_GENERATED}
src/BodyNode.cpp
src/Skeleton.cpp
src/skel_parser.cpp
src/template_registry.cpp
)
target_link_libraries("${PROJECT_NAME}"
${Boost_LIBRARIES}
${DART_LIBRARIES}
${PYTHON_LIBRARIES}
)
set_target_properties("${PROJECT_NAME}" PROPERTIES
PREFIX ""
SUFFIX ".so" # python uses '.so' extension even on macOS
)
if(CMAKE_COMPILER_IS_GNUCXX)
target_compile_options("${PROJECT_NAME}"
PRIVATE -fabi-version=6
)
endif()
install(TARGETS "${PROJECT_NAME}"
LIBRARY DESTINATION "${PYTHON_SITE_PACKAGES}"
)
else()
add_custom_target(${PROJECT_NAME} ALL
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --red "ERROR: Generate bindings using \\'make binding\\' before attempting to build."
COMMAND false
)
endif()
add_subdirectory(tests)