-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
260 lines (221 loc) · 6.7 KB
/
Copy pathCMakeLists.txt
File metadata and controls
260 lines (221 loc) · 6.7 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
248
249
250
251
252
253
254
255
256
257
258
259
260
cmake_minimum_required(VERSION 3.14)
project(LightweightNumericalOptimizationTools VERSION 1.0.0 LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# List of compiler flags
set(LNOT_SAN_FLAGS -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer)
set(LNOT_GNU_C_COMPILE_OPTIONS
-Wstrict-prototypes
-Wmissing-prototypes
-Wnested-externs
-Wbad-function-cast
-Wimplicit-function-declaration
-Wreturn-type)
set(LNOT_Clang_C_COMPILE_OPTIONS
-Wstrict-prototypes
-Wmissing-prototypes
-Wnested-externs
-Wbad-function-cast
-Wimplicit-function-declaration
-Wreturn-type
-Wno-error=pass-failed
)
set(LNOT_GNU_CXX_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)
set(LNOT_Clang_CXX_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
-Wno-error=pass-failed)
# Set default build type if not specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo" "MinSizeRel")
endif()
# === Options ===
option(LNOT_WITH_BLAS "Enable BLAS support via pkg-config" OFF)
option(LNOT_NATIVE_OPT "Enable CPU-specific optimizations (-march=native -mtune=native)" OFF)
option(LNOT_BUILD_DEMO "Build demo executable" OFF)
option(LNOT_BUILD_DOC "Build Doxygen documentation" OFF)
# === Dependencies ===
find_package(fmt REQUIRED)
if(LNOT_WITH_BLAS)
find_package(PkgConfig REQUIRED)
pkg_check_modules(OpenBLAS REQUIRED openblas)
message(STATUS "OpenBLAS found: ${OpenBLAS_INCLUDE_DIRS}")
endif()
include(FetchContent)
FetchContent_Declare(
BIC
GIT_REPOSITORY https://github.com/alexandrehoffmann/BetterIntegralConstant.git
GIT_TAG main
)
if(NOT BetterIntegralConstant_POPULATED)
message(STATUS "Fetching BetterIntegralConstant...")
else()
message(STATUS "BetterIntegralConstant already available, skipping fetch")
endif()
FetchContent_MakeAvailable(BIC)
# === Doxygen ===
if(LNOT_BUILD_DOC)
find_package(Doxygen REQUIRED dot)
# Set default values for Doxyfile
set(DOXYGEN_PROJECT_NAME "Lightweight Numerical Optimization Tools (LNOT)")
set(DOXYGEN_INPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/doc")
set(DOXYGEN_FILE ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${DOXYGEN_FILE} @ONLY)
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
endif()
# === Demo subdir ===
if(LNOT_BUILD_DEMO)
add_subdirectory(demo)
endif()
# === Library Target ===
set(LNOT_SRC
src/LNOT/Containers/CircularBuffer.cpp
#
src/LNOT/BasicLinalg/BasicLinalg.c
src/LNOT/BasicLinalg/SymmetricDenseMatrixOp.cpp
src/LNOT/BasicLinalg/DiagonalPreconditionerOp.cpp
#
src/LNOT/LinearSolvers/ConjugateGradient.cpp
src/LNOT/LinearSolvers/LanczosSolver.cpp
#
src/LNOT/TRSSolvers/TruncatedConjugateGradient.cpp
src/LNOT/TRSSolvers/LanczosTRSSolver.cpp
src/LNOT/TRSSolvers/LanczosFullOrthTRSSolver.cpp
#
src/LNOT/LineSearches/BacktrackingLineSearch.cpp
src/LNOT/LineSearches/BisectionLineSearch.cpp
src/LNOT/LineSearches/NoLineSearch.cpp
#
src/LNOT/GeneralSolvers/NewtonSolver.cpp
src/LNOT/GeneralSolvers/GradientDescent.cpp
src/LNOT/GeneralSolvers/BFGS.cpp
src/LNOT/GeneralSolvers/LBFGS.cpp
src/LNOT/GeneralSolvers/NonLinearConjugateGradient.cpp
src/LNOT/GeneralSolvers/NewtonTrustRegionSolver.cpp
src/LNOT/GeneralSolvers/SR1TrustRegionSolver.cpp
src/LNOT/GeneralSolvers/LSR1TrustRegionSolver.cpp
)
add_library(LNOT STATIC ${LNOT_SRC})
target_include_directories(LNOT
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(LNOT PUBLIC fmt::fmt BIC)
if(LNOT_WITH_BLAS)
target_include_directories(LNOT PUBLIC ${OpenBLAS_INCLUDE_DIRS})
target_link_libraries(LNOT PUBLIC ${OpenBLAS_LIBRARIES})
target_compile_definitions(LNOT PUBLIC LNOT_WITH_BLAS)
endif()
target_compile_options(LNOT PRIVATE
$<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:GNU>>:${LNOT_GNU_C_COMPILE_OPTIONS}>
$<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:Clang>>:${LNOT_Clang_C_COMPILE_OPTIONS}>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:GNU>>:${LNOT_GNU_CXX_COMPILE_OPTIONS}>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:Clang>>:${LNOT_Clang_CXX_COMPILE_OPTIONS}>
)
if(LNOT_NATIVE_OPT)
message(STATUS "Enabling native CPU optimizations (-march=native -mtune=native)")
target_compile_options(LNOT PRIVATE -march=native -mtune=native)
endif()
set_source_files_properties(
src/LNOT/BasicLinalg/BasicLinalg.c
PROPERTIES
COMPILE_OPTIONS "-ffast-math"
)
# === Installation ===
include(GNUInstallDirs)
install(DIRECTORY include/LNOT DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS LNOT
EXPORT LNOTTargets
)
install(EXPORT LNOTTargets
FILE LNOTTargets.cmake
NAMESPACE LNOT::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/LNOT
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/LNOTConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/LNOTConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/LNOTConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/LNOT
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/LNOTConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/LNOTConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/LNOT
)
# === pkg-config ===
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/lnot.pc.in
${CMAKE_CURRENT_BINARY_DIR}/lnot.pc
@ONLY
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lnot.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)