-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
247 lines (202 loc) · 8.95 KB
/
CMakeLists.txt
File metadata and controls
247 lines (202 loc) · 8.95 KB
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
cmake_minimum_required(VERSION 3.16)
set(CMAKE_CXX_STANDARD 17)
# Build the Qt GUI debugger (see htm_gui/).
# Default OFF so headless builds do not require Qt to be installed.
option(HTM_FLOW_WITH_GUI "Build Qt6 GUI debugger" OFF)
# Cmake option to enable building CUDA GPU section or not. Requires CUDA 11.0 or higher.
# To use specify -DUSE_GPU=ON when running cmake.
option(USE_GPU "Enable GPU support" OFF)
# Check if USE_GPU option is set to ON
if(USE_GPU)
project("htm_flow" VERSION 0.9 LANGUAGES CXX CUDA DESCRIPTION "A sparse distributed pattern recognizer using cpp taskflow library.")
set(CUDA_DIR ${PROJECT_SOURCE_DIR}/cuda)
else()
# If USE_GPU is OFF, then build the project without CUDA
project("htm_flow" VERSION 0.9 LANGUAGES CXX DESCRIPTION "A sparse distributed pattern recognizer using cpp taskflow library.")
endif()
# Error settings
add_library(error_settings INTERFACE)
add_library(tf::error_settings ALIAS error_settings)
target_compile_options(
error_settings
INTERFACE
$<$<CXX_COMPILER_ID:AppleClang>:-Wall -Wextra -Wfatal-errors>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:Clang>>:-Wall -Wextra -Wfatal-errors>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:GNU>>:-Wall -Wextra -Wfatal-errors>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/W3 /permissive->
)
# -----------------------------------------------------------------------------
# Find NVCC
# https://cliutils.gitlab.io/modern-cmake/chapters/packages/CUDA.html
# -----------------------------------------------------------------------------
if(USE_GPU)
include(CheckLanguage)
message(STATUS "Configuring CUDA ...")
check_language(CUDA)
if(NOT CMAKE_CUDA_COMPILER)
message(FATAL_ERROR "\nNo CUDA compiler found")
endif()
enable_language(CUDA)
if(CMAKE_CUDA_COMPILER_VERSION VERSION_LESS "11")
message(STATUS "CMAKE_CUDA_COMPILER_VERSION: ${CMAKE_CUDA_COMPILER_VERSION}")
message(FATAL_ERROR "\nTaskflow requires CUDA at least v11")
endif()
endif()
# Default settings
add_library(default_settings INTERFACE)
add_library(tf::default_settings ALIAS default_settings)
target_link_libraries(
default_settings
INTERFACE
tf::error_settings
)
# Include directories
include_directories("include")
# Include directories for the project source files
include_directories(${PROJECT_SOURCE_DIR})
# -----------------------------------------------------------------------------
# yaml-cpp for config file loading
# -----------------------------------------------------------------------------
if(EXISTS "${PROJECT_SOURCE_DIR}/lib/yaml-cpp/CMakeLists.txt")
set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "" FORCE)
add_subdirectory(lib/yaml-cpp)
endif()
if(USE_GPU)
add_subdirectory(cuda)
# Add test task flow executable (use this to confirm that task flow is working)
# Test script name
set(TEST_SCRIPT_NAME task_flow_test)
add_executable(${TEST_SCRIPT_NAME} ./src/task_flow_test.cpp)
target_compile_features(${TEST_SCRIPT_NAME} PRIVATE cxx_std_17)
target_link_libraries(${TEST_SCRIPT_NAME} PRIVATE task_gpu_test)
install(TARGETS ${TEST_SCRIPT_NAME} DESTINATION bin)
endif()
# Add all the cpp files in the src directory
file(GLOB_RECURSE SRC_FILES ${PROJECT_SOURCE_DIR}/src/overlap/*.cpp
${PROJECT_SOURCE_DIR}/src/inhibition/*.cpp
${PROJECT_SOURCE_DIR}/src/spatiallearn/*.cpp
${PROJECT_SOURCE_DIR}/src/sequence_pooler/*/*.cpp
${PROJECT_SOURCE_DIR}/src/temporal_pooler/*.cpp
${PROJECT_SOURCE_DIR}/src/utilities/*.cpp)
# Build the Project executable
add_executable(${PROJECT_NAME}
./src/main.cpp
./src/gui_runtime.cpp
./src/config.cpp
./src/config_loader.cpp
./src/htm_layer.cpp
./src/htm_region.cpp
./src/region_runtime.cpp
${SRC_FILES}
)
# `HtmFlowRuntime` depends on the GUI interface headers (no Qt dependency).
if(EXISTS "${PROJECT_SOURCE_DIR}/htm_gui/include")
target_include_directories(${PROJECT_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/htm_gui/include")
endif()
# Required for CUDA debugging in Visual Studio Code. This adds a -G flag to compilation.
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${PROJECT_NAME} PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-G>)
endif()
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
# Link yaml-cpp if available
if(TARGET yaml-cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE yaml-cpp)
endif()
if(USE_GPU)
target_link_libraries(${PROJECT_NAME} PRIVATE task_gpu_test gpu_overlap)
endif()
if(HTM_FLOW_WITH_GUI)
if(EXISTS "${PROJECT_SOURCE_DIR}/htm_gui/CMakeLists.txt")
add_subdirectory(htm_gui)
target_link_libraries(${PROJECT_NAME} PRIVATE htm_gui)
target_compile_definitions(${PROJECT_NAME} PRIVATE HTM_FLOW_WITH_GUI)
else()
message(WARNING "HTM_FLOW_WITH_GUI is ON but 'htm_gui/' is missing; building without GUI.")
endif()
endif()
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
# -----------------------------------------------------------------------------
# Debug region runner - for debugging integration test configurations with GUI
# -----------------------------------------------------------------------------
add_executable(debug_region
./src/debug_region.cpp
./src/config.cpp
./src/config_loader.cpp
./src/htm_layer.cpp
./src/htm_region.cpp
./src/region_runtime.cpp
${SRC_FILES}
)
if(EXISTS "${PROJECT_SOURCE_DIR}/htm_gui/include")
target_include_directories(debug_region PRIVATE "${PROJECT_SOURCE_DIR}/htm_gui/include")
endif()
target_compile_features(debug_region PRIVATE cxx_std_17)
# Link yaml-cpp if available
if(TARGET yaml-cpp)
target_link_libraries(debug_region PRIVATE yaml-cpp)
endif()
if(USE_GPU)
target_link_libraries(debug_region PRIVATE task_gpu_test gpu_overlap)
endif()
if(HTM_FLOW_WITH_GUI)
if(TARGET htm_gui)
target_link_libraries(debug_region PRIVATE htm_gui)
target_compile_definitions(debug_region PRIVATE HTM_FLOW_WITH_GUI)
endif()
endif()
install(TARGETS debug_region DESTINATION bin)
####################################################################
# Build tests if (BUILD_TESTS) is ON
option(BUILD_TESTS "Build the tests" ON)
if(BUILD_TESTS)
include_directories(cuda
src
include/htm_flow
include/utilities
)
# Add the Google Test subdirectory
add_subdirectory(lib/googletest)
# Enable testing for your project
enable_testing()
include(GoogleTest)
# Add all the cpp files in the test directory and include the necessary source files
file(GLOB_RECURSE TEST_FILES ./test/*.cpp ${PROJECT_SOURCE_DIR}/src/inhibition/inhibition.cpp
${PROJECT_SOURCE_DIR}/src/overlap/overlap.cpp
${PROJECT_SOURCE_DIR}/src/overlap/overlap_utils.cpp
${PROJECT_SOURCE_DIR}/src/spatiallearn/spatiallearn.cpp
${PROJECT_SOURCE_DIR}/src/sequence_pooler/active_cells/active_cells.cpp
${PROJECT_SOURCE_DIR}/src/sequence_pooler/predict_cells/predict_cells.cpp
${PROJECT_SOURCE_DIR}/src/sequence_pooler/sequence_learning/sequence_learning.cpp
${PROJECT_SOURCE_DIR}/src/temporal_pooler/temporal_pooler.cpp
${PROJECT_SOURCE_DIR}/src/utilities/stopwatch.cpp
${PROJECT_SOURCE_DIR}/src/config.cpp
${PROJECT_SOURCE_DIR}/src/config_loader.cpp
${PROJECT_SOURCE_DIR}/src/htm_layer.cpp
${PROJECT_SOURCE_DIR}/src/htm_region.cpp
${PROJECT_SOURCE_DIR}/src/region_runtime.cpp)
# Filter out the GPU test files if GPU flag is set to FALSE
if(NOT USE_GPU)
list(FILTER TEST_FILES EXCLUDE REGEX ".*gpu.*\.cpp$")
endif()
# Add your test files
add_executable(${PROJECT_NAME}_tests ${TEST_FILES})
# Add htm_gui include directory for IHtmRuntime interface (no Qt dependency)
if(EXISTS "${PROJECT_SOURCE_DIR}/htm_gui/include")
target_include_directories(${PROJECT_NAME}_tests PRIVATE "${PROJECT_SOURCE_DIR}/htm_gui/include")
endif()
# Link your test executable to the Google Test library and other libraries
if(USE_GPU)
target_link_libraries(${PROJECT_NAME}_tests gtest gtest_main task_gpu_test gpu_overlap)
else()
target_link_libraries(${PROJECT_NAME}_tests gtest gtest_main)
endif()
# Link yaml-cpp if available
if(TARGET yaml-cpp)
target_link_libraries(${PROJECT_NAME}_tests yaml-cpp)
endif()
# Register individual gtest TEST() cases with CTest so `ctest -R <pattern>` works.
gtest_discover_tests(${PROJECT_NAME}_tests DISCOVERY_TIMEOUT 30)
endif()