Skip to content

Commit

Permalink
🔧🔨 Fix CMake's handling of OpenSSL + Install it in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFouchy committed Feb 6, 2025
1 parent 4a2a376 commit 07e7755
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 41 deletions.
42 changes: 41 additions & 1 deletion .github/workflows/build_and_run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,41 @@ jobs:
if: matrix.config.name == 'Windows MSVC'
uses: ilammy/[email protected]

- name: Cache vcpkg
if: runner.os == 'Windows'
uses: actions/cache@v4
with:
path: |
${{ runner.temp }}/vcpkg
key: vcpkg-${{ runner.os }}-${{ hashFiles('**/vcpkg.json') }}
restore-keys: vcpkg-${{ runner.os }}-

- name: Cache vcpkg installed packages
if: runner.os == 'Windows'
uses: actions/cache@v4
with:
path: |
${{ runner.temp }}/vcpkg/installed
${{ runner.temp }}/vcpkg/buildtrees
key: vcpkg-packages-${{ runner.os }}-${{ hashFiles('**/vcpkg.json') }}
restore-keys: vcpkg-packages-${{ runner.os }}-

- name: Install vcpkg
if: runner.os == 'Windows'
run: |
if not exist "${{ runner.temp }}\vcpkg" (
git clone https://github.com/microsoft/vcpkg.git ${{ runner.temp }}\vcpkg
cd ${{ runner.temp }}\vcpkg
.\bootstrap-vcpkg.bat
)
shell: cmd

- name: Install Windows dependencies
if: runner.os == 'Windows'
run: |
${{ runner.temp }}\vcpkg\vcpkg.exe install openssl:x64-windows
shell: cmd

- name: Install Linux dependencies
if: runner.os == 'Linux'
run: |
Expand All @@ -82,12 +117,17 @@ jobs:
with:
key: ${{matrix.config.name}}-${{matrix.build_type}}

- name: Set CMake Toolchain Argument
if: runner.os == 'Windows'
run: echo "CMAKE_TOOLCHAIN_ARG=-D CMAKE_TOOLCHAIN_FILE=${{ runner.temp }}\vcpkg\scripts\buildsystems\vcpkg.cmake" >> $GITHUB_ENV
shell: bash

- name: Build
uses: lukka/run-cmake@v3
with:
cmakeListsOrSettingsJson: CMakeListsTxtAdvanced
cmakeListsTxtPath: ${{github.workspace}}/${{env.cmakelists_folder}}/CMakeLists.txt
cmakeAppendedArgs: ${{env.cmake_configure_args}} -D CMAKE_BUILD_TYPE=${{matrix.build_type}} ${{matrix.config.cmake_configure_args}} -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
cmakeAppendedArgs: ${{env.cmake_configure_args}} -D CMAKE_BUILD_TYPE=${{matrix.build_type}} ${{matrix.config.cmake_configure_args}} -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache ${{ env.CMAKE_TOOLCHAIN_ARG }}
buildWithCMakeArgs: --config ${{matrix.build_type}} --target ${{env.cmake_target}}
cmakeBuildType: ${{matrix.build_type}}
buildDirectory: ${{github.workspace}}/build
Expand Down
42 changes: 41 additions & 1 deletion .github/workflows/create_release_executables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,41 @@ jobs:
if: matrix.config.name == 'Windows'
uses: ilammy/[email protected]

- name: Cache vcpkg
if: runner.os == 'Windows'
uses: actions/cache@v4
with:
path: |
${{ runner.temp }}/vcpkg
key: vcpkg-${{ runner.os }}-${{ hashFiles('**/vcpkg.json') }}
restore-keys: vcpkg-${{ runner.os }}-

- name: Cache vcpkg installed packages
if: runner.os == 'Windows'
uses: actions/cache@v4
with:
path: |
${{ runner.temp }}/vcpkg/installed
${{ runner.temp }}/vcpkg/buildtrees
key: vcpkg-packages-${{ runner.os }}-${{ hashFiles('**/vcpkg.json') }}
restore-keys: vcpkg-packages-${{ runner.os }}-

- name: Install vcpkg
if: runner.os == 'Windows'
run: |
if not exist "${{ runner.temp }}\vcpkg" (
git clone https://github.com/microsoft/vcpkg.git ${{ runner.temp }}\vcpkg
cd ${{ runner.temp }}\vcpkg
.\bootstrap-vcpkg.bat
)
shell: cmd

- name: Install Windows dependencies
if: runner.os == 'Windows'
run: |
${{ runner.temp }}\vcpkg\vcpkg.exe install openssl:x64-windows
shell: cmd

- name: Install Linux dependencies
if: runner.os == 'Linux'
run: |
Expand All @@ -64,12 +99,17 @@ jobs:
with:
key: ${{matrix.config.name}} Clang-Release # Key name should match the one used in build_and_run_tests.yml so that we can reuse its cache.

- name: Set CMake Toolchain Argument
if: runner.os == 'Windows'
run: echo "CMAKE_TOOLCHAIN_ARG=-D CMAKE_TOOLCHAIN_FILE=${{ runner.temp }}\vcpkg\scripts\buildsystems\vcpkg.cmake" >> $GITHUB_ENV
shell: bash

- name: Build
uses: lukka/run-cmake@v3
with:
cmakeListsOrSettingsJson: CMakeListsTxtAdvanced
cmakeListsTxtPath: ${{github.workspace}}/${{env.cmakelists_folder}}/CMakeLists.txt
cmakeAppendedArgs: ${{env.cmake_configure_args}} -D CPACK_GENERATOR=${{matrix.config.cpack_generator}} -D CMAKE_BUILD_TYPE=Release ${{matrix.config.cmake_configure_args}} -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
cmakeAppendedArgs: ${{env.cmake_configure_args}} -D CPACK_GENERATOR=${{matrix.config.cpack_generator}} -D CMAKE_BUILD_TYPE=Release ${{matrix.config.cmake_configure_args}} -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache ${{ env.CMAKE_TOOLCHAIN_ARG }}
buildWithCMakeArgs: --config Release --target ${{env.cmake_target}}
cmakeBuildType: Release
buildDirectory: ${{github.workspace}}/build
Expand Down
46 changes: 14 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,43 +54,25 @@ target_include_directories(Coollab-Properties INTERFACE lib/range-v3/include)
install(FILES "lib/range-v3/LICENSE.txt" DESTINATION "license/range-v3")

set(COOLLAB_REQUIRE_ALL_FEATURES OFF CACHE BOOL "Some features are optional, like making HTTPS requests to post images to the Coollab gallery. If you don't have the necessary dependencies these features will be disabled. If you want to make sure you have all the features of Coollab enabled, set this option to ON.")
set(COOLLAB_BUILD_WITH_OPENSSL ON CACHE BOOL "Needed to make HTTPS requests to post images to the Coollab gallery.")

# ----------------
# ---OpenSSL---
# ----------------
# Link OpenSSL if we find it. It will be used
# to send images to the Coollab gallery.
# If OpenSSL is not found this feature will be disabled.
# Note: cpp-httplib can only work with OpenSSL versions 3 or 1.1.1
# Set the path to OpenSSL library directory
if(COOLLAB_BUILD_WITH_OPENSSL)
set(OPENSSL_USE_STATIC_LIBS TRUE)

if(NOT APPLE) # Disabled on Mac for now, because brew installs versions 3.3 now, which isn't compatible with cpp-httplib
find_package(OpenSSL 3)

if(NOT OpenSSL_FOUND)
if(COOLLAB_REQUIRE_ALL_FEATURES)
find_package(OpenSSL 1.1.1 REQUIRED)
else()
find_package(OpenSSL 1.1.1)
endif()
endif()
endif()

if(OpenSSL_FOUND)
message("[Coollab] Found OpenSSL.")
target_link_libraries(Coollab-Properties INTERFACE OpenSSL::SSL OpenSSL::Crypto)
target_compile_definitions(Coollab-Properties INTERFACE "COOLLAB_HAS_OPENSSL")
else()
message("[Coollab] Did not find OpenSSL. Posting images to the Coollab gallery will be disabled.")
endif()
# -----------------
# ---cpp-httplib---
# -----------------
set(OPENSSL_USE_STATIC_LIBS ON CACHE BOOL "" FORCE)

if(COOLLAB_REQUIRE_ALL_FEATURES)
set(HTTPLIB_REQUIRE_OPENSSL ON CACHE BOOL "" FORCE)
set(HTTPLIB_USE_OPENSSL_IF_AVAILABLE OFF CACHE BOOL "" FORCE)
else()
message("[Coollab] Disabled building with OpenSSL.")
set(HTTPLIB_REQUIRE_OPENSSL OFF CACHE BOOL "" FORCE)
set(HTTPLIB_USE_OPENSSL_IF_AVAILABLE ON CACHE BOOL "" FORCE)
endif()

add_subdirectory(lib/cpp-httplib)
target_link_libraries(Coollab-Properties INTERFACE httplib)
install(FILES "lib/cpp-httplib/LICENSE" DESTINATION "license/cpp-httplib")

# License
install(FILES "LICENSE.txt" DESTINATION "license" RENAME "Coollab-LICENSE.txt")

# Grab all the source files
Expand Down
2 changes: 1 addition & 1 deletion Cool
Submodule Cool updated 1 files
+6 −6 src/Cool/Task/TaskManager.cpp
2 changes: 1 addition & 1 deletion src/Gallery/GalleryPublisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ GalleryPublisher::GalleryPublisher()
}

static constexpr bool has_openssl =
#if COOLLAB_HAS_OPENSSL
#if CPPHTTPLIB_OPENSSL_SUPPORT
true;
#else
false;
Expand Down
6 changes: 1 addition & 5 deletions src/Gallery/Task_PublishImageToGallery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#include "Cool/ImGui/markdown.h"
#include "Cool/String/String.h"
#include "ImGuiNotify/ImGuiNotify.hpp"

#if COOLLAB_HAS_OPENSSL
#define CPPHTTPLIB_OPENSSL_SUPPORT
#include "cpp-httplib/httplib.h"

static auto escape(std::string str) -> std::string
Expand Down Expand Up @@ -45,13 +42,12 @@ TEST_CASE("process_link()")
CHECK(process_link("@@") == "https://www.instagram.com/@");
}
#endif
#endif

namespace Lab {

void Task_PublishImageToGallery::execute()
{
#if COOLLAB_HAS_OPENSSL
#if CPPHTTPLIB_OPENSSL_SUPPORT
auto const image_png_data =
img::save_png_to_string(
_image,
Expand Down

0 comments on commit 07e7755

Please sign in to comment.