-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
431 lines (381 loc) · 15.2 KB
/
CMakeLists.txt
File metadata and controls
431 lines (381 loc) · 15.2 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
cmake_minimum_required(VERSION 3.13)
# This file is part of the Aaru Data Preservation Suite.
# Copyright (c) 2019-2026 Natalia Portillo.
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, see <http://www.gnu.org/licenses/>.
if(APPLE)
# Too early cmake has not yet set it
if((NOT DEFINED CMAKE_SYSTEM_PROCESSOR) AND (NOT DEFINED AARU_MACOS_TARGET_ARCH))
execute_process(COMMAND uname -m OUTPUT_VARIABLE AARU_MACOS_TARGET_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
if(NOT DEFINED AARU_MACOS_TARGET_ARCH)
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for macOS" FORCE)
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64")
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "Build architectures for macOS" FORCE)
else()
message(FATAL_ERROR "Unknown system processor ${CMAKE_SYSTEM_PROCESSOR} for macOS")
endif()
elseif(AARU_MACOS_TARGET_ARCH STREQUAL "x86_64")
set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for macOS" FORCE)
elseif(AARU_MACOS_TARGET_ARCH STREQUAL "arm64")
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "Build architectures for macOS" FORCE)
else()
message(FATAL_ERROR "Unknown Aaru target architecture ${AARU_MACOS_TARGET_ARCH} for macOS")
endif()
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version")
endif(APPLE)
# Integrate vcpkg toolchain if available but not explicitly provided.
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
if(DEFINED ENV{VCPKG_ROOT} AND EXISTS "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
set(CMAKE_TOOLCHAIN_FILE
"$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "Vcpkg toolchain file")
message(STATUS "vcpkg toolchain configured: $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
endif()
elseif(DEFINED CMAKE_TOOLCHAIN_FILE AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
message(STATUS "vcpkg toolchain already set: ${CMAKE_TOOLCHAIN_FILE}")
endif()
project(libaaruformat C)
# Option to enable slog logging (disabled by default)
option(USE_SLOG "Enable slog logging" OFF)
# Option to enable address sanitizer (disabled by default)
option(USE_ASAN "Enable address sanitizer" OFF)
# Set C standard
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
# Enable position independent code by default
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# MSVC ARM specific override
if("${CMAKE_C_COMPILER_ID}" MATCHES "MSVC" AND "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" MATCHES "ARMV7")
set(CMAKE_C_STANDARD 11)
endif()
# Global compile definitions
add_compile_definitions(__STDC_FORMAT_MACROS=1)
# POSIX functions (strdup, fseeko, ftello, etc.) require feature test macros
# when building with C_EXTENSIONS OFF. Define on non-Windows platforms.
if(NOT WIN32)
add_compile_definitions(_POSIX_C_SOURCE=200809L)
endif()
# Configure large-file support consistently across compilers and architectures.
# POSIX builds use fseeko()/ftello() with 64-bit file offsets, while Windows
# builds route stdio positioning through the native 64-bit APIs.
function(aaru_enable_large_file_support target)
if(WIN32)
target_compile_definitions(${target} PRIVATE AARU_USE_WIN32_FILEIO64)
# Some bundled third-party sources use POSIX large-file APIs directly.
# On MSVC, remap them to the native 64-bit stdio functions without
# modifying the vendored sources.
if(MSVC)
target_compile_definitions(${target} PRIVATE
fseeko=_fseeki64
ftello=_ftelli64)
endif()
else()
target_compile_definitions(${target} PRIVATE
_FILE_OFFSET_BITS=64
_LARGEFILE_SOURCE
AARU_USE_POSIX_FILEIO64)
endif()
endfunction()
# MinGW specific configuration
if("${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW")
if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "aarch64" OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm")
set(WIN32 TRUE)
endif()
# Statically link the MinGW/GCC runtime and winpthread so the executable
# does not depend on libgcc_s_*.dll or libwinpthread-1.dll at runtime.
add_link_options(-static-libgcc -static-libstdc++
-Wl,-Bstatic,--whole-archive
-Wl,--no-whole-archive,-Bdynamic)
endif()
message(STATUS "Detected system processor: ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "Detected vs platform name: ${CMAKE_C_COMPILER_ARCHITECTURE_ID}")
message(STATUS "Detected compiler: ${CMAKE_C_COMPILER_ID}")
message(STATUS "Detected build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Detected platform: ${CMAKE_C_PLATFORM_ID}")
message(STATUS "Size of (void*): ${CMAKE_SIZEOF_VOID_P}")
# Check if target is 64-bit
if("${CMAKE_SIZEOF_VOID_P}" MATCHES "8"
OR "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" MATCHES "x64"
OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64"
OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AMD64"
OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "aarch64"
OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "riscv64")
set(ARCHITECTURE_IS_64BIT TRUE)
endif()
if("${CMAKE_BUILD_TYPE}" MATCHES "Release")
add_compile_definitions(NDEBUG)
if("${CMAKE_C_COMPILER_ID}" MATCHES "MSVC")
add_compile_options("/O2" "/fp:fast")
if(${CMAKE_C_COMPILER_ARCHITECTURE_ID} MATCHES "X86" OR ${CMAKE_C_COMPILER_ARCHITECTURE_ID} MATCHES "x64")
add_compile_options("/arch:SSE2")
endif()
else()
add_compile_options(-ffast-math -O3)
# Architecture-specific flags are only set for native builds.
# Cross-compilation toolchain files provide their own -march/-mtune/-mfpu.
if(NOT CMAKE_CROSSCOMPILING)
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64"
OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i686"
OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64")
if(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang")
add_compile_options(-march=core2 -mtune=westmere -mfpmath=sse)
endif()
add_compile_options(-msse3)
if(NOT "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW")
add_compile_options(-flto)
endif()
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
if(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang")
add_compile_options(-march=armv8-a)
endif()
if(NOT "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW")
add_compile_options(-flto)
endif()
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "armv7l" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
if(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang")
add_compile_options(-march=armv7+fp -mfpu=vfpv3-d16)
endif()
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips")
if(NOT "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW")
add_compile_options(-flto)
endif()
endif()
endif()
endif()
endif()
# Address sanitizer configuration
if(USE_ASAN)
message(STATUS "Address sanitizer enabled")
if("${CMAKE_C_COMPILER_ID}" MATCHES "MSVC")
# MSVC address sanitizer flags
add_compile_options(/fsanitize=address)
add_link_options(/fsanitize=address)
else()
# GCC/Clang address sanitizer flags
add_compile_options(-fsanitize=address -fno-omit-frame-pointer -g)
add_link_options(-fsanitize=address)
endif()
else()
message(STATUS "Address sanitizer disabled (enable with -DUSE_ASAN=ON)")
endif()
# Library type controlled by BUILD_SHARED_LIBS (CMake standard).
# -DBUILD_SHARED_LIBS=ON → shared library (default, backwards compatible)
# -DBUILD_SHARED_LIBS=OFF → static library
if(NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
endif()
if(BUILD_SHARED_LIBS)
message(STATUS "Building shared library (use -DBUILD_SHARED_LIBS=OFF for static)")
else()
message(STATUS "Building static library")
endif()
add_library(aaruformat
include/aaruformat/consts.h
include/aaruformat/enums.h
include/aaru.h
include/aaruformat.h
include/aaruformat/decls.h
include/aaruformat/structs.h
src/identify.c
src/open.c
include/aaruformat/context.h
src/close.c
src/close_write.c
include/aaruformat/errors.h
src/read.c
include/aaruformat/crc64.h
src/compression/cst.c
src/checksum/ecc_cd.c
src/helpers.c
src/checksum/simd.c
include/aaruformat/simd.h
src/crc64/crc64.c
src/crc64/crc64_clmul.c
src/crc64/crc64_vmull.c
src/crc64/arm_vmull.c
src/crc64/arm_vmull.h
src/checksum/spamsum.c
include/aaruformat/spamsum.h
include/aaruformat/flac.h
src/compression/flac.c
src/compression/lzma.c
src/lru.c
include/aaruformat/lru.h
include/aaruformat/endian.h
src/verify.c
include/aaruformat/structs/header.h
include/aaruformat/structs/ddt.h
include/aaruformat/structs/index.h
include/aaruformat/structs/data.h
include/aaruformat/structs/metadata.h
include/aaruformat/structs/dump.h
include/aaruformat/structs/checksum.h
include/aaruformat/structs/optical.h
src/index/index_v1.c
include/internal.h
src/index/index_v2.c
src/blocks/data.c
src/ddt/ddt_v1.c
src/blocks/metadata.c
src/blocks/optical.c
src/blocks/dump.c
src/blocks/checksum.c
src/index/index_v3.c
src/ddt/ddt_v2.c
include/aaruformat/structs/options.h
src/options.c
src/create.c
src/time.c
src/write.c
include/log.h
src/ddt/hash_map.c
include/aaruformat/hash_map.h
src/ddt/static_lru_hash_map.c
include/aaruformat/static_lru_hash_map.h
src/checksum/md5.c
include/md5.h
src/checksum/sha1.c
include/sha1.h
src/checksum/sha256.c
include/sha256.h
src/lisa_tag.c
include/aaruformat/structs/lisa_tag.h
src/metadata.c
src/metadata_write.c
src/dump.c
include/aaruformat/structs/tape.h
src/blocks/tape.c
src/blocks/flux.c
src/lib/aes128.c
src/lib/aes128.h
src/ps3/ps3_crypto.c
src/ps3/ps3_crypto.h
src/ps3/ps3_encryption_map.c
src/ps3/ps3_encryption_map.h
src/wiiu/wiiu_crypto.c
src/wiiu/wiiu_crypto.h
src/ngcw/lfg.c
src/ngcw/lfg.h
src/ngcw/ngcw_junk.c
src/ngcw/ngcw_junk.h
src/ngcw/wii_crypto.c
src/ngcw/wii_crypto.h
src/compression/zstd.c
src/lib/gf256.c
src/lib/gf256.h
src/lib/reed_solomon.c
src/lib/reed_solomon.h
src/erasure.c
include/erasure_internal.h
include/aaruformat/structs/erasure.h)
# Set up include directories for the target
target_include_directories(aaruformat
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/aaruformat>
$<INSTALL_INTERFACE:include>
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/uthash/include
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/uthash/src
)
aaru_enable_large_file_support(aaruformat)
# Load third-party dependencies
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake-modules")
include(3rdparty/flac.cmake)
include(3rdparty/lzma.cmake)
include(3rdparty/xxhash.cmake)
include(3rdparty/blake3.cmake)
include(3rdparty/zstd.cmake)
if(TARGET blake3)
target_link_libraries(aaruformat blake3)
endif()
macro(TARGET_LINK_LIBRARIES_WHOLE_ARCHIVE target)
if(MSVC)
foreach(lib IN LISTS ARGN)
set_target_properties(${target} PROPERTIES LINK_FLAGS "/WHOLEARCHIVE:${lib}")
endforeach()
elseif(APPLE)
foreach(lib IN LISTS ARGN)
target_link_libraries(${target} -Wl,-force_load ${lib})
endforeach()
elseif(UNIX)
foreach(lib IN LISTS ARGN)
target_link_libraries(${target} -Wl,--whole-archive ${lib} -Wl,--no-whole-archive)
endforeach()
endif()
endmacro()
# MinGW/ARM specific: disable PIC
if(NOT "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW"
OR (NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm"
AND NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64"))
set_property(TARGET aaruformat PROPERTY POSITION_INDEPENDENT_CODE TRUE)
else()
set_property(TARGET aaruformat PROPERTY POSITION_INDEPENDENT_CODE FALSE)
endif()
# Add slog submodule
if(POLICY CMP0000)
cmake_policy(VERSION 3.5)
endif()
# Conditionally enable slog logging
if(USE_SLOG)
add_subdirectory(3rdparty/slog)
# Include slog headers
target_include_directories(aaruformat PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/slog/src)
# Enable TRACE and slog output
target_compile_definitions(aaruformat PRIVATE ENABLE_TRACE ENABLE_FATAL USE_SLOG)
# Link slog
target_link_libraries(aaruformat slog)
message(STATUS "slog logging enabled")
else()
message(STATUS "slog logging disabled (enable with -DUSE_SLOG=ON)")
endif()
# Check for math library
include(CheckLibraryExists)
check_library_exists(m cos "" HAVE_LIB_M)
if(HAVE_LIB_M)
target_link_libraries(aaruformat m)
endif()
# Find Doxygen for documentation generation
find_package(Doxygen)
if(DOXYGEN_FOUND)
# Set Doxygen configuration variables
set(DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/docs")
set(PROJECT_VERSION "1.0")
# Configure the Doxyfile
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
# Add custom target to generate documentation
add_custom_target(doxygen
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
message(STATUS "Found Doxygen: ${DOXYGEN_EXECUTABLE}")
message(STATUS "Added 'doxygen' target to generate API documentation")
message(STATUS "Documentation will be generated in: ${DOXYGEN_OUTPUT_DIR}/html")
else()
message(STATUS "Doxygen not found - 'doxygen' target will not be available")
message(STATUS "Install it to generate API documentation")
endif()
if(NOT AARU_BUILD_PACKAGE)
add_subdirectory(tests)
option(BUILD_TOOL "Build the CLI tool (requires Argtable3)" OFF)
if(BUILD_TOOL)
add_subdirectory(tool)
endif()
add_subdirectory(docs/spec)
endif()