forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
123 lines (95 loc) · 3.51 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
# -*- 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()
find_package(Bazel 0.6.1 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(CMAKE_BUILD_TYPE STREQUAL Debug)
set(BAZEL_COMPILATION_MODE dbg)
else()
set(BAZEL_COMPILATION_MODE opt)
endif()
set(BAZEL_ENV "CC=${CMAKE_C_COMPILER}" "CXX=${CMAKE_CXX_COMPILER}")
set(BAZEL_ARGS
--compilation_mode=${BAZEL_COMPILATION_MODE}
--config=unsupported_crosstool
--cxxopt=${CMAKE_CXX14_STANDARD_COMPILE_OPTION}
--host_cxxopt=${CMAKE_CXX14_STANDARD_COMPILE_OPTION}
)
if(CMAKE_VERBOSE_MAKEFILE)
list(APPEND BAZEL_ARGS --subcommands)
endif()
option(WITH_GUROBI "Build with support for GUROBI. Experimental." OFF)
if(WITH_GUROBI)
list(APPEND BAZEL_ARGS --config=gurobi)
endif()
option(WITH_MATLAB "Build with support for MATLAB" OFF)
if(WITH_MATLAB)
list(APPEND BAZEL_ARGS --define=NO_IPOPT=ON)
endif()
option(WITH_MOSEK "Build with support for MOSEK. Experimental." 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}" build ${BAZEL_ARGS} ${BAZEL_TARGETS}
BUILD_IN_SOURCE 1
BUILD_ALWAYS 1
INSTALL_COMMAND ${BAZEL_ENV} "${Bazel_EXECUTABLE}" run ${BAZEL_ARGS} ${BAZEL_TARGETS} -- "${CMAKE_INSTALL_PREFIX}"
USES_TERMINAL_BUILD 1
USES_TERMINAL_INSTALL 1
)
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()