1# SPDX-License-Identifier: Apache-2.0 2 3cmake_minimum_required(VERSION 3.13.1) 4find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 5project(initiator) 6 7FILE(GLOB app_sources 8 src/*.c 9 ../../common/sock_ipv6.c 10 ../../../externals/zcbor/src/*.c 11 ../../../externals/compact25519/src/c25519/*.c 12 ../../../externals/compact25519/src/*.c 13 ../../../externals/mbedtls/library/*.c) 14target_sources(app PRIVATE ${app_sources}) 15 16 17target_include_directories(app PRIVATE 18 $ENV{ZEPHYR_BASE}/subsys/net/ip 19 ../../common 20 ../../../inc 21 ../../../test_vectors 22 ../../../externals/zcbor/include 23 ../../../externals/mbedtls/library 24 ../../../externals/mbedtls/include 25 ../../../externals/mbedtls/include/mbedtls 26 ../../../externals/mbedtls/include/psa) 27 28 29 30add_definitions( 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 58 59if(CMAKE_GENERATOR STREQUAL "Unix Makefiles") 60# https://www.gnu.org/software/make/manual/html_node/MAKE-Variable.html 61set(submake "$(MAKE)") 62else() # Obviously no MAKEFLAGS. Let's hope a "make" can be found somewhere. 63set(submake "make") 64endif() 65 66message("build_dir: ${build_dir}") 67message("CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}") 68message("CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}") 69message("LIB_TEST_LIB_DIR: ${LIB_TEST_LIB_DIR}") 70message("INCLUDE_DIR: ${INCLUDE_DIR}") 71 72 73 74ExternalProject_Add( 75 oscore_edhoc_project # Name for custom target 76 PREFIX ${build_dir} # Root dir for entire project 77 SOURCE_DIR ${src_dir} 78 BINARY_DIR ${src_dir} # This particular build system is invoked from the root 79 CONFIGURE_COMMAND "" # Skip configuring the project, e.g. with autoconf 80 BUILD_COMMAND 81 ${submake} 82 PREFIX=${build_dir} 83 CC=${CMAKE_C_COMPILER} 84 AR=${CMAKE_AR} 85 CFLAGS=${external_project_cflags} 86 INSTALL_COMMAND "" # This particular build system has no install command 87 BUILD_BYPRODUCTS ${build_dir}/libuoscore-uedhoc.a 88 ) 89 90# Create a wrapper CMake library that our app can link with 91add_library(test STATIC IMPORTED GLOBAL) 92add_dependencies( 93 test 94 oscore_edhoc_project) 95 96set_target_properties(test PROPERTIES IMPORTED_LOCATION 97 ${build_dir}/libuoscore-uedhoc.a) 98 99target_include_directories(test INTERFACE 100 ${INCLUDE_DIR}) 101 102target_link_libraries(app PRIVATE test) 103