-
Notifications
You must be signed in to change notification settings - Fork 56
/
CMakeLists.txt
106 lines (90 loc) · 3.86 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#
# Copyright (c) 2016-2017 UAVCAN Team
#
cmake_minimum_required (VERSION 3.22.1)
project(Canard)
# check arguments for 32-bit build
option(CMAKE_32BIT "Enable 32 bit build" OFF)
option(CANARD_ENABLE_CANFD "Enable CAN Flexible Data-Rate" OFF)
if (${CANARD_ENABLE_CANFD})
add_definitions(-DCANARD_ENABLE_CANFD=1)
endif()
option(CANARD_ENABLE_DEADLINE "Enable Deadline" OFF)
if (${CANARD_ENABLE_DEADLINE})
add_definitions(-DCANARD_ENABLE_DEADLINE=1)
endif()
option(CANARD_MULTI_IFACE "Enable Multi-Interface" OFF)
if (${CANARD_MULTI_IFACE})
add_definitions(-DCANARD_MULTI_IFACE=1)
endif()
# Compiler configuration - supporting only Clang and GCC
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Werror")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall -Wextra -Werror -pedantic")
# turn on debug symbols by default
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
if (CMAKE_32BIT)
message(STATUS "Building for 32-bit")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
else()
message(STATUS "Building for 64-bit")
endif()
# C warnings
set(CANARD_C_FLAGS "${CANARD_C_FLAGS} -Wdouble-promotion -Wswitch-enum -Wfloat-equal -Wundef")
set(CANARD_C_FLAGS "${CANARD_C_FLAGS} -Wconversion -Wtype-limits")
set(CANARD_C_FLAGS "${CANARD_C_FLAGS} -Wsign-conversion -Wcast-align -Wmissing-declarations")
# C++ warnings
set(CANARD_CXX_FLAGS "${CANARD_CXX_FLAGS} -Wdouble-promotion -Wswitch-enum -Wfloat-equal -Wundef")
set(CANARD_CXX_FLAGS "${CANARD_CXX_FLAGS} -Wconversion -Wsign-promo")
set(CANARD_CXX_FLAGS "${CANARD_CXX_FLAGS} -Wsign-conversion -Wcast-align -Wmissing-declarations")
set(CANARD_CXX_FLAGS "${CANARD_CXX_FLAGS} -Wtype-limits -Wzero-as-null-pointer-constant -Wnon-virtual-dtor")
set(CANARD_CXX_FLAGS "${CANARD_CXX_FLAGS} -Woverloaded-virtual -Wsign-promo")
# We allow the following warnings for compatibility with the C codebase:
set(CANARD_CXX_FLAGS "${CANARD_CXX_FLAGS} -Wno-error=old-style-cast -Wno-error=zero-as-null-pointer-constant")
# add coverage flags
option(CANARD_ENABLE_COVERAGE "Enable Code Coverage" OFF)
if (${CANARD_ENABLE_COVERAGE})
set(CANARD_CXX_FLAGS "${CANARD_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CANARD_C_FLAGS "${CANARD_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CANARD_LINK_FLAGS "${CANARD_LINK_FLAGS} -fprofile-arcs -ftest-coverage")
endif()
add_library(canard_tgt canard.c canard.h)
target_compile_options(canard_tgt PUBLIC -Wall -g)
target_include_directories(canard_tgt
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)
add_library(canard_private_tgt canard_internals.h canard.c)
target_compile_options(canard_private_tgt PUBLIC
-Wall
-g)
target_link_libraries(canard_private_tgt PUBLIC canard_tgt)
include(CTest)
if(${BUILD_TESTING})
add_definitions(-DCANARD_INTERNAL=)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.13.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(BUILD_GTEST ON CACHE BOOL "" FORCE)
# disable GMOCK
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
add_subdirectory(tests)
add_subdirectory(canard/tests)
if (CANARD_ENABLE_COVERAGE)
add_custom_target(coverage
COMMAND lcov --directory . --capture --output-file coverage.info
COMMAND lcov --remove coverage.info '/usr/*' '*gtest*' '*tests/*' '*dsdlc_generated/*' --output-file coverage.info
COMMAND lcov --list coverage.info
COMMAND genhtml coverage.info --output-directory coverage
COMMENT echo "Coverage report generated at ${CMAKE_BINARY_DIR}/coverage/index.html"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
add_custom_command(TARGET coverage POST_BUILD COMMAND ;)
endif()
endif()