forked from eki-project/finn-cpp-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
249 lines (203 loc) · 7.8 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
cmake_minimum_required(VERSION 3.16)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
message(STATUS "${CMAKE_MODULE_PATH}")
SET(FINN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
SET(FINN_BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
SET(CMAKE_COLOR_MAKEFILE ON)
include(cmake/PreventInSourceBuilds.cmake)
project(FinnCPPDriver)
# specify the C++ standard
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "Using C++ Standard ${CMAKE_CXX_STANDARD}")
include(cmake/StandardProjectSettings.cmake)
include(FetchContent)
# Enable building when the device is offline
set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG main
GIT_SHALLOW TRUE
)
FetchContent_Declare(
googlebenchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG main
GIT_SHALLOW TRUE
)
set(BENCHMARK_ENABLE_TESTING OFF)
include(cmake/CheckSubmodules.cmake)
# Doxygen
option(FINN_BUILD_DOC "Build documentation" OFF)
if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(FINN_BUILD_DOC ON)
endif()
# Setup the doxygen code documentation
if(FINN_BUILD_DOC)
find_package(Doxygen)
if (DOXYGEN_FOUND)
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message("Doxygen build started")
add_custom_target(doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
else(DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen need to be installed to generate the doxygen documentation.")
endif()
endif()
#INCLUDES
#set(Boost_USE_STATIC_LIBS ON)
#Threads
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
#XRT
find_package(OpenCL REQUIRED)
set(XRT_DIR "${CMAKE_SOURCE_DIR}/cmake")
find_package(XRT REQUIRED)
#OpenMP
find_package(OpenMP)
#Boost
set(Boost_DEBUG OFF)
set(Boost_NO_SYSTEM_PATHS ON)
set(BOOST_ROOT "${FINN_BASE_DIR}/deps/finn_boost")
set(BOOST_INCLUDEDIR "${FINN_BASE_DIR}/deps/finn_boost")
set(BOOST_LIBRARYDIR "${FINN_BASE_DIR}/deps/finn_boost/stage/lib/boost")
set(Boost_NAMESPACE "finnBoost")
set(FINN_SAVE_BOOST_ROOT $ENV{BOOST_ROOT})
set(ENV{BOOST_ROOT} "")
find_package(Boost 1.80.0 COMPONENTS system log log_setup program_options filesystem ${BOOST_THREAD} REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
set(ENV{BOOST_ROOT} ${FINN_SAVE_BOOST_ROOT})
message(STATUS "${Boost_LIBRARIES}")
#mdspan
include_directories(SYSTEM external/mdspan/include)
#xsimd
add_subdirectory(external/xsimd)
include_directories(SYSTEM external/xsimd/include)
#xtl
add_subdirectory(external/xtl)
include_directories(SYSTEM external/xtl/include)
#xtensor
add_subdirectory(external/xtensor)
include_directories(SYSTEM external/xtensor/include)
#Nlohmann json
set(JSON_BuildTests OFF)
add_subdirectory(external/json)
include_directories(SYSTEM external/json/include/)
# Custom paths for the unittest configuration and the header for in-use compilation
if(DEFINED FINN_CUSTOM_UNITTEST_CONFIG)
message(STATUS "Added custom unittest config path (${FINN_CUSTOM_UNITTEST_CONFIG})!")
add_definitions(-DFINN_CUSTOM_UNITTEST_CONFIG=${FINN_CUSTOM_UNITTEST_CONFIG})
get_filename_component(FINN_CUSTOM_UNITTEST_CONFIG_FOLDER ${FINN_CUSTOM_UNITTEST_CONFIG} DIRECTORY)
get_filename_component(FINN_CUSTOM_UNITTEST_CONFIG_NAME ${FINN_CUSTOM_UNITTEST_CONFIG} NAME)
if (EXISTS "${FINN_CUSTOM_UNITTEST_CONFIG_FOLDER}/${FINN_CUSTOM_UNITTEST_CONFIG_NAME}" AND NOT IS_DIRECTORY "${FINN_CUSTOM_UNITTEST_CONFIG_FOLDER}/${FINN_CUSTOM_UNITTEST_CONFIG_NAME}")
message(STATUS "Custom FINN header: found")
else()
message(FATAL_ERROR "Could not find FINN header at ${FINN_CUSTOM_UNITTEST_CONFIG_FOLDER}/${FINN_CUSTOM_UNITTEST_CONFIG_NAME}!")
endif()
endif()
if(DEFINED FINN_HEADER_LOCATION)
message(STATUS "Added custom FINN-compiled header path (${FINN_HEADER_LOCATION})!")
add_definitions(-DFINN_HEADER_LOCATION=${FINN_HEADER_LOCATION})
get_filename_component(FINN_HEADER_LOCATION_FOLDER ${FINN_HEADER_LOCATION} DIRECTORY)
get_filename_component(FINN_HEADER_LOCATION_NAME ${FINN_HEADER_LOCATION} NAME)
if (EXISTS "${FINN_HEADER_LOCATION_FOLDER}/${FINN_HEADER_LOCATION_NAME}" AND NOT IS_DIRECTORY "${FINN_HEADER_LOCATION_FOLDER}/${FINN_HEADER_LOCATION_NAME}")
message(STATUS "Custom FINN header: found")
else()
message(FATAL_ERROR "Could not find FINN header at ${FINN_HEADER_LOCATION_FOLDER}/${FINN_HEADER_LOCATION_NAME}!")
endif()
endif()
# Build Unit tests
# Include before clang-tidy inclusion to exclude folder from clang-tidy
set(FINN_ENABLE_TESTING "Build all tests (default is ON)" ON)
FetchContent_MakeAvailable(googletest googlebenchmark)
include(cmake/AddUnittest.cmake)
include(cmake/AddBenchmark.cmake)
include(cmake/AddIntegrationtest.cmake)
enable_testing()
set(ENV{GTEST_OUTPUT} "json")
if (FINN_ENABLE_TESTING)
message(STATUS "Finn C++ unittests:")
add_subdirectory(unittests)
message(STATUS "Finn C++ benchmarks:")
add_subdirectory(benchmarks)
message(STATUS "Finn C++ integrationtests:")
add_subdirectory(integrationtest)
endif()
#Compiler Options
add_library(finnc_options INTERFACE)
add_library(finnc::finnc_options ALIAS finnc_options)
OPTION(FINN_ENABLE_ALLOPT "Enable all optimizations" ON)
if(${FINN_ENABLE_ALLOPT})
message(STATUS "All optimizations are enabled")
target_compile_options(
finnc_options
INTERFACE -O3 -march=native -mtune=native -fstack-protector-strong -fopenmp -ffunction-sections -fdata-sections -pipe -funroll-loops)
endif()
### Enable compiler warnings
option(FINN_ENABLE_WARNINGS "Enable warnings" ON)
if (FINN_ENABLE_WARNINGS)
include(cmake/CompilerWarnings.cmake)
finnc_set_project_warnings(
finnc_options
OFF
""
""
""
"")
endif (FINN_ENABLE_WARNINGS)
#
# Create options for including cmake files from the cmake folder with a bit of output.
#
macro(check_include)
if(NOT ${ARGC} EQUAL 3)
message(FATAL_ERROR "Call to 'check_include' with ${ARGC} arguments instead of 3")
endif()
OPTION(${ARGV0} "Enable ${ARGV0}" ON)
if (${ARGV0})
message(STATUS "${ARGV1}: enabled")
include(cmake/${ARGV2})
else()
message(STATUS "${ARGV1}: disabled")
endif()
endmacro()
#Enable all checks in debug mode
#message(STATUS "Build mode ${CMAKE_BUILD_TYPE}")
if (CMAKE_BUILD_TYPE STREQUAL "Release")
#message(WARNING "Analysers are off for Release build!")
set(FINN_CLANG_FORMAT OFF)
set(FINN_CLANG_TIDY OFF)
set(FINN_CPP_CHECK OFF)
set(FINN_IWYU OFF)
endif ()
#Sanitizers & Checks
include(cmake/Sanitizers.cmake)
OPTION(FINN_ENABLE_SANITIZERS "Enable default analyzers" ON)
OPTION(FINN_ENABLE_THREAD_SANITIZERS "Enable thread analyzer" OFF)
OPTION(FINN_ENABLE_MEMORY_SANITIZERS "Enable memory analyzer" OFF)
if (FINN_ENABLE_SANITIZERS)
finncpp_enable_sanitizers(finnc_options
${FINN_ENABLE_SANITIZERS}
${FINN_ENABLE_SANITIZERS}
${FINN_ENABLE_SANITIZERS}
${FINN_ENABLE_THREAD_SANITIZERS}
${FINN_ENABLE_MEMORY_SANITIZERS})
else()
message(STATUS "All Sanitizers disabled.")
endif()
message(STATUS "Checks:")
list(APPEND CMAKE_MESSAGE_INDENT " ") #indent +1
check_include(FINN_IPO "InterproceduralOptimization" InterproceduralOptimization.cmake)
check_include(FINN_CLANG_FORMAT "clang-format" ClangFormat.cmake)
check_include(FINN_CLANG_TIDY "clang-tidy" ClangTidy.cmake)
check_include(FINN_CPP_CHECK "cppcheck" CppCheck.cmake)
check_include(FINN_IWYU "iwyu" IWYU.cmake)
list(POP_BACK CMAKE_MESSAGE_INDENT) #indent -1
add_subdirectory(src)