Skip to content

Commit

Permalink
Enable LIBOQS_DIR as cache entry and environment variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
thb-sb committed Oct 6, 2023
1 parent 5fd47f9 commit 196bdab
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,86 @@ jobs:
with:
name: oqsprovider-aarch64
path: build/*.deb

test_cmake_liboqs_dir_value:
name: "Test CMake `liboqs_DIR` and `LIBOQS_DIR` values"
runs-on: ubuntu-latest
strategy:
fail-fast: false
container:
image: openquantumsafe/ci-ubuntu-jammy:latest
env:
OPENSSL_BRANCH: "master"
INSTALL_ALT_DIR: "/opt/install"
LIBOQS_CMAKE_PACKAGE_DIR: "/usr/lib/cmake/liboqs"
LIBOQS_CMAKE_PACKAGE_ALT_DIR: "/opt/install/lib/cmake/liboqs"

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Prepare install directory
run: mkdir -p "${INSTALL_DIR}"

- name: Clone and build liboqs for linux-aarch64
working-directory: /opt/
run: |
git clone --depth=1 --branch main https://github.com/open-quantum-safe/liboqs.git liboqs
cd liboqs
mkdir build install
cmake -GNinja -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DOQS_USE_OPENSSL=OFF
cmake --build build -j$(nproc)
cmake --install build
cmake --install build --prefix "${INSTALL_ALT_DIR}"
- name: Test oqs-provider CMake script against `liboqs_DIR`, `LIBOQS_DIR`
run: |
get_liboqs_dir() {
cmake -L build/ | grep '^liboqs_DIR' | cut -d'=' -f2
}
cmake -B build -Dliboqs_DIR="${LIBOQS_CMAKE_PACKAGE_ALT_DIR}"
value="$(get_liboqs_dir)"
if [[ "${value}" != "${LIBOQS_CMAKE_PACKAGE_ALT_DIR}" ]]; then
echo "liboqs_DIR cache entry did not work: got ${value}, expected ${LIBOQS_CMAKE_PACKAGE_ALT_DIR}"
exit 1
fi
rm -rf build
cmake -B build -DLIBOQS_DIR="${LIBOQS_CMAKE_PACKAGE_ALT_DIR}"
value="$(get_liboqs_dir)"
if [[ "${value}" != "${LIBOQS_CMAKE_PACKAGE_ALT_DIR}" ]]; then
echo "LIBOQS_DIR cache entry did not work: got ${value}, expected ${LIBOQS_CMAKE_PACKAGE_ALT_DIR}"
exit 1
fi
rm -rf build
if cmake -B build -Dliboqs_DIR="${LIBOQS_CMAKE_PACKAGE_DIR}" -DLIBOQS_DIR="${LIBOQS_CMAKE_PACKAGE_ALT_DIR}"; then
echo "cmake succeed when it should have failed: liboqs_DIR and LIBOQS_DIR cache entries mismatched"
exit 1
fi
rm -rf build
env LIBOQS_DIR="${LIBOQS_CMAKE_PACKAGE_ALT_DIR}" cmake -B build
value="$(get_liboqs_dir)"
if [[ "${value}" != "${LIBOQS_CMAKE_PACKAGE_ALT_DIR}" ]]; then
echo "LIBOQS_DIR environment variable did not work: got ${value}, expected ${LIBOQS_CMAKE_PACKAGE_ALT_DIR}"
exit 1
fi
rm -rf build
if env LIBOQS_DIR="${LIBOQS_CMAKE_PACKAGE_ALT_DIR}" cmake -B build -Dliboqs_DIR="${LIBOQS_CMAKE_PACKAGE_DIR}"; then
echo "cmake succeed when it should have failed: LIBOQS_DIR cache entry and LIBOQS_DIR environment variable mismatched"
exit 1
fi
rm -rf build
env liboqs_DIR="${LIBOQS_CMAKE_PACKAGE_ALT_DIR}" cmake -B build
value="$(get_liboqs_dir)"
if [[ "${value}" != "${LIBOQS_CMAKE_PACKAGE_ALT_DIR}" ]]; then
echo "liboqs_DIR environment variable did not work: got ${value}, expected ${LIBOQS_CMAKE_PACKAGE_ALT_DIR}"
exit 1
fi
40 changes: 40 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,46 @@ get_filename_component(OPENSSL_LIB_DIR ${OPENSSL_CRYPTO_LIBRARY} DIRECTORY)
set(OPENSSL_MODULES_PATH ${OPENSSL_LIB_DIR}/ossl-modules)
endif()

if(DEFINED liboqs_DIR)
get_filename_component(value "${liboqs_DIR}" REALPATH)
set(liboqs_DIR "${value}" CACHE PATH "Path to liboqs CMake configuration directory" FORCE)
endif()

set(liboqs_search_path NULL)
if (DEFINED LIBOQS_DIR)
get_filename_component(LIBOQS_DIR "${LIBOQS_DIR}" REALPATH)
if (DEFINED liboqs_DIR AND NOT "${liboqs_DIR}" STREQUAL "${LIBOQS_DIR}")
message(FATAL_ERROR "`liboqs_DIR` and `LIBOQS_DIR` cache entries mismatch ('${liboqs_DIR}' != '${LIBOQS_DIR}').")
endif()
set(liboqs_search_path "${LIBOQS_DIR}")
endif()

if (DEFINED ENV{LIBOQS_DIR})
get_filename_component(value "$ENV{LIBOQS_DIR}" REALPATH)
if (DEFINED liboqs_DIR AND NOT "${liboqs_DIR}" STREQUAL "${value}")
message(FATAL_ERROR "`liboqs_DIR` cache entry and `LIBOQS_DIR` environment variable mismatch ('${liboqs_DIR}' != '${value}').")
endif()
if (liboqs_search_path AND NOT "${liboqs_search_path}" STREQUAL "${value}")
message(FATAL_ERROR "`LIBOQS_DIR` cache entry and `LIBOQS_DIR` environment variable mismatch ('${LIBOQS_DIR}' != '$ENV{LIBOQS_DIR}').")
endif()
set(liboqs_search_path "${value}")
endif()

if (DEFINED ENV{liboqs_DIR})
get_filename_component(value "$ENV{liboqs_DIR}" REALPATH)
if (DEFINED liboqs_DIR AND NOT "${liboqs_DIR}" STREQUAL "${value}")
message(FATAL_ERROR "`liboqs_DIR` cache entry and `liboqs_DIR` environment variable mismatch ('${liboqs_DIR}' != '${value}'.")
endif()
if (liboqs_search_path AND NOT "${liboqs_search_path}" STREQUAL "${value}")
message(FATAL_ERROR "`libos_DIR` environment variable does not match the value previously set ('${value}' != '${liboqs_search_path}').")
endif()
set(liboqs_search_path "${value}")
endif()

if (liboqs_search_path)
set(liboqs_DIR "${liboqs_search_path}" CACHE PATH "Path to liboqs configuration directory" FORCE)
endif()

# Add required include for liboqs
find_package(liboqs REQUIRED)
get_target_property(LIBOQS_INCLUDE_DIR OQS::oqs INTERFACE_INCLUDE_DIRECTORIES)
Expand Down

0 comments on commit 196bdab

Please sign in to comment.