-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
181 lines (147 loc) · 5.98 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
cmake_minimum_required(VERSION 3.10)
project(blink1-lib VERSION 1.0.0)
set(LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
if (CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DDEBUG_PRINTF)
endif (CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_EXPORT_COMPILE_COMMANDS yes)
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
option(BLINK1_LIB_BUILD_STATIC no)
option(BLINK1_LIB_BUILD_SHARED no)
if ((HAS_PARENT OR BLINK1_LIB_BUILD_STATIC) AND NOT BLINK1_LIB_BUILD_SHARED)
set(LIBRARY_TYPE STATIC)
elseif ((NOT HAS_PARENT OR BLINK1_LIB_BUILD_SHARED) AND NOT BLINK1_LIB_BUILD_STATIC)
set(LIBRARY_TYPE SHARED)
else()
message(FATAL_ERROR "Must set exactly 1 of BLINK1_LIB_BUILD_SHARED or BLINK1_LIB_BUILD_STATIC, or neither of them.")
endif()
message("-- blink1-lib library type: ${LIBRARY_TYPE}")
if (HAS_PARENT)
set(INCLUDE_DIR_SYSTEM SYSTEM)
else(HAS_PARENT)
set(INCLUDE_DIR_SYSTEM "")
endif(HAS_PARENT)
##############
# BLINK1-LIB #
##############
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAG_RELEASE} -O3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -DDEBUG -g")
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(INCLUDES ${INCLUDE_DIR})
set(SOURCES
${SOURCE_DIR}/Blink1Device.cpp
${SOURCE_DIR}/PatternLine.cpp
${SOURCE_DIR}/PatternLineN.cpp
${SOURCE_DIR}/PlayState.cpp
${SOURCE_DIR}/RGB.cpp
${SOURCE_DIR}/RGBN.cpp
)
set(CXX_STANDARD_REQUIRED yes)
add_library(blink1 ${LIBRARY_TYPE} ${SOURCES})
add_library(blink1-testing ${LIBRARY_TYPE} ${SOURCES} ${SOURCE_DIR}/Blink1TestingLibrary.cpp)
set_property(TARGET blink1 PROPERTY CXX_STANDARD 20)
set_property(TARGET blink1-testing PROPERTY CXX_STANDARD 20)
###############
# BLINK1-TOOL #
###############
set(BLINK1_DIR ${LIB_DIR}/blink1-tool)
set(LIB_BLINK1_LOC ${BLINK1_DIR}/libblink1.so)
set(INCLUDES ${INCLUDES} ${BLINK1_DIR} ${BLINK1_DIR}/hidapi/hidapi)
add_definitions(-DUSE_HIDAPI)
add_custom_command(OUTPUT ${LIB_BLINK1_LOC}
COMMAND $(MAKE) lib
WORKING_DIRECTORY ${BLINK1_DIR})
add_custom_target(libblink1_target DEPENDS ${LIB_BLINK1_LOC})
add_library(libblink1 STATIC IMPORTED GLOBAL)
set_target_properties(libblink1 PROPERTIES IMPORTED_LOCATION ${LIB_BLINK1_LOC})
add_dependencies(libblink1 libblink1_target)
target_link_libraries(blink1 libblink1)
target_include_directories(blink1 ${INCLUDE_DIR_SYSTEM} PUBLIC ${INCLUDES})
target_include_directories(blink1-testing ${INCLUDE_DIR_SYSTEM} PUBLIC ${INCLUDES})
if(NOT HAS_PARENT)
###########
# DOXYGEN #
###########
set(DOXYGEN_GENERATE_HTML YES)
set(DOXYGEN_GENERATE_MAN YES)
set(DOXYGEN_GENERATE_TREEVIEW YES)
set(DOXYGEN_HTML_EXTRA_STYLESHEET "${LIB_DIR}/doxygen-awesome-css/doxygen-awesome.css")
find_package(Doxygen)
if (DOXYGEN_FOUND)
doxygen_add_docs(
doxygen
${INCLUDE_DIR}
COMMENT "Generate documentation"
)
endif(DOXYGEN_FOUND)
###########
# Testing #
###########
add_subdirectory(${LIB_DIR}/googletest)
include(GoogleTest)
set(TEST_EXECUTABLE_NAME blink1_lib_test)
set(TEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
set(TEST_SOURCES
${TEST_SOURCE_DIR}/Blink1Device_BadInit_test.cpp
${TEST_SOURCE_DIR}/Blink1Device_Blocking_test.cpp
${TEST_SOURCE_DIR}/Blink1Device_GoodInit_test.cpp
${TEST_SOURCE_DIR}/Blink1Device_GoodInitBadFunction_test.cpp
${TEST_SOURCE_DIR}/PatternLineN_test.cpp
${TEST_SOURCE_DIR}/PatternLine_test.cpp
${TEST_SOURCE_DIR}/PlayState_test.cpp
${TEST_SOURCE_DIR}/RGBN_test.cpp
${TEST_SOURCE_DIR}/RGB_test.cpp
)
enable_testing()
add_executable(${TEST_EXECUTABLE_NAME} ${TEST_SOURCES})
target_link_libraries(${TEST_EXECUTABLE_NAME} blink1-testing gtest gtest_main gmock gmock_main)
gtest_discover_tests(${TEST_EXECUTABLE_NAME})
set_property(TARGET ${TEST_EXECUTABLE_NAME} PROPERTY CXX_STANDARD 20)
set(WARNINGS "-Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wpedantic -Wconversion -Wsign-conversion")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Set specific warnings if they ever exist
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(WARNINGS "${WARNINGS} -Wmisleading-indentation")
endif()
set_target_properties(${TEST_EXECUTABLE_NAME} PROPERTIES COMPILE_FLAGS "${WARNINGS}")
############
# COVERAGE #
############
if (CMAKE_BUILD_TYPE MATCHES Debug)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules")
include(CodeCoverage)
set(COVERAGE_EXCLUDES "/usr/*" "${LIB_DIR}/*" "${TEST_SOURCE_DIR}/*")
APPEND_COVERAGE_COMPILER_FLAGS()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(GCOV_PATH "${CMAKE_CURRENT_SOURCE_DIR}/scripts/llvm-cov.sh")
SETUP_TARGET_FOR_COVERAGE_LCOV(NAME coverage
EXECUTABLE ${TEST_EXECUTABLE_NAME}
DEPENDENCIES ${TEST_EXECUTABLE_NAME})
else()
SETUP_TARGET_FOR_COVERAGE_GCOVR_HTML(NAME coverage
EXECUTABLE ${TEST_EXECUTABLE_NAME}
DEPENDENCIES ${TEST_EXECUTABLE_NAME})
endif()
add_definitions(-DDEBUG_PRINTF)
set_target_properties(
blink1
PROPERTIES
CXX_CLANG_TIDY "clang-tidy"
)
endif (CMAKE_BUILD_TYPE MATCHES Debug)
################
# OPTIMIZATION #
################
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT error)
if (ipo_supported)
message(STATUS "IPO/LTO enabled")
set_property(TARGET ${TEST_EXECUTABLE_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO/LTO not supported")
endif()
endif(NOT HAS_PARENT)