-
Notifications
You must be signed in to change notification settings - Fork 344
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
362 lines (316 loc) · 12.4 KB
/
Copy pathCMakeLists.txt
File metadata and controls
362 lines (316 loc) · 12.4 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
# cmake-format: off
# Copyright (c) 2025, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Intel Corporation nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# cmake-format: on
cmake_minimum_required(VERSION 3.12)
cmake_policy(VERSION 3.12)
project(ISA-L
VERSION 2.32.1
DESCRIPTION "Intel's ISA-L (Intelligent Storage Acceleration Library)"
LANGUAGES C
)
# Enable NASM for x86_64 builds
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
enable_language(ASM_NASM)
endif()
# Enable testing
option(ISAL_BUILD_TESTS "Build the testing tree" ON)
if(ISAL_BUILD_TESTS)
enable_testing()
include(CTest)
endif()
# Enable performance tests
option(ISAL_BUILD_PERF_TESTS "Build performance tests" ON)
# Enable fuzz testing (requires Clang)
option(ISAL_BUILD_FUZZ_TESTS "Build fuzz tests with LibFuzzer" OFF)
if(ISAL_BUILD_FUZZ_TESTS)
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_subdirectory(tests/fuzz)
else()
message(WARNING "ISAL_BUILD_FUZZ_TESTS requires Clang compiler")
endif()
endif()
# Enable building ISAL shim library
option(ISAL_BUILD_ISAL_SHIM "Build the ISAL shim library" ON)
# Enable building igzip CLI program
option(ISAL_BUILD_IGZIP_CLI "Build the igzip command-line program" OFF)
if(ISAL_BUILD_ISAL_SHIM)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
# Set default build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# Detect processor architecture
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
set(CPU_X86_64 ON)
set(ARCH_DEF "x86_64")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(CPU_AARCH64 ON)
set(ARCH_DEF "aarch64")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64le")
set(CPU_PPC64LE ON)
set(ARCH_DEF "ppc64le")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
set(CPU_RISCV64 ON)
set(ARCH_DEF "riscv64")
else()
set(CPU_UNDEFINED ON)
endif()
# Compiler and assembler setup
if(CPU_X86_64)
# Configure NASM flags
if(WIN32)
set(CMAKE_ASM_NASM_FLAGS "-f win64")
elseif(APPLE)
set(CMAKE_ASM_NASM_FLAGS "-f macho64 --prefix=_")
else()
set(CMAKE_ASM_NASM_FLAGS "-f elf64 -D LINUX")
endif()
set(CMAKE_ASM_NASM_INCLUDES "-I ${CMAKE_CURRENT_SOURCE_DIR}/include/")
set(USE_NASM ON)
elseif(CPU_AARCH64 OR CPU_RISCV64)
# Use C compiler for assembly on ARM and RISC-V
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
enable_language(ASM)
set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -D__ASSEMBLY__")
endif()
# Set include directories
set(ISAL_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/include
)
# Initialize EXTERN_HEADERS list
set(EXTERN_HEADERS)
# Compiler flags
if(ARCH_DEF)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D${ARCH_DEF}")
endif()
# On MinGW-w64, two measures are needed to prevent "32 bit pseudo relocation
# out of range" runtime aborts (STATUS_STACK_BUFFER_OVERRUN / 0xc0000409).
# ASLR can place system DLLs (e.g. ucrtbase.dll) more than 2 GB from the
# binary, which overflows 32-bit pseudo-relocation deltas.
#
# 1. -fPIC at compile time makes GCC reference external C runtime data via
# the IAT (.refptr stubs) instead of 32-bit PC-relative references,
# eliminating pseudo-relocations from user-compiled object files.
#
# 2. --enable-runtime-pseudo-reloc-v2 at link time upgrades any residual
# pseudo-relocations (e.g. those baked into pre-compiled MinGW CRT startup
# objects such as libmingw32.a) from the 32-bit v1 format to the 64-bit v2
# format, which the MinGW runtime can apply regardless of address gap.
if(WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fPIC>)
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -Wl,--enable-runtime-pseudo-reloc-v2")
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -Wl,--enable-runtime-pseudo-reloc-v2")
endif()
# Library version (semantic versioning)
set(LIBISAL_VERSION_MAJOR 2)
set(LIBISAL_VERSION_MINOR 32)
set(LIBISAL_VERSION_PATCH 1)
# Include CMake modules for each library component
include(cmake/erasure_code.cmake)
include(cmake/raid.cmake)
include(cmake/crc.cmake)
include(cmake/igzip.cmake)
include(cmake/mem.cmake)
include(cmake/misc.cmake)
# Add test.h to extern headers (used by all modules)
list(APPEND EXTERN_HEADERS include/test.h)
# Create the main ISA-L library
# Build type option
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
# Use module definition file to explicitly control exported symbols.
# On Windows the .def file lists every public and arch-specific symbol, so the
# linker creates proper export-table entries and import-library thunks for all
# of them (including NASM-assembled functions, which the MinGW linker does not
# auto-export).
if(WIN32 AND BUILD_SHARED_LIBS)
set(ISAL_DEF_FILE "${CMAKE_CURRENT_SOURCE_DIR}/isa-l.def")
endif()
# Mirror install layout in build tree to support '#include <isa-l/header.h>' via FetchContent
set(BUILD_INTERFACE_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/build_include")
file(MAKE_DIRECTORY "${BUILD_INTERFACE_INCLUDE_DIR}/isa-l")
file(GLOB_RECURSE ISAL_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
file(COPY ${ISAL_HEADERS} DESTINATION "${BUILD_INTERFACE_INCLUDE_DIR}/isa-l")
# Create the main ISA-L library
add_library(isal
${ISAL_DEF_FILE}
${ERASURE_CODE_SOURCES}
${RAID_SOURCES}
${CRC_SOURCES}
${IGZIP_SOURCES}
${MEM_SOURCES}
${MISC_SOURCES}
)
# Set library properties
set_target_properties(isal PROPERTIES
VERSION ${LIBISAL_VERSION_MAJOR}.${LIBISAL_VERSION_MINOR}.${LIBISAL_VERSION_PATCH}
SOVERSION ${LIBISAL_VERSION_MAJOR}
)
# Match Makefile.nmake naming convention. On Windows the import table embeds
# the DLL name from the .def LIBRARY directive (isa-l), so the produced DLL
# must be named isa-l.dll for both MSVC and MinGW. Clearing PREFIX/IMPORT_PREFIX
# stops MinGW from adding the "lib" prefix (libisa-l.dll), which would otherwise
# not match the name recorded in the consumers' import tables.
if(WIN32)
set_target_properties(isal PROPERTIES
OUTPUT_NAME "isa-l"
PREFIX ""
IMPORT_PREFIX ""
)
endif()
# Configure include directories for NASM assembly files
if(CPU_X86_64 AND USE_NASM)
# Filter assembly files by module and set appropriate include directories
foreach(source IN LISTS ERASURE_CODE_SOURCES RAID_SOURCES CRC_SOURCES IGZIP_SOURCES MEM_SOURCES)
if(source MATCHES "\\.asm$")
get_filename_component(source_dir ${source} DIRECTORY)
set_source_files_properties(${source} PROPERTIES
INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_CURRENT_SOURCE_DIR}/${source_dir}")
endif()
endforeach()
endif()
# Suppress deprecation warnings when building the library internally
target_compile_definitions(isal PRIVATE ISAL_DEPRECATED_INTERNAL)
# Include directories
target_include_directories(isal
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
INTERFACE
$<BUILD_INTERFACE:${BUILD_INTERFACE_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>
)
# Conditionally build ISAL shim library
if(ISAL_BUILD_ISAL_SHIM)
add_subdirectory(igzip/shim)
endif()
# Install targets
include(GNUInstallDirs)
# Build igzip CLI program
if(ISAL_BUILD_IGZIP_CLI)
if(WIN32)
message(WARNING "ISAL_BUILD_IGZIP_CLI is not supported on Windows")
else()
add_executable(igzip_cli programs/igzip_cli.c)
set_target_properties(igzip_cli PROPERTIES
OUTPUT_NAME igzip
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/programs"
)
target_include_directories(igzip_cli PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_link_libraries(igzip_cli PRIVATE isal)
install(TARGETS igzip_cli
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/programs/igzip.1")
install(FILES programs/igzip.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
)
endif()
endif()
endif() # ISAL_BUILD_IGZIP_CLI
# Generate isa-l.h header
set(ISAL_HEADER "${CMAKE_CURRENT_BINARY_DIR}/isa-l.h")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/isa-l.h.in ${ISAL_HEADER} @ONLY)
# Copy generated header to build interface dir for FetchContent support
file(COPY ${ISAL_HEADER} DESTINATION "${BUILD_INTERFACE_INCLUDE_DIR}")
# add uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(
uninstall COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake)
# Install library
install(TARGETS isal
EXPORT ISALTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# Install generated header
install(FILES ${ISAL_HEADER}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# Install headers
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/isa-l
FILES_MATCHING PATTERN "*.h"
)
# Export targets
install(EXPORT ISALTargets
FILE ISALTargets.cmake
NAMESPACE ISAL::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ISAL
)
# Generate and install package config files
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/ISALConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/ISALConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ISAL
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/ISALConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/ISALConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/ISALConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ISAL
)
# Optional: Create pkg-config file
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix \${prefix})
set(libdir \${prefix}/${CMAKE_INSTALL_LIBDIR})
set(includedir \${prefix}/${CMAKE_INSTALL_INCLUDEDIR})
set(VERSION ${PROJECT_VERSION})
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/libisal.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libisal.pc"
@ONLY
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libisal.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
# Print configuration summary
message(STATUS "")
message(STATUS "ISA-L ${PROJECT_VERSION} configuration summary:")
message(STATUS " Build type : ${CMAKE_BUILD_TYPE}")
message(STATUS " Architecture : ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS " Shared libs : ${BUILD_SHARED_LIBS}")
message(STATUS " Install prefix : ${CMAKE_INSTALL_PREFIX}")
message(STATUS " Build tests : ${ISAL_BUILD_TESTS}")
message(STATUS " Build perf tests : ${ISAL_BUILD_PERF_TESTS}")
message(STATUS " Build fuzz tests : ${ISAL_BUILD_FUZZ_TESTS}")
message(STATUS " Build ISAL shim : ${ISAL_BUILD_ISAL_SHIM}")
message(STATUS " Build igzip CLI : ${ISAL_BUILD_IGZIP_CLI}")
message(STATUS "")