|
| 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 | +) |
0 commit comments