-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
226 lines (182 loc) · 6.46 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#********************************************************************
# _ _ _
# _ __ | |_ _ | | __ _ | |__ ___
# | '__|| __|(_)| | / _` || '_ \ / __|
# | | | |_ _ | || (_| || |_) |\__ \
# |_| \__|(_)|_| \__,_||_.__/ |___/
#
# http://www.rt-labs.com
# Copyright 2022 rt-labs AB, Sweden. All rights reserved.
#
# See the file LICENSE.md distributed with this software for full
# license information.
#*******************************************************************/
cmake_minimum_required (VERSION 3.14)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/tools")
project (CLINK VERSION 1.12.0)
# Default settings if this is the main project
if (CMAKE_PROJECT_NAME STREQUAL CLINK)
# Create a compile_commands.json file for use with clang-tidy
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(CTest)
# Make option visible in ccmake, cmake-gui
option(BUILD_SHARED_LIBS "Build shared library" OFF)
option(BUILD_FUZZ "Build fuzz test" OFF)
# Default to release build with debug info
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage"
FORCE)
endif (NOT CMAKE_BUILD_TYPE)
# Default to installing in build directory
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${CLINK_BINARY_DIR}/install
CACHE PATH "Default install path" FORCE)
endif()
message(STATUS "Current build type is: ${CMAKE_BUILD_TYPE}")
message(STATUS "Current install path is: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "Building for ${CMAKE_SYSTEM_NAME}")
endif()
include(AddOsal)
include(GenerateExportHeader)
include(CMakeDependentOption)
include(GetGitRevision)
# Always use standard .o suffix
set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
set(LOG_STATE_VALUES "ON;OFF")
set(LOG_LEVEL_VALUES "DEBUG;INFO;WARNING;ERROR;FATAL")
set(LOG_LEVEL FATAL CACHE STRING "default log level")
set_property(CACHE LOG_LEVEL PROPERTY STRINGS ${LOG_LEVEL_VALUES})
set(CL_CLAL_LOG ON CACHE STRING "CLAL log")
set_property(CACHE CL_CLAL_LOG PROPERTY STRINGS ${LOG_STATE_VALUES})
set(CL_ETH_LOG ON CACHE STRING "ETH log")
set_property(CACHE CL_ETH_LOG PROPERTY STRINGS ${LOG_STATE_VALUES})
set(CL_CCIEFB_LOG ON CACHE STRING "CCIEFB log")
set_property(CACHE CL_CCIEFB_LOG PROPERTY STRINGS ${LOG_STATE_VALUES})
set(CL_SLMP_LOG ON CACHE STRING "SLMP log")
set_property(CACHE CL_SLMP_LOG PROPERTY STRINGS ${LOG_STATE_VALUES})
set(CL_LOG ON CACHE STRING "c-link log")
set_property(CACHE CL_LOG PROPERTY STRINGS ${LOG_STATE_VALUES})
set(CL_MAX_DIRECTORYPATH_SIZE "240"
CACHE STRING "Max directory path size, including termination")
set(CLS_MAX_OCCUPIED_STATIONS "4"
CACHE STRING "Max number of occupied slave stations. Allowed 1..16 Tests use 4.")
set(CLM_MAX_GROUPS "5"
CACHE STRING "Max number of groups. Allowed 1..64 Tests use 5.")
set(CLM_MAX_OCCUPIED_STATIONS_PER_GROUP "13"
CACHE STRING "Max number of occupied slave stations per group. Allowed 1..16 Tests use 13.")
set(CLM_MAX_NODE_SEARCH_DEVICES "20"
CACHE STRING "Max number of node search response stored in database")
# Generate version numbers
configure_file (
include/cl_version.h.in
${CLINK_BINARY_DIR}/include/cl_version.h
)
# Generate config options
configure_file (
include/cl_options.h.in
${CLINK_BINARY_DIR}/include/cl_options.h
)
# Add platform-dependent targets early, so they can be configured by
# platform
add_library(clink "")
if (CMAKE_PROJECT_NAME STREQUAL CLINK AND NOT BUILD_FUZZ)
add_executable(cl_sample_slave "")
add_executable(cl_sample_master "")
endif()
if (CMAKE_PROJECT_NAME STREQUAL CLINK AND BUILD_TESTING AND NOT BUILD_FUZZ)
add_executable(cl_test "")
endif()
if (CMAKE_PROJECT_NAME STREQUAL CLINK AND BUILD_FUZZ)
add_executable(cl_fuzz_slave_cyclic "")
add_executable(cl_fuzz_slave_slmp "")
add_executable(cl_fuzz_master_cyclic "")
add_executable(cl_fuzz_master_slmp "")
endif()
# Platform configuration
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${CMAKE_SYSTEM_NAME}.cmake)
generate_export_header(clink
BASE_NAME cl
EXPORT_FILE_NAME ${CLINK_BINARY_DIR}/include/cl_export.h
)
set_target_properties (clink
PROPERTIES
C_STANDARD 99
)
target_compile_features(clink PUBLIC c_std_99)
target_include_directories(clink
PUBLIC
$<BUILD_INTERFACE:${CLINK_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CLINK_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CLINK_BINARY_DIR}/src
src
)
target_link_libraries(clink PUBLIC osal)
install (
TARGETS clink
EXPORT ClinkConfig
)
install(
EXPORT ClinkConfig
DESTINATION cmake
)
install (FILES
include/cl_common.h
include/cls_api.h
include/clm_api.h
${CLINK_BINARY_DIR}/include/cl_export.h
${CLINK_BINARY_DIR}/include/cl_options.h
${CLINK_BINARY_DIR}/include/cl_version.h
DESTINATION include
)
add_subdirectory(src)
if (CMAKE_PROJECT_NAME STREQUAL CLINK AND NOT BUILD_FUZZ)
add_subdirectory(sample_apps)
endif()
if (CMAKE_PROJECT_NAME STREQUAL CLINK AND BUILD_TESTING AND NOT BUILD_FUZZ)
add_subdirectory(test)
include(AddGoogleTest)
add_gtest(cl_test)
# Create a HTML coverage report in <build>/coverage.html
find_program(GCOVR gcovr)
if (GCOVR AND CMAKE_BUILD_TYPE MATCHES "Coverage")
add_custom_target(coverage-report
COMMAND mkdir -p coverage_html
COMMAND ${GCOVR}
--html-details
--object-directory ${CLINK_BINARY_DIR}
--html-title "c-link test coverage report"
--html-medium-threshold 95
--html-high-threshold 100
--html-self-contained
--root ${CLINK_SOURCE_DIR}/src
--exclude ${CLINK_SOURCE_DIR}/src/ports
-o coverage_html/coverage.html
COMMENT "Generating coverage HTML report"
)
add_dependencies(coverage-report check)
endif()
endif()
if (CMAKE_PROJECT_NAME STREQUAL CLINK AND BUILD_FUZZ)
add_subdirectory(fuzz)
endif()
if (CMAKE_PROJECT_NAME STREQUAL CLINK AND NOT BUILD_FUZZ)
add_subdirectory(docs)
add_custom_target(codespell
COMMAND codespell
${CLINK_SOURCE_DIR}/include/
${CLINK_SOURCE_DIR}/docs/
${CLINK_SOURCE_DIR}/src/
${CLINK_SOURCE_DIR}/test/
--skip *mypy_cache*
COMMENT "Running spell check on source code"
)
endif()
include (InstallRequiredSystemLibraries)
set (CPACK_RESOURCE_FILE_LICENSE "${CLINK_SOURCE_DIR}/LICENSE.md")
set (CPACK_PACKAGE_CONTACT [email protected])
include (CPack)