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 8FILE(GLOB app_sources 9 *.c 10 edhoc_integration_tests/*.c 11 oscore_integration_tests/*.c 12 oscore_unit_tests/*.c 13 mocks/*.c 14 ../externals/zcbor/src/*.c 15 ../externals/compact25519/src/c25519/*.c 16 ../externals/compact25519/src/*.c 17 ../externals/mbedtls/library/*.c) 18target_sources(app PRIVATE ${app_sources}) 19 20include_directories( 21 ../inc 22 ../test_vectors 23 ../externals/zcbor/include 24 ../externals/mbedtls/library 25 ../externals/mbedtls/include 26 ../externals/mbedtls/include/mbedtls 27 ../externals/mbedtls/include/psa) 28 29add_definitions( 30 -DUNIT_TEST 31 -DDEBUG_PRINT 32 -DZCBOR_CANONICAL 33) 34 35# The external static library that we are linking with does not know 36# how to build for this platform so we export all the flags used in 37# this zephyr build to the external build system. 38zephyr_get_include_directories_for_lang_as_string(C includes) 39zephyr_get_system_include_directories_for_lang_as_string(C system_includes) 40zephyr_get_compile_definitions_for_lang_as_string(C definitions) 41zephyr_get_compile_options_for_lang_as_string(C options) 42 43set(external_project_cflags 44 "${includes} ${definitions} ${options} ${system_includes}" 45) 46 47include(ExternalProject) 48 49# Add an external project to be able download and build the third 50# party library. In this case downloading is not necessary as it has 51# been committed to the repository. 52set(src_dir ${CMAKE_CURRENT_SOURCE_DIR}/..) 53set(build_dir ${CMAKE_CURRENT_BINARY_DIR}/uoscore_uedhoc) 54 55set(LIB_TEST_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../build) 56set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..) 57 58if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") 59 # https://www.gnu.org/software/make/manual/html_node/MAKE-Variable.html 60 set(submake "$(MAKE)") 61else() # Obviously no MAKEFLAGS. Let's hope a "make" can be found somewhere. 62 set(submake "make") 63endif() 64 65message("build_dir: ${build_dir}") 66message("CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}") 67message("CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}") 68message("LIB_TEST_LIB_DIR: ${LIB_TEST_LIB_DIR}") 69message("INCLUDE_DIR: ${INCLUDE_DIR}") 70 71ExternalProject_Add( 72 oscore_edhoc_project # Name for custom target 73 PREFIX ${build_dir} # Root dir for entire project 74 SOURCE_DIR ${src_dir} 75 BINARY_DIR ${src_dir} # This particular build system is invoked from the root 76 CONFIGURE_COMMAND "" # Skip configuring the project, e.g. with autoconf 77 BUILD_COMMAND 78 ${submake} 79 PREFIX=${build_dir} 80 CC=${CMAKE_C_COMPILER} 81 AR=${CMAKE_AR} 82 CFLAGS=${external_project_cflags} 83 INSTALL_COMMAND "" # This particular build system has no install command 84 BUILD_BYPRODUCTS ${build_dir}/libuoscore-uedhoc.a 85) 86 87# Create a wrapper CMake library that our app can link with 88add_library(test STATIC IMPORTED GLOBAL) 89add_dependencies( 90 test 91 oscore_edhoc_project 92) 93set_target_properties(test PROPERTIES IMPORTED_LOCATION ${build_dir}/libuoscore-uedhoc.a) 94target_include_directories(test INTERFACE 95 ${INCLUDE_DIR} 96) 97 98target_link_libraries(app PRIVATE test) 99