| 1 |
#Copyright (c) Microsoft. All rights reserved. |
| 2 |
#Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 |
|
| 4 |
cmake_minimum_required (VERSION 3.5) |
| 5 |
|
| 6 |
if (TARGET aziotsharedutil) |
| 7 |
RETURN() |
| 8 |
endif() |
| 9 |
|
| 10 |
project(azure_c_shared_utility) |
| 11 |
|
| 12 |
FILE(READ ${CMAKE_CURRENT_LIST_DIR}/version.txt C_SHARED_VERSION) |
| 13 |
|
| 14 |
# Include the common build rules for the C SDK |
| 15 |
include(configs/azure_iot_build_rules.cmake) |
| 16 |
|
| 17 |
#the following variables are project-wide and can be used with cmake-gui |
| 18 |
option(run_unittests "set run_unittests to ON to run unittests (default is OFF)" OFF) |
| 19 |
option(skip_samples "set skip_samples to ON to skip building samples (default is OFF)[if possible, they are always built]" OFF) |
| 20 |
option(use_http "set use_http to ON if http is to be used, set to OFF to not use http" ON) |
| 21 |
option(use_condition "set use_condition to ON if the condition module and its adapters should be enabled" ON) |
| 22 |
option(use_wsio "set use_wsio to ON to build WebSockets support (default is ON)" ON) |
| 23 |
option(nuget_e2e_tests "set nuget_e2e_tests to ON to generate e2e tests to run with nuget packages (default is OFF)" OFF) |
| 24 |
option(use_installed_dependencies "set use_installed_dependencies to ON to use installed packages instead of building dependencies from submodules" OFF) |
| 25 |
option(use_default_uuid "set use_default_uuid to ON to use the out of the box UUID that comes with the SDK rather than platform specific implementations" OFF) |
| 26 |
option(run_e2e_tests "set run_e2e_tests to ON to run e2e tests (default is OFF). Chsare dutility does not have any e2e tests, but the option needs to exist to evaluate in IF statements" OFF) |
| 27 |
option(run_int_tests "set run_int_tests to ON to integration tests (default is OFF)." OFF) |
| 28 |
option(use_builtin_httpapi "set use_builtin_httpapi to ON to use the built-in httpapi_compact that comes with C shared utility (default is OFF)" OFF) |
| 29 |
option(use_cppunittest "set use_cppunittest to ON to build CppUnitTest tests on Windows (default is OFF)" OFF) |
| 30 |
option(suppress_header_searches "do not try to find headers - used when compiler check will fail" OFF) |
| 31 |
option(use_custom_heap "use externally defined heap functions instead of the malloc family" OFF) |
| 32 |
option(no_openssl_engine "Disables the use of ENGINEs in OpenSSL" OFF) |
| 33 |
option(enable_ipv6 "set enable_ipv6 to ON to enable dual-ip-stack (IPv4 and IPv6) support (default is OFF for IPv4 only)" OFF) |
| 34 |
|
| 35 |
if(${use_custom_heap}) |
| 36 |
add_definitions(-DGB_USE_CUSTOM_HEAP) |
| 37 |
endif() |
| 38 |
|
| 39 |
if (${enable_ipv6}) |
| 40 |
add_definitions(-DIPV6_ENABLED) |
| 41 |
endif() |
| 42 |
|
| 43 |
if(WIN32) |
| 44 |
option(use_schannel "set use_schannel to ON if schannel is to be used, set to OFF to not use schannel" ON) |
| 45 |
option(use_openssl "set use_openssl to ON if openssl is to be used, set to OFF to not use openssl" OFF) |
| 46 |
option(use_mbedtls "set use_mbedtls to ON if mbedtls is to be used, set to OFF to not use mbedtls" OFF) |
| 47 |
option(use_wolfssl "set use_wolfssl to ON if wolfssl is to be used, set to OFF to not use wolfssl" OFF) |
| 48 |
option(use_bearssl "set use_bearssl to ON if BearSSL is to be used, set to OFF to not use BearSSL" OFF) |
| 49 |
option(logerror_captures_stack_traces "LogError will make a reasonable attempt to capture the stack trace at the time of calling LogError. Only available on Windows" OFF) |
| 50 |
option(use_socketio "set use_socketio to ON if socketio is to be included in the library, set to OFF if a different implementation will be provided" ON) |
| 51 |
|
| 52 |
set(use_etw OFF CACHE STRING "set use_etw to OFF = No ETW logging, TRACELOGGING = Use ETW from tracelogging.h, TRACELOGGING_WITH_CONSOLE = Use ETW from tracelogging.h and call console logger. Default is OFF") |
| 53 |
set_property(CACHE use_etw PROPERTY STRINGS TRACELOGGING_WITH_CONSOLE TRACELOGGING OFF) |
| 54 |
|
| 55 |
else() |
| 56 |
option(use_schannel "set use_schannel to ON if schannel is to be used, set to OFF to not use schannel" OFF) |
| 57 |
if(DEFINED MACOSX) |
| 58 |
option(use_openssl "set use_openssl to ON if openssl is to be used, set to OFF to not use openssl" OFF) |
| 59 |
option(use_socketio "set use_socketio to ON if socketio is to be included in the library, set to OFF if a different implementation will be provided" OFF) |
| 60 |
else() |
| 61 |
option(use_openssl "set use_openssl to ON if openssl is to be used, set to OFF to not use openssl" ON) |
| 62 |
option(use_socketio "set use_socketio to ON if socketio is to be included in the library, set to OFF if a different implementation will be provided" ON) |
| 63 |
endif() |
| 64 |
option(use_mbedtls "set use_mbedtls to ON if mbedtls is to be used, set to OFF to not use mbedtls" OFF) |
| 65 |
option(use_wolfssl "set use_wolfssl to ON if wolfssl is to be used, set to OFF to not use wolfssl" OFF) |
| 66 |
option(use_bearssl "set use_bearssl to ON if BearSSL is to be used, set to OFF to not use BearSSL" OFF) |
| 67 |
option(use_c_ares "set use_c_ares to ON if c-ares is to be used, set to OFF to not use c-ares" OFF) |
| 68 |
endif() |
| 69 |
|
| 70 |
option(no_logging "disable logging (default is OFF)" OFF) |
| 71 |
|
| 72 |
# The options setting for use_socketio is not reliable. If openssl is used, make sure it's on, |
| 73 |
# and if apple tls is used then use_socketio must be off. |
| 74 |
if (DEFINED MACOSX) |
| 75 |
if (${use_openssl}) |
| 76 |
set(use_socketio ON) |
| 77 |
else() |
| 78 |
# MACOSX only has native tls and open ssl, so this must be the native apple tls |
| 79 |
set(use_applessl ON) |
| 80 |
set(use_socketio OFF) |
| 81 |
endif() |
| 82 |
endif() |
| 83 |
|
| 84 |
if(WIN32) |
| 85 |
|
| 86 |
if(${use_etw} STREQUAL "TRACELOGGING_WITH_CONSOLE") |
| 87 |
add_definitions(-DUSE_TRACELOGGING) |
| 88 |
add_definitions(-DCALL_CONSOLE_LOGGER) |
| 89 |
endif() #(${use_etw} STREQUAL "TRACELOGGING_WITH_CONSOLE") |
| 90 |
|
| 91 |
if(${use_etw} STREQUAL "TRACELOGGING") |
| 92 |
add_definitions(-DUSE_TRACELOGGING) |
| 93 |
endif() #(${use_etw} STREQUAL "TRACELOGGING") |
| 94 |
|
| 95 |
endif() |
| 96 |
|
| 97 |
if(${logerror_captures_stack_traces}) |
| 98 |
#set a preprocessor option (LOGERROR_CAPTURES_STACK_TRACES) and add the files that provide the functionality |
| 99 |
add_definitions(-DLOGERROR_CAPTURES_STACK_TRACES) |
| 100 |
set(LOGGING_STACKTRACE_C_FILE ./src/logging_stacktrace.c) |
| 101 |
set(LOGGING_STACKTRACE_H_FILE ./inc/azure_c_shared_utility/logging_stacktrace.h) |
| 102 |
else() |
| 103 |
set(LOGGING_STACKTRACE_C_FILE) |
| 104 |
set(LOGGING_STACKTRACE_H_FILE) |
| 105 |
endif() |
| 106 |
|
| 107 |
option(build_as_dynamic "build the C Shared libaries as shared" OFF) |
| 108 |
|
| 109 |
if(${memory_trace}) |
| 110 |
add_definitions(-DGB_MEASURE_MEMORY_FOR_THIS -DGB_DEBUG_ALLOC) |
| 111 |
add_definitions(-DGB_MEASURE_NETWORK_FOR_THIS -DGB_DEBUG_NETWORK) |
| 112 |
endif() |
| 113 |
|
| 114 |
if(${use_openssl}) |
| 115 |
if(${no_openssl_engine}) |
| 116 |
add_definitions(-DOPENSSL_NO_ENGINE) |
| 117 |
endif() |
| 118 |
|
| 119 |
if("${OPENSSL_ROOT_DIR}" STREQUAL "" AND NOT ("$ENV{OpenSSLDir}" STREQUAL "")) |
| 120 |
set(OPENSSL_ROOT_DIR $ENV{OpenSSLDir} CACHE PATH "") |
| 121 |
endif() |
| 122 |
|
| 123 |
# If OpenSSL::SSL OR OpenSSL::Crypto are not set then you need to run |
| 124 |
# the find package for openssl |
| 125 |
if (NOT TARGET OpenSSL::SSL OR NOT TARGET OpenSSL::Crypto OR NOT ${OPENSSL_INCLUDE_DIR}) |
| 126 |
find_package(OpenSSL REQUIRED) |
| 127 |
endif() |
| 128 |
|
| 129 |
# The block below enables the v1 back-compatibility layer in OpenSSL 3, |
| 130 |
# if using that version or later. For reference, please check the OpenSSL |
| 131 |
# official documentation: https://www.openssl.org/docs/man3.0/man7/openssl_user_macros.html |
| 132 |
if (DEFINED OPENSSL_VERSION AND (${OPENSSL_VERSION} GREATER_EQUAL 3)) |
| 133 |
add_definitions(-DOPENSSL_API_COMPAT=0x10101000L) |
| 134 |
endif() |
| 135 |
|
| 136 |
include_directories(${OPENSSL_INCLUDE_DIR}) |
| 137 |
endif() |
| 138 |
|
| 139 |
if(${use_applessl}) |
| 140 |
# MACOSX only has native tls and open ssl, so use the native apple tls |
| 141 |
find_library(cf_foundation Foundation) |
| 142 |
find_library(cf_network CFNetwork) |
| 143 |
endif() |
| 144 |
|
| 145 |
if(${no_logging}) |
| 146 |
add_definitions(-DNO_LOGGING) |
| 147 |
endif() |
| 148 |
# Start of variables used during install |
| 149 |
set (LIB_INSTALL_DIR lib CACHE PATH "Library object file directory") |
| 150 |
|
| 151 |
#Setup the platform files |
| 152 |
include("${CMAKE_CURRENT_LIST_DIR}/configs/azure_c_shared_utilityFunctions.cmake") |
| 153 |
set_platform_files(${CMAKE_CURRENT_LIST_DIR}) |
| 154 |
|
| 155 |
if(MSVC) |
| 156 |
if(${use_openssl}) |
| 157 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_OPENSSL") |
| 158 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_OPENSSL") |
| 159 |
endif() |
| 160 |
if(${use_mbedtls}) |
| 161 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_MBEDTLS") |
| 162 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_MBEDTLS") |
| 163 |
endif() |
| 164 |
if(${use_bearssl}) |
| 165 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BEARSSL") |
| 166 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_BEARSSL") |
| 167 |
endif() |
| 168 |
if(${use_wolfssl}) |
| 169 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_WOLFSSL") |
| 170 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_WOLFSSL") |
| 171 |
|
| 172 |
# Disables error if a bit-field is used on non-integer variable |
| 173 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /wd4214") |
| 174 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /wd4214") |
| 175 |
endif() |
| 176 |
elseif(LINUX) #LINUX OR APPLE |
| 177 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat=2 -Wformat-security") |
| 178 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat=2 -Wformat-security") |
| 179 |
if(${use_openssl}) |
| 180 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_OPENSSL") |
| 181 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_OPENSSL") |
| 182 |
endif() |
| 183 |
if(${use_mbedtls}) |
| 184 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_MBEDTLS") |
| 185 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_MBEDTLS") |
| 186 |
endif() |
| 187 |
if(${use_bearssl}) |
| 188 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BEARSSL") |
| 189 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_BEARSSL") |
| 190 |
endif() |
| 191 |
if(${use_wolfssl}) |
| 192 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_WOLFSSL") |
| 193 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_WOLFSSL") |
| 194 |
endif() |
| 195 |
# Turn off warning that can not be fixed right now |
| 196 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable -Wno-missing-braces -Wno-missing-field-initializers -Wno-format-nonliteral") |
| 197 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-variable -Wno-missing-braces -Wno-missing-field-initializers -Wno-format-nonliteral") |
| 198 |
elseif(APPLE) |
| 199 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wformat-security") |
| 200 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wformat-security") |
| 201 |
if(${use_openssl}) |
| 202 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_OPENSSL") |
| 203 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_OPENSSL") |
| 204 |
endif() |
| 205 |
if(${use_mbedtls}) |
| 206 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_MBEDTLS") |
| 207 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_MBEDTLS") |
| 208 |
endif() |
| 209 |
if(${use_wolfssl}) |
| 210 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_WOLFSSL") |
| 211 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_WOLFSSL") |
| 212 |
endif() |
| 213 |
endif() |
| 214 |
|
| 215 |
|
| 216 |
include_directories(${UMOCK_C_INC_FOLDER}) |
| 217 |
|
| 218 |
#these are the C source files |
| 219 |
set(source_c_files |
| 220 |
./src/azure_base32.c |
| 221 |
./src/azure_base64.c |
| 222 |
./src/buffer.c |
| 223 |
./src/constbuffer_array.c |
| 224 |
./src/constbuffer_array_batcher.c |
| 225 |
./src/connection_string_parser.c |
| 226 |
./src/constbuffer.c |
| 227 |
${LOGGING_C_FILE} |
| 228 |
./src/crt_abstractions.c |
| 229 |
./src/constmap.c |
| 230 |
./src/doublylinkedlist.c |
| 231 |
./src/gballoc.c |
| 232 |
./src/gbnetwork.c |
| 233 |
./src/gb_stdio.c |
| 234 |
./src/gb_time.c |
| 235 |
./src/hmac.c |
| 236 |
./src/hmacsha256.c |
| 237 |
./src/xio.c |
| 238 |
./src/singlylinkedlist.c |
| 239 |
./src/map.c |
| 240 |
./src/sastoken.c |
| 241 |
./src/sha1.c |
| 242 |
./src/sha224.c |
| 243 |
./src/sha384-512.c |
| 244 |
./src/strings.c |
| 245 |
./src/string_token.c |
| 246 |
./src/string_tokenizer.c |
| 247 |
./src/uuid.c |
| 248 |
./src/urlencode.c |
| 249 |
./src/usha.c |
| 250 |
./src/vector.c |
| 251 |
${XLOGGING_C_FILE} |
| 252 |
./src/optionhandler.c |
| 253 |
./src/memory_data.c |
| 254 |
./adapters/agenttime.c |
| 255 |
${CONDITION_C_FILE} |
| 256 |
${LOCK_C_FILE} |
| 257 |
${TIMER_C_FILE} |
| 258 |
${RANDOM_C_FILE} |
| 259 |
${STRING_UTILS_C_FILE} |
| 260 |
${PLATFORM_C_FILE} |
| 261 |
${SOCKETIO_C_FILE} |
| 262 |
${TICKCOUTER_C_FILE} |
| 263 |
${THREAD_C_FILE} |
| 264 |
${UNIQUEID_C_FILE} |
| 265 |
${ENVIRONMENT_VARIABLE_C_FILE} |
| 266 |
${LOGGING_STACKTRACE_C_FILE} |
| 267 |
${DNS_C_FILE} |
| 268 |
) |
| 269 |
|
| 270 |
if(UNIX) #LINUX OR APPLE |
| 271 |
set(source_c_files ${source_c_files} |
| 272 |
./adapters/linux_time.c |
| 273 |
) |
| 274 |
endif() |
| 275 |
|
| 276 |
if(${use_http}) |
| 277 |
set(source_c_files ${source_c_files} |
| 278 |
./src/httpapiex.c |
| 279 |
./src/httpapiexsas.c |
| 280 |
./src/httpheaders.c |
| 281 |
${HTTP_C_FILE} |
| 282 |
) |
| 283 |
add_definitions(-DUSE_HTTP) |
| 284 |
endif() |
| 285 |
|
| 286 |
if(${use_schannel}) |
| 287 |
set(source_c_files ${source_c_files} |
| 288 |
./adapters/tlsio_schannel.c |
| 289 |
./adapters/x509_schannel.c |
| 290 |
) |
| 291 |
endif() |
| 292 |
# If SocketIO isn't used, then we need to substitute stubs for HTTP Proxy |
| 293 |
# since it depends on SocketIO |
| 294 |
if(${use_socketio}) |
| 295 |
set(source_c_files ${source_c_files} |
| 296 |
./src/http_proxy_io.c |
| 297 |
) |
| 298 |
else() |
| 299 |
set(source_c_files ${source_c_files} |
| 300 |
./src/http_proxy_stub.c |
| 301 |
) |
| 302 |
endif() |
| 303 |
if(${use_wolfssl}) |
| 304 |
set(source_c_files ${source_c_files} |
| 305 |
./adapters/tlsio_wolfssl.c |
| 306 |
) |
| 307 |
endif() |
| 308 |
if(${use_mbedtls}) |
| 309 |
set(source_c_files ${source_c_files} |
| 310 |
./adapters/tlsio_mbedtls.c |
| 311 |
) |
| 312 |
endif() |
| 313 |
if(${use_bearssl}) |
| 314 |
set(source_c_files ${source_c_files} |
| 315 |
./adapters/tlsio_bearssl.c |
| 316 |
) |
| 317 |
endif() |
| 318 |
if(${use_openssl}) |
| 319 |
set(source_c_files ${source_c_files} |
| 320 |
./adapters/tlsio_openssl.c |
| 321 |
./adapters/x509_openssl.c |
| 322 |
) |
| 323 |
endif() |
| 324 |
if(${use_applessl}) |
| 325 |
set(source_c_files ${source_c_files} |
| 326 |
./pal/ios-osx/tlsio_appleios.c |
| 327 |
./pal/tlsio_options.c |
| 328 |
) |
| 329 |
include_directories(./pal/ios-osx/) |
| 330 |
endif() |
| 331 |
|
| 332 |
if (WIN32 AND ("${CMAKE_SYSTEM_VERSION}" VERSION_EQUAL "10.0.17763.0" OR "${CMAKE_SYSTEM_VERSION}" VERSION_GREATER "10.0.17763.0")) |
| 333 |
# Windows added support for UNIX domain sockets to the OS and SDK |
| 334 |
# in the Oct 2018 update (10.0.17763.0, aka RS5) |
| 335 |
add_definitions(-DAF_UNIX_ON_WINDOWS) |
| 336 |
endif() |
| 337 |
|
| 338 |
#these are the C headers |
| 339 |
set(source_h_files |
| 340 |
./inc/azure_c_shared_utility/agenttime.h |
| 341 |
./inc/azure_c_shared_utility/azure_base32.h |
| 342 |
./inc/azure_c_shared_utility/azure_base64.h |
| 343 |
./inc/azure_c_shared_utility/buffer_.h |
| 344 |
./inc/azure_c_shared_utility/constbuffer_array.h |
| 345 |
./inc/azure_c_shared_utility/constbuffer_array_batcher.h |
| 346 |
./inc/azure_c_shared_utility/connection_string_parser.h |
| 347 |
./inc/azure_c_shared_utility/crt_abstractions.h |
| 348 |
./inc/azure_c_shared_utility/constmap.h |
| 349 |
./inc/azure_c_shared_utility/condition.h |
| 350 |
./inc/azure_c_shared_utility/const_defines.h |
| 351 |
${LOGGING_H_FILE} |
| 352 |
./inc/azure_c_shared_utility/doublylinkedlist.h |
| 353 |
./inc/azure_c_shared_utility/envvariable.h |
| 354 |
./inc/azure_c_shared_utility/gballoc.h |
| 355 |
./inc/azure_c_shared_utility/gbnetwork.h |
| 356 |
./inc/azure_c_shared_utility/gb_stdio.h |
| 357 |
./inc/azure_c_shared_utility/gb_time.h |
| 358 |
./inc/azure_c_shared_utility/hmac.h |
| 359 |
./inc/azure_c_shared_utility/hmacsha256.h |
| 360 |
./inc/azure_c_shared_utility/http_proxy_io.h |
| 361 |
./inc/azure_c_shared_utility/singlylinkedlist.h |
| 362 |
./inc/azure_c_shared_utility/lock.h |
| 363 |
./inc/azure_c_shared_utility/map.h |
| 364 |
./inc/azure_c_shared_utility/optimize_size.h |
| 365 |
./inc/azure_c_shared_utility/platform.h |
| 366 |
./inc/azure_c_shared_utility/refcount.h |
| 367 |
./inc/azure_c_shared_utility/sastoken.h |
| 368 |
./inc/azure_c_shared_utility/sha-private.h |
| 369 |
./inc/azure_c_shared_utility/shared_util_options.h |
| 370 |
./inc/azure_c_shared_utility/sha.h |
| 371 |
./inc/azure_c_shared_utility/socketio.h |
| 372 |
./inc/azure_c_shared_utility/stdint_ce6.h |
| 373 |
./inc/azure_c_shared_utility/strings.h |
| 374 |
./inc/azure_c_shared_utility/strings_types.h |
| 375 |
./inc/azure_c_shared_utility/string_token.h |
| 376 |
./inc/azure_c_shared_utility/string_tokenizer.h |
| 377 |
./inc/azure_c_shared_utility/string_tokenizer_types.h |
| 378 |
./inc/azure_c_shared_utility/string_utils.h |
| 379 |
./inc/azure_c_shared_utility/tlsio_options.h |
| 380 |
./inc/azure_c_shared_utility/tickcounter.h |
| 381 |
./inc/azure_c_shared_utility/threadapi.h |
| 382 |
./inc/azure_c_shared_utility/xio.h |
| 383 |
./inc/azure_c_shared_utility/uniqueid.h |
| 384 |
./inc/azure_c_shared_utility/uuid.h |
| 385 |
./inc/azure_c_shared_utility/urlencode.h |
| 386 |
./inc/azure_c_shared_utility/vector.h |
| 387 |
./inc/azure_c_shared_utility/vector_types.h |
| 388 |
./inc/azure_c_shared_utility/vector_types_internal.h |
| 389 |
./inc/azure_c_shared_utility/xlogging.h |
| 390 |
./inc/azure_c_shared_utility/constbuffer.h |
| 391 |
./inc/azure_c_shared_utility/tlsio.h |
| 392 |
./inc/azure_c_shared_utility/optionhandler.h |
| 393 |
./inc/azure_c_shared_utility/memory_data.h |
| 394 |
./inc/azure_c_shared_utility/safe_math.h |
| 395 |
${LOGGING_STACKTRACE_H_FILE} |
| 396 |
) |
| 397 |
|
| 398 |
if(UNIX) #LINUX OR APPLE |
| 399 |
set(source_h_files ${source_h_files} |
| 400 |
./adapters/linux_time.h |
| 401 |
) |
| 402 |
endif() |
| 403 |
|
| 404 |
if(${use_wsio}) |
| 405 |
set(source_h_files ${source_h_files} |
| 406 |
./inc/azure_c_shared_utility/wsio.h |
| 407 |
./inc/azure_c_shared_utility/uws_client.h |
| 408 |
./inc/azure_c_shared_utility/uws_frame_encoder.h |
| 409 |
./inc/azure_c_shared_utility/utf8_checker.h |
| 410 |
./inc/azure_c_shared_utility/ws_url.h |
| 411 |
) |
| 412 |
set(source_c_files ${source_c_files} |
| 413 |
./src/wsio.c |
| 414 |
./src/uws_client.c |
| 415 |
./src/uws_frame_encoder.c |
| 416 |
./src/utf8_checker.c |
| 417 |
./src/ws_url.c |
| 418 |
) |
| 419 |
endif() |
| 420 |
|
| 421 |
if(${use_http}) |
| 422 |
set(source_h_files ${source_h_files} |
| 423 |
./inc/azure_c_shared_utility/httpapi.h |
| 424 |
./inc/azure_c_shared_utility/httpapiex.h |
| 425 |
./inc/azure_c_shared_utility/httpapiexsas.h |
| 426 |
./inc/azure_c_shared_utility/httpheaders.h |
| 427 |
) |
| 428 |
endif() |
| 429 |
|
| 430 |
if(${use_schannel}) |
| 431 |
set(source_h_files ${source_h_files} |
| 432 |
./inc/azure_c_shared_utility/tlsio_schannel.h |
| 433 |
./inc/azure_c_shared_utility/x509_schannel.h |
| 434 |
) |
| 435 |
endif() |
| 436 |
|
| 437 |
if(${use_wolfssl}) |
| 438 |
set(source_h_files ${source_h_files} |
| 439 |
./inc/azure_c_shared_utility/tlsio_wolfssl.h |
| 440 |
) |
| 441 |
if(WIN32) |
| 442 |
include_directories($ENV{WolfSSLDir}) |
| 443 |
endif() |
| 444 |
endif() |
| 445 |
if(${use_mbedtls}) |
| 446 |
set(source_h_files ${source_h_files} |
| 447 |
./inc/azure_c_shared_utility/tlsio_mbedtls.h |
| 448 |
) |
| 449 |
endif() |
| 450 |
if(${use_openssl}) |
| 451 |
set(source_h_files ${source_h_files} |
| 452 |
./inc/azure_c_shared_utility/tlsio_openssl.h |
| 453 |
./inc/azure_c_shared_utility/x509_openssl.h |
| 454 |
) |
| 455 |
endif() |
| 456 |
if(${use_applessl}) |
| 457 |
set(source_h_files ${source_h_files} |
| 458 |
./pal/ios-osx/tlsio_appleios.h |
| 459 |
) |
| 460 |
include_directories(./pal/ios-osx/) |
| 461 |
endif() |
| 462 |
if(${use_bearssl}) |
| 463 |
set(source_h_files ${source_h_files} |
| 464 |
./inc/azure_c_shared_utility/tlsio_bearssl.h |
| 465 |
) |
| 466 |
endif() |
| 467 |
FILE(GLOB aziotsharedutil_md_files "devdoc/*.md") |
| 468 |
SOURCE_GROUP(devdoc FILES ${aziotsharedutil_md_files}) |
| 469 |
|
| 470 |
# Add ignore deprecated functions so we may use 1.1.1 APIs |
| 471 |
# in OpenSSL 3 |
| 472 |
if(DEFINED LINUX OR DEFINED MACOSX) |
| 473 |
set_property( |
| 474 |
SOURCE |
| 475 |
${CMAKE_CURRENT_LIST_DIR}/adapters/tlsio_openssl.c |
| 476 |
${CMAKE_CURRENT_LIST_DIR}/adapters/x509_openssl.c |
| 477 |
${CMAKE_CURRENT_LIST_DIR}/adapters/httpapi_curl.c |
| 478 |
PROPERTY COMPILE_OPTIONS |
| 479 |
-Wno-deprecated-declarations |
| 480 |
) |
| 481 |
endif() |
| 482 |
|
| 483 |
#this is the product (a library) |
| 484 |
add_library(aziotsharedutil ${source_c_files} ${source_h_files} ${aziotsharedutil_md_files}) |
| 485 |
setTargetBuildProperties(aziotsharedutil) |
| 486 |
|
| 487 |
target_include_directories(aziotsharedutil PUBLIC $<BUILD_INTERFACE:${SHARED_UTIL_INC_FOLDER}>) |
| 488 |
|
| 489 |
if(MSVC) |
| 490 |
set(source_h_files ${source_h_files} |
| 491 |
./pal/windows/refcount_os.h |
| 492 |
) |
| 493 |
target_include_directories(aziotsharedutil PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>$<BUILD_INTERFACE:${SHARED_UTIL_FOLDER}/pal/windows>) |
| 494 |
else() |
| 495 |
set(source_h_files ${source_h_files} |
| 496 |
./pal/linux/refcount_os.h |
| 497 |
) |
| 498 |
target_include_directories(aziotsharedutil PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>$<BUILD_INTERFACE:${SHARED_UTIL_FOLDER}/pal/linux>) |
| 499 |
endif() |
| 500 |
|
| 501 |
|
| 502 |
if(${build_as_dynamic}) |
| 503 |
# need to create a def file from existing def files due to cmake |
| 504 |
# not letting us build more than one file |
| 505 |
file(READ ./src/aziotsharedutil.def DEF_FILE_CONTENT) |
| 506 |
file(WRITE "${CMAKE_BINARY_DIR}/shared_util.def" ${DEF_FILE_CONTENT}) |
| 507 |
file(READ ./src/aziotsharedutil_http.def DEF_FILE_CONTENT) |
| 508 |
file(APPEND "${CMAKE_BINARY_DIR}/shared_util.def" ${DEF_FILE_CONTENT}) |
| 509 |
file(READ ./src/aziotsharedutil_wsio.def DEF_FILE_CONTENT) |
| 510 |
file(APPEND "${CMAKE_BINARY_DIR}/shared_util.def" ${DEF_FILE_CONTENT}) |
| 511 |
|
| 512 |
set(def_files "${CMAKE_BINARY_DIR}/shared_util.def") |
| 513 |
|
| 514 |
#make sure we can link as dll/so |
| 515 |
add_library(aziotsharedutil_dll SHARED |
| 516 |
${source_c_files} |
| 517 |
${source_h_files} |
| 518 |
${def_files} |
| 519 |
) |
| 520 |
set_target_properties(aziotsharedutil_dll PROPERTIES OUTPUT_NAME "aziotsharedutil_dll") |
| 521 |
endif() |
| 522 |
|
| 523 |
set(aziotsharedutil_target_libs) |
| 524 |
|
| 525 |
if(${logerror_captures_stack_traces}) |
| 526 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} Dbghelp.lib) |
| 527 |
endif() |
| 528 |
|
| 529 |
if(${use_http}) |
| 530 |
if(WIN32) |
| 531 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} crypt32 winhttp) |
| 532 |
else() |
| 533 |
if (NOT use_builtin_httpapi) |
| 534 |
|
| 535 |
# try CMake find_package first |
| 536 |
find_package(CURL) |
| 537 |
|
| 538 |
# As mentioned at https://cmake.org/Wiki/CMake_Cross_Compiling the |
| 539 |
# pkg-config tool can not be used by cmake while cross compiling. |
| 540 |
if (NOT CMAKE_CROSSCOMPILING) |
| 541 |
# if find_package didn't work, try pkg-config |
| 542 |
if(NOT CURL_FOUND) |
| 543 |
find_package(PkgConfig) |
| 544 |
if(PKG_CONFIG_FOUND) |
| 545 |
pkg_check_modules(CURL libcurl) |
| 546 |
endif() |
| 547 |
endif() |
| 548 |
endif() |
| 549 |
|
| 550 |
set(CURL_FIND_REQUIRED 1) |
| 551 |
find_package_handle_standard_args(CURL DEFAULT_MSG CURL_LIBRARIES) |
| 552 |
|
| 553 |
include_directories(${CURL_INCLUDE_DIRS}) |
| 554 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} ${CURL_LIBRARIES}) |
| 555 |
endif(NOT use_builtin_httpapi) |
| 556 |
endif() |
| 557 |
endif(${use_http}) |
| 558 |
|
| 559 |
if(${use_schannel}) |
| 560 |
if(WIN32) |
| 561 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} crypt32 ws2_32 secur32 advapi32 ncrypt) |
| 562 |
endif() |
| 563 |
endif() |
| 564 |
|
| 565 |
if(${use_mbedtls}) |
| 566 |
if (WIN32) |
| 567 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} ws2_32 |
| 568 |
$ENV{mbedtlsLibDir}/mbedtls.lib |
| 569 |
$ENV{mbedtlsLibDir}/mbedx509.lib |
| 570 |
$ENV{mbedtlsLibDir}/mbedcrypto.lib |
| 571 |
) |
| 572 |
include_directories("$ENV{mbedtlsDir}/include") |
| 573 |
else() |
| 574 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} mbedtls mbedx509 mbedcrypto) |
| 575 |
endif() |
| 576 |
endif() |
| 577 |
|
| 578 |
if(${use_bearssl}) |
| 579 |
if (WIN32) |
| 580 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} |
| 581 |
$ENV{bearsslDir}/build/bearssls.lib |
| 582 |
) |
| 583 |
include_directories("$ENV{bearsslDir}/inc") |
| 584 |
else() |
| 585 |
include_directories($ENV{bearsslDir}/inc) |
| 586 |
link_directories($ENV{bearsslDir}/build) |
| 587 |
find_library(bearssl bearssl $ENV{bearsslDir}/build/) |
| 588 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} ${bearssl}) |
| 589 |
endif() |
| 590 |
endif() |
| 591 |
|
| 592 |
if(${use_openssl}) |
| 593 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} ${OPENSSL_LIBRARIES}) |
| 594 |
if (WIN32) |
| 595 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} crypt32 ws2_32 secur32) |
| 596 |
endif() |
| 597 |
endif() |
| 598 |
|
| 599 |
if(${use_wolfssl}) |
| 600 |
if (WIN32) |
| 601 |
if (CMAKE_BUILD_TYPE EQUAL "DEBUG") |
| 602 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} $ENV{WolfSSLDir}/Debug/wolfssl.lib) |
| 603 |
else() |
| 604 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} $ENV{WolfSSLDir}/Release/wolfssl.lib) |
| 605 |
endif() |
| 606 |
else() |
| 607 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} wolfssl) |
| 608 |
endif() |
| 609 |
endif() |
| 610 |
|
| 611 |
|
| 612 |
if(${use_applessl}) |
| 613 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} ${cf_foundation} ${cf_network}) |
| 614 |
endif() |
| 615 |
|
| 616 |
if(WIN32) |
| 617 |
if (NOT ${use_default_uuid}) |
| 618 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} rpcrt4.lib) |
| 619 |
endif() |
| 620 |
endif() |
| 621 |
|
| 622 |
if(LINUX) |
| 623 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} pthread m rt) |
| 624 |
if (NOT ${use_default_uuid}) |
| 625 |
if(APPLE) |
| 626 |
find_package(PkgConfig REQUIRED) |
| 627 |
pkg_search_module(UUID REQUIRED uuid) |
| 628 |
link_directories(${UUID_LIBRARY_DIRS}) |
| 629 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} -L${UUID_LIBRARY_DIRS} ${UUID_LIBRARIES}) |
| 630 |
else() |
| 631 |
if (DEFINED UUID_INCLUDE_DIR) |
| 632 |
include_directories(${UUID_INCLUDE_DIR}) |
| 633 |
endif() |
| 634 |
|
| 635 |
if (DEFINED UUID_LIBRARY_DIRS) |
| 636 |
link_directories(${UUID_LIBRARY_DIRS}) |
| 637 |
endif() |
| 638 |
|
| 639 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} uuid) |
| 640 |
endif() |
| 641 |
endif() |
| 642 |
if(${use_c_ares}) |
| 643 |
set(aziotsharedutil_target_libs ${aziotsharedutil_target_libs} cares) |
| 644 |
endif() |
| 645 |
endif() |
| 646 |
|
| 647 |
target_link_libraries(aziotsharedutil ${aziotsharedutil_target_libs}) |
| 648 |
if(${build_as_dynamic}) |
| 649 |
target_link_libraries(aziotsharedutil_dll ${aziotsharedutil_target_libs}) |
| 650 |
endif() |
| 651 |
|
| 652 |
set(original_run_e2e_tests ${run_e2e_tests}) |
| 653 |
set(original_run_unittests ${run_unittests}) |
| 654 |
set(original_run_int_tests ${run_int_tests}) |
| 655 |
|
| 656 |
set(run_e2e_tests OFF) |
| 657 |
set(run_unittests OFF) |
| 658 |
set(run_int_tests OFF) |
| 659 |
|
| 660 |
include(dependencies.cmake) |
| 661 |
|
| 662 |
if (${original_run_unittests} OR ${original_run_e2e_tests}) |
| 663 |
include("${CMAKE_CURRENT_LIST_DIR}/dependencies-test.cmake") |
| 664 |
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/testtools) |
| 665 |
|
| 666 |
setTargetBuildProperties(ctest) |
| 667 |
setTargetBuildProperties(testrunnerswitcher) |
| 668 |
setTargetBuildProperties(umock_c) |
| 669 |
endif() |
| 670 |
|
| 671 |
set(run_e2e_tests ${original_run_e2e_tests}) |
| 672 |
set(run_unittests ${original_run_unittests}) |
| 673 |
set(run_int_tests ${original_run_int_tests}) |
| 674 |
|
| 675 |
include_directories(${MACRO_UTILS_INC_FOLDER}) |
| 676 |
include_directories(${UMOCK_C_INC_FOLDER}) |
| 677 |
|
| 678 |
if (${run_unittests} OR ${run_int_tests}) |
| 679 |
add_subdirectory(tests) |
| 680 |
endif() |
| 681 |
|
| 682 |
function(FindDllFromLib var libFile) |
| 683 |
get_filename_component(_libName ${libFile} NAME_WE) |
| 684 |
get_filename_component(_libDir ${libFile} DIRECTORY) |
| 685 |
|
| 686 |
while(NOT ("${_libDir}" STREQUAL "")) |
| 687 |
file(GLOB_RECURSE _dllList "${_libDir}/${_libName}.dll") |
| 688 |
list(LENGTH _dllList _listLen) |
| 689 |
if(${_listLen} GREATER 0) |
| 690 |
list(GET _dllList 0 _dll) |
| 691 |
set(${var} "${_dll}" PARENT_SCOPE) |
| 692 |
break() |
| 693 |
endif() |
| 694 |
get_filename_component(_libDir ${_libDir} DIRECTORY) |
| 695 |
endwhile() |
| 696 |
endfunction() |
| 697 |
|
| 698 |
if (NOT ${skip_samples}) |
| 699 |
if(${use_openssl} AND WIN32) |
| 700 |
FindDllFromLib(SSL_DLL "${OPENSSL_SSL_LIBRARY}") |
| 701 |
FindDllFromLib(CRYPTO_DLL "${OPENSSL_CRYPTO_LIBRARY}") |
| 702 |
endif() |
| 703 |
add_subdirectory(samples) |
| 704 |
endif() |
| 705 |
|
| 706 |
# Set CMAKE_INSTALL_* if not defined |
| 707 |
include(GNUInstallDirs) |
| 708 |
|
| 709 |
|
| 710 |
# Install Azure C Shared Utility |
| 711 |
if(NOT DEFINED CMAKE_INSTALL_LIBDIR) |
| 712 |
set(CMAKE_INSTALL_LIBDIR "lib") |
| 713 |
endif() |
| 714 |
|
| 715 |
set(package_location "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") |
| 716 |
|
| 717 |
if(${build_as_dynamic}) |
| 718 |
set(targets aziotsharedutil aziotsharedutil_dll) |
| 719 |
else(${build_as_dynamic}) |
| 720 |
set(targets aziotsharedutil) |
| 721 |
endif(${build_as_dynamic}) |
| 722 |
|
| 723 |
install (TARGETS ${targets} EXPORT aziotsharedutilTargets |
| 724 |
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 725 |
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 726 |
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 727 |
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/azureiot |
| 728 |
) |
| 729 |
install (FILES ${source_h_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/azure_c_shared_utility) |
| 730 |
install (FILES ${micromock_h_files_full_path} ${INSTALL_H_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/azureiot) |
| 731 |
|
| 732 |
|
| 733 |
include(CMakePackageConfigHelpers) |
| 734 |
|
| 735 |
write_basic_package_version_file( |
| 736 |
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake" |
| 737 |
VERSION ${C_SHARED_VERSION} |
| 738 |
COMPATIBILITY SameMajorVersion |
| 739 |
) |
| 740 |
|
| 741 |
configure_file("configs/${PROJECT_NAME}Config.cmake" |
| 742 |
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake" |
| 743 |
COPYONLY |
| 744 |
) |
| 745 |
|
| 746 |
install(EXPORT aziotsharedutilTargets |
| 747 |
FILE |
| 748 |
"${PROJECT_NAME}Targets.cmake" |
| 749 |
DESTINATION |
| 750 |
${package_location} |
| 751 |
) |
| 752 |
|
| 753 |
install( |
| 754 |
FILES |
| 755 |
"configs/${PROJECT_NAME}Config.cmake" |
| 756 |
"configs/${PROJECT_NAME}Functions.cmake" |
| 757 |
"configs/azure_iot_build_rules.cmake" |
| 758 |
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake" |
| 759 |
DESTINATION |
| 760 |
${package_location} |
| 761 |
) |
| 762 |
|
| 763 |
compileTargetAsC99(aziotsharedutil) |