-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
74 lines (62 loc) · 2.61 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#######################################
# General
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(nrf52-libmicrofido C)
if (CONFIG_NRF_SECURITY STREQUAL "y")
add_compile_definitions(USE_HW_CRYPTO=1)
set(additional_libmicrofido2_cmake_flags
"-DENABLE_SOFTWARE_CRYPTO=OFF"
)
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
target_sources(app PRIVATE
src/main.c
clock/clock_cycles.c
hw_crypto/hw_crypto.c
stateless_rp/stateless_rp.c
stateless_rp/stateless_rp_nfc_simulator.c
)
#######################################
# libmicrofido2
# Necessary for building libmicrofido2
include(ExternalProject)
# Extract the Zephyr compilation settings.
zephyr_get_include_directories_for_lang_as_string( C includes)
zephyr_get_system_include_directories_for_lang_as_string(C system_includes)
zephyr_get_compile_definitions_for_lang_as_string( C definitions)
zephyr_get_compile_options_for_lang_as_string( C options)
set(external_project_cflags
"${includes} ${definitions} ${options} ${system_includes} --specs=nosys.specs"
)
# Directory settings.
set(libmicrofido2_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../)
set(libmicrofido2_build_dir ${CMAKE_CURRENT_BINARY_DIR}/libmicrofido2)
set(LIBMICROFIDO2_LIB_DIR ${libmicrofido2_build_dir})
set(LIBMICROFIDO2_INCLUDE_DIR ${libmicrofido2_src_dir}/include)
ExternalProject_Add(
libmicrofido2_project # Name for custom target
PREFIX ${libmicrofido2_build_dir} # Root directory for the lib.
SOURCE_DIR ${libmicrofido2_src_dir}
BINARY_DIR ${libmicrofido2_build_dir}
CMAKE_ARGS # Pass the necessary build flags.
-DCMAKE_C_FLAGS=${external_project_cflags}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_AR=${CMAKE_AR}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DZEPHYR=1
${additional_libmicrofido2_cmake_flags}
INSTALL_COMMAND "" # No installation necessary, just build it.
BUILD_BYPRODUCTS ${LIBMICROFIDO2_LIB_DIR}/libmicrofido2.a
)
# Create a wrapper CMake library that our app can link with.
add_library(libmicrofido2_lib STATIC IMPORTED GLOBAL)
add_dependencies(
libmicrofido2_lib
libmicrofido2_project
)
set_target_properties(libmicrofido2_lib PROPERTIES IMPORTED_LOCATION ${LIBMICROFIDO2_LIB_DIR}/libmicrofido2.a)
file(MAKE_DIRECTORY ${LIBMICROFIDO2_INCLUDE_DIR}) # Hack to make the line below work on the first download.
set_target_properties(libmicrofido2_lib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${LIBMICROFIDO2_INCLUDE_DIR})
# Link with libmicrofido2
target_link_libraries(app PUBLIC libmicrofido2_lib)