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