-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
165 lines (136 loc) · 7.15 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
# This file should be used as a template for creating new projects with Python
# wrapping using the CMake tools
# ##############################################################################
cmake_minimum_required(VERSION 3.9)
project(incopt CXX C)
set(CXX_STANDARD 11)
# ##############################################################################
# * 2. Find GTSAM components so we have access to the GTSAM Cython install path
find_package(GTSAM REQUIRED) # Uses installed package
# Note: Since Jan-2019, GTSAMConfig.cmake defines exported CMake targets that
# automatically do include the include_directories() without the need to call
# include_directories(), just target_link_libraries(NAME gtsam)
# include_directories(${GTSAM_INCLUDE_DIR})
# ##############################################################################
# * 3. Add the local source directory for CMake Ensure that local folder is
# searched before library folders
include_directories(BEFORE "${PROJECT_SOURCE_DIR}")
# ##############################################################################
# * 4. Build static library from common sources. This is a common cmake step
# where we load all the source files and link against the GTSAM library.
file(GLOB KINEMATICSH "cpp/thirdparty/gpmp2/kinematics/*.h")
file(GLOB OBSTACLESH "cpp/thirdparty/gpmp2/obstacle/*.h")
file(GLOB GPSH "cpp/thirdparty/gpmp2/gp/*.h")
file(GLOB PUSHINGCONSTRAINTSH "cpp/pushing/constraints/*.h")
file(GLOB PUSHINGDATAIOSH "cpp/pushing/dataio/*.h")
file(GLOB KINEMATICSCPP "cpp/thirdparty/gpmp2/kinematics/*.cpp")
file(GLOB OBSTACLESCPP "cpp/thirdparty/gpmp2/obstacle/*.cpp")
file(GLOB GPCPP "cpp/thirdparty/gpmp2/gp/*.cpp")
file(GLOB PUSHINGCONSTRAINTCPP "cpp/pushing/constraints/*.cpp")
file(GLOB PUSHINGDATAIOCPP "cpp/pushing/dataio/*.cpp")
add_library(${PROJECT_NAME} SHARED cpp/incopt.h
${PUSHINGCONSTRAINTSH} ${PUSHINGDATAIOSH}
${PUSHINGCONSTRAINTCPP} ${PUSHINGDATAIOCPP}
${KINEMATICSH} ${OBSTACLESH}
${GPSH} ${KINEMATICSCPP}
${OBSTACLESCPP} ${GPCPP})
target_link_libraries(${PROJECT_NAME} gtsam)
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
# ##############################################################################
# * 5. Install library
install(
TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin)
message(" starting setup .. ")
# ##############################################################################
# # Build tests (CMake tracks the dependecy to link with GTSAM through our
# project's static library) gtsamAddTestsGlob("${PROJECT_NAME}"
# "tests/test*.cpp" "" "${PROJECT_NAME}")
# ##############################################################################
# # Build scripts (CMake tracks the dependecy to link with GTSAM through our
# project's static library) gtsamAddExamplesGlob("*.cpp" "" "${PROJECT_NAME}")
# ##############################################################################
# * 6. Find the gtwrap package (either installed via GTSAM or as a standalone
# package) The cmake code for wrapping is included automatically.
find_package(gtwrap REQUIRED)
# ##############################################################################
# * 7. Set the python version Load the default Python version strings and
# variables.
set(WRAP_PYTHON_VERSION
"Default"
CACHE STRING "The Python version to use for wrapping")
gtwrap_get_python_version(${WRAP_PYTHON_VERSION})
# ##############################################################################
# * 8. Configure all the files for the Python module. Set the version string,
# needed for generating setup.py
set(GTSAM_VERSION_STRING 0.0.1)
# We use this as a convenience variable. It points to `python/` in this case.
set(GTSAM_MODULE_PATH ${PROJECT_BINARY_DIR}/python)
# Copy over the setup.py.in file. This will become `python/setup.py`.
configure_file(${PROJECT_SOURCE_DIR}/wrapper/setup.py.in
${GTSAM_MODULE_PATH}/setup.py)
# Copy over the __init__.py file. This is now
configure_file(${PROJECT_SOURCE_DIR}/wrapper/__init__.py.in
${GTSAM_MODULE_PATH}/${PROJECT_NAME}/__init__.py)
# Copy over the pybind .tpl file. This is now `build/incopt.tpl`.
configure_file(${PROJECT_SOURCE_DIR}/wrapper/pybind_wrapper.tpl.example
${PROJECT_BINARY_DIR}/${PROJECT_NAME}.tpl)
# Copy over C++ headers to use for wrapping
file(COPY "${PROJECT_SOURCE_DIR}/wrapper/preamble.h"
DESTINATION "${PROJECT_BINARY_DIR}/python")
file(COPY "${PROJECT_SOURCE_DIR}/wrapper/specializations.h"
DESTINATION "${PROJECT_BINARY_DIR}/python")
# Copy all the tests files to module folder.
#file(COPY "${PROJECT_SOURCE_DIR}/python/tests"
# DESTINATION "${GTSAM_MODULE_PATH}")
# We print out our configuration for an easy visual check
message("========== Configuration Options ==========")
message(STATUS "Project: ${PROJECT_NAME}")
message(STATUS "Python Version: ${WRAP_PYTHON_VERSION}")
message(STATUS "Python Module Path: ${GTSAM_MODULE_PATH}")
message("===========================================")
# ##############################################################################
# * 9. Build Pybind wrapper This is where the crux of the wrapping happens.
# Ignoring the non-concrete types (type aliases and typedefs). We don't have any
# in our current project so this is left as empty.
set(ignore "")
message("${PROJECT_BINARY_DIR}")
# This is the main function that generates the cpp file which Pybind11 will use.
message("${PROJECT_NAME}.i")
pybind_wrap(
${PROJECT_NAME}_py # target
${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.i # interface header file
# (incopt.i in the root
# directory)
"${PROJECT_NAME}.cpp" # the generated cpp (incopt.cpp)
"${PROJECT_NAME}" # module_name (incopt)
"${PROJECT_NAME}" # top namespace in the cpp file (incopt)
"${ignore}" # ignore classes
${PROJECT_BINARY_DIR}/${PROJECT_NAME}.tpl
${PROJECT_NAME} # libs
"${PROJECT_NAME}" # dependencies, we need the library built in step 6 as the
# minimum.
ON # we are using boost::shared_ptr not std
)
message("${GTSAM_MODULE_PATH}/${PROJECT_NAME}")
# We define where we wish to save the wrapped .so file once we run `make`. It
# will be stored in `build/gtsam_example/incopt` to conform to standard
# python module structure.
set_target_properties(
${PROJECT_NAME}_py
PROPERTIES OUTPUT_NAME "${PROJECT_NAME}"
LIBRARY_OUTPUT_DIRECTORY "${GTSAM_MODULE_PATH}/${PROJECT_NAME}"
DEBUG_POSTFIX "" # Otherwise you will have a wrong name
RELWITHDEBINFO_POSTFIX "" # Otherwise you will have a wrong name
)
# ##############################################################################
# * 10. Python install command Finally we add a custom make command which we can
# invoke to install the generated module. Simply type `make python-install`
# and we can now access the wrapped module as an installed library.
add_custom_target(
python-install
COMMAND ${PYTHON_EXECUTABLE} ${GTSAM_MODULE_PATH}/setup.py install
DEPENDS ${PROJECT_NAME}_py
WORKING_DIRECTORY ${GTSAM_MODULE_PATH})