1
+ # cmake-format: off
2
+ # Copyright (c) 2025, Intel Corporation
3
+ #
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # * Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ # * Redistributions in binary form must reproduce the above copyright
10
+ # notice, this list of conditions and the following disclaimer in the
11
+ # documentation and/or other materials provided with the distribution.
12
+ # * Neither the name of Intel Corporation nor the names of its contributors
13
+ # may be used to endorse or promote products derived from this software
14
+ # without specific prior written permission.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+ # cmake-format: on
27
+ cmake_minimum_required (VERSION 3.12)
28
+ cmake_policy (VERSION 3.12)
29
+
30
+ project (ISA-L
31
+ VERSION 2.31.0
32
+ DESCRIPTION "Intel's ISA-L (Intelligent Storage Acceleration Library)"
33
+ LANGUAGES C ASM
34
+ )
35
+
36
+ # Enable NASM for x86_64 builds
37
+ if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" )
38
+ enable_language (ASM_NASM)
39
+ endif ()
40
+
41
+ # Enable testing
42
+ option (BUILD_TESTS "Build the testing tree" ON )
43
+ if (BUILD_TESTS)
44
+ enable_testing ()
45
+ include (CTest)
46
+ endif ()
47
+
48
+ # Enable building ISAL shim library
49
+ option (BUILD_ISAL_SHIM "Build the ISAL shim library" OFF )
50
+
51
+ # Set default build type
52
+ if (NOT CMAKE_BUILD_TYPE )
53
+ set (CMAKE_BUILD_TYPE Release)
54
+ endif ()
55
+
56
+ # Detect processor architecture
57
+ if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" )
58
+ set (CPU_X86_64 ON )
59
+ set (ARCH_DEF "x86_64" )
60
+ elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" )
61
+ set (CPU_AARCH64 ON )
62
+ set (ARCH_DEF "aarch64" )
63
+ elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64le" )
64
+ set (CPU_PPC64LE ON )
65
+ set (ARCH_DEF "ppc64le" )
66
+ elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64" )
67
+ set (CPU_RISCV64 ON )
68
+ set (ARCH_DEF "riscv64" )
69
+ else ()
70
+ set (CPU_UNDEFINED ON )
71
+ endif ()
72
+
73
+ # Compiler and assembler setup
74
+ if (CPU_X86_64)
75
+ # Configure NASM flags
76
+ set (CMAKE_ASM_NASM_FLAGS "-f elf64 -D LINUX" )
77
+ set (CMAKE_ASM_NASM_INCLUDES "-I ${CMAKE_SOURCE_DIR} /include/" )
78
+ set (USE_NASM ON )
79
+ elseif (CPU_AARCH64 OR CPU_RISCV64)
80
+ # Use C compiler for assembly on ARM and RISC-V
81
+ set (ASM_FILTER "${CMAKE_C_COMPILER} -D__ASSEMBLY__" )
82
+ endif ()
83
+
84
+ # Set include directories
85
+ set (ISAL_INCLUDE_DIRS
86
+ ${CMAKE_SOURCE_DIR} /include
87
+ )
88
+
89
+ # Initialize EXTERN_HEADERS list
90
+ set (EXTERN_HEADERS)
91
+
92
+ # Compiler flags
93
+ if (ARCH_DEF)
94
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D${ARCH_DEF} " )
95
+ endif ()
96
+
97
+ if (CPU_AARCH64 OR CPU_RISCV64)
98
+ set (CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} " )
99
+ endif ()
100
+
101
+ # Library version (semantic versioning)
102
+ set (LIBISAL_VERSION_MAJOR 2)
103
+ set (LIBISAL_VERSION_MINOR 31)
104
+ set (LIBISAL_VERSION_PATCH 0)
105
+
106
+ # Include CMake modules for each library component
107
+ include (cmake/erasure_code.cmake)
108
+ include (cmake/raid.cmake)
109
+ include (cmake/crc.cmake)
110
+ include (cmake/igzip.cmake)
111
+ include (cmake/mem.cmake)
112
+
113
+ # Conditionally build ISAL shim library
114
+ if (BUILD_ISAL_SHIM)
115
+ add_subdirectory (igzip/shim)
116
+ endif ()
117
+
118
+ # Add test.h to extern headers (used by all modules)
119
+ list (APPEND EXTERN_HEADERS include /test .h)
120
+
121
+ # Create the main ISA-L library
122
+ # Build type option
123
+ option (BUILD_SHARED_LIBS "Build shared libraries" ON )
124
+
125
+ # Create the main ISA-L library
126
+ add_library (isal
127
+ ${ERASURE_CODE_SOURCES}
128
+ ${RAID_SOURCES}
129
+ ${CRC_SOURCES}
130
+ ${IGZIP_SOURCES}
131
+ ${MEM_SOURCES}
132
+ )
133
+
134
+ # Set library properties
135
+ set_target_properties (isal PROPERTIES
136
+ VERSION ${LIBISAL_VERSION_MAJOR} .${LIBISAL_VERSION_MINOR} .${LIBISAL_VERSION_PATCH}
137
+ SOVERSION ${LIBISAL_VERSION_MAJOR}
138
+ PUBLIC_HEADER "${EXTERN_HEADERS} "
139
+ )
140
+
141
+ # Configure include directories for NASM assembly files
142
+ if (CPU_X86_64 AND USE_NASM)
143
+ # Filter assembly files by module and set appropriate include directories
144
+ foreach (source IN LISTS ERASURE_CODE_SOURCES RAID_SOURCES CRC_SOURCES IGZIP_SOURCES MEM_SOURCES)
145
+ if (source MATCHES "\\ .asm$" )
146
+ get_filename_component (source_dir ${source} DIRECTORY )
147
+ set_source_files_properties (${source} PROPERTIES
148
+ INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR} /include;${CMAKE_SOURCE_DIR} /${source_dir} " )
149
+ endif ()
150
+ endforeach ()
151
+ endif ()
152
+
153
+ # Include directories
154
+ target_include_directories (isal
155
+ PUBLIC
156
+ $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR} /include >
157
+ $<INSTALL_INTERFACE:include >
158
+ )
159
+
160
+ # Generate isa-l.h header
161
+ set (ISAL_HEADER "${CMAKE_BINARY_DIR} /isa-l.h" )
162
+ configure_file (${CMAKE_SOURCE_DIR} /cmake/isa-l.h.in ${ISAL_HEADER} @ONLY)
163
+
164
+ # Install targets
165
+ include (GNUInstallDirs)
166
+
167
+ # Install library
168
+ install (TARGETS isal
169
+ EXPORT ISALTargets
170
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
171
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
172
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
173
+ PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /isa-l
174
+ )
175
+
176
+ # Install generated header
177
+ install (FILES ${ISAL_HEADER}
178
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
179
+ )
180
+
181
+ # Install headers
182
+ install (DIRECTORY include /
183
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /isa-l
184
+ FILES_MATCHING PATTERN "*.h"
185
+ )
186
+
187
+ # Export targets
188
+ install (EXPORT ISALTargets
189
+ FILE ISALTargets.cmake
190
+ NAMESPACE ISAL::
191
+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/ISAL
192
+ )
193
+
194
+ # Generate and install package config files
195
+ include (CMakePackageConfigHelpers)
196
+
197
+ configure_package_config_file(
198
+ "${CMAKE_SOURCE_DIR} /cmake/ISALConfig.cmake.in"
199
+ "${CMAKE_BINARY_DIR} /ISALConfig.cmake"
200
+ INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/ISAL
201
+ )
202
+
203
+ write_basic_package_version_file(
204
+ "${CMAKE_BINARY_DIR} /ISALConfigVersion.cmake"
205
+ VERSION ${PROJECT_VERSION}
206
+ COMPATIBILITY SameMajorVersion
207
+ )
208
+
209
+ install (FILES
210
+ "${CMAKE_BINARY_DIR} /ISALConfig.cmake"
211
+ "${CMAKE_BINARY_DIR} /ISALConfigVersion.cmake"
212
+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/ISAL
213
+ )
214
+
215
+ # Optional: Create pkg-config file
216
+ set (prefix ${CMAKE_INSTALL_PREFIX} )
217
+ set (exec_prefix \${prefix} )
218
+ set (libdir \${prefix} /${CMAKE_INSTALL_LIBDIR} )
219
+ set (includedir \${prefix} /${CMAKE_INSTALL_INCLUDEDIR} )
220
+ set (VERSION ${PROJECT_VERSION} )
221
+
222
+ configure_file (
223
+ "${CMAKE_SOURCE_DIR} /libisal.pc.in"
224
+ "${CMAKE_BINARY_DIR} /libisal.pc"
225
+ @ONLY
226
+ )
227
+
228
+ install (FILES "${CMAKE_BINARY_DIR} /libisal.pc"
229
+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig
230
+ )
0 commit comments