|
| 1 | +#/********************************************************************** |
| 2 | +# Copyright(c) 2025 Intel Corporation All rights reserved. |
| 3 | +# |
| 4 | +# Redistribution and use in source and binary forms, with or without |
| 5 | +# modification, are permitted provided that the following conditions |
| 6 | +# are met: |
| 7 | +# * Redistributions of source code must retain the above copyright |
| 8 | +# notice, 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 |
| 11 | +# the documentation and/or other materials provided with the |
| 12 | +# distribution. |
| 13 | +# * Neither the name of Intel Corporation nor the names of its |
| 14 | +# contributors may be used to endorse or promote products derived |
| 15 | +# from this software without specific prior written permission. |
| 16 | +# |
| 17 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 | +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 | +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 | +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 | +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 | +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 | +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 | +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 | +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | +#**********************************************************************/ |
| 29 | + |
| 30 | +# Only set project and cmake_minimum_required if this is the root project |
| 31 | +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| 32 | + cmake_minimum_required(VERSION 3.16) |
| 33 | + # Project name |
| 34 | + project(isal_shim LANGUAGES C) |
| 35 | +endif() |
| 36 | + |
| 37 | +# Set the library name |
| 38 | +set(LIBRARY_NAME isal-shim) |
| 39 | + |
| 40 | +# Collect all source files in the current directory |
| 41 | +file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.c") |
| 42 | + |
| 43 | +# Add the include directory for the header file |
| 44 | +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../include") |
| 45 | + |
| 46 | +# Set default build type to Release if not specified |
| 47 | +if(NOT CMAKE_BUILD_TYPE) |
| 48 | + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build" FORCE) |
| 49 | +endif() |
| 50 | + |
| 51 | +# Set debug flags for Debug build type |
| 52 | +set(CMAKE_C_FLAGS_DEBUG "-g -O0 -DDEBUG") |
| 53 | + |
| 54 | +# Create the shared library |
| 55 | +add_library(${LIBRARY_NAME} SHARED ${SOURCES}) |
| 56 | + |
| 57 | +# Handle linking differently based on whether this is built as part of the main project or standalone |
| 58 | +if(TARGET isal) |
| 59 | + # Building as part of the main ISA-L project - link with the isal target |
| 60 | + target_link_libraries(${LIBRARY_NAME} PRIVATE isal) |
| 61 | + target_include_directories(${LIBRARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/include") |
| 62 | +else() |
| 63 | + # Building standalone - find and link with installed isal library |
| 64 | + if (NOT DEFINED ISAL_INSTALL_DIR) |
| 65 | + # Link the library with isal |
| 66 | + find_library(ISAL_LIBRARY isal REQUIRED) |
| 67 | + target_link_libraries(${LIBRARY_NAME} PRIVATE ${ISAL_LIBRARY}) |
| 68 | + else() |
| 69 | + # Link the library with isal built and installed in ISAL_INSTALL_DIR |
| 70 | + find_library(ISAL_LIBRARY isal PATHS "${ISAL_INSTALL_DIR}/lib" NO_DEFAULT_PATH REQUIRED) |
| 71 | + target_include_directories(${LIBRARY_NAME} PRIVATE "${ISAL_INSTALL_DIR}/include") |
| 72 | + target_link_libraries(${LIBRARY_NAME} PRIVATE ${ISAL_LIBRARY}) |
| 73 | + endif() |
| 74 | +endif() |
| 75 | + |
| 76 | +# Set the output name for the shared library |
| 77 | +set_target_properties(${LIBRARY_NAME} PROPERTIES OUTPUT_NAME "isal-shim") |
| 78 | + |
| 79 | +# Remove the "lib" prefix from the shared library name |
| 80 | +set_target_properties(${LIBRARY_NAME} PROPERTIES PREFIX "") |
| 81 | + |
| 82 | +# Install the shim library when built as part of the main project |
| 83 | +if(TARGET isal) |
| 84 | + include(GNUInstallDirs) |
| 85 | + install(TARGETS ${LIBRARY_NAME} |
| 86 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 87 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 88 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 89 | + ) |
| 90 | +endif() |
0 commit comments