forked from bristlemouth/bm_protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
80 lines (65 loc) · 2.16 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
75
76
77
78
79
80
cmake_minimum_required(VERSION 3.18)
project(spotter
LANGUAGES C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
include(cmake/CPM.cmake)
include(cmake/CheckAndApplyFlags.cmake)
include(BuildOptions.cmake)
##################
# Compiler Flags #
##################
# If we're not a subproject, globally apply our warning flags
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
add_compile_options(-Wall -Wextra)
endif()
# This function can be used to generate a linker map file on an executable target
# in a compiler-agnostic way (currently supports GCC and Clang compiler families)
function(target_linker_map target)
check_c_linker_flag("-Wl,-Map,test.map" _Map1)
if("${_Map1}")
set(GEN_MAP_FILE "-Wl,-Map,")
else()
check_c_linker_flag("-Wl,-map,test.map" _Map2)
if("${_Map2}")
set(GEN_MAP_FILE "-Wl,-map,")
else()
message("[WARNING] ${CMAKE_C_COMPILER_ID} does not have a defined linker map argument.")
return()
endif()
endif()
get_target_property(map_dir ${target} BINARY_DIR)
target_link_options(${target} PRIVATE ${GEN_MAP_FILE}${map_dir}/${target}.map)
set_target_properties(${target} PROPERTIES
ADDITIONAL_CLEAN_FILES ${target}.map)
endfunction()
find_program(DOXYGEN doxygen)
if(DOXYGEN)
add_custom_target(docs
COMMAND ${DOXYGEN} docs/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
# This property will remove a directory, while add_custom_target BYPRODUCTS will not.
set_target_properties(docs PROPERTIES ADDITIONAL_CLEAN_FILES ${CMAKE_BINARY_DIR}/doc/)
endif()
if(CMAKE_CROSSCOMPILING)
message(STATUS "Cross Compiling - Building Firmware")
add_subdirectory(src)
else()
message(STATUS "Native compiling - Building Tests")
set(SRC_DIR ${CMAKE_SOURCE_DIR}/src)
set(TEST_DIR ${CMAKE_SOURCE_DIR}/test)
# Setup testing
include(CTest)
# Get v1.10.0 of googletest from github and compile
CPMAddPackage(
NAME googletest
GITHUB_REPOSITORY google/googletest
GIT_TAG release-1.11.0
)
add_subdirectory("test")
endif()