forked from hpc-maths/LightweightAutoDiff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
176 lines (142 loc) · 5.48 KB
/
Copy pathCMakeLists.txt
File metadata and controls
176 lines (142 loc) · 5.48 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
cmake_minimum_required(VERSION 3.24)
cmake_policy(SET CMP0135 NEW)
########################################################################
#### Project metadata ####
########################################################################
project(LightweightAutoDiff
VERSION 0.1.0
DESCRIPTION "LAD: Lightweight Automatic Differentiation - a small autodiff tool. Support reverse mode thought a Taper that records instruction an then performs back-propagation WRT a given variable."
LANGUAGES CXX)
########################################################################
#### Variables ####
########################################################################
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build.")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo" "MinSizeRel")
endif()
set(LAD_SAN_FLAGS -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer)
set(LAD_COMMON_COMPILE_OPTIONS
-fopenmp-simd
-Wundef
-Wvarargs
-Wall
-Wextra
-Winit-self
-Wpedantic
-Werror
-Wconversion
-Wuninitialized
-Wmissing-declarations
-Wsign-conversion
-Wshadow
-Wcast-align
-Wnull-dereference
-Wformat=2
-flax-vector-conversions
-pedantic
-pedantic-errors
-Wno-error=array-bounds
-Wno-c99-extensions
-Wdouble-promotion
-Wswitch-enum
-Wrange-loop-construct
-Wnon-virtual-dtor
-Wold-style-cast
-Woverloaded-virtual
-Wvexing-parse
-fopenmp-simd
-Wundef
-Wvarargs
-Wall
-Wextra
-Winit-self
-Wpedantic
-Werror
-Wconversion
-Wuninitialized
-Wmissing-declarations
-Wsign-conversion
-Wshadow
-Wcast-align
-Wnull-dereference
-Wformat=2
-flax-vector-conversions
-pedantic
-pedantic-errors
-Wno-error=array-bounds
-Wno-c99-extensions
-Wdouble-promotion
-Wswitch-enum
-Wrange-loop-construct
-Wnon-virtual-dtor
-Wold-style-cast
-Woverloaded-virtual
-Wvexing-parse)
set(LAD_GNU_CXX_COMPILE_OPTIONS
${LAD_COMMON_COMPILE_OPTIONS})
set(LAD_Clang_CXX_COMPILE_OPTIONS
${LAD_COMMON_COMPILE_OPTIONS})
########################################################################
#### Options ####
########################################################################
option(LAD_ENABLE_SANITIZERS "Enable sanitizers in Debug builds" OFF)
option(LAD_BUILD_DOC "Build Doxygen documentation" OFF)
option(LAD_USE_NATIVE_OPT "Enable -march=native -mtune=native" OFF)
option(LAD_BUILD_TESTS "Build tests for LAD" OFF)
option(LAD_BUILD_DEMOS "Build demos for LAD" OFF)
########################################################################
#### Tests ####
########################################################################
if(${LAD_BUILD_TESTS})
enable_testing()
endif()
########################################################################
#### Dependencies ####
########################################################################
include(FetchContent)
FetchContent_Declare(fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git GIT_TAG 12.1.0 FIND_PACKAGE_ARGS NAMES fmt VERSION 12.1.0)
FetchContent_MakeAvailable(fmt)
########################################################################
#### SubDirectories ####
########################################################################
if(${LAD_BUILD_TESTS})
add_subdirectory(tests)
endif()
if(${LAD_BUILD_DEMOS})
add_subdirectory(demos)
endif()
########################################################################
#### Targets ####
########################################################################
add_library(LightweightAutoDiff_include INTERFACE)
add_library(LightweightAutoDiff_options INTERFACE)
add_library(LAD)
########################################################################
#### Sources ####
########################################################################
target_sources(LAD PRIVATE
src/LAD/Tape.cpp
src/LAD/Variable.cpp
src/LAD/Dual.cpp
src/LAD/DualVariable.cpp)
target_include_directories(LightweightAutoDiff_include INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
########################################################################
#### Link ####
########################################################################
target_link_libraries(LAD
PUBLIC LightweightAutoDiff_include
PUBLIC LightweightAutoDiff_options
PUBLIC fmt)
########################################################################
#### Compile options ####
########################################################################
target_compile_features(LightweightAutoDiff_options INTERFACE cxx_std_20)
target_compile_options(LightweightAutoDiff_options INTERFACE
$<$<CXX_COMPILER_ID:GNU>:${LAD_GNU_CXX_COMPILE_OPTIONS}>
$<$<CXX_COMPILER_ID:Clang>:${LAD_Clang_CXX_COMPILE_OPTIONS}>)
if(LAD_ENABLE_SANITIZERS)
target_compile_options(LightweightAutoDiff_options INTERFACE $<$<CONFIG:Debug>:${SAN_FLAGS}>)
endif()
if(LAD_USE_NATIVE_OPT)
target_compile_options(LightweightAutoDiff_options INTERFACE -march=native -mtune=native)
endif()