Skip to content

Commit 612c210

Browse files
committed
Add inital CMake build system
Signed-off-by: Pablo de Lara <[email protected]> Signed-off-by: Harry van Haaren <[email protected]>
1 parent d414b27 commit 612c210

File tree

10 files changed

+975
-1
lines changed

10 files changed

+975
-1
lines changed

CMakeLists.txt

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
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+
# Set default build type
42+
if(NOT CMAKE_BUILD_TYPE)
43+
set(CMAKE_BUILD_TYPE Release)
44+
endif()
45+
46+
# Detect processor architecture
47+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
48+
set(CPU_X86_64 ON)
49+
set(ARCH_DEF "x86_64")
50+
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
51+
set(CPU_AARCH64 ON)
52+
set(ARCH_DEF "aarch64")
53+
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64le")
54+
set(CPU_PPC64LE ON)
55+
set(ARCH_DEF "ppc64le")
56+
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
57+
set(CPU_RISCV64 ON)
58+
set(ARCH_DEF "riscv64")
59+
else()
60+
set(CPU_UNDEFINED ON)
61+
endif()
62+
63+
# Compiler and assembler setup
64+
if(CPU_X86_64)
65+
# Configure NASM flags
66+
set(CMAKE_ASM_NASM_FLAGS "-f elf64 -D LINUX")
67+
set(CMAKE_ASM_NASM_INCLUDES "-I ${CMAKE_SOURCE_DIR}/include/")
68+
set(USE_NASM ON)
69+
elseif(CPU_AARCH64 OR CPU_RISCV64)
70+
# Use C compiler for assembly on ARM and RISC-V
71+
set(ASM_FILTER "${CMAKE_C_COMPILER} -D__ASSEMBLY__")
72+
endif()
73+
74+
# Set include directories
75+
set(ISAL_INCLUDE_DIRS
76+
${CMAKE_SOURCE_DIR}/include
77+
)
78+
79+
# Initialize EXTERN_HEADERS list
80+
set(EXTERN_HEADERS)
81+
82+
# Compiler flags
83+
if(ARCH_DEF)
84+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D${ARCH_DEF}")
85+
endif()
86+
87+
if(CPU_AARCH64 OR CPU_RISCV64)
88+
set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}")
89+
endif()
90+
91+
# Library version (semantic versioning)
92+
set(LIBISAL_VERSION_MAJOR 2)
93+
set(LIBISAL_VERSION_MINOR 31)
94+
set(LIBISAL_VERSION_PATCH 0)
95+
96+
# Include CMake modules for each library component
97+
include(cmake/erasure_code.cmake)
98+
include(cmake/raid.cmake)
99+
include(cmake/crc.cmake)
100+
include(cmake/igzip.cmake)
101+
include(cmake/mem.cmake)
102+
103+
# Add test.h to extern headers (used by all modules)
104+
list(APPEND EXTERN_HEADERS include/test.h)
105+
106+
# Create the main ISA-L library
107+
# Build type option
108+
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
109+
110+
# Create the main ISA-L library
111+
add_library(isal
112+
${ERASURE_CODE_SOURCES}
113+
${RAID_SOURCES}
114+
${CRC_SOURCES}
115+
${IGZIP_SOURCES}
116+
${MEM_SOURCES}
117+
)
118+
119+
# Set library properties
120+
set_target_properties(isal PROPERTIES
121+
VERSION ${LIBISAL_VERSION_MAJOR}.${LIBISAL_VERSION_MINOR}.${LIBISAL_VERSION_PATCH}
122+
SOVERSION ${LIBISAL_VERSION_MAJOR}
123+
PUBLIC_HEADER "${EXTERN_HEADERS}"
124+
)
125+
126+
# Configure include directories for NASM assembly files
127+
if(CPU_X86_64 AND USE_NASM)
128+
# Filter assembly files by module and set appropriate include directories
129+
foreach(source IN LISTS ERASURE_CODE_SOURCES RAID_SOURCES CRC_SOURCES IGZIP_SOURCES MEM_SOURCES)
130+
if(source MATCHES "\\.asm$")
131+
get_filename_component(source_dir ${source} DIRECTORY)
132+
set_source_files_properties(${source} PROPERTIES
133+
INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/include;${CMAKE_SOURCE_DIR}/${source_dir}")
134+
endif()
135+
endforeach()
136+
endif()
137+
138+
# Include directories
139+
target_include_directories(isal
140+
PUBLIC
141+
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
142+
$<INSTALL_INTERFACE:include>
143+
)
144+
145+
# Generate isa-l.h header
146+
set(ISAL_HEADER "${CMAKE_BINARY_DIR}/isa-l.h")
147+
configure_file(${CMAKE_SOURCE_DIR}/cmake/isa-l.h.in ${ISAL_HEADER} @ONLY)
148+
149+
# Install targets
150+
include(GNUInstallDirs)
151+
152+
# Install library
153+
install(TARGETS isal
154+
EXPORT ISALTargets
155+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
156+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
157+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
158+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/isa-l
159+
)
160+
161+
# Install generated header
162+
install(FILES ${ISAL_HEADER}
163+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
164+
)
165+
166+
# Install headers
167+
install(DIRECTORY include/
168+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/isa-l
169+
FILES_MATCHING PATTERN "*.h"
170+
)
171+
172+
# Export targets
173+
install(EXPORT ISALTargets
174+
FILE ISALTargets.cmake
175+
NAMESPACE ISAL::
176+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ISAL
177+
)
178+
179+
# Generate and install package config files
180+
include(CMakePackageConfigHelpers)
181+
182+
configure_package_config_file(
183+
"${CMAKE_SOURCE_DIR}/cmake/ISALConfig.cmake.in"
184+
"${CMAKE_BINARY_DIR}/ISALConfig.cmake"
185+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ISAL
186+
)
187+
188+
write_basic_package_version_file(
189+
"${CMAKE_BINARY_DIR}/ISALConfigVersion.cmake"
190+
VERSION ${PROJECT_VERSION}
191+
COMPATIBILITY SameMajorVersion
192+
)
193+
194+
install(FILES
195+
"${CMAKE_BINARY_DIR}/ISALConfig.cmake"
196+
"${CMAKE_BINARY_DIR}/ISALConfigVersion.cmake"
197+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ISAL
198+
)
199+
200+
# Optional: Create pkg-config file
201+
set(prefix ${CMAKE_INSTALL_PREFIX})
202+
set(exec_prefix \${prefix})
203+
set(libdir \${prefix}/${CMAKE_INSTALL_LIBDIR})
204+
set(includedir \${prefix}/${CMAKE_INSTALL_INCLUDEDIR})
205+
set(VERSION ${PROJECT_VERSION})
206+
207+
configure_file(
208+
"${CMAKE_SOURCE_DIR}/libisal.pc.in"
209+
"${CMAKE_BINARY_DIR}/libisal.pc"
210+
@ONLY
211+
)
212+
213+
install(FILES "${CMAKE_BINARY_DIR}/libisal.pc"
214+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
215+
)

cmake/ISALConfig.cmake.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@PACKAGE_INIT@
2+
3+
include("${CMAKE_CURRENT_LIST_DIR}/ISALTargets.cmake")
4+
5+
check_required_components(ISAL)

cmake/README.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# CMake Build System for ISA-L
2+
3+
This directory contains CMake build configuration files for the ISA-L library (Intelligent Storage Acceleration Library).
4+
5+
## Prerequisites
6+
7+
### Required Tools
8+
9+
- **CMake** 3.12 or later
10+
- **C compiler** (GCC, Clang, or compatible)
11+
12+
### Architecture-Specific Requirements
13+
14+
#### x86_64
15+
- **NASM** (Netwide Assembler) - Required for optimized assembly implementations
16+
17+
#### ARM64/AArch64, RISC-V, PowerPC
18+
- Standard C compiler with assembly support
19+
20+
## Building
21+
22+
### Quick Start
23+
24+
```bash
25+
mkdir build
26+
cd build
27+
cmake ..
28+
make -j$(nproc)
29+
```
30+
31+
### Build Options
32+
33+
#### Specify build type
34+
```bash
35+
cmake -DCMAKE_BUILD_TYPE=Release .. # Default
36+
cmake -DCMAKE_BUILD_TYPE=Debug ..
37+
```
38+
39+
#### Cross-compilation example
40+
```bash
41+
cmake -DCMAKE_TOOLCHAIN_FILE=path/to/toolchain.cmake ..
42+
```
43+
44+
## Installation
45+
46+
```bash
47+
make install
48+
```
49+
50+
Default installation paths:
51+
- Libraries: `/usr/local/lib`
52+
- Headers: `/usr/local/include/isa-l/`
53+
- CMake config: `/usr/local/lib/cmake/ISAL/`
54+
- pkg-config: `/usr/local/lib/pkgconfig/`
55+
56+
### Custom installation prefix
57+
```bash
58+
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
59+
make install
60+
```
61+
62+
## Library Modules
63+
64+
The CMake build system is organized into the following modules:
65+
66+
- **erasure_code** - Erasure coding and Galois Field operations
67+
- **raid** - RAID XOR and P+Q generation functions
68+
- **crc** - CRC16, CRC32, and CRC64 implementations
69+
- **igzip** - Fast deflate/inflate compression
70+
- **mem** - Memory utility functions
71+
72+
## Using ISA-L in Your Project
73+
74+
### CMake Integration
75+
76+
```cmake
77+
find_package(ISAL REQUIRED)
78+
target_link_libraries(your_target ISAL::isal)
79+
```
80+
81+
### pkg-config Integration
82+
83+
```bash
84+
gcc $(pkg-config --cflags --libs libisal) your_program.c
85+
```
86+
87+
### Direct Header Include
88+
89+
```c
90+
#include <isa-l.h> // Includes all ISA-L headers
91+
// or include specific headers:
92+
#include <isa-l/erasure_code.h>
93+
#include <isa-l/raid.h>
94+
#include <isa-l/crc.h>
95+
```
96+
97+
## Architecture Support
98+
99+
| Architecture | Status | Assembly Optimizations |
100+
|--------------|--------|------------------------|
101+
| x86_64 || SSE, AVX, AVX2, AVX-512 |
102+
| AArch64 || NEON, SVE |
103+
| RISC-V 64 || RVV (Vector extensions) |
104+
| PowerPC64LE || VSX |
105+
106+
## Build Targets
107+
108+
- `isal` - Main shared library
109+
- `install` - Install library and headers
110+
111+
## Troubleshooting
112+
113+
### NASM not found (x86_64)
114+
```
115+
sudo apt-get install nasm # Ubuntu/Debian
116+
sudo yum install nasm # RHEL/CentOS
117+
brew install nasm # macOS
118+
```
119+
120+
### Assembly compilation errors
121+
Ensure you have the correct assembler for your platform:
122+
- x86_64: NASM
123+
- ARM/RISC-V: GCC with assembly support
124+
125+
## Contributing
126+
127+
When adding new source files, update the appropriate module file in the `cmake/` directory:
128+
- `cmake/erasure_code.cmake`
129+
- `cmake/raid.cmake`
130+
- `cmake/crc.cmake`
131+
- `cmake/igzip.cmake`
132+
- `cmake/mem.cmake`

0 commit comments

Comments
 (0)