forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
258 lines (204 loc) · 7.55 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# -*- mode: cmake -*-
# vi: set ft=cmake :
cmake_minimum_required(VERSION 3.5.1)
project(drake)
list(INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules")
include(CTest)
configure_file(CTestCustom.cmake.in CTestCustom.cmake @ONLY)
if(CYGWIN OR NOT UNIX)
message(FATAL_ERROR "Cygwin and non-Unix platforms are NOT supported")
endif()
set(MINIMUM_BAZEL_VERSION 0.14.1)
find_package(Bazel ${MINIMUM_BAZEL_VERSION} MODULE REQUIRED)
get_filename_component(C_COMPILER_REALPATH "${CMAKE_C_COMPILER}" REALPATH)
get_filename_component(C_COMPILER_NAME "${C_COMPILER_REALPATH}" NAME)
get_filename_component(CXX_COMPILER_REALPATH "${CMAKE_CXX_COMPILER}" REALPATH)
get_filename_component(CXX_COMPILER_NAME "${CXX_COMPILER_REALPATH}" NAME)
if(C_COMPILER_NAME STREQUAL ccache OR CXX_COMPILER_NAME STREQUAL ccache)
message(FATAL_ERROR
"Compilation with ccache is NOT supported due to incompatibility with Bazel"
)
endif()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are None Debug Release RelWithDebInfo MinSizeRel"
FORCE
)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
STRINGS None Debug Release RelWithDebInfo MinSizeRel
)
endif()
if(APPLE)
# Ensure that the python2 executable or link is used in preference to the
# python and python2.7 executables or links.
find_program(PYTHON_EXECUTABLE NAMES python2)
endif()
find_package(PythonInterp 2.7 EXACT MODULE REQUIRED)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(BAZEL_COMPILATION_MODE dbg)
else()
set(BAZEL_COMPILATION_MODE opt)
endif()
set(BAZEL_ENV)
if(NOT APPLE)
# Patches applied to the compiler by particular distributions may have broken
# the behavior expected by bazel when identifying the built-in include
# directories, so call a wrapper script that intercepts certain calls and
# fixes the output.
foreach(LANG C CXX)
set(COMPILER ${CMAKE_${LANG}_COMPILER})
configure_file(tools/cc_toolchain/wrapper.sh.in ${LANG}_wrapper.sh @ONLY)
endforeach()
list(APPEND BAZEL_ENV
"CC=${CMAKE_CURRENT_BINARY_DIR}/C_wrapper.sh"
"CXX=${CMAKE_CURRENT_BINARY_DIR}/CXX_wrapper.sh"
)
endif()
get_filename_component(PROJECT_BINARY_DIR_REALPATH
"${PROJECT_BINARY_DIR}" REALPATH
)
get_filename_component(PROJECT_SOURCE_DIR_REALPATH
"${PROJECT_SOURCE_DIR}" REALPATH
)
# Check whether the PROJECT_BINARY_DIR is a subdirectory of the
# PROJECT_SOURCE_DIR.
string(FIND "${PROJECT_BINARY_DIR_REALPATH}/" "${PROJECT_SOURCE_DIR_REALPATH}/"
STRING_FIND_RESULT_VARIABLE
)
if(STRING_FIND_RESULT_VARIABLE EQUAL 0)
# The --output_base cannot be within the WORKSPACE (a subdirectory of
# PROJECT_SOURCE_DIR), so fallback to the using the same parent directory
# that bazel uses by default for its --output_base.
if(APPLE)
set(BAZEL_OUTPUT_BASE "/var/tmp")
else()
set(BAZEL_OUTPUT_BASE "$ENV{HOME}/.cache/bazel")
endif()
else()
set(BAZEL_OUTPUT_BASE "${PROJECT_BINARY_DIR}")
endif()
# Compute the MD5 of the PROJECT_BINARY_DIR rather than the WORKSPACE
# (PROJECT_SOURCE_DIR) to avoid colliding with the directory that bazel uses by
# default.
string(MD5 PROJECT_BINARY_DIR_MD5 "${PROJECT_BINARY_DIR_REALPATH}")
set(BAZEL_OUTPUT_BASE
"${BAZEL_OUTPUT_BASE}/_bazel_$ENV{USER}/${PROJECT_BINARY_DIR_MD5}"
)
configure_file(tools/cc_toolchain/bazel.rc.in bazel.rc @ONLY)
set(BAZEL_STARTUP_ARGS "--bazelrc=${CMAKE_CURRENT_BINARY_DIR}/bazel.rc")
set(BAZEL_ARGS)
if(CMAKE_VERBOSE_MAKEFILE)
list(APPEND BAZEL_ARGS --subcommands)
endif()
option(WITH_GUROBI "Build with support for Gurobi" OFF)
if(WITH_GUROBI)
find_package(Gurobi 8.0.0 MODULE REQUIRED)
list(APPEND BAZEL_ARGS --config=gurobi)
if(NOT APPLE)
get_filename_component(GUROBI_PATH "${Gurobi_INCLUDE_DIRS}" DIRECTORY)
list(APPEND BAZEL_ENV "GUROBI_PATH=${GUROBI_PATH}")
endif()
endif()
option(WITH_MATLAB "Build with support for MATLAB" OFF)
if(WITH_MATLAB)
list(APPEND BAZEL_ARGS
--define=NO_IPOPT=ON
--define=NO_OSQP=ON
)
endif()
option(WITH_MOSEK "Build with support for MOSEK" OFF)
if(WITH_MOSEK)
list(APPEND BAZEL_ARGS --config=mosek)
endif()
option(WITH_SNOPT "Build with support for SNOPT" OFF)
if(WITH_SNOPT)
list(APPEND BAZEL_ARGS --config=snopt)
endif()
set(BAZEL_TARGETS //:install)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/install" CACHE STRING
"Install path prefix, prepended onto install directories" FORCE
)
endif()
include(ExternalProject)
ExternalProject_Add(drake_cxx_python
SOURCE_DIR "${PROJECT_SOURCE_DIR}"
CONFIGURE_COMMAND :
BUILD_COMMAND ${BAZEL_ENV} "${Bazel_EXECUTABLE}" ${BAZEL_STARTUP_ARGS} build ${BAZEL_ARGS} ${BAZEL_TARGETS}
BUILD_IN_SOURCE 1
BUILD_ALWAYS 1
INSTALL_COMMAND ${BAZEL_ENV} "${Bazel_EXECUTABLE}" ${BAZEL_STARTUP_ARGS} run ${BAZEL_ARGS} ${BAZEL_TARGETS} -- "${CMAKE_INSTALL_PREFIX}"
USES_TERMINAL_BUILD 1
USES_TERMINAL_INSTALL 1
)
set(GIT_DIR "${PROJECT_SOURCE_DIR}/.git")
set(GIT_REVISION HEAD)
find_package(Git)
if(GIT_FOUND AND EXISTS "${GIT_DIR}")
execute_process(COMMAND "${GIT_EXECUTABLE}" "--git-dir=${GIT_DIR}" rev-parse HEAD
RESULT_VARIABLE GIT_REV_PARSE_RESULT_VARIABLE
OUTPUT_VARIABLE GIT_REV_PARSE_OUTPUT_VARIABLE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(GIT_REV_PARSE_RESULT_VARIABLE EQUAL 0)
set(GIT_REVISION "${GIT_REV_PARSE_OUTPUT_VARIABLE}")
endif()
endif()
string(TIMESTAMP BUILD_TIMESTAMP "%Y%m%d%H%M%S")
configure_file(tools/install/libdrake/VERSION.TXT.in VERSION.TXT @ONLY)
install(FILES "${PROJECT_BINARY_DIR}/VERSION.TXT" DESTINATION share/doc/drake)
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}")
if(WITH_MATLAB)
ExternalProject_Add(drake_matlab
DEPENDS drake_cxx_python
SOURCE_DIR "${PROJECT_SOURCE_DIR}/matlab"
CMAKE_ARGS
-DBUILD_TESTING:BOOL=${BUILD_TESTING}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
"-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}"
"-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}"
"-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}"
"-DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}"
"-DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS}"
-DCMAKE_VERBOSE_MAKEFILE:BOOL=${CMAKE_VERBOSE_MAKEFILE}
BINARY_DIR "${PROJECT_BINARY_DIR}/drake_matlab-build"
BUILD_ALWAYS 1
)
endif()
set(CPACK_GENERATOR TGZ)
set(CPACK_INSTALLED_DIRECTORIES "${CMAKE_INSTALL_PREFIX}" .)
set(CPACK_PACKAGE_CONTACT RobotLocomotion)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"Planning, control, and analysis toolbox for nonlinear dynamical systems"
)
set(CPACK_PACKAGE_VENDOR RobotLocomotion)
set(CPACK_PACKAGE_VERSION_MAJOR 0)
set(CPACK_PACKAGE_VERSION_MINOR 0)
set(CPACK_PACKAGE_VERSION_PATCH 0)
set(CPACK_PACKAGE_CHECKSUM SHA256)
set(CPACK_SET_DESTDIR ON)
set(CPACK_SOURCE_GENERATOR "")
if(APPLE)
set(CPACK_SYSTEM_NAME mac)
else()
string(TOLOWER "${CMAKE_SYSTEM_NAME}" CPACK_SYSTEM_NAME)
list(APPEND CPACK_GENERATOR DEB)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION ON)
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE http://drake.mit.edu/)
set(CPACK_DEBIAN_PACKAGE_RELEASE 1)
set(CPACK_DEBIAN_PACKAGE_SECTION contrib/devel)
file(STRINGS setup/ubuntu/16.04/binary_distribution/packages.txt
CPACK_DEBIAN_PACKAGE_DEPENDS
)
string(REGEX REPLACE "([a-z0-9\\-]+)=([a-z0-9\\-\\.~]+)" "\\1 (= \\2)"
CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}"
)
string(REPLACE ";" ", " CPACK_DEBIAN_PACKAGE_DEPENDS
"${CPACK_DEBIAN_PACKAGE_DEPENDS}"
)
endif()
set(CPACK_PACKAGE_FILE_NAME
"${PROJECT_NAME}-${BUILD_TIMESTAMP}-${CPACK_SYSTEM_NAME}"
)
include(CPack)