-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
166 lines (136 loc) · 5.3 KB
/
CMakeLists.txt
File metadata and controls
166 lines (136 loc) · 5.3 KB
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
cmake_minimum_required(VERSION 3.20)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
project(
rodos
VERSION 0.1.0
LANGUAGES C CXX ASM
)
# Developer mode enables targets and code paths in the CMake scripts that are only relevant for
# the developers of RODOS. Targets necessary to build the project must be provided
# unconditionally, so consumers can trivially build and package the project. The option is ON by
# default for backward compatibility.
option(RODOS_DEVELOPER_MODE "Enable developer mode" ON)
if (RODOS_DEVELOPER_MODE)
option(COVERAGE "Enable code coverage generation" OFF)
if (COVERAGE)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
message(STATUS "Coverage enabled, setting build type to Debug")
endif ()
include(cmake/CodeCoverage.cmake)
append_coverage_compiler_flags()
endif ()
endif ()
if (NOT DEFINED port_dir)
message(FATAL_ERROR "port not correct (CMAKE_TOOLCHAIN_FILE, see readme)")
endif ()
#___________________________________________________________________
file(GLOB_RECURSE independent_sources
src/independent/*.cpp
support/support-libs/*.cpp)
add_library(rodos_rodos STATIC ${independent_sources})
add_library(rodos::rodos ALIAS rodos_rodos)
add_library(rodos ALIAS rodos_rodos)
set_target_properties(rodos_rodos PROPERTIES
EXPORT_NAME rodos
OUTPUT_NAME rodos
)
file(GLOB port_sources
src/${port_dir}/*.cpp
src/${port_dir}/*.c
src/${port_dir}/hal/*.cpp
src/${port_dir}/*.S)
target_sources(rodos_rodos PRIVATE ${port_sources})
target_include_directories(rodos_rodos PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/api>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/api/hal>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/${port_dir}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/${port_dir}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/support/support-libs>
)
target_compile_options(rodos_rodos PUBLIC -fno-exceptions)
target_compile_features(rodos_rodos PUBLIC cxx_std_20)
if (RODOS_DEVELOPER_MODE)
target_compile_options(
rodos_rodos PUBLIC -g -Wall -Wpedantic -Wextra -Wcast-qual -Wconversion -Wsign-conversion
-Wfloat-conversion -Wdouble-promotion -Wnull-dereference -Wstrict-aliasing -Wno-long-long
-Wno-cpp
)
endif ()
option(ENABLE_RODOS_RTTI "Build RODOS with run-time type information" OFF)
if (NOT ENABLE_RODOS_RTTI)
target_compile_options(rodos_rodos PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
endif ()
option(DISABLE_TIMEEVENTS "Disable manual TimeEvents (interrupts on specified time)" OFF)
if(DISABLE_TIMEEVENTS)
add_compile_definitions(DISABLE_TIMEEVENTS)
endif()
#___________________________________________________________________
if (is_port_baremetal)
file(GLOB baremetal_generic_sources src/bare-metal-generic/*.cpp)
target_sources(rodos_rodos PRIVATE ${baremetal_generic_sources})
target_include_directories(rodos_rodos PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/bare-metal-generic>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/bare-metal-generic/ip/lwip/include>)
option(DISABLE_SLEEP_WHEN_IDLE "Do not go to sleep mode when idling" OFF)
if(DISABLE_SLEEP_WHEN_IDLE)
add_compile_definitions(DISABLE_SLEEP_WHEN_IDLE)
endif()
endif ()
#___________________________________________________________________
# optional extra files which are port dependent. See cmake/port/xxx.cmake
#___________________________________________________________________
if (compile_definitions)
target_compile_definitions(rodos_rodos PUBLIC ${compile_definitions})
endif ()
if (compile_options)
target_compile_options(rodos_rodos PUBLIC ${compile_options})
endif ()
if (link_options)
target_link_options(rodos_rodos PUBLIC ${link_options})
endif ()
if (sources_to_add)
file(GLOB files ${sources_to_add})
target_sources(rodos_rodos PRIVATE ${files})
endif ()
if (directories_to_include)
foreach(dir ${directories_to_include})
target_include_directories(rodos_rodos PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${dir}>)
endforeach()
endif ()
if (directories_to_link)
target_link_directories(rodos_rodos PUBLIC ${directories_to_link})
endif ()
if (libraries_to_link)
target_link_libraries(rodos_rodos PUBLIC ${libraries_to_link})
endif ()
if (linker_script)
target_link_options(rodos_rodos PUBLIC -T${linker_script})
endif()
option(EXECUTABLE "Build executables for RODOS tutorials" OFF)
if (EXECUTABLE)
include(cmake/executable.cmake)
add_subdirectory(tutorials)
endif ()
# Install rules
include(cmake/install-rules.cmake)
if (RODOS_DEVELOPER_MODE)
if (COVERAGE)
setup_lcov_coverage(
NAME coverage
LCOV_ARGS "--no-external")
message("Generate coverage report with 'make coverage_collect'")
add_custom_command(TARGET coverage_collect POST_BUILD
COMMAND sed -ie "s@SF:${CMAKE_CURRENT_SOURCE_DIR}/\\(.*\\)@SF:\\1@g"
${CMAKE_CURRENT_BINARY_DIR}/coverage.info
COMMENT "Changing paths in coverage.info to relative paths."
VERBATIM
)
endif ()
enable_testing()
add_subdirectory(test-suite)
option(UNIT_TESTS "Enable building unit tests" OFF)
if (UNIT_TESTS)
add_subdirectory(support/test)
endif ()
endif ()