-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathCMakeLists.txt
123 lines (101 loc) · 3.68 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
cmake_minimum_required(VERSION 3.12)
project(Tutorial LANGUAGES CXX)
if(UNIX AND NOT APPLE)
set(CMAKE_C_COMPILER "/usr/bin/gcc")
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
elseif(APPLE)
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
else()
message(WARNING "Only support LINUX and APPLE for now.")
endif()
# for color output only
if(NOT WIN32)
string(ASCII 27 Esc)
set(ColourReset "${Esc}[m")
set(ColourBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif()
SET(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,${CMAKE_SOURCE_DIR}/build")
# for using casadi
find_package(casadi REQUIRED)
# For multi threading
find_package(Threads REQUIRED)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
# set the g++ compiler flags
set(CMAKE_CXX_FLAGS "-Wall -Wextra -pthread")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(CMAKE_CXX_COMPILER_LOADED)
message(STATUS "Compiler Path: ${CMAKE_CXX_COMPILER}")
message(STATUS "Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "Compiler Version: ${CMAKE_CXX_COMPILER_VERSION}")
endif()
# set the Ipopt library and include directory
set(LIBRARY_DIRS /usr/local/lib)
if(UNIX AND NOT APPLE)
set(IPOPT_INCLUDE_DIRS /usr/include/coin)
elseif(APPLE)
set(IPOPT_INCLUDE_DIRS /usr/local/include/coin-or)
endif()
# set casadi include directory
set(CASADI_INCLUDE_DIR /usr/local/include/casadi)
# find casadi library
find_library(CASADI_LIBRARY
NAMES casadi
HINTS ${CASADI_INCLUDE_DIR}/../lib $ENV{CASADI_PREFIX}/lib)
if(CASADI_LIBRARY)
set(CASADI_LIBRARIES ${CASADI_LIBRARIES} ${CASADI_LIBRARY})
endif()
# find the following packages
find_package(Threads REQUIRED)
# include header directories
include_directories(
${CMAKE_SOURCE_DIR}/include
SYSTEM ${IPOPT_INCLUDE_DIRS}
SYSTEM ${CASADI_INCLUDE_DIR}
${CODE_GEN_INCLUDE_DIR})
# library directories
link_directories(${LIBRARY_DIRS})
# find all the header files
file(GLOB HEADER_FILES_HPP ${CMAKE_SOURCE_DIR}/include/*.hpp)
file(GLOB HEADER_FILES_H ${CMAKE_SOURCE_DIR}/include/*.h)
# add executable files for test
# casadi + ipopt test
add_executable(example_racecar example/example_racecar.cpp)
target_link_libraries(example_racecar ${CASADI_LIBRARIES} ipopt)
# casadi basic operations
add_executable(example_basic_operations example/example_basic_operations.cpp)
target_link_libraries(example_basic_operations ${CASADI_LIBRARIES})
# casadi function C code auto generation
add_executable(example_code_gen example/example_code_gen.cpp)
target_link_libraries(example_code_gen ${CASADI_LIBRARIES})
# a test file to use auto generated code library
# compile the test file
add_executable(example_use_code_gen example/example_use_code_gen.cpp)
target_link_libraries(example_use_code_gen ${CASADI_LIBRARIES})
# compile a nonlinear programming to a shared library
add_executable(example_nlp_code_gen example/example_nlp_code_gen.cpp)
target_link_libraries(example_nlp_code_gen ${CASADI_LIBRARIES})
# solve a NLP given a compiled shared library
add_executable(example_use_nlp_external example/example_use_nlp_external.cpp)
target_link_libraries(example_use_nlp_external ${CASADI_LIBRARIES})