From 31391735689077c238623591655753160168ad38 Mon Sep 17 00:00:00 2001 From: Pierre Wendling Date: Sun, 6 Aug 2023 15:08:28 -0400 Subject: CI: Test consuming the exported CMake configs. --- .github/workflows/cmake_config.yml | 85 ++++++++++++++++++++++++++++++++++++++ tests/cmake/CMakeLists.txt | 37 +++++++++++++++++ tests/cmake/crypto.c | 7 ++++ tests/cmake/ssl.c | 6 +++ tests/cmake/tls.c | 6 +++ 5 files changed, 141 insertions(+) create mode 100644 .github/workflows/cmake_config.yml create mode 100644 tests/cmake/CMakeLists.txt create mode 100644 tests/cmake/crypto.c create mode 100644 tests/cmake/ssl.c create mode 100644 tests/cmake/tls.c diff --git a/.github/workflows/cmake_config.yml b/.github/workflows/cmake_config.yml new file mode 100644 index 0000000..ad1ad75 --- /dev/null +++ b/.github/workflows/cmake_config.yml @@ -0,0 +1,85 @@ +name: cmake_config + +on: [push, pull_request] + +jobs: + cmake-check: + defaults: + run: + shell: bash + strategy: + matrix: + os: [windows-latest, macos-latest, ubuntu-latest] + runs-on: ${{ matrix.os }} + continue-on-error: false + name: ${{ matrix.os }} + steps: + - name: Setup Windows dependencies + if: runner.os == 'Windows' + uses: msys2/setup-msys2@v2 + with: + update: true + install: >- + autoconf + automake + diffutils + libtool + gcc + git + patch + perl + + - name: Setup macOS dependencies + if: runner.os == 'macOS' + run: brew install automake + + - uses: actions/checkout@main + + - name: Prepare source tree for build (Windows) + if: runner.os == 'Windows' + run: ./autogen.sh + shell: msys2 {0} + + - name: Prepare source tree for build (Unix) + if: runner.os != 'Windows' + run: ./autogen.sh + + - name: Configure + run: | + cmake -S . \ + -B build \ + -D CMAKE_BUILD_TYPE=Release \ + -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/../local + + - name: Build + run: cmake --build build --config Release --verbose + + - name: Install + run: cmake --install build --config Release + + - name: Consume from the build directory - Configure + run: | + cmake -S tests/cmake \ + -B consumer-build \ + -D CMAKE_BUILD_TYPE=Release \ + -D LibreSSL_DIR=$GITHUB_WORKSPACE/build + - name: Consume from the build directory - Build + run: cmake --build consumer-build --config Release --verbose + + - name: Consume from the install directory (CMAKE_PREFIX_PATH) - Configure + run: | + cmake -S tests/cmake \ + -B consumer-install-prefix \ + -D CMAKE_BUILD_TYPE=Release \ + -D CMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/../local + - name: Consume from the install directory (CMAKE_PREFIX_PATH) - Build + run: cmake --build consumer-install-prefix --config Release --verbose + + - name: Consume from the install directory (LibreSSL_DIR) - Configure + run: | + cmake -S tests/cmake \ + -B consumer-install-dir \ + -D CMAKE_BUILD_TYPE=Release \ + -D LibreSSL_DIR=$GITHUB_WORKSPACE/../local/lib/cmake/LibreSSL + - name: Consume from the install directory (LibreSSL_DIR) - Build + run: cmake --build consumer-install-dir --config Release --verbose diff --git a/tests/cmake/CMakeLists.txt b/tests/cmake/CMakeLists.txt new file mode 100644 index 0000000..956fbfd --- /dev/null +++ b/tests/cmake/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.5) + +project(LibreSSL_Consumer LANGUAGES C) + +find_package( + LibreSSL + CONFIG + REQUIRED + COMPONENTS Crypto SSL TLS +) + +set(RESULTS_TO_CHECK + "LIBRESSL_VERSION" + "LIBRESSL_FOUND" + "LIBRESSL_INCLUDE_DIR" + "LIBRESSL_LIBRARIES" + "LIBRESSL_CRYPTO_LIBRARY" + "LIBRESSL_SSL_LIBRARY" + "LIBRESSL_TLS_LIBRARY" +) + +foreach(RESULT_VAR IN LISTS RESULTS_TO_CHECK) + if(${RESULT_VAR}) + message(STATUS "${RESULT_VAR}: ${${RESULT_VAR}}") + else() + message(FATAL_ERROR "${RESULT_VAR} was not set by the package.") + endif() +endforeach() + +add_executable(crypto crypto.c) +target_link_libraries(crypto PRIVATE LibreSSL::Crypto) + +add_executable(ssl ssl.c) +target_link_libraries(ssl PRIVATE LibreSSL::SSL) + +add_executable(tls tls.c) +target_link_libraries(tls PRIVATE LibreSSL::TLS) diff --git a/tests/cmake/crypto.c b/tests/cmake/crypto.c new file mode 100644 index 0000000..3838180 --- /dev/null +++ b/tests/cmake/crypto.c @@ -0,0 +1,7 @@ +#include + +int main(void) { + OPENSSL_init_crypto(0, NULL); + OPENSSL_cleanup(); + return 0; +} diff --git a/tests/cmake/ssl.c b/tests/cmake/ssl.c new file mode 100644 index 0000000..2123d6a --- /dev/null +++ b/tests/cmake/ssl.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + SSL_library_init(); + return 0; +} diff --git a/tests/cmake/tls.c b/tests/cmake/tls.c new file mode 100644 index 0000000..1493ab0 --- /dev/null +++ b/tests/cmake/tls.c @@ -0,0 +1,6 @@ +#include + +int main(void) { + tls_init(); + return 0; +} -- cgit v1.2.3-55-g6feb