2019-09-25 01:21:12 +03:00
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT
2020-03-10 23:54:43 +03:00
cmake_minimum_required ( VERSION 3.10 )
2019-10-10 03:27:16 +03:00
2020-04-30 01:26:50 +03:00
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake-modules" )
2020-02-28 02:59:10 +03:00
2019-12-14 09:10:47 +03:00
option ( WARNINGS_AS_ERRORS "Treat compiler warnings as errors" ON )
2020-05-13 01:03:45 +03:00
option ( TRANSPORT_CURL "Build internal http transport implementation with CURL for HTTP Pipeline" OFF )
2020-02-28 02:59:10 +03:00
option ( UNIT_TESTING "Build unit test projects" OFF )
2020-05-13 01:03:45 +03:00
option ( UNIT_TESTING_MOCKS "wrap PAL functions with mock implementation for tests" OFF )
2020-05-13 01:58:31 +03:00
option ( TRANSPORT_PAHO "Build IoT Samples with Paho MQTT support" OFF )
2020-05-13 01:03:45 +03:00
option ( PRECONDITIONS "Build SDK with preconditions enabled" ON )
2020-05-14 22:05:46 +03:00
option ( LOGGING "Build SDK with logging support" ON )
2022-07-06 01:32:22 +03:00
option ( ADDRESS_SANITIZER "Build with address sanitizer" OFF )
2020-04-16 01:05:30 +03:00
2022-09-14 20:51:35 +03:00
# vcpkg integration
include ( AzureVcpkg )
az_vcpkg_integrate ( )
2020-04-30 19:40:03 +03:00
# disable preconditions when it's set to OFF
2020-05-13 01:03:45 +03:00
if ( NOT PRECONDITIONS )
2020-05-20 01:45:28 +03:00
add_compile_definitions ( AZ_NO_PRECONDITION_CHECKING )
2020-04-16 01:05:30 +03:00
endif ( )
2020-03-12 22:04:19 +03:00
2020-05-14 22:05:46 +03:00
if ( NOT LOGGING )
2020-05-20 01:45:28 +03:00
add_compile_definitions ( AZ_NO_LOGGING )
2020-05-14 22:05:46 +03:00
endif ( )
2020-04-30 19:40:03 +03:00
# enable mock functions with link option -ld
2020-05-13 01:03:45 +03:00
if ( UNIT_TESTING_MOCKS )
2020-05-20 01:45:28 +03:00
add_compile_definitions ( _az_MOCK_ENABLED )
endif ( )
# make libcurl option enabled to be visible to code
if ( TRANSPORT_CURL )
add_compile_definitions ( TRANSPORT_CURL )
2020-03-12 22:04:19 +03:00
endif ( )
2019-12-14 09:10:47 +03:00
2019-09-20 21:40:56 +03:00
project ( az LANGUAGES C )
2019-09-25 01:21:12 +03:00
enable_testing ( )
2020-01-17 03:47:19 +03:00
2022-07-06 01:32:22 +03:00
include ( eng/cmake/global_compile_options.cmake )
2020-09-15 22:41:12 +03:00
include ( create_map_file )
2020-01-17 03:47:19 +03:00
2020-06-15 21:10:36 +03:00
# Include function for creating code coverage targets
include ( CreateCodeCoverageTargets )
2020-04-03 03:10:20 +03:00
# List of projects that generate coverage
# This write empty makes sure that if file is already there, we replace it for an empty one
# Then each project will APPEND to this file
# At the end of cmake generate, this file will list the targets for code cov
file ( WRITE ${ CMAKE_BINARY_DIR } /coverage_targets.txt "" )
2020-06-15 21:10:36 +03:00
# Determine platform to build
if ( AZ_PLATFORM_IMPL STREQUAL "WIN32" )
2020-05-20 01:45:28 +03:00
set ( PAL az_win32 )
2020-06-15 21:10:36 +03:00
elseif ( AZ_PLATFORM_IMPL STREQUAL "POSIX" )
set ( PAL az_posix )
2020-12-02 21:02:17 +03:00
elseif ( AZ_PLATFORM_IMPL STREQUAL "CUSTOM" )
if ( NOT DEFINED AZ_CUSTOM_PLATFORM_IMPL_NAME )
message ( FATAL_ERROR "When using AZ_PLATFORM_IMPL=CUSTOM, AZ_CUSTOM_PLATFORM_IMPL_NAME must be defined as well. See Readme." )
endif ( )
set ( PAL ${ AZ_CUSTOM_PLATFORM_IMPL_NAME } )
2020-05-16 01:52:54 +03:00
else ( )
2020-06-15 21:10:36 +03:00
#noplatform
2020-05-20 01:45:28 +03:00
set ( PAL az_noplatform )
endif ( )
2020-06-15 21:10:36 +03:00
add_subdirectory ( sdk/src/azure/core )
2020-06-13 03:03:25 +03:00
2020-06-15 21:10:36 +03:00
# SDK Clients
add_subdirectory ( sdk/src/azure/iot )
2020-06-13 03:03:25 +03:00
2020-06-15 21:10:36 +03:00
#PAL (Hardware + HTTP)
add_subdirectory ( sdk/src/azure/platform )
2020-02-13 22:42:12 +03:00
2020-02-26 01:44:29 +03:00
# User can disable samples generation by setting env variable AZ_SDK_C_NO_SAMPLES
2020-02-13 22:42:12 +03:00
if ( NOT DEFINED ENV{AZ_SDK_C_NO_SAMPLES} )
2020-05-13 01:58:31 +03:00
if ( TRANSPORT_PAHO )
2020-07-16 02:03:58 +03:00
add_subdirectory ( sdk/samples/iot )
2020-04-10 01:29:12 +03:00
endif ( )
2020-02-13 22:42:12 +03:00
endif ( )
2020-02-26 02:48:50 +03:00
2020-02-28 02:59:10 +03:00
# default for Unit testing with cmocka is OFF, however, this will be ON on CI and tests must
2020-07-28 23:48:47 +03:00
# pass before committing changes
2020-02-28 02:59:10 +03:00
if ( UNIT_TESTING )
2020-09-30 19:39:49 +03:00
# make generate step fail if cmocka dependency is not found
find_package ( cmocka CONFIG REQUIRED )
2022-07-06 01:32:22 +03:00
# Old versions of cmocka (including the latest stable) don't define an imported target
if ( NOT TARGET cmocka::cmocka )
2020-09-30 19:39:49 +03:00
set ( CMOCKA_LIB ${ CMOCKA_LIBRARIES } )
else ( )
set ( CMOCKA_LIB cmocka::cmocka )
endif ( )
# for gcc, we need to add no-clobbered compile opt to avoid warning about set-jump function
set ( NO_CLOBBERED_WARNING "" )
if ( CMAKE_C_COMPILER_ID MATCHES "GNU" )
set ( NO_CLOBBERED_WARNING "-Wno-clobbered" )
endif ( )
2020-10-02 05:24:31 +03:00
2020-06-15 21:10:36 +03:00
# Core
add_subdirectory ( sdk/tests/core )
# IoT
2022-08-02 00:20:31 +03:00
add_subdirectory ( sdk/tests/iot/adu )
2020-06-15 21:10:36 +03:00
add_subdirectory ( sdk/tests/iot/common )
add_subdirectory ( sdk/tests/iot/hub )
add_subdirectory ( sdk/tests/iot/provisioning )
2020-02-28 02:59:10 +03:00
endif ( )
2020-07-15 02:40:03 +03:00
# Fail generation when setting MOCKS ON without GCC
if ( UNIT_TESTING_MOCKS )
if ( UNIT_TESTING )
if ( NOT CMAKE_C_COMPILER_ID MATCHES "GNU" )
# Fail generation when asking for MOCK without GCC
message ( FATAL_ERROR "Unsupported Compiler Option.\nOption `UNIT_TESTING_MOCKS` is not supported on ${CMAKE_C_COMPILER_ID}. It is only supported by GNU gcc.\nRemove option `UNIT_TESTING_MOCKS` to build tests without using MOCK." )
endif ( )
else ( )
# Mention MOCK is ignored
message ( WARNING "UNIT_TESTING_MOCKS will be ignored because UNIT_TESTING is not enabled." )
endif ( )
endif ( )