Skip to content

Commit

Permalink
Build oqs-internal library
Browse files Browse the repository at this point in the history
  • Loading branch information
SWilson4 committed Jan 12, 2024
1 parent 29f2286 commit 9ca233b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,34 @@ add_library(oqs kem/kem.c
sig/sig.c
${SIG_OBJS}
${COMMON_OBJS})

# Internal library to be used only by test programs
add_library(oqs-internal ${INTERNAL_OBJS})

set(COMMON_OBJS ${COMMON_OBJS} PARENT_SCOPE)
set(_ALL_OBJS ${KEM_OBJS} ${SIG_OBJS} ${COMMON_OBJS} $<TARGET_OBJECTS:oqs>)
set(ALL_OBJS ${_ALL_OBJS} PARENT_SCOPE)
if(DEFINED SANITIZER_LD_FLAGS)
target_link_libraries(oqs PUBLIC ${SANITIZER_LD_FLAGS})
target_link_libraries(oqs-internal PUBLIC ${SANITIZER_LD_FLAGS})
endif()
if(${OQS_USE_OPENSSL})
target_link_libraries(oqs PRIVATE ${OPENSSL_CRYPTO_LIBRARY})
target_link_libraries(oqs-internal PRIVATE ${OPENSSL_CRYPTO_LIBRARY})
endif()

target_include_directories(oqs
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

target_include_directories(oqs-internal
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

set_target_properties(oqs
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib"
Expand All @@ -77,6 +90,14 @@ set_target_properties(oqs
# For Windows DLLs
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")

set_target_properties(oqs-internal
PROPERTIES
C_VISIBILITY_PRESET default
ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib"
# For Windows DLLs
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/liboqsConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/liboqs
Expand Down
19 changes: 19 additions & 0 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include(CheckSymbolExists)

# initialize to avoid --warn-uninitialized report
set(_COMMON_OBJS "")
set(_INTERNAL_OBJS "")

if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
CMAKE_C_COMPILER_ID MATCHES "Clang")
Expand Down Expand Up @@ -81,8 +82,17 @@ add_library(common OBJECT ${AES_IMPL}
rand/rand.c
rand/rand_nist.c)

# Implementations of the internal API to be exposed to test programs
add_library(internal OBJECT ${AES_IMPL}
${SHA2_IMPL}
${SHA3_IMPL}
${OSSL_HELPERS}
common.c)
set_property(TARGET internal PROPERTY C_VISIBILITY_PRESET default)

if(${OQS_USE_OPENSSL})
target_include_directories(common PRIVATE ${OPENSSL_INCLUDE_DIR})
target_include_directories(internal PRIVATE ${OPENSSL_INCLUDE_DIR})
else()
check_symbol_exists(getentropy "unistd.h;sys/random.h" CMAKE_HAVE_GETENTROPY)
if(${CMAKE_HAVE_GETENTROPY})
Expand All @@ -91,6 +101,7 @@ else()
endif()
if(CMAKE_USE_PTHREADS_INIT)
target_link_libraries(common PRIVATE Threads::Threads)
target_link_libraries(internal PRIVATE Threads::Threads)
endif()

# check available functions to perform aligned mallocs
Expand All @@ -100,14 +111,17 @@ check_symbol_exists(memalign malloc.h CMAKE_HAVE_MEMALIGN)

if(CMAKE_HAVE_ALIGNED_ALLOC)
target_compile_definitions(common PRIVATE OQS_HAVE_ALIGNED_ALLOC)
target_compile_definitions(internal PRIVATE OQS_HAVE_ALIGNED_ALLOC)
endif()

if(CMAKE_HAVE_POSIX_MEMALIGN)
target_compile_definitions(common PRIVATE OQS_HAVE_POSIX_MEMALIGN)
target_compile_definitions(internal PRIVATE OQS_HAVE_POSIX_MEMALIGN)
endif()

if(CMAKE_HAVE_MEMALIGN)
target_compile_definitions(common PRIVATE OQS_HAVE_MEMALIGN)
target_compile_definitions(internal PRIVATE OQS_HAVE_MEMALIGN)
endif()

# check if explicit_bzero exists or memset_s
Expand All @@ -116,15 +130,20 @@ check_symbol_exists(memset_s string.h CMAKE_HAVE_MEMSET_S)

if(CMAKE_HAVE_EXPLICIT_BZERO)
target_compile_definitions(common PRIVATE OQS_HAVE_EXPLICIT_BZERO)
target_compile_definitions(internal PRIVATE OQS_HAVE_EXPLICIT_BZERO)
endif()

if(CMAKE_HAVE_MEMSET_S)
target_compile_definitions(common PRIVATE OQS_HAVE_MEMSET_S)
target_compile_definitions(internal PRIVATE OQS_HAVE_MEMSET_S)
endif()

if(${OQS_ENABLE_SHA3_xkcp_low}) # using XKCP
set(_COMMON_OBJS ${_COMMON_OBJS} ${XKCP_LOW_OBJS})
set(_INTERNAL_OBJS ${_INTERNAL_OBJS} ${XKCP_LOW_OBJS})
endif()

set(_COMMON_OBJS ${_COMMON_OBJS} $<TARGET_OBJECTS:common>)
set(COMMON_OBJS ${_COMMON_OBJS} PARENT_SCOPE)
set(_INTERNAL_OBJS ${_INTERNAL_OBJS} $<TARGET_OBJECTS:internal>)
set(INTERNAL_OBJS ${_INTERNAL_OBJS} PARENT_SCOPE)

0 comments on commit 9ca233b

Please sign in to comment.