-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
215 lines (171 loc) · 6.98 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
cmake_minimum_required(VERSION 3.22)
# ============================= PROJECT SETUP ===============================================
project(ismpc_cpp VERSION 0.1 LANGUAGES CXX)
set(ISMPC_CPP_LIBRARY ${PROJECT_NAME})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(PROJECT ismpc_cpp)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_library(cxx_setup INTERFACE)
target_compile_options(cxx_setup INTERFACE -Wall -Wpedantic -Wextra)
target_compile_features(cxx_setup INTERFACE cxx_std_20)
if(CMAKE_CXX_COMPILER_LOADED)
message(STATUS "Path: ${CMAKE_CXX_COMPILER}")
message(STATUS "Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "Compiler Version: ${CMAKE_CXX_COMPILER_VERSION}")
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/executables")
# =============================================================================================
# ============================ BUILD OPTIONS ==================================================
option(BUILD_TESTS "Build tests" OFF)
option(BUILD_PYTHON_BINDINGS "Build python bindings" OFF)
option(BUILD_ROS "Build ros package" OFF)
option(BUILD_DART "Build with DART" OFF)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_definitions("DEBUG")
endif()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
# =============================================================================================
# ============================ UTILITY STUFF ==================================================
execute_process(
COMMAND date "+%Y-%m-%d %H:%M:%S"
OUTPUT_VARIABLE TIMESTAMP
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Write the timestamp to a header file
set(TIMESTAMP_HEADER "${CMAKE_BINARY_DIR}/timestamp.h")
file(WRITE ${TIMESTAMP_HEADER} "#pragma once\n")
file(APPEND ${TIMESTAMP_HEADER} "#define BUILD_TIMESTAMP \"${TIMESTAMP}\"\n")
# Config file with system variables
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/ismpc_cpp/tools/systemvars.h.in
${CMAKE_CURRENT_SOURCE_DIR}/include/ismpc_cpp/tools/systemvars.h
@ONLY
)
# =============================================================================================
# ============================ EXTERNAL LIBRARIES =============================================
include(FetchContent)
# EIGEN3
set(EIGEN_INCLUDE_DIR /usr/include/eigen3)
# YAML-CPP
FetchContent_Declare(
yaml-cpp
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
GIT_TAG master
)
FetchContent_MakeAvailable(yaml-cpp)
# PROXSUITE
FetchContent_Declare(
proxsuite
GIT_REPOSITORY https://github.com/Simple-Robotics/proxsuite.git
GIT_TAG main
)
FetchContent_MakeAvailable(proxsuite)
# CASADI
set(CASADI_INCLUDE_DIR /usr/local/include/casadi)
include_directories(
SYSTEM ${CASADI_INCLUDE_DIR}
)
set(LIBRARY_DIRS /usr/local/lib)
link_directories(${LIBRARY_DIRS})
find_library(CASADI_LIBRARY NAMES casadi HINTS ${LIBRARY_DIRS})
if(CASADI_LIBRARY)
set(LIBCASADI ${CASADI_LIBRARY})
message(STATUS "Found CasADi libs: ${LIBCASADI}")
endif()
# DART
if(BUILD_DART)
find_package(DART 6.10.0 REQUIRED COMPONENTS gui-osg utils-urdf dart CONFIG)
message(STATUS "DART found: ${DART_VERSION}")
message(STATUS "DART include dirs: ${DART_INCLUDE_DIRS}")
endif()
# ============================ ISMPC LIBRARY ==================================================
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
file(GLOB_RECURSE ISMPC_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
add_library(${ISMPC_CPP_LIBRARY} STATIC ${ISMPC_SRCS})
target_include_directories(${ISMPC_CPP_LIBRARY}
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${proxsuite_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${yaml-cpp_SOURCE_DIR}/include>
${DART_INCLUDE_DIRS}
${EIGEN_INCLUDE_DIR}
)
set(ISMPC_CPP_EXTRA_LIBRARIES
$<BUILD_INTERFACE:cxx_setup>
$<BUILD_INTERFACE:yaml-cpp::yaml-cpp>
$<BUILD_INTERFACE:proxsuite>
${DART_LIBRARIES}
${LIBCASADI}
)
target_link_libraries(${ISMPC_CPP_LIBRARY} PUBLIC ${ISMPC_CPP_EXTRA_LIBRARIES})
if(BUILD_ROS)
find_package(ament_cmake REQUIRED)
add_definitions(-DUSING_ROS2)
message(STATUS "------------------------------------------")
message(STATUS "ismpc_cpp is being built using AMENT.")
message(STATUS "------------------------------------------")
set(CMAKE_CONFIG_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CONFIG_PATH})
find_package(ament_index_cpp REQUIRED)
list(APPEND ISMPC_CPP_EXTRA_LIBRARIES $<BUILD_INTERFACE:ament_index_cpp::ament_index_cpp>)
ament_export_dependencies(ament_index_cpp)
ament_export_dependencies(yaml-cpp)
set(ISMPC_CPP_LIB_DESTINATION lib)
set(ISMPC_CPP_INCLUDE_DESTINATION include)
set(ISMPC_CPP_BIN_DESTINATION bin)
mark_as_advanced(
ISMPC_CPP_EXTRA_LIBRARIES
ISMPC_CPP_LIB_DESTINATION
ISMPC_CPP_INCLUDE_DESTINATION
ISMPC_CPP_BIN_DESTINATION
)
install(
TARGETS ${ISMPC_CPP_LIBRARY}
EXPORT ${ISMPC_CPP_LIBRARY}Targets
ARCHIVE DESTINATION ${ISMPC_CPP_LIB_DESTINATION}
LIBRARY DESTINATION ${ISMPC_CPP_LIB_DESTINATION}
RUNTIME DESTINATION ${ISMPC_CPP_BIN_DESTINATION}
INCLUDES DESTINATION ${ISMPC_CPP_INCLUDE_DESTINATION}
)
INSTALL(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/include/
$<BUILD_INTERFACE:${proxsuite_SOURCE_DIR}/include/proxsuite>
${EIGEN_INCLUDE_DIR}
$<BUILD_INTERFACE:${nanobind_SOURCE_DIR}/include/nanobind>
$<BUILD_INTERFACE:${yaml-cpp_SOURCE_DIR}/include/yaml-cpp>
DESTINATION ${ISMPC_CPP_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h*"
)
install(
DIRECTORY include/
DESTINATION include
)
ament_export_include_directories(include)
ament_export_libraries(${ISMPC_CPP_LIBRARY})
ament_export_targets(${ISMPC_CPP_LIBRARY}Targets HAS_LIBRARY_TARGET)
ament_package()
endif()
# =============================================================================================
# ============================ PYTHON BINDINGS =================================================
if(BUILD_PYTHON_BINDINGS)
add_subdirectory(bindings)
endif()
# =============================================================================================
# =========================== GOOGLE TEST =====================================================
if(BUILD_TESTS)
add_subdirectory(test)
endif()
# =============================================================================================
# ============================ EXECUTABLES ====================================================
add_executable(ismpc_main ${CMAKE_CURRENT_SOURCE_DIR}/src/cppmain.cpp)
target_link_libraries(ismpc_main PRIVATE ${ISMPC_CPP_LIBRARY})
add_executable(dart_main ${CMAKE_CURRENT_SOURCE_DIR}/src/dartmain.cpp)
target_link_libraries(dart_main PRIVATE ${ISMPC_CPP_LIBRARY})
# =============================================================================================