Skip to content

Commit

Permalink
Build a module instead of a shared library. (#207)
Browse files Browse the repository at this point in the history
Fix #202.

This commit switches the default type in CMake from `SHARED` to `MODULE`.

Using [`SUFFIX`](https://cmake.org/cmake/help/latest/prop_tgt/SUFFIX.html)
property of CMake targets to explicitly specify the module extension when building for
a XNU-based platform (macOS, iOS, watchOS, etc.) and Windows such as to allow
OpenSSL to find the provider on a given platform.
  • Loading branch information
thb-sb authored Jul 7, 2023
1 parent 773289a commit 466a537
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@ jobs:
key: ${{ runner.os }}-cygwinopenssl32
- name: build oqs-provider
run: bash -c "git config --global --add safe.directory $(cygpath -u $PWD) && liboqs_DIR='${{ env.IP }}' cmake -GNinja -DCMAKE_C_COMPILER=gcc -DOPENSSL_ROOT_DIR=/opt/openssl32 -S . -B _build && cd _build && ninja && cd .."
- name: Adapt oqsprovider.dll name
run: bash -c "cp oqsprovider-1.dll oqsprovider.dll"
working-directory: _build/bin
- name: Check Openssl providers
run: bash -c "OPENSSL_MODULES=_build/bin /opt/openssl32/bin/openssl list -providers -provider oqsprovider -provider default"
run: bash -c "OPENSSL_MODULES=_build/lib /opt/openssl32/bin/openssl list -providers -provider oqsprovider -provider default"
- name: Run tests
run: bash -c "echo $PATH && PATH=/opt/openssl32/bin:/usr/bin ctest -V"
working-directory: _build
Expand Down Expand Up @@ -200,5 +197,5 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: oqs-provider-msvc
path: D:/a/oqs-provider/oqs-provider/_build/bin/oqsprovider.dll
path: D:/a/oqs-provider/oqs-provider/_build/lib/oqsprovider.dll

29 changes: 28 additions & 1 deletion oqsprov/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ set(PROVIDER_SOURCE_FILES
set(PROVIDER_HEADER_FILES
oqs_prov.h oqs_endecoder_local.h
)
add_library(oqsprovider SHARED ${PROVIDER_SOURCE_FILES})
add_library(oqsprovider MODULE ${PROVIDER_SOURCE_FILES})
if (USE_ENCODING_LIB)
add_dependencies(oqsprovider encoder)
endif()
Expand All @@ -43,8 +43,35 @@ set_target_properties(oqsprovider
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
VERSION ${OQSPROVIDER_VERSION_TEXT}
SOVERSION 1
# Compatibility version (-compatibility_version) and current version
# (-current_version) are not compatible with a `MODULE` library.
# However, `VERSION` and `SOVERSION` set these two flags.
# The following two flags remove them.
MACHO_COMPATIBILITY_VERSION OFF
MACHO_CURRENT_VERSION OFF
# For Windows DLLs
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

if (APPLE)
# OpenSSL looks for `.dylib` files on XNU-based platforms.
# Because `MODULE` writes to a `.so` file by default, we must explicitely
# set the suffix here.
set_target_properties(oqsprovider
PROPERTIES
SUFFIX ".dylib"
)
endif()

if (CYGWIN OR MSVC)
# OpenSSL looks for `.dll` files on Windows platforms.
# Because `MODULE` writes to a `.so` file by default, we must explicitely
# set the suffix here.
set_target_properties(oqsprovider
PROPERTIES
SUFFIX ".dll"
)
endif()

target_link_libraries(oqsprovider OQS::oqs ${OPENSSL_CRYPTO_LIBRARY} ${OQS_ADDL_SOCKET_LIBS})
if (USE_ENCODING_LIB)
target_link_libraries(oqsprovider qsc_key_encoder)
Expand Down
4 changes: 0 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
include(GNUInstallDirs)
if (WIN32 OR CYGWIN)
set(OQS_PROV_BINARY_DIR ${CMAKE_BINARY_DIR}/bin)
else()
set(OQS_PROV_BINARY_DIR ${CMAKE_BINARY_DIR}/lib)
endif()

add_test(
NAME oqs_signatures
Expand Down

0 comments on commit 466a537

Please sign in to comment.