-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
48 lines (40 loc) · 1.41 KB
/
Copy pathCMakeLists.txt
File metadata and controls
48 lines (40 loc) · 1.41 KB
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
cmake_minimum_required(VERSION 3.10)
project(FirmwareChallenge VERSION 1.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# platform detection
if(APPLE)
set(PLATFORM "macos-universal")
elseif(WIN32)
set(PLATFORM "windows-x64")
else()
set(PLATFORM "linux-x86_64")
endif()
# locate pre-compiled HAL library
set(HAL_LIB_DIR ${CMAKE_SOURCE_DIR}/hal/lib/${PLATFORM})
if(WIN32)
set(HAL_LIB_FILE ${HAL_LIB_DIR}/hal-${PLATFORM}/Release/hal.lib)
else()
set(HAL_LIB_FILE ${HAL_LIB_DIR}/hal-${PLATFORM}/libhal.a)
endif()
if(NOT EXISTS ${HAL_LIB_FILE})
message(FATAL_ERROR
"Pre-compiled HAL not found for platform '${PLATFORM}'.\n"
"Expected: ${HAL_LIB_FILE}\n"
"Contact the challenge organiser.")
endif()
# import HAL as a pre-built static library
add_library(hal STATIC IMPORTED GLOBAL)
set_target_properties(hal PROPERTIES
IMPORTED_LOCATION ${HAL_LIB_FILE}
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/hal)
# helper: add a firmware executable linked against the HAL
function(add_firmware target source)
add_executable(${target} ${source})
target_link_libraries(${target} PRIVATE hal)
endfunction()
# targets
add_firmware(example example/main.cpp)
add_firmware(ex01 exercises/01_parts_counter/main.cpp)
add_firmware(ex02 exercises/02_frequency_estimator/main.cpp)
add_firmware(ex03 exercises/03_i2c_bitbang/main.cpp)