Skip to content

Commit

Permalink
Merge pull request #97 from ndsev/less-submodules-introduce-conan
Browse files Browse the repository at this point in the history
Use FetchContent instead of submodules
  • Loading branch information
josephbirkner authored Jul 24, 2023
2 parents 95f9a3a + 0cf9547 commit 400470f
Show file tree
Hide file tree
Showing 18 changed files with 468 additions and 80 deletions.
31 changes: 22 additions & 9 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@ jobs:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
runs-on: ubuntu-latest
container: ghcr.io/klebert-engineering/manylinux-cpp17-py${{ matrix.python-version }}:2023.1
container: ghcr.io/klebert-engineering/manylinux-cpp17-py${{ matrix.python-version }}:2023.2
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Cache Conan packages
uses: actions/cache@v2
with:
path: ~/.conan/data
key: ${{ runner.os }}-conan-${{ hashFiles('**/conanfile.txt') }}
restore-keys: |
${{ runner.os }}-conan-
- name: Configure
run: |
python3 -m venv venv && . ./venv/bin/activate
pip install -U setuptools wheel pip
pip install -U setuptools wheel pip conan==2.0.8
mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release ..
- name: Build
working-directory: build
run: |
export LD_LIBRARY_PATH=$(pwd)/bin:${LD_LIBRARY_PATH}
. ../venv/bin/activate
cmake --build .
mv bin/wheel bin/wheel-auditme
Expand All @@ -40,40 +48,45 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest]
os: [macos-13, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Cache Conan packages
uses: actions/cache@v2
with:
path: ~/.conan/data
key: ${{ runner.os }}-conan-${{ hashFiles('**/conanfile.txt') }}
restore-keys: |
${{ runner.os }}-conan-
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: python -m pip install setuptools wheel
- run: python -m pip install setuptools wheel conan==2.0.8
- run: mkdir build
- name: Build (macOS)
if: matrix.os == 'macos-latest' || matrix.os == 'macos-10.15'
if: matrix.os == 'macos-13'
working-directory: build
run: |
export MACOSX_DEPLOYMENT_TARGET=10.15
python -m pip install delocate
brew install openssl
export OPENSSL_ROOT_DIR=$(brew --prefix openssl)
cmake -DPython3_ROOT_DIR=$pythonLocation \
-DPython3_FIND_FRAMEWORK=LAST \
-DCMAKE_BUILD_TYPE=Release \
-DHTTPLIB_USE_BROTLI_IF_AVAILABLE=OFF ..
cmake --build .
mv bin/wheel bin/wheel-auditme # Same as on Linux
mkdir bin/wheel && mv bin/wheel-auditme/zswag*.whl bin/wheel
../deps/python-cmake-wheel/repair-wheel-macos.bash \
_deps/python-cmake-wheel-src/repair-wheel-macos.bash \
"$(pwd)"/bin/wheel-auditme/pyzswagcl*.whl \
"$(pwd)"/bin/wheel pyzswagcl
- name: Build (Windows)
if: matrix.os == 'windows-latest'
working-directory: build
run: |
choco install --no-progress -y openssl
echo "cmake -DPython3_ROOT_DIR=$env:pythonLocation"
cmake "-DPython3_ROOT_DIR=$env:pythonLocation" -DPython3_FIND_REGISTRY=LAST -DHTTPLIB_USE_ZLIB_IF_AVAILABLE=OFF -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,9 @@ dmypy.json
# Pyre type checker
.pyre/
dist/

# VSCode stuff
.vscode/

# CodeChecker stuff
.codechecker/
24 changes: 0 additions & 24 deletions .gitmodules

This file was deleted.

124 changes: 99 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.24)
# Add conan 2.0 support
set(CMAKE_PROJECT_TOP_LEVEL_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/conan-provider.cmake)

if (NOT PROJECT_NAME)
set (ZSWAG_ENABLE_TESTING ON)
endif()

project(zswag)
enable_testing()

include(FetchContent)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -27,21 +31,39 @@ set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${ZSWAG_DEPLOY_DIR}")
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${ZSWAG_DEPLOY_DIR}")

##############
# deps
# dependencies

find_package(OpenSSL REQUIRED)
find_package(OpenSSL CONFIG REQUIRED)
if(ZSWAG_KEYCHAIN_SUPPORT)
find_package(keychain CONFIG REQUIRED)
endif()

if (ZSWAG_BUILD_WHEELS)
FetchContent_Declare(python-cmake-wheel
GIT_REPOSITORY "https://github.com/Klebert-Engineering/python-cmake-wheel"
GIT_TAG "debug-macos-zswag-build"
GIT_SHALLOW ON)

FetchContent_GetProperties(python-cmake-wheel)

if(NOT python-cmake-wheel_POPULATED)
FetchContent_Populate(python-cmake-wheel)
set(CMAKE_MODULE_PATH "${python-cmake-wheel_SOURCE_DIR}" ${CMAKE_MODULE_PATH})
endif()

if (NOT TARGET wheel)
set(Python3_FIND_STRATEGY LOCATION)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/deps/python-cmake-wheel")
include(python-wheel)
set(WHEEL_DEPLOY_DIRECTORY "${ZSWAG_DEPLOY_DIR}/wheel")
endif()
endif()

if (NOT TARGET yaml-cpp)
add_subdirectory(deps/yaml-cpp)
FetchContent_Declare(yaml-cpp
GIT_REPOSITORY "https://github.com/jbeder/yaml-cpp.git"
GIT_TAG "yaml-cpp-0.7.0"
GIT_SHALLOW ON)
FetchContent_MakeAvailable(yaml-cpp)
endif()

if (NOT TARGET stx)
Expand All @@ -60,39 +82,37 @@ if (NOT TARGET speedyj)
FetchContent_MakeAvailable(speedyj)
endif()

if (NOT TARGET spdlog)
FetchContent_Declare(spdlog
GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
GIT_TAG "v1.x"
GIT_SHALLOW ON)
FetchContent_MakeAvailable(spdlog)
endif()

if (NOT TARGET Catch2)
add_subdirectory(deps/Catch2)
FetchContent_Declare(Catch2
GIT_REPOSITORY "https://github.com/catchorg/Catch2.git"
GIT_TAG "v3.1.0"
GIT_SHALLOW ON)
FetchContent_MakeAvailable(Catch2)
endif()

if (NOT TARGET httplib)
add_subdirectory(deps/cpp-httplib)
FetchContent_Declare(httplib
GIT_REPOSITORY "https://github.com/yhirose/cpp-httplib.git"
GIT_TAG "v0.12.2"
GIT_SHALLOW ON)
FetchContent_MakeAvailable(httplib)
target_compile_definitions(httplib
INTERFACE
CPPHTTPLIB_OPENSSL_SUPPORT)
target_link_libraries(httplib INTERFACE OpenSSL::SSL)
endif()

if (ZSWAG_KEYCHAIN_SUPPORT)
if (NOT TARGET keychain)
add_subdirectory(deps/keychain)
endif()
endif()

if (ZSWAG_BUILD_WHEELS AND NOT TARGET pybind11)
add_subdirectory(deps/pybind11)
if(ZSWAG_BUILD_WHEELS AND NOT TARGET pybind11)
find_package(pybind11 REQUIRED)
endif()

if (NOT TARGET zserio-cmake-helper)
set(ZSERIO_REPO_ROOT "${CMAKE_CURRENT_LIST_DIR}/deps/zserio")
add_subdirectory(deps/zserio-cmake-helper)
set(ZSERIO_VERSION "2.11.0")
FetchContent_Declare(zserio-cmake-helper
GIT_REPOSITORY "https://github.com/Klebert-Engineering/zserio-cmake-helper.git"
GIT_TAG "main"
GIT_SHALLOW ON)
FetchContent_MakeAvailable(zserio-cmake-helper)
if (NOT TARGET ZserioCppRuntime)
add_zserio_cpp_runtime()
endif()
Expand All @@ -118,3 +138,57 @@ if (ZSWAG_BUILD_WHEELS)
${Python3_EXECUTABLE} setup.py ${ZSWAG_VERSION} bdist_wheel -d "${WHEEL_DEPLOY_DIRECTORY}")
add_dependencies(wheel zswag-server-wheel)
endif()

##############
# deploy openssl libs

if (WIN32)
set(OPENSSL_DEPLOY_DIR "${ZSWAG_DEPLOY_DIR}/${CMAKE_BUILD_TYPE}")
else()
set(OPENSSL_DEPLOY_DIR "${ZSWAG_DEPLOY_DIR}")
endif()

message(STATUS "Deploying to ${OPENSSL_DEPLOY_DIR}")
message(STATUS "OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")

if(APPLE)
set(OPENSSL_LIB_DIR "${OPENSSL_INCLUDE_DIR}/../lib")
set(OPENSSL_LIBS
"${OPENSSL_LIB_DIR}/libcrypto.1.1.dylib"
"${OPENSSL_LIB_DIR}/libssl.1.1.dylib"
)
elseif(MSVC)
set(OPENSSL_LIB_DIR "${OPENSSL_INCLUDE_DIR}/../bin")
set(OPENSSL_LIBS
"${OPENSSL_LIB_DIR}/libcrypto-1_1-x64.dll"
"${OPENSSL_LIB_DIR}/libssl-1_1-x64.dll"
)
elseif(UNIX AND NOT APPLE)
set(OPENSSL_LIB_DIR "${OPENSSL_INCLUDE_DIR}/../lib")
set(OPENSSL_LIBS
"${OPENSSL_LIB_DIR}/libcrypto.so.1.1"
"${OPENSSL_LIB_DIR}/libssl.so.1.1"
)
endif()

foreach(file_i ${OPENSSL_LIBS})
get_filename_component(filename ${file_i} NAME)
add_custom_command(
OUTPUT "${OPENSSL_DEPLOY_DIR}/${filename}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${file_i}"
"${OPENSSL_DEPLOY_DIR}/${filename}"
DEPENDS "${file_i}"
COMMENT "Copying ${file_i} to ${OPENSSL_DEPLOY_DIR}"
)
list(APPEND COPIED_OPENSSL_LIBS "${OPENSSL_DEPLOY_DIR}/${filename}")
endforeach(file_i)

add_custom_target(copy_openssl_libs ALL DEPENDS ${COPIED_OPENSSL_LIBS})

add_dependencies(zswagcl copy_openssl_libs)





14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ Using CMake, you can ...
* 🌟build the zswag wheels for a custom Python version.
* 🌟[integrate the C++ client into a C++ project.](#c-client)

Dependencies are managed via CMake's `FetchContent` mechanism and Conan 2.0.
Make sure you have a recent version of CMake (>= 3.24) and Conan (>= 2.0.5) installed.

The basic setup follows the usual CMake configure/build steps:
```bash
mkdir build && cd build
Expand Down Expand Up @@ -461,7 +464,16 @@ project(myapp)

# This is how C++ will know about the zswag lib
# and its dependencies, such as zserio.
add_subdirectory(zswag)
if (NOT TARGET zswag)
FetchContent_Declare(zswag
GIT_REPOSITORY "https://github.com/ndsev/zswag.git"
GIT_TAG "v1.5.0"
GIT_SHALLOW ON)
FetchContent_MakeAvailable(zswag)
endif()

find_package(OpenSSL CONFIG REQUIRED)
target_link_libraries(httplib INTERFACE OpenSSL::SSL)

# This command is provided by zswag to easily create
# a CMake C++ reflection library from zserio code.
Expand Down
Loading

0 comments on commit 400470f

Please sign in to comment.