From 97b9086e728765f2f956fe9263736b0cf933219e Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Wed, 31 Jul 2024 09:52:28 -0700 Subject: [PATCH] Fix OpenSSL dependency in CMake (#2447) --- .github/workflows/build.yml | 31 +++++++++++++++++++++++--- scripts/example-project/CMakeLists.txt | 11 +++++++++ scripts/example-project/example.cpp | 3 +++ scripts/wabt-config.cmake.in | 5 +++++ 4 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 scripts/example-project/CMakeLists.txt create mode 100644 scripts/example-project/example.cpp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5932a2c4e3..3a4442b38b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -80,7 +80,7 @@ jobs: docker exec emscripten emcc -v docker exec emscripten emcmake cmake -B emscripten -DWERROR=ON docker exec -w /src/emscripten emscripten make -j $(nproc) - + wasi: name: wasi runs-on: ubuntu-latest @@ -162,10 +162,35 @@ jobs: python -m pip install -U setuptools wheel pip python -m pip install "cmake==${WABT_CMAKE_VER}.*" cmake --version - - name: Configure WABT + + - name: configure (OpenSSL) run: cmake -G Ninja -S . -B out -DCMAKE_BUILD_TYPE=Release - - name: build + - name: build (OpenSSL) run: cmake --build out + - name: install (OpenSSL) + run: cmake --install out --prefix install + + - name: configure (PicoSHA2) + run: cmake -G Ninja -S . -B out-picosha -DCMAKE_BUILD_TYPE=Release -DUSE_INTERNAL_SHA256=ON + - name: build (PicoSHA2) + run: cmake --build out-picosha + - name: install (PicoSHA2) + run: cmake --install out-picosha --prefix install-picosha + + - name: test CMake package (OpenSSL) + run: > + ctest --build-and-test scripts/example-project example-openssl + --build-generator Ninja + --build-options -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PWD/install + --test-command ctest + + - name: test CMake package (PicoSHA2) + run: > + ctest --build-and-test scripts/example-project example-picosha + --build-generator Ninja + --build-options -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PWD/install-picosha + --test-command ctest + - name: unittests run: cmake --build out --target run-unittests - name: c-api-tests diff --git a/scripts/example-project/CMakeLists.txt b/scripts/example-project/CMakeLists.txt new file mode 100644 index 0000000000..0ff3bb3261 --- /dev/null +++ b/scripts/example-project/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.16) +project(example CXX) + +enable_testing() + +find_package(wabt REQUIRED) + +add_executable(example example.cpp) +target_link_libraries(example PRIVATE wabt::wabt) + +add_test(NAME example COMMAND example) diff --git a/scripts/example-project/example.cpp b/scripts/example-project/example.cpp new file mode 100644 index 0000000000..680b99e3a7 --- /dev/null +++ b/scripts/example-project/example.cpp @@ -0,0 +1,3 @@ +#include + +int main () {} diff --git a/scripts/wabt-config.cmake.in b/scripts/wabt-config.cmake.in index 56e8bf8e1f..d66ff676bc 100644 --- a/scripts/wabt-config.cmake.in +++ b/scripts/wabt-config.cmake.in @@ -1,5 +1,10 @@ cmake_minimum_required(VERSION 3.8) @PACKAGE_INIT@ +if ("@HAVE_OPENSSL_SHA_H@") + include(CMakeFindDependencyMacro) + find_dependency(OpenSSL) +endif () + include("${CMAKE_CURRENT_LIST_DIR}/wabt-targets.cmake") check_required_components(wabt)