-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
92 lines (72 loc) · 2.89 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
cmake_minimum_required(VERSION 3.13)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Options
option(ENABLE_WARNINGS "Enable all warnings on build" OFF)
option(ENABLE_WARNINGS_AS_ERROR "Enable all warnings as errors" OFF)
option(ENABLE_TESTS "Build the tests" OFF)
option(ENABLE_CLANG_TIDY_CHECK "Enable clang tidy check on compilation" OFF)
option(ENABLE_ERROR_ON_MISSING_TOOL "If a tools (clang-tidy, clang-format, doxygen) is not disabled and not installed, throws error" OFF)
option(DISABLE_EXTERNAL_WARNINGS "Disables warnings from exernal libs (gtest, freertos, etc)" ON)
option(ENABLE_TARGET_IPERF_SERVER "Starts an iperf server on the target device for network monitoring" OFF)
option(ENABLE_TARGET_RUNTIME_STATS "Starts an task logging the run time stats of each tasks. (Only supported for h7 for now)" OFF)
option(ENABLE_HARDWARE_TESTS "Compiles a second executable to do various hardware tests (only works for STM32H7)" OFF)
# Init compile variable
set(COMPILE_STM32 0)
set(COMPILE_STM32_F429ZI 0)
set(COMPILE_STM32_H735ZG 0)
# Define project
project(hive_mind CXX C ASM)
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
set(CMAKE_CXX_STANDARD 17)
if(${COMPILE_STM32_F429ZI} OR ${COMPILE_STM32_H735ZG})
set(COMPILE_STM32 1)
endif()
# Warning flags constants
set(WARNING_FLAG -Wall -Wextra -Wsign-conversion -Wuninitialized -Wunused-variable -Wpedantic )
set(WARNING_NO_EXCEPTION_FLAG -fno-exceptions)
set(WARNING_AS_ERROR_FLAG -Werror)
# Generator expression doesn't work with clang-tidy, we need to make an IF statement manually
if(ENABLE_WARNINGS)
add_compile_options(${WARNING_FLAG})
if(${CMAKE_CROSSCOMPILING})
# Only remove exception support for target as ROS uses exceptions
add_compile_options(${WARNING_NO_EXCEPTION_FLAG})
# Disable RTTI for C++ libraries
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
endif()
endif()
if(ENABLE_WARNINGS_AS_ERROR)
add_compile_options(${WARNING_AS_ERROR_FLAG})
endif()
if(ENABLE_TARGET_IPERF_SERVER)
# Must be set before including any source files
add_definitions(-DIPERF_SERVER)
endif()
if(ENABLE_TARGET_RUNTIME_STATS)
# Must be set before including any source files
add_definitions(-DRUNTIME_STATS)
endif()
# Includes
include(utils)
include(ros/generators.cmake)
include(catkin/common)
include(propolis/common)
include(clang-tools/clang-tidy)
include(clang-tools/clang-format)
include(doc/doxygen)
# Testing
if(ENABLE_TESTS)
include(googletest/common)
enable_testing()
if(NOT TARGET gtest)
googletest_fetch_populate()
endif()
if(DISABLE_EXTERNAL_WARNINGS)
googletest_disable_warnings()
endif()
endif()
# Include src to compile
add_subdirectory(src)
# Disable clang-tidy after generating all targets so it isn't used for other packages in the same catkin workspace
set(CMAKE_CXX_CLANG_TIDY "" CACHE STRING "" FORCE)
set(CMAKE_C_CLANG_TIDY "" CACHE STRING "" FORCE)