Skip to content

Commit c06db64

Browse files
committed
cmake: Extract setting of defines in separate functions
The CMake function for setting the C defines for a target was getting bigger. It is now split into smaller functions.
1 parent 13ac3b6 commit c06db64

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

wakaama.cmake

+27-7
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ set(WAKAAMA_WITH_CONNECTION_IMPLEMENTATION
7676
)
7777
set_property(CACHE WAKAAMA_WITH_CONNECTION_IMPLEMENTATION PROPERTY STRINGS NONE PLAIN TINYDTLS TESTING)
7878

79-
# Set the defines for logging configuration
80-
function(set_defines target)
81-
# Mode
79+
# Set mode related defines for target
80+
function(set_defines_for_mode target)
8281
if(WAKAAMA_MODE_CLIENT)
8382
target_compile_definitions(${target} PUBLIC LWM2M_CLIENT_MODE)
8483
endif()
@@ -88,17 +87,21 @@ function(set_defines target)
8887
if(WAKAAMA_MODE_BOOTSTRAP_SERVER)
8988
target_compile_definitions(${target} PUBLIC LWM2M_BOOTSTRAP_SERVER_MODE)
9089
endif()
90+
endfunction()
9191

92-
# Client
92+
# Set client related defines for target
93+
function(set_defines_for_client target)
9394
if(WAKAAMA_CLIENT_INITIATED_BOOTSTRAP)
9495
target_compile_definitions(${target} PUBLIC LWM2M_BOOTSTRAP)
9596
endif()
9697

9798
if(WAKAAMA_CLIENT_LWM2M_V_1_0)
9899
target_compile_definitions(${target} PUBLIC LWM2M_VERSION_1_0)
99100
endif()
101+
endfunction()
100102

101-
# Data Types
103+
# Set data types related defines for target
104+
function(set_defines_for_datatypes target)
102105
if(WAKAMA_DATA_TLV)
103106
target_compile_definitions(${target} PUBLIC LWM2M_SUPPORT_TLV)
104107
endif()
@@ -117,15 +120,19 @@ function(set_defines target)
117120
if(WAKAAMA_DATA_OLD_CONTENT_FORMAT)
118121
target_compile_definitions(${target} PUBLIC LWM2M_OLD_CONTENT_FORMAT_SUPPORT)
119122
endif()
123+
endfunction()
120124

121-
# CoAP
125+
# Set CoAP related defines for target
126+
function(set_defines_for_coap target)
122127
if(WAKAAMA_RAW_BLOCK1_REQUESTS)
123128
target_compile_definitions(${target} PUBLIC LWM2M_RAW_BLOCK1_REQUESTS)
124129
endif()
125130

126131
target_compile_definitions(${target} PUBLIC LWM2M_COAP_DEFAULT_BLOCK_SIZE=${WAKAAMA_COAP_DEFAULT_BLOCK_SIZE})
132+
endfunction()
127133

128-
# Logging
134+
# Set logging related defines for target
135+
function(set_defines_for_logging target)
129136
target_compile_definitions(${target} PUBLIC LWM2M_LOG_LEVEL=LWM2M_${WAKAAMA_LOG_LEVEL})
130137

131138
if(WAKAAMA_LOG_CUSTOM_HANDLER)
@@ -135,6 +142,19 @@ function(set_defines target)
135142
target_compile_definitions(${target} PUBLIC LWM2M_LOG_MAX_MSG_TXT_SIZE=${WAKAAMA_LOG_MAX_MSG_TXT_SIZE})
136143
endfunction()
137144

145+
# Set the relevant defines for target
146+
function(set_defines target)
147+
set_defines_for_mode(target)
148+
149+
set_defines_for_client(target)
150+
151+
set_defines_for_datatypes(target)
152+
153+
set_defines_for_coap(target)
154+
155+
set_defines_for_logging(target)
156+
endfunction()
157+
138158
# Add data format source files to an existing target.
139159
#
140160
# Separated from target_sources_wakaama() for testability reasons.

0 commit comments

Comments
 (0)