-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
158 lines (130 loc) · 6.27 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
cmake_minimum_required(VERSION 3.12)
# project description
project(Hummus VERSION 0.1
DESCRIPTION "Hummus spiking neural network simulator"
LANGUAGES CXX)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY AUTOGEN_TARGETS_FOLDER _autogen)
# setting default build type
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif()
# setting options
option(TBB "Compiles with Intel TBB" ON)
option(TORCH "Compiles with Libtorch" ON)
option(QT "Compiles with Qt5" ON)
######### HUMMUS LIBRARY #########
# creating header-only library
add_library(hummus_library INTERFACE)
# collecting headers automatically - only for CMake 3.12 or later
file(GLOB_RECURSE header_list CONFIGURE_DEPENDS "third_party/*.hpp"
"source/*.hpp")
# allowing IDE to display the headers
target_sources(hummus_library INTERFACE ${header_list})
# preserving directory hierarchy inside IDE
foreach(header IN LISTS header_list)
file(RELATIVE_PATH path "${CMAKE_SOURCE_DIR}" "${header}")
source_group(TREE ${CMAKE_SOURCE_DIR} FILES "${path}")
endforeach()
# Setting which directories are needed
target_include_directories(hummus_library INTERFACE third_party/
source/
/usr/local/include)
# blaze dependency
find_package(blaze REQUIRED)
if(blaze_FOUND)
message("-- Compiling with Blaze")
add_compile_definitions(BLAZE)
add_library(blaze_target INTERFACE)
target_link_libraries(blaze_target INTERFACE blaze::blaze)
endif()
# handles optional Intel Threading Building Blocks (TBB) linking and includes
if (TBB)
find_library(tbb_location NAMES tbb)
message("-- Compiling with intel TBB")
add_compile_definitions(TBB)
add_library(tbb SHARED IMPORTED)
set_target_properties(tbb PROPERTIES IMPORTED_LOCATION ${tbb_location})
target_link_libraries(hummus_library INTERFACE tbb)
endif()
# handles optional libtorch (C++ frontend of pytorch) linking and includes
if (TORCH)
find_package(Torch REQUIRED)
message("-- Compiling with Libtorch")
add_compile_definitions(TORCH)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
target_link_libraries(hummus_library INTERFACE ${TORCH_LIBRARIES})
endif()
# handles optional Qt 5 linking and includes
if(QT)
message("-- Compiling with Qt5")
add_compile_definitions(QT QT_NO_KEYWORDS)
set_property(GLOBAL PROPERTY AUTOGEN_SOURCE_GROUP _moc)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
# Qt for Linux
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(EXISTS /usr/include/qt5/)
set(CMAKE_PREFIX_PATH /usr/include/qt5/)
else()
set(CMAKE_PREFIX_PATH /usr/include/x86_64-linux-gnu/qt5/)
endif()
find_package(Qt5 COMPONENTS Core Gui Qml Quick Widgets Charts REQUIRED)
target_include_directories(hummus_library INTERFACE ${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Qml_INCLUDE_DIRS}
${Qt5Quick_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
${Qt5Charts_INCLUDE_DIRS})
target_link_libraries(hummus_library INTERFACE Qt5::Core
Qt5::Gui
Qt5::Qml
Qt5::Quick
Qt5::Widgets
Qt5::Charts)
# Qt for macOS
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_PREFIX_PATH /usr/local/opt/qt/)
find_package(Qt5 COMPONENTS Core Gui Qml Quick Widgets QuickControls2 Charts REQUIRED)
target_include_directories(hummus_library INTERFACE ${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Qml_INCLUDE_DIRS}
${Qt5Quick_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
${Qt5QuickControls2_INCLUDE_DIRS}
${Qt5Charts_INCLUDE_DIRS})
target_link_libraries(hummus_library INTERFACE Qt5::Core
Qt5::Gui
Qt5::Qml
Qt5::Quick
Qt5::Widgets
Qt5::QuickControls2
Qt5::Charts)
endif()
source_group(_moc REGULAR_EXPRESSION "\\.rule$")
endif()
# Linux specific configuration
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
find_package(Threads REQUIRED)
target_link_libraries(hummus_library INTERFACE Threads::Threads)
endif()
# All users of this library will need at least C++17
target_compile_features(hummus_library INTERFACE cxx_std_17)
######### HUMMUS EXECUTABLES #########
# gather all .cpp inside the applications folder
file(GLOB application_list CONFIGURE_DEPENDS "applications/*.cpp")
# build executable for each application
foreach(app IN LISTS application_list)
get_filename_component(app_name "${app}" NAME_WE)
if (QT)
add_executable(${app_name} applications/${app_name}.cpp source/GUI/gui.qrc)
else()
add_executable(${app_name} applications/${app_name}.cpp)
endif()
source_group("applications" FILES applications/${app_name}.cpp)
target_compile_features(${app_name} PRIVATE cxx_std_17)
target_link_libraries(${app_name} PRIVATE hummus_library)
endforeach()