-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
128 lines (109 loc) · 3.58 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
##############################
# Preamble
##############################
cmake_minimum_required(VERSION 3.2)
list(APPEND CMAKE_MESSAGE_CONTEXT tinympc)
project(tinyMPC VERSION 0.1 LANGUAGES C CXX)
##############################
# Project wide
##############################
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS NO)
# include(CMakePrintHelpers)
# include(GNUInstallDirs)
# include(Functions)
include(FetchContent)
# Add CPM Dependency Manager
include(FindCPM)
# Handle default build type
set(TINY_DEFAULT_BUILD_TYPE "Debug")
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "No build type specified. Setting CMAKE_BUILD_TYPE to ${TINY_DEFAULT_BUILD_TYPE}")
set(CMAKE_BUILD_TYPE ${TINY_DEFAULT_BUILD_TYPE} CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif ()
# Enable testing
option(TINY_BUILD_TESTS "Build tests for TinyMPC" ON)
# Enable clang-tidy analysis
option(TINY_CLANG_TIDY "Run clang-tidy analyzer on the source code." OFF)
# Floating point precision
set(TINY_FLOAT double CACHE STRING "Floating point precision for TinyMPC (float,double).")
# Build examples
option(TINY_BUILD_EXAMPLES "Build examples for TinyMPC." ON)
# Build with -march=native
option(TINY_VECTORIZE "Compile with -march=native" OFF)
##############################
# Dependencies
##############################
# slap
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
FetchContent_Declare(slap
GIT_REPOSITORY https://github.com/bjack205/slap
GIT_TAG main
)
set(SLAP_BUILD_TESTS OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(slap)
endif ()
# Google Test
if (TINY_BUILD_TESTS)
CPMAddPackage(
NAME googletest
GITHUB_REPOSITORY google/googletest
VERSION 1.13.0
DOWNLOAD_EXTRACT_TIMESTAMP
OPTIONS
"INSTALL_GTEST OFF"
"gtest_force_shared_crt ON"
)
add_library(gtest::gtest ALIAS gtest_main)
enable_testing()
include(GoogleTest)
include(CTest)
endif ()
##############################
# Main build targets
##############################
# Compile options
if (NOT WIN32)
add_compile_options(-Wall -Wextra -pedantic -Werror -Wno-error=unknown-pragmas)
# add_compile_options(-Wformat=2 -Wno-unused-parameter -Wshadow
# -Wwrite-strings -Wstrict-prototypes -Wold-style-definition
# -Wredundant-decls -Wnested-externs -Wmissing-include-dirs)
if (TINY_VECTORIZE)
add_compile_options(-march=native)
endif()
endif()
# if (CMAKE_C_COMPILER_ID MATCHES "GNU")
# add_compile_options(-Wjump-misses-init -Wlogical-op)
# endif()
# TODO: Future options to optimize library for specific use of constraints
option(SET_GOAL_CONSTRAINT "Set goal constraint" OFF)
if (SET_GOAL_CONSTRAINT)
add_definitions(-DGOAL_CONSTRAINT)
endif()
option(SET_INPUT_CONSTRAINT "Set input constraints" ON)
if (SET_INPUT_CONSTRAINT)
add_definitions(-DINPUT_CONSTRAINT)
endif()
option(SET_STATE_CONSTRAINT "Set state constraints" ON)
if (SET_STATE_CONSTRAINT)
add_definitions(-DSTATE_CONSTRAINT)
endif()
# Make all includes relative to src/ directory
include_directories(${PROJECT_SOURCE_DIR}/src)
# Build source files
add_subdirectory(src/tinympc)
##############################
# Tests
##############################
if (TINY_BUILD_TESTS)
add_subdirectory(test)
endif()
##############################
# Examples
##############################
if (TINY_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()