forked from Open-Agriculture/AgIsoStack-plus-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
179 lines (158 loc) · 5.29 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
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)
# Make CTest available which adds the option BUILD_TESTING
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(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# Find packages required for Socket CAN
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()
# 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)
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")
add_subdirectory("examples/task_controller_client")
add_subdirectory("examples/guidance")
endif()
if(BUILD_TESTING)
find_package(GTest QUIET)
if(NOT GTest_FOUND)
# Find GoogleTest
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1)
# For Windows: Prevent overriding the parent project's compiler/linker
# settings
set(gtest_force_shared_crt
ON
CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
# For before CMAKE 3.20, GTest::gtest_main didn't exist, so add it in All
# linking to gtest should be done using the new GTest::gtest_main library
# for forward compatability
if(NOT TARGET GTest::gtest_main)
add_library(GTest::gtest_main ALIAS GTest::Main)
endif()
endif()
# For cmake<3.20 and older GTest
if(NOT TARGET GTest::gtest_main)
set_target_properties(GTest::Main PROPERTIES IMPORTED_GLOBAL TRUE)
add_library(GTest::gtest_main ALIAS GTest::Main)
endif()
# Set test source files
set(TEST_SRC
test/identifier_tests.cpp
test/diagnostic_protocol_tests.cpp
test/core_network_management_tests.cpp
test/virtual_can_plugin_tests.cpp
test/address_claim_tests.cpp
test/can_name_tests.cpp
test/hardware_interface_tests.cpp
test/vt_client_tests.cpp
test/language_command_interface_tests.cpp
test/tc_client_tests.cpp
test/ddop_tests.cpp
test/event_dispatcher_tests.cpp
test/isb_tests.cpp
test/cf_functionalities_tests.cpp
test/guidance_tests.cpp
test/speed_distance_message_tests.cpp
test/maintain_power_tests.cpp
test/vt_object_tests.cpp
test/nmea2000_message_tests.cpp)
add_executable(unit_tests ${TEST_SRC})
set_target_properties(
unit_tests
PROPERTIES CXX_STANDARD 14
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON)
target_link_libraries(
unit_tests
PRIVATE GTest::gtest_main ${PROJECT_NAME}::Isobus
${PROJECT_NAME}::HardwareIntegration ${PROJECT_NAME}::Utility)
include(GoogleTest)
gtest_discover_tests(unit_tests name_tests identifier_tests)
endif()
install(
TARGETS Isobus Utility HardwareIntegration
EXPORT isobusTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin)
# Install all the header files for all the libraries
install(
DIRECTORY isobus/include/
DESTINATION include
FILES_MATCHING
PATTERN "*.hpp")
install(
DIRECTORY hardware_integration/include/
DESTINATION include
FILES_MATCHING
PATTERN "*.hpp")
install(
DIRECTORY utility/include/
DESTINATION include
FILES_MATCHING
PATTERN "*.hpp")
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)