-
Notifications
You must be signed in to change notification settings - Fork 10
/
CMakeLists.txt
115 lines (94 loc) · 3.77 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
# Used 3.23 features
# - PROJECT_IS_TOP_LEVEL (3.21)
# - FILE_SETS (3.23)
cmake_minimum_required(VERSION 3.23)
list(APPEND CMAKE_MESSAGE_CONTEXT altro)
project(altro VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 14)
# Organization info
set(ORGANIZATION_NAME_FULL "Robotic Exploration Lab")
set(ORGANIZATION_NAME "rexlab")
# Include needed modules
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(CMakePrintHelpers)
include(FetchContent)
include(AltroCMakeFunctions)
include(FindThreads)
include(GNUInstallDirs)
#############################################
# Options
#############################################
# Handle default build type
set(ALTRO_DEFAULT_BUILD_TYPE "Release")
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "No build type specified. Setting CMAKE_BUILD_TYPE to ${ALTRO_DEFAULT_BUILD_TYPE}")
set(CMAKE_BUILD_TYPE ${ALTRO_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(ALTRO_BUILD_TESTS "Build tests for altro" ON)
if (${ALTRO_BUILD_TESTS})
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG 58d77fa8070e8cec2dc1ed015d66b454c8d78850
)
FetchContent_MakeAvailable(googletest)
enable_testing()
include(GoogleTest)
include(CTest)
endif()
# Code Coverage
option(ALTRO_CODECOV "Compile altro with code coverage" OFF)
if (ALTRO_CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
message(STATUS "Compiler altro with coverage info.")
add_compile_options(-O0 -g -fprofile-arcs -ftest-coverage)
endif()
# Documentation
option(ALTRO_BUILD_DOCS "Build documentation for altro." OFF)
# Use -fPIC option
#option(ALTRO_POSITION_INDEPENDENT_CODE "Use -fPIC flag when compiling altro" ON)
if (BUILD_SHARED_LIBS)
# set(CMAKE_POSITION_INDEPENDENT_CODE ON FORCE)
message(STATUS "Building shared library.")
add_compile_options(-fPIC)
else()
message(STATUS "Building static library. Note that a shared library is recommended.")
endif()
# Set default install prefix to /opt/rexlab/altro
if(NOT WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND PROJECT_IS_TOP_LEVEL)
message(STATUS "Setting Altro install prefix to /opt/${ORGANIZATION_NAME}/${PROJECT_NAME}")
set(CMAKE_INSTALL_PREFIX "/opt/${ORGANIZATION_NAME}/${PROJECT_NAME}" CACHE FILEPATH "Base install location" FORCE)
set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OFF)
endif()
# Arduino library installation
option(ALTRO_ENABLE_RUNTIME_EXCEPTIONS "Enable C++ runtime exceptions. If disabled, error return codes will be returned instead." OFF)
option(ALTRO_ENABLE_ARDUINO_LIB_INSTALL "Add the install_arduino_lib target" ON)
set(ALTRO_ARDUINO_LIB_INSTALL_DIR $ENV{HOME}/Arduino/libraries CACHE FILEPATH "Directory where the altro Arduino library should be installed")
cmake_print_variables(ALTRO_ARDUINO_LIB_INSTALL_DIR)
#############################################
# Dependencies
#############################################
add_subdirectory(deps)
#############################################
# Documentation
#############################################
if (ALTRO_BUILD_DOCS)
message(STATUS "Adding altro_docs target to build documentation.")
add_subdirectory(docs EXCLUDE_FROM_ALL)
endif()
#############################################
# Build
#############################################
# Output all binaries
add_subdirectory(src)
#############################################
# Testing
#############################################
if (${ALTRO_BUILD_TESTS})
message(STATUS "Building altro testing suite.")
add_subdirectory(test)
endif()
#############################################
# Installation
#############################################
add_subdirectory(install)