-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
168 lines (147 loc) · 6.02 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
cmake_minimum_required(VERSION 3.20.2)
project(
riccati
VERSION 0.1.0
LANGUAGES C CXX)
include(FetchContent)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED NO)
cmake_policy(SET CMP0135 NEW)
cmake_policy(SET CMP0077 NEW)
set(CMAKE_CXX_EXTENSIONS NO)
if (CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_VERBOSE_MAKEFILE YES)
endif()
option(RICCATI_BUILD_TESTING "Build the test targets for the library" OFF)
option(RICCATI_BUILD_BENCHMARKS "Build the benchmarks target" OFF)
option(RICCATI_BUILD_DOXYGEN "Build the doxygen docs target" OFF)
option(RICCATI_BUILD_PYTHON "Build the python target" OFF)
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_options(-Wno-deprecated-declarations)
endif()
# Build Types
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}
CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel tsan asan lsan msan ubsan"
FORCE)
# ThreadSanitizer
set(CMAKE_C_FLAGS_TSAN
"-fsanitize=thread -g -O1 -march=native -mtune=native"
CACHE STRING "Flags used by the C compiler during ThreadSanitizer builds."
FORCE)
set(CMAKE_CXX_FLAGS_TSAN
"-fsanitize=thread -g -O1 -march=native -mtune=native"
CACHE STRING "Flags used by the C++ compiler during ThreadSanitizer builds."
FORCE)
# AddressSanitize
set(CMAKE_C_FLAGS_ASAN
"-fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g -Og -march=native -mtune=native"
CACHE STRING "Flags used by the C compiler during AddressSanitizer builds."
FORCE)
set(CMAKE_CXX_FLAGS_ASAN
"-fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g -Og -Wall -march=native -mtune=native"
CACHE STRING "Flags used by the C++ compiler during AddressSanitizer builds."
FORCE)
# LeakSanitizer
set(CMAKE_C_FLAGS_LSAN
"-fsanitize=leak -fno-omit-frame-pointer -g -O1"
CACHE STRING "Flags used by the C compiler during LeakSanitizer builds."
FORCE)
set(CMAKE_CXX_FLAGS_LSAN
"-fsanitize=leak -fno-omit-frame-pointer -ggdb3 -O1"
CACHE STRING "Flags used by the C++ compiler during LeakSanitizer builds."
FORCE)
if(APPLE)
set(CMAKE_CXX_FLAGS_DEBUG
"-fno-omit-frame-pointer -glldb -Og -DRICCATI_DEBUG=true"
CACHE STRING "Flags used by the C++ compiler during Debug builds."
FORCE)
else()
set(CMAKE_CXX_FLAGS_DEBUG
"-fno-omit-frame-pointer -ggdb3 -Og -DRICCATI_DEBUG=true"
CACHE STRING "Flags used by the C++ compiler during Debug builds."
FORCE)
endif()
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS_RELEASE
"-O3 -march=native -mtune=native -DRICCATI_DEBUG=false"
CACHE STRING "Flags used by the C++ compiler during Release builds."
FORCE)
endif()
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cmake_deps)
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_options(
-DNO_FPRINTF_OUTPUT
-Wall)
endif()
# Define the include directory for this library
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Optionally, specify install rules for your library
# This is necessary for FetchContent to work properly
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
INCLUDES DESTINATION include
)
install(DIRECTORY include/ DESTINATION include)
# Create and install the CMake configuration files for your library
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${VERSION}
COMPATIBILITY SameMajorVersion
)
install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Config.cmake
NAMESPACE riccaticpp::
DESTINATION lib/cmake/${PROJECT_NAME}
)
if (RICCATI_BUILD_TESTING)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
endif()
if (RICCATI_BUILD_BENCHMARKS)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/benchmarks)
endif()
# Check if Doxygen is installed
if (RICCATI_BUILD_DOXYGEN)
set(Eigen_INCLUDE_DIR "${Eigen3_SOURCE_DIR}")
find_package(Doxygen)
if(DOXYGEN_FOUND)
# Set input and output files
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/docs/Doxyfile)
# Request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message(STATUS "Doxygen build started")
# Note: do not put 'ALL' keyword since you probably don't want documentation
# to be generated every time you build the project.
add_custom_target( doc_doxygen
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
else()
message("Doxygen need to be installed to generate the doxygen documentation")
endif()
endif()
if (RICCATI_BUILD_PYTHON)
# Find the module development requirements (requires FindPython from 3.17 or
# scikit-build-core's built-in backport)
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)
# Add a library using FindPython's tooling (pybind11 also provides a helper like
# this)
python_add_library(pyriccaticpp MODULE src/pymain.cpp WITH_SOABI)
target_link_libraries(pyriccaticpp PRIVATE pybind11::headers riccati Eigen3::Eigen)
# This is passing in the version as a define just as an example
target_compile_definitions(pyriccaticpp PRIVATE VERSION_INFO=${PROJECT_VERSION} RICCATI_PYTHON)
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(pyriccaticpp PRIVATE -Wno-deprecated-declarations)
endif()
#target_compile_options(pyriccaticpp PRIVATE -Og -glldb)
# The install directory is the output (wheel) directory
install(TARGETS pyriccaticpp DESTINATION pyriccaticpp)
endif()