Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable LIBOQS_DIR as cache entry and environment variable. #275

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,85 @@ 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_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_INSTALL_PREFIX="${INSTALL_DIR}" \
-DOQS_USE_OPENSSL=OFF
cmake --build build -j$(nproc)
cmake --install build

- 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}"
cmake -L build/
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}" ABSOLUTE)
set(liboqs_DIR "${value}" CACHE PATH "Path to liboqs CMake configuration directory" FORCE)
endif()

set(liboqs_search_path "")
if (DEFINED LIBOQS_DIR)
get_filename_component(LIBOQS_DIR "${LIBOQS_DIR}" ABSOLUTE)
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}" ABSOLUTE)
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}" ABSOLUTE)
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
Loading