forked from Open-Agriculture/AgIsoStack-plus-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
157 lines (136 loc) · 4.9 KB
/
CMakeLists.txt
File metadata and controls
157 lines (136 loc) · 4.9 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
cmake_minimum_required(VERSION 3.16)
project(
isobus
VERSION 0.1
LANGUAGES CXX
DESCRIPTION
"A control function focused implementation of the major ISOBUS and J1939 transport layers"
)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(cmake/CheckHasStdThreads.cmake)
# Make CTest available and the BUILD_TESTING option (OFF by default)
option(BUILD_TESTING "Set to ON to enable building of tests from top level" OFF)
include(CTest)
if(BUILD_TESTING
AND NOT MSVC
AND NOT APPLE)
# Set --coverage flag for gcovr (SonarCloud)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
endif()
if(ESP_PLATFORM)
add_compile_options(-Wall -Wextra)
elseif(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
option(DISABLE_BUSLOAD_MONITORING "Disable CAN bus load monitoring" OFF)
option(
CAN_STACK_DISABLE_THREADS
"Set to ON to disable multi-threading, which removes the need for std::thread, std::mutex, and related libraries."
OFF)
# Disable threads if the toolchain doesn't support them
check_std_thread_support(STD_THREAD_SUPPORTED)
if(NOT STD_THREAD_SUPPORTED)
message(
WARNING
"C++ threading model is not supported. Setting CAN_STACK_DISABLE_THREADS to ON."
)
set(CAN_STACK_DISABLE_THREADS ON)
endif()
if(NOT CAN_STACK_DISABLE_THREADS AND NOT ARDUINO)
# Find packages required for Threading
set(THREADS_PREFER_PTHREAD_FLAG ON)
# ESP-IDF doesn't implement find_package(Threads) correctly (dec 2022)
if(NOT ESP_PLATFORM)
find_package(Threads REQUIRED)
endif()
endif()
# Fail build if code in our stack includes <thread>/<mutex> etc.
if(CAN_STACK_DISABLE_THREADS)
set(NO_STD_THREADS_DIR "${CMAKE_BINARY_DIR}/no_std_threads/include")
file(MAKE_DIRECTORY "${NO_STD_THREADS_DIR}")
set(_forbidden_headers
thread
mutex
shared_mutex
condition_variable
future
stop_token
barrier
latch
semaphore)
foreach(header IN LISTS _forbidden_headers)
file(
WRITE "${NO_STD_THREADS_DIR}/${header}"
"// Auto-generated by CMake when CAN_STACK_DISABLE_THREADS=ON
#error \"Forbidden header <${header}>: std threading is disabled in this build configuration.\"
")
endforeach()
endif()
# A handy function to prepend text to all elements in a list (useful for
# subdirectories)
function(prepend var prefix)
set(listVar "")
foreach(arg ${ARGN})
list(APPEND listVar "${prefix}/${arg}")
endforeach(arg)
set(${var}
"${listVar}"
PARENT_SCOPE)
endfunction(prepend)
# Add subdirectories
add_subdirectory("utility")
add_subdirectory("isobus")
add_subdirectory("hardware_integration")
option(BUILD_EXAMPLES "Set to ON to enable building of examples from top level"
OFF)
if(BUILD_EXAMPLES AND CAN_STACK_DISABLE_THREADS)
message(
WARNING
"You are trying to build examples while the isobus library is configured in single-threaded mode, examples cannot be built in this mode. The current build configuration is (BUILD_EXAMPLES == ON AND CAN_STACK_DISABLE_THREADS == ON), please change the configuration."
)
endif()
if(BUILD_EXAMPLES)
add_subdirectory("examples/transport_layer")
add_subdirectory("examples/diagnostic_protocol")
add_subdirectory("examples/pgn_requests")
add_subdirectory("examples/nmea2000/fast_packet_protocol")
add_subdirectory("examples/nmea2000/nmea2000_generator")
add_subdirectory("examples/nmea2000/nmea2000_parser")
add_subdirectory("examples/virtual_terminal/version3_object_pool")
add_subdirectory("examples/virtual_terminal/aux_functions")
add_subdirectory("examples/virtual_terminal/aux_inputs")
if(NOT CAN_STACK_DISABLE_THREADS)
# Cannot build without threading as vt server is multi-threaded
add_subdirectory("examples/virtual_terminal/iop_parser_tester")
add_subdirectory("examples/virtual_terminal/iop_load_tester")
endif()
add_subdirectory("examples/task_controller_client")
add_subdirectory("examples/task_controller_server")
add_subdirectory("examples/guidance")
add_subdirectory("examples/seeder_example")
endif()
if(BUILD_TESTING)
add_subdirectory("test")
endif()
if(ESP_PLATFORM)
return()
endif()
install(
EXPORT isobusTargets
FILE isobusTargets.cmake
NAMESPACE isobus::
DESTINATION lib/cmake/isobus)
configure_file(cmake/isobusConfig.cmake.in isobusConfig.cmake @ONLY)
write_basic_package_version_file(isobusConfigVersion.cmake
COMPATIBILITY SameMajorVersion)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/isobusConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/isobusConfigVersion.cmake"
DESTINATION lib/cmake/isobus)
set(CPACK_PACKAGE_CONTACT "delgrossoengineering@protonmail.com")
set(CPACK_DEBIAN_FILENAME DEB-DEFAULT)
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE
"https://github.com/Open-Agriculture/AgIsoStack-plus-plus")
set(CPACK_PACKAGE_VENDOR "Open-Agriculture")
set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE)
include(CPack)