-
Notifications
You must be signed in to change notification settings - Fork 163
/
CMakeLists.txt
172 lines (149 loc) · 6.22 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
# Check if we are building a pico-sdk based project
# (or more exactly: if we just got included in a pico-sdk based project)
if (PICO_SDK_PATH)
# If so, load the relevant CMakeLists-file but don't do anything else
include(${CMAKE_CURRENT_LIST_DIR}/cmake/usePicoSDK.cmake)
return()
endif()
############################
# for non-RPi-Pico platforms
############################
cmake_minimum_required(VERSION 3.15)
# Set the project name to your project name
project(RF24Network C CXX)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/StandardProjectSettings.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/PreventInSourceBuilds.cmake)
# get library info from Arduino IDE's required library.properties file
include(${CMAKE_CURRENT_LIST_DIR}/cmake/GetLibInfo.cmake) # sets the variable LibTargetName
# detect any applicable external libs (like pigpio)
include(cmake/AutoConfig_RF24_DRIVER.cmake)
# Link this 'library' to set the c++ standard / compile-time options requested
add_library(${LibTargetName}_project_options INTERFACE)
target_compile_features(${LibTargetName}_project_options INTERFACE cxx_std_17)
add_compile_options(-Ofast -Wall)
# allow using CMake options to adjust RF24Network_config.h without modiying source code
option(RF24NETWORK_DEBUG "enable/disable general debugging output" OFF)
option(RF24NETWORK_DEBUG_MINIMAL "enable/disable minimal debugging output" OFF)
option(RF24NETWORK_DEBUG_ROUTING
"enable/disable debugging output related to transmission routing"
OFF
)
option(RF24NETWORK_DEBUG_FRAGMENTATION
"enable/disable debugging output related to message fragmentation"
OFF
)
option(RF24NETWORK_DEBUG_FRAGMENTATION_L2
"enable/disable debugging output related to fragmented messages' transmission success"
OFF
)
option(DISABLE_FRAGMENTATION "disable message fragmentation" OFF)
option(DISABLE_DYNAMIC_PAYLOADS "force usage of static payload size" OFF)
# detect CPU and add compiler flags accordingly
include(cmake/detectCPU.cmake)
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
option(ENABLE_BUILD_WITH_TIME_TRACE "Enable -ftime-trace to generate time tracing .json files on clang" OFF)
if(ENABLE_BUILD_WITH_TIME_TRACE)
add_compile_definitions(project_options INTERFACE -ftime-trace)
endif()
endif()
# Link this 'library' to use the warnings specified in CompilerWarnings.cmake
add_library(${LibTargetName}_project_warnings INTERFACE)
# enable cache system
include(${CMAKE_CURRENT_LIST_DIR}/cmake/Cache.cmake)
# standard compiler warnings
include(${CMAKE_CURRENT_LIST_DIR}/cmake/CompilerWarnings.cmake)
set_project_warnings(${LibTargetName}_project_warnings)
# setup CPack options
include(${CMAKE_CURRENT_LIST_DIR}/cmake/CPackInfo.cmake)
if(NOT DEFINED USE_RF24_LIB_SRC)
find_library(RF24 rf24 REQUIRED)
message(STATUS "using RF24 library: ${RF24}")
endif()
###########################
# create target for bulding the RF24Network lib
###########################
add_library(${LibTargetName} SHARED
RF24Network.cpp
)
target_include_directories(${LibTargetName} PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
if(DEFINED USE_RF24_LIB_SRC OR pybind11_FOUND OR SKBUILD)
message(STATUS "Building lib from RF24 source")
target_compile_definitions(${LibTargetName} PUBLIC USE_RF24_LIB_SRC)
if(NOT DEFINED RF24_LIB_PATH)
target_include_directories(${LibTargetName} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../RF24)
else()
target_include_directories(${LibTargetName} PUBLIC ${RF24_LIB_PATH})
endif()
target_link_libraries(${LibTargetName}
INTERFACE ${LibTargetName}_project_options
INTERFACE ${LibTargetName}_project_warnings
)
else()
target_link_libraries(${LibTargetName}
INTERFACE ${LibTargetName}_project_options
INTERFACE ${LibTargetName}_project_warnings
SHARED ${RF24}
)
endif()
set_target_properties(
${LibTargetName}
PROPERTIES
SOVERSION ${${LibName}_VERSION_MAJOR}
VERSION ${${LibName}_VERSION_STRING}
)
# assert the appropriate preprocessor macros for RF24Network_config.h
if(RF24NETWORK_DEBUG)
message(STATUS "RF24NETWORK_DEBUG asserted")
target_compile_definitions(${LibTargetName} PUBLIC RF24NETWORK_DEBUG)
endif()
if(RF24NETWORK_DEBUG_MINIMAL)
message(STATUS "RF24NETWORK_DEBUG_MINIMAL asserted")
target_compile_definitions(${LibTargetName} PUBLIC RF24NETWORK_DEBUG_MINIMAL)
endif()
if(RF24NETWORK_DEBUG_ROUTING)
message(STATUS "RF24NETWORK_DEBUG_ROUTING asserted")
target_compile_definitions(${LibTargetName} PUBLIC RF24NETWORK_DEBUG_ROUTING)
endif()
if(RF24NETWORK_DEBUG_FRAGMENTATION)
message(STATUS "RF24NETWORK_DEBUG_FRAGMENTATION asserted")
target_compile_definitions(${LibTargetName} PUBLIC RF24NETWORK_DEBUG_FRAGMENTATION)
endif()
if(RF24NETWORK_DEBUG_FRAGMENTATION_L2)
message(STATUS "RF24NETWORK_DEBUG_FRAGMENTATION_L2 asserted")
target_compile_definitions(${LibTargetName} PUBLIC RF24NETWORK_DEBUG_FRAGMENTATION_L2)
endif()
if(DISABLE_FRAGMENTATION)
message(STATUS "DISABLE_FRAGMENTATION asserted")
target_compile_definitions(${LibTargetName} PUBLIC DISABLE_FRAGMENTATION)
endif()
if(DISABLE_DYNAMIC_PAYLOADS)
message(STATUS "DISABLE_DYNAMIC_PAYLOADS asserted")
target_compile_definitions(${LibTargetName} PUBLIC DISABLE_DYNAMIC_PAYLOADS)
endif()
# for MAX_PAYLOAD_SIZE, we let the default be configured in source code
if(DEFINED MAX_PAYLOAD_SIZE) # don't use CMake's `option()` for this one
message(STATUS "MAX_PAYLOAD_SIZE set to ${MAX_PAYLOAD_SIZE}")
target_compile_definitions(${LibTargetName} PUBLIC MAX_PAYLOAD_SIZE=${MAX_PAYLOAD_SIZE})
endif()
if(DEFINED SLOW_ADDR_POLL_RESPONSE)
message(STATUS "SLOW_ADDR_POLL_RESPONSE set to ${SLOW_ADDR_POLL_RESPONSE}")
target_compile_definitions(${LibTargetName} PUBLIC SLOW_ADDR_POLL_RESPONSE=${SLOW_ADDR_POLL_RESPONSE})
endif()
###########################
# target install rules for the RF24Network lib
###########################
install(TARGETS ${LibTargetName}
DESTINATION lib
)
install(FILES
RF24Network.h
RF24Network_config.h
DESTINATION include/RF24Network
)
# CMAKE_CROSSCOMPILING is only TRUE when CMAKE_TOOLCHAIN_FILE is specified via CLI
if("${CMAKE_CROSSCOMPILING}" STREQUAL "FALSE")
install(CODE "message(STATUS \"Updating ldconfig\")")
install(CODE "execute_process(COMMAND ldconfig)")
endif()