-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
113 lines (90 loc) · 3.32 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
cmake_minimum_required(VERSION 3.17)
list(APPEND CMAKE_MESSAGE_CONTEXT rsLQR)
project(rsLQR VERSION 0.1 LANGUAGES C CXX)
include(CMakePrintHelpers)
include(GNUInstallDirs)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# Set RPATH
# This ensures any shared libraries generated by the project
# can be found when installed
# See 26.2.2 of Professional CMake
file(RELATIVE_PATH relDir
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
)
set(CMAKE_INSTALL_RPATH $ORIGIN $ORIGIN/${relDir})
##############################
# Options
##############################
# Handle default build type
set(RSLQR_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 ${RSLQR_DEFAULT_BUILD_TYPE}.")
set(CMAKE_BUILD_TYPE ${RSLQR_DEFAULT_BUILD_TYPE} CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# Pick the linear algebra library
set(RSLQR_LINALG_LIBRARY "InternalRoutines" CACHE STRING "Linear algebra library.")
set_property(CACHE RSLQR_LINALG_LIBRARY PROPERTY STRINGS BLAS MKL Eigen InternalRoutines)
# Enable testing
option(RSLQR_BUILD_TESTS "Build tests for rsLQR" "ON")
# Code Coverage
option(RSLQR_CODE_COVERAGE "Compile rsLQR with Code Coverage." OFF)
if(RSLQR_CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
message(STATUS "Compiling rsLQR with coverage info.")
add_compile_options(-O0 -g -fprofile-arcs -ftest-coverage)
add_link_options(-fprofile-arcs -ftest-coverage)
endif()
# Test threads
set(RSLQR_NTHREADS_TEST 2 CACHE STRING "Number of threads to use in tests.")
set_property(CACHE RSLQR_NTHREADS_TEST PROPERTY STRINGS 1 2 4 6 16)
# Run full test suite
option(RSLQR_RUN_FULL_TEST "Run the full, computationally intensive test suite." ON)
##############################
# Dependencies
##############################
add_subdirectory(deps)
# Find required packages
find_package(OpenMP REQUIRED)
include(FindLinearAlgebra)
find_package(Doxygen)
##############################
# Build
##############################
# Compile options
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
add_compile_options(-fPIC)
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
add_compile_options(-fPIE -fPIC)
endif()
add_compile_options(-Wall -Wextra -pedantic -Werror -Wno-error=unknown-pragmas)
add_compile_options(-mavx2 -mfma)
# Make all includes relative to src/ folder
include_directories(${rsLQR_SOURCE_DIR}/src)
# Build source files
add_subdirectory(src)
##############################
# Testing
##############################
if (RSLQR_BUILD_TESTS)
enable_testing()
include_directories(${rsLQR_SOURCE_DIR})
add_subdirectory(test)
endif()
##############################
# Documentation
##############################
if (DOXYGEN_FOUND)
set(DOXYGEN_IN ${PROJECT_SOURCE_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${PROJECT_SOURCE_DIR}/docs/Doxyfile)
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
add_custom_target(doxygen
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Build documentation with Doxygen."
)
endif()
##############################
# Packaging
##############################
add_subdirectory(packaging)