Skip to content

Commit

Permalink
cmake/crypto: use ExternalProject to build isal crypto library
Browse files Browse the repository at this point in the history
instead of building isa-l_crypto source files directly into the
ceph_crypto_isal plugin, use a cmake ExternalProject to build the
library with make and expose the static library as cmake target
ISAL::Crypto

Signed-off-by: Casey Bodley <[email protected]>
  • Loading branch information
cbodley committed Sep 5, 2024
1 parent 5e51a6e commit 3bfc1ae
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
31 changes: 31 additions & 0 deletions cmake/modules/BuildISALCrypto.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# use an ExternalProject to build isa-l_crypto using its makefile
function(build_isal_crypto)
set(ISAL_CRYPTO_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/crypto/isa-l/isa-l_crypto)
set(ISAL_CRYPTO_INCLUDE_DIR "${ISAL_CRYPTO_SOURCE_DIR}/include")
set(ISAL_CRYPTO_LIBRARY "${ISAL_CRYPTO_SOURCE_DIR}/bin/isa-l_crypto.a")

include(FindMake)
find_make("MAKE_EXECUTABLE" "make_cmd")

include(ExternalProject)
ExternalProject_Add(isal_crypto_ext
SOURCE_DIR ${ISAL_CRYPTO_SOURCE_DIR}
CONFIGURE_COMMAND ""
BUILD_COMMAND ${make_cmd} -f <SOURCE_DIR>/Makefile.unx
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${ISAL_CRYPTO_LIBRARY}
INSTALL_COMMAND ""
UPDATE_COMMAND ""
LOG_CONFIGURE ON
LOG_BUILD ON
LOG_MERGED_STDOUTERR ON
LOG_OUTPUT_ON_FAILURE ON)

# add imported library target ISAL::Crypto
add_library(ISAL::Crypto STATIC IMPORTED GLOBAL)
add_dependencies(ISAL::Crypto isal_crypto_ext)
set_target_properties(ISAL::Crypto PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${ISAL_CRYPTO_INCLUDE_DIR}
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION ${ISAL_CRYPTO_LIBRARY})
endfunction()
29 changes: 5 additions & 24 deletions src/crypto/isa-l/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
set(isal_dir ${CMAKE_SOURCE_DIR}/src/crypto/isa-l/isa-l_crypto)
set(CMAKE_ASM_FLAGS "-i ${isal_dir}/aes/ -i ${isal_dir}/include/ ${CMAKE_ASM_FLAGS}")
# build isa-l_crypto from its makefile and expose as target ISAL::Crypto
include(BuildISALCrypto)
build_isal_crypto()

set(isal_crypto_plugin_srcs
isal_crypto_accel.cc
isal_crypto_plugin.cc
${isal_dir}/aes/cbc_pre.c
${isal_dir}/aes/cbc_multibinary.asm
${isal_dir}/aes/keyexp_128.asm
${isal_dir}/aes/keyexp_192.asm
${isal_dir}/aes/keyexp_256.asm
${isal_dir}/aes/keyexp_multibinary.asm
${isal_dir}/aes/cbc_dec_128_x4_sse.asm
${isal_dir}/aes/cbc_dec_128_x8_avx.asm
${isal_dir}/aes/cbc_dec_192_x4_sse.asm
${isal_dir}/aes/cbc_dec_192_x8_avx.asm
${isal_dir}/aes/cbc_dec_256_x4_sse.asm
${isal_dir}/aes/cbc_dec_256_x8_avx.asm
${isal_dir}/aes/cbc_enc_128_x4_sb.asm
${isal_dir}/aes/cbc_enc_128_x8_sb.asm
${isal_dir}/aes/cbc_enc_192_x4_sb.asm
${isal_dir}/aes/cbc_enc_192_x8_sb.asm
${isal_dir}/aes/cbc_enc_256_x4_sb.asm
${isal_dir}/aes/cbc_enc_256_x8_sb.asm)
isal_crypto_plugin.cc)

if(HAVE_NASM_X64)
add_dependencies(crypto_plugins ceph_crypto_isal)
endif(HAVE_NASM_X64)

add_library(ceph_crypto_isal SHARED ${isal_crypto_plugin_srcs})
target_include_directories(ceph_crypto_isal PRIVATE ${isal_dir}/include)

target_link_libraries(ceph_crypto_isal PRIVATE Boost::context)
target_link_libraries(ceph_crypto_isal PRIVATE ISAL::Crypto Boost::context)

set_target_properties(ceph_crypto_isal PROPERTIES
VERSION 1.0.0
Expand Down

0 comments on commit 3bfc1ae

Please sign in to comment.