-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathCMakeLists.txt
190 lines (174 loc) · 5.24 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
182
183
184
185
186
187
188
189
190
message(STATUS "Building pybind11 interfaces")
set(BINDINGS_MODULE_NAME "math${PROJECT_VERSION_MAJOR}")
# Split from main extension and converted to pybind11
pybind11_add_module(${BINDINGS_MODULE_NAME} MODULE
src/_gz_math_pybind11.cc
src/Angle.cc
src/AxisAlignedBox.cc
src/Capsule.cc
src/Color.cc
src/CoordinateVector3.cc
src/DiffDriveOdometry.cc
src/Ellipsoid.cc
src/Filter.cc
src/Frustum.cc
src/GaussMarkovProcess.cc
src/Helpers.cc
src/Interval.cc
src/Kmeans.cc
src/Line2.cc
src/Line3.cc
src/MassMatrix3.cc
src/Material.cc
src/Matrix3.cc
src/Matrix4.cc
src/Matrix6.cc
src/MecanumDriveOdometry.cc
src/MovingWindowFilter.cc
src/PID.cc
src/Polynomial3.cc
src/Pose3.cc
src/Quaternion.cc
src/Rand.cc
src/Region3.cc
src/RollingMean.cc
src/RotationSpline.cc
src/SemanticVersion.cc
src/SignalStats.cc
src/SphericalCoordinates.cc
src/Spline.cc
src/StopWatch.cc
src/Temperature.cc
src/Triangle.cc
src/Triangle3.cc
src/Vector2.cc
src/Vector3.cc
src/Vector4.cc
src/Vector3Stats.cc
)
target_link_libraries(${BINDINGS_MODULE_NAME} PRIVATE
${PROJECT_LIBRARY_TARGET_NAME}
)
target_compile_definitions(${BINDINGS_MODULE_NAME} PRIVATE
BINDINGS_MODULE_NAME=${BINDINGS_MODULE_NAME})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# Workaround for Clang and pybind11 on Focal
# https://github.com/pybind/pybind11/issues/1604
# Resolved by newer versions of pybind11
if(${pybind11_VERSION} VERSION_LESS "2.4.4")
target_compile_options(${BINDINGS_MODULE_NAME} PRIVATE -fsized-deallocation)
endif()
# Suppress warnings that clang misidentifies:
# https://github.com/pybind/pybind11/issues/1893
target_compile_options(${BINDINGS_MODULE_NAME} PRIVATE -Wno-self-assign-overloaded)
endif()
if(USE_SYSTEM_PATHS_FOR_PYTHON_INSTALLATION)
if(NOT Python3_SITEARCH)
# Get install variable from Python3 module
find_package(Python3 COMPONENTS Interpreter)
endif()
if(USE_DIST_PACKAGES_FOR_PYTHON)
string(REPLACE "site-packages" "dist-packages" GZ_PYTHON_INSTALL_PATH ${Python3_SITEARCH})
else()
# custom cmake command is returning dist-packages
string(REPLACE "dist-packages" "site-packages" GZ_PYTHON_INSTALL_PATH ${Python3_SITEARCH})
endif()
else()
# If not a system installation, respect local paths
set(GZ_PYTHON_INSTALL_PATH ${GZ_LIB_INSTALL_DIR}/python)
endif()
set(GZ_PYTHON_INSTALL_PATH "${GZ_PYTHON_INSTALL_PATH}/gz")
# Set the build location and install location for a CPython extension
function(configure_build_install_location _library_name)
# Install into test folder in build space for unit tests to import
set_target_properties(${_library_name} PROPERTIES
# Use generator expression to avoid prepending a build type specific directory on Windows
LIBRARY_OUTPUT_DIRECTORY $<1:${CMAKE_CURRENT_BINARY_DIR}/test/gz>
RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_CURRENT_BINARY_DIR}/test/gz>)
# Touch an init file to mark this directory as a usable python module
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test/gz/)
file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/test/gz/__init__.py)
# Install library for actual use
install(TARGETS ${_library_name}
DESTINATION "${GZ_PYTHON_INSTALL_PATH}/"
)
endfunction()
configure_build_install_location(${BINDINGS_MODULE_NAME})
if (BUILD_TESTING)
# Add the Python tests
set(python_tests
Angle_TEST
AxisAlignedBox_TEST
Box_TEST
Capsule_TEST
Color_TEST
Cone_TEST
CoordinateVector3_TEST
Cylinder_TEST
DiffDriveOdometry_TEST
Ellipsoid_TEST
Filter_TEST
Frustum_TEST
GaussMarkovProcess_TEST
Helpers_TEST
Inertial_TEST
Interval_TEST
Kmeans_TEST
Line2_TEST
Line3_TEST
MassMatrix3_TEST
Material_TEST
Matrix3_TEST
Matrix4_TEST
Matrix6_TEST
MecanumDriveOdometry_TEST
MovingWindowFilter_TEST
OrientedBox_TEST
PID_TEST
Plane_TEST
Polynomial3_TEST
Pose3_TEST
Quaternion_TEST
Rand_TEST
Region3_TEST
RollingMean_TEST
RotationSpline_TEST
SemanticVersion_TEST
SignalStats_TEST
Sphere_TEST
SphericalCoordinates_TEST
Spline_TEST
StopWatch_TEST
Temperature_TEST
Triangle3_TEST
Triangle_TEST
Vector2_TEST
Vector3_TEST
Vector3Stats_TEST
Vector4_TEST
)
execute_process(COMMAND "${Python3_EXECUTABLE}" -m pytest --version
OUTPUT_VARIABLE PYTEST_output
ERROR_VARIABLE PYTEST_error
RESULT_VARIABLE PYTEST_result)
if(${PYTEST_result} EQUAL 0)
set(pytest_FOUND TRUE)
else()
message("")
message(WARNING "Pytest package not available: ${PYTEST_error}")
endif()
foreach (test ${python_tests})
if (pytest_FOUND)
add_test(NAME ${test}.py COMMAND
"${Python3_EXECUTABLE}" -m pytest "${CMAKE_SOURCE_DIR}/src/python_pybind11/test/${test}.py" --junitxml "${CMAKE_BINARY_DIR}/test_results/${test}.xml")
else()
add_test(NAME ${test}.py COMMAND
"${Python3_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/src/python_pybind11/test/${test}.py")
endif()
set(_env_vars)
list(APPEND _env_vars "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/test")
list(APPEND _env_vars "LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/test:$ENV{LD_LIBRARY_PATH}")
set_tests_properties(${test}.py PROPERTIES
ENVIRONMENT "${_env_vars}")
endforeach()
endif()