1# SPDX-License-Identifier: Apache-2.0 2 3cmake_minimum_required(VERSION 3.13.1) 4find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 5 6project(auto_test) 7 8if(COMMAND_LINE_FLAGS MATCHES "ASAN") 9target_compile_options(app PRIVATE -fsanitize=address -fomit-frame-pointer) 10endif() 11 12FILE(GLOB app_sources 13 *.c 14 edhoc_integration_tests/*.c 15 oscore_integration_tests/*.c 16 oscore_unit_tests/*.c 17 oscore_latency_tests/*.c 18 mocks/*.c 19 ../externals/zcbor/src/*.c 20 ../externals/compact25519/src/c25519/*.c 21 ../externals/compact25519/src/*.c 22 ../externals/mbedtls/library/*.c 23 ../externals/tinycrypt/lib/source/*.c 24 ../test_vectors/*.c) 25target_sources(app PRIVATE ${app_sources}) 26 27include_directories( 28 . 29 ../inc 30 ../test_vectors 31 ../externals/zcbor/include 32 ../externals/mbedtls/library 33 ../externals/mbedtls/include 34 ../externals/mbedtls/include/mbedtls 35 ../externals/mbedtls/include/psa 36 ../externals/tinycrypt/lib/include) 37 38add_definitions( 39 -DMBEDTLS_CONFIG_FILE="mbedtls_config_uoscore_uedhoc.h" 40 -DUNIT_TEST 41 #-DDEBUG_PRINT 42 -DZCBOR_CANONICAL 43 #-DMEASURE_LATENCY_ON 44 #-DREPORT_STACK_USAGE 45) 46 47# The external static library that we are linking with does not know 48# how to build for this platform so we export all the flags used in 49# this zephyr build to the external build system. 50zephyr_get_include_directories_for_lang_as_string(C includes) 51zephyr_get_system_include_directories_for_lang_as_string(C system_includes) 52zephyr_get_compile_definitions_for_lang_as_string(C definitions) 53zephyr_get_compile_options_for_lang_as_string(C options) 54 55#message("C includes is: ${includes}") 56#message("C system_includes is: ${system_includes}") 57#message("C definitions is: ${definitions}") 58#message("C options is: ${options}") 59 60# To provide flags with west use COMMAND_LINE_FLAGS, e.g.: 61# west build -b native_posix -- -DCOMMAND_LINE_FLAGS="-DVLA" 62set(external_project_cflags 63 "${COMMAND_LINE_FLAGS} ${includes} ${definitions} ${options} ${system_includes}" 64) 65 66include(ExternalProject) 67 68# Add an external project to be able download and build the third 69# party library. In this case downloading is not necessary as it has 70# been committed to the repository. 71set(src_dir ${CMAKE_CURRENT_SOURCE_DIR}/..) 72set(build_dir ${CMAKE_CURRENT_BINARY_DIR}/uoscore_uedhoc) 73 74set(LIB_TEST_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../build) 75set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..) 76 77if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") 78 # https://www.gnu.org/software/make/manual/html_node/MAKE-Variable.html 79 set(submake "$(MAKE)") 80else() # Obviously no MAKEFLAGS. Let's hope a "make" can be found somewhere. 81 set(submake "make") 82endif() 83 84message("build_dir: ${build_dir}") 85message("CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}") 86message("CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}") 87message("LIB_TEST_LIB_DIR: ${LIB_TEST_LIB_DIR}") 88message("INCLUDE_DIR: ${INCLUDE_DIR}") 89 90ExternalProject_Add( 91 oscore_edhoc_project # Name for custom target 92 PREFIX ${build_dir} # Root dir for entire project 93 SOURCE_DIR ${src_dir} 94 BINARY_DIR ${src_dir} # This particular build system is invoked from the root 95 CONFIGURE_COMMAND "" # Skip configuring the project, e.g. with autoconf 96 BUILD_COMMAND 97 ${submake} 98 PREFIX=${build_dir} 99 CC=${CMAKE_C_COMPILER} 100 AR=${CMAKE_AR} 101 CFLAGS=${external_project_cflags} 102 INSTALL_COMMAND "" # This particular build system has no install command 103 BUILD_BYPRODUCTS ${build_dir}/libuoscore-uedhoc.a 104) 105 106# Create a wrapper CMake library that our app can link with 107add_library(test STATIC IMPORTED GLOBAL) 108add_dependencies( 109 test 110 oscore_edhoc_project 111) 112set_target_properties(test PROPERTIES IMPORTED_LOCATION ${build_dir}/libuoscore-uedhoc.a) 113target_include_directories(test INTERFACE 114 ${INCLUDE_DIR} 115) 116 117target_link_libraries(app PRIVATE test) 118