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