-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
119 lines (104 loc) · 3.19 KB
/
Copy pathCMakeLists.txt
File metadata and controls
119 lines (104 loc) · 3.19 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
cmake_minimum_required(VERSION 3.20)
project(fast_mnist_nn VERSION 0.1.0 LANGUAGES CXX)
option(FAST_MNIST_ENABLE_OPENMP "Enable OpenMP support" ON)
option(FAST_MNIST_ENABLE_NATIVE "Enable -march=native" OFF)
option(FAST_MNIST_ENABLE_BENCHMARKS "Enable Google Benchmark" OFF)
option(FAST_MNIST_ENABLE_DOXYGEN "Enable Doxygen docs target" OFF)
add_library(fast_mnist
src/Matrix.cpp
src/NeuralNet.cpp
)
target_include_directories(fast_mnist
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_compile_features(fast_mnist PUBLIC cxx_std_17)
if(MSVC)
target_compile_options(fast_mnist PRIVATE /W4)
else()
target_compile_options(fast_mnist PRIVATE -Wall -Wextra -Wpedantic)
endif()
if(FAST_MNIST_ENABLE_NATIVE)
if(MSVC)
message(WARNING "FAST_MNIST_ENABLE_NATIVE is not supported on MSVC")
else()
target_compile_options(fast_mnist PRIVATE -march=native)
endif()
endif()
if(FAST_MNIST_ENABLE_OPENMP)
find_package(OpenMP QUIET)
if(OpenMP_CXX_FOUND)
target_link_libraries(fast_mnist PUBLIC OpenMP::OpenMP_CXX)
target_compile_definitions(fast_mnist PUBLIC FAST_MNIST_USE_OPENMP=1)
elseif(APPLE)
find_library(OPENMP_LIB omp
PATHS /opt/homebrew/opt/libomp/lib /usr/local/opt/libomp/lib
)
if(OPENMP_LIB)
target_compile_options(fast_mnist PUBLIC -Xpreprocessor -fopenmp)
target_include_directories(fast_mnist PUBLIC
/opt/homebrew/opt/libomp/include
/usr/local/opt/libomp/include
)
target_link_libraries(fast_mnist PUBLIC ${OPENMP_LIB})
target_compile_definitions(fast_mnist PUBLIC FAST_MNIST_USE_OPENMP=1)
else()
message(STATUS "OpenMP not found; building without OpenMP")
endif()
else()
message(STATUS "OpenMP not found; building without OpenMP")
endif()
endif()
add_executable(fast_mnist_cli apps/fast_mnist_cli.cpp)
target_link_libraries(fast_mnist_cli PRIVATE fast_mnist)
include(CTest)
if(BUILD_TESTING)
include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.5.2
)
FetchContent_MakeAvailable(Catch2)
add_executable(fast_mnist_tests
tests/test_matrix.cpp
tests/test_neural_net.cpp
)
target_link_libraries(fast_mnist_tests
PRIVATE
fast_mnist
Catch2::Catch2WithMain
)
include(Catch)
catch_discover_tests(fast_mnist_tests)
endif()
if(FAST_MNIST_ENABLE_BENCHMARKS)
include(FetchContent)
FetchContent_Declare(
benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.9.1
)
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(benchmark)
add_executable(fast_mnist_benchmarks
benchmarks/bench_matrix.cpp
)
target_link_libraries(fast_mnist_benchmarks
PRIVATE fast_mnist benchmark::benchmark
)
endif()
if(FAST_MNIST_ENABLE_DOXYGEN)
find_package(Doxygen QUIET)
if(DOXYGEN_FOUND)
add_custom_target(docs
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating Doxygen documentation"
VERBATIM
)
else()
message(STATUS "Doxygen not found; docs target disabled")
endif()
endif()