diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index baf9e9f..00eacdc 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -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 @@ -40,25 +48,31 @@ 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 \ @@ -66,14 +80,13 @@ jobs: 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 diff --git a/.gitignore b/.gitignore index 5babcd6..cb24db9 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,9 @@ dmypy.json # Pyre type checker .pyre/ dist/ + +# VSCode stuff +.vscode/ + +# CodeChecker stuff +.codechecker/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 3826145..0000000 --- a/.gitmodules +++ /dev/null @@ -1,24 +0,0 @@ -[submodule "deps/keychain"] - path = deps/keychain - url = https://github.com/hrantzsch/keychain.git -[submodule "deps/zserio"] - path = deps/zserio - url = https://github.com/ndsev/zserio.git -[submodule "deps/pybind11"] - path = deps/pybind11 - url = https://github.com/pybind/pybind11.git -[submodule "deps/Catch2"] - path = deps/Catch2 - url = https://github.com/catchorg/Catch2.git -[submodule "deps/cpp-httplib"] - path = deps/cpp-httplib - url = https://github.com/yhirose/cpp-httplib.git -[submodule "deps/yaml-cpp"] - path = deps/yaml-cpp - url = https://github.com/jbeder/yaml-cpp.git -[submodule "deps/python-cmake-wheel"] - path = deps/python-cmake-wheel - url = https://github.com/klebert-engineering/python-cmake-wheel.git -[submodule "deps/zserio-cmake-helper"] - path = deps/zserio-cmake-helper - url = https://github.com/klebert-engineering/zserio-cmake-helper diff --git a/CMakeLists.txt b/CMakeLists.txt index 847d844..e5df794 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,6 @@ -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) @@ -6,7 +8,9 @@ endif() project(zswag) enable_testing() + include(FetchContent) +set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -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) @@ -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() @@ -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) + + + + + diff --git a/README.md b/README.md index 07f1c49..d7a293e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/cmake/conan-provider.cmake b/cmake/conan-provider.cmake new file mode 100644 index 0000000..6c31158 --- /dev/null +++ b/cmake/conan-provider.cmake @@ -0,0 +1,295 @@ +set(CONAN_MINIMUM_VERSION 2.0.5) + + +function(detect_os OS OS_API_LEVEL OS_VERSION OS_SUBSYSTEM) + # it could be cross compilation + message(STATUS "CMake-Conan: cmake_system_name=${CMAKE_SYSTEM_NAME}") + if(CMAKE_SYSTEM_NAME AND NOT CMAKE_SYSTEM_NAME STREQUAL "Generic") + if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + set(${OS} Macos PARENT_SCOPE) + message(STATUS "CMake-Conan: cmake_osx_deployment_target=${CMAKE_OSX_DEPLOYMENT_TARGET}") + set(${OS_VERSION} ${CMAKE_OSX_DEPLOYMENT_TARGET} PARENT_SCOPE) + elseif(${CMAKE_SYSTEM_NAME} STREQUAL "QNX") + set(${OS} Neutrino PARENT_SCOPE) + elseif(${CMAKE_SYSTEM_NAME} STREQUAL "CYGWIN") + set(${OS} Windows PARENT_SCOPE) + set(${OS_SUBSYSTEM} cygwin PARENT_SCOPE) + elseif(${CMAKE_SYSTEM_NAME} MATCHES "^MSYS") + set(${OS} Windows PARENT_SCOPE) + set(${OS_SUBSYSTEM} msys2 PARENT_SCOPE) + else() + set(${OS} ${CMAKE_SYSTEM_NAME} PARENT_SCOPE) + endif() + if(${CMAKE_SYSTEM_NAME} STREQUAL "Android") + string(REGEX MATCH "[0-9]+" _OS_API_LEVEL ${ANDROID_PLATFORM}) + message(STATUS "CMake-Conan: android_platform=${ANDROID_PLATFORM}") + set(${OS_API_LEVEL} ${_OS_API_LEVEL} PARENT_SCOPE) + endif() + endif() +endfunction() + + +function(detect_arch ARCH) + if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64") + set(_ARCH armv8) + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "armv7-a|armv7l") + set(_ARCH armv7) + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686") + set(_ARCH x86) + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|amd64|x86_64") + set(_ARCH x86_64) + endif() + message(STATUS "CMake-Conan: cmake_system_processor=${_ARCH}") + set(${ARCH} ${_ARCH} PARENT_SCOPE) +endfunction() + + +function(detect_cxx_standard CXX_STANDARD) + set(${CXX_STANDARD} ${CMAKE_CXX_STANDARD} PARENT_SCOPE) + if(CMAKE_CXX_EXTENSIONS) + set(${CXX_STANDARD} "gnu${CMAKE_CXX_STANDARD}" PARENT_SCOPE) + endif() +endfunction() + + +function(detect_lib_cxx OS LIB_CXX) + if(${OS} STREQUAL "Android") + message(STATUS "CMake-Conan: android_stl=${ANDROID_STL}") + set(${LIB_CXX} ${ANDROID_STL} PARENT_SCOPE) + endif() +endfunction() + + +function(detect_compiler COMPILER COMPILER_VERSION) + if(DEFINED CMAKE_CXX_COMPILER_ID) + set(_COMPILER ${CMAKE_CXX_COMPILER_ID}) + set(_COMPILER_VERSION ${CMAKE_CXX_COMPILER_VERSION}) + else() + if(NOT DEFINED CMAKE_C_COMPILER_ID) + message(FATAL_ERROR "C or C++ compiler not defined") + endif() + set(_COMPILER ${CMAKE_C_COMPILER_ID}) + set(_COMPILER_VERSION ${CMAKE_C_COMPILER_VERSION}) + endif() + + message(STATUS "CMake-Conan: CMake compiler=${_COMPILER}") + message(STATUS "CMake-Conan: CMake compiler version=${_COMPILER_VERSION}") + + if(_COMPILER MATCHES MSVC) + set(_COMPILER "msvc") + string(SUBSTRING ${MSVC_VERSION} 0 3 _COMPILER_VERSION) + elseif(_COMPILER MATCHES AppleClang) + set(_COMPILER "apple-clang") + string(REPLACE "." ";" VERSION_LIST ${CMAKE_CXX_COMPILER_VERSION}) + list(GET VERSION_LIST 0 _COMPILER_VERSION) + elseif(_COMPILER MATCHES Clang) + set(_COMPILER "clang") + string(REPLACE "." ";" VERSION_LIST ${CMAKE_CXX_COMPILER_VERSION}) + list(GET VERSION_LIST 0 _COMPILER_VERSION) + elseif(_COMPILER MATCHES GNU) + set(_COMPILER "gcc") + string(REPLACE "." ";" VERSION_LIST ${CMAKE_CXX_COMPILER_VERSION}) + list(GET VERSION_LIST 0 _COMPILER_VERSION) + endif() + + message(STATUS "CMake-Conan: [settings] compiler=${_COMPILER}") + message(STATUS "CMake-Conan: [settings] compiler.version=${_COMPILER_VERSION}") + + set(${COMPILER} ${_COMPILER} PARENT_SCOPE) + set(${COMPILER_VERSION} ${_COMPILER_VERSION} PARENT_SCOPE) +endfunction() + +function(detect_build_type BUILD_TYPE) + if(NOT CMAKE_CONFIGURATION_TYPES) + # Only set when we know we are in a single-configuration generator + # Note: we may want to fail early if `CMAKE_BUILD_TYPE` is not defined + set(${BUILD_TYPE} ${CMAKE_BUILD_TYPE} PARENT_SCOPE) + endif() +endfunction() + + +function(detect_host_profile output_file) + detect_os(MYOS MYOS_API_LEVEL MYOS_VERSION MYOS_SUBSYSTEM) + detect_arch(MYARCH) + detect_compiler(MYCOMPILER MYCOMPILER_VERSION) + detect_cxx_standard(MYCXX_STANDARD) + detect_lib_cxx(MYOS MYLIB_CXX) + detect_build_type(MYBUILD_TYPE) + + set(PROFILE "") + string(APPEND PROFILE "include(default)\n") + string(APPEND PROFILE "[settings]\n") + if(MYARCH) + string(APPEND PROFILE arch=${MYARCH} "\n") + endif() + if(MYOS) + string(APPEND PROFILE os=${MYOS} "\n") + endif() + if(MYOS_API_LEVEL) + string(APPEND PROFILE os.api_level=${MYOS_API_LEVEL} "\n") + endif() + if(MYOS_VERSION) + string(APPEND PROFILE os.version=${MYOS_VERSION} "\n") + endif() + if(MYOS_SUBSYSTEM) + string(APPEND PROFILE os.subsystem=${MYOS_SUBSYSTEM} "\n") + endif() + if(MYCOMPILER) + string(APPEND PROFILE compiler=${MYCOMPILER} "\n") + endif() + if(MYCOMPILER_VERSION) + string(APPEND PROFILE compiler.version=${MYCOMPILER_VERSION} "\n") + endif() + if(MYCXX_STANDARD) + string(APPEND PROFILE compiler.cppstd=${MYCXX_STANDARD} "\n") + endif() + if(MYLIB_CXX) + string(APPEND PROFILE compiler.libcxx=${MYLIB_CXX} "\n") + endif() + if(MYBUILD_TYPE) + string(APPEND PROFILE "build_type=${MYBUILD_TYPE}\n") + endif() + + if(NOT DEFINED output_file) + set(_FN "${CMAKE_BINARY_DIR}/profile") + else() + set(_FN ${output_file}) + endif() + + string(APPEND PROFILE "[conf]\n") + string(APPEND PROFILE "tools.cmake.cmaketoolchain:generator=${CMAKE_GENERATOR}\n") + if(${MYOS} STREQUAL "Android") + string(APPEND PROFILE "tools.android:ndk_path=${CMAKE_ANDROID_NDK}\n") + endif() + + message(STATUS "CMake-Conan: Creating profile ${_FN}") + file(WRITE ${_FN} ${PROFILE}) + message(STATUS "CMake-Conan: Profile: \n${PROFILE}") +endfunction() + + +function(conan_profile_detect_default) + message(STATUS "CMake-Conan: Checking if a default profile exists") + execute_process(COMMAND ${CONAN_COMMAND} profile path default + RESULT_VARIABLE return_code + OUTPUT_VARIABLE conan_stdout + ERROR_VARIABLE conan_stderr + ECHO_ERROR_VARIABLE # show the text output regardless + ECHO_OUTPUT_VARIABLE + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + if(NOT ${return_code} EQUAL "0") + message(STATUS "CMake-Conan: The default profile doesn't exist, detecting it.") + execute_process(COMMAND ${CONAN_COMMAND} profile detect + RESULT_VARIABLE return_code + OUTPUT_VARIABLE conan_stdout + ERROR_VARIABLE conan_stderr + ECHO_ERROR_VARIABLE # show the text output regardless + ECHO_OUTPUT_VARIABLE + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + endif() +endfunction() + + +function(conan_install) + cmake_parse_arguments(ARGS CONAN_ARGS ${ARGN}) + set(CONAN_OUTPUT_FOLDER ${CMAKE_BINARY_DIR}/conan) + # Invoke "conan install" with the provided arguments + set(CONAN_ARGS ${CONAN_ARGS} -of=${CONAN_OUTPUT_FOLDER}) + message(STATUS "CMake-Conan: conan install ${CMAKE_SOURCE_DIR} ${CONAN_ARGS} ${ARGN}") + execute_process(COMMAND ${CONAN_COMMAND} install ${CMAKE_SOURCE_DIR} ${CONAN_ARGS} ${ARGN} --format=json + RESULT_VARIABLE return_code + OUTPUT_VARIABLE conan_stdout + ERROR_VARIABLE conan_stderr + ECHO_ERROR_VARIABLE # show the text output regardless + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + if(NOT "${return_code}" STREQUAL "0") + message(FATAL_ERROR "Conan install failed='${return_code}'") + else() + # the files are generated in a folder that depends on the layout used, if + # one is specified, but we don't know a priori where this is. + # TODO: this can be made more robust if Conan can provide this in the json output + string(JSON CONAN_GENERATORS_FOLDER GET ${conan_stdout} graph nodes 0 generators_folder) + # message("conan stdout: ${conan_stdout}") + message(STATUS "CMake-Conan: CONAN_GENERATORS_FOLDER=${CONAN_GENERATORS_FOLDER}") + set_property(GLOBAL PROPERTY CONAN_GENERATORS_FOLDER "${CONAN_GENERATORS_FOLDER}") + # reconfigure on conanfile changes + string(JSON CONANFILE GET ${conan_stdout} graph nodes 0 label) + message(STATUS "CMake-Conan: CONANFILE=${CMAKE_SOURCE_DIR}/${CONANFILE}") + set_property(DIRECTORY ${CMAKE_SOURCE_DIR} APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/${CONANFILE}") + # success + set_property(GLOBAL PROPERTY CONAN_INSTALL_SUCCESS TRUE) + endif() +endfunction() + + +function(conan_get_version conan_command conan_current_version) + execute_process( + COMMAND ${conan_command} --version + OUTPUT_VARIABLE conan_output + RESULT_VARIABLE conan_result + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(conan_result) + message(FATAL_ERROR "CMake-Conan: Error when trying to run Conan") + endif() + + string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" conan_version ${conan_output}) + set(${conan_current_version} ${conan_version} PARENT_SCOPE) +endfunction() + + +function(conan_version_check) + set(options ) + set(oneValueArgs MINIMUM CURRENT) + set(multiValueArgs ) + cmake_parse_arguments(CONAN_VERSION_CHECK + "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT CONAN_VERSION_CHECK_MINIMUM) + message(FATAL_ERROR "CMake-Conan: Required parameter MINIMUM not set!") + endif() + if(NOT CONAN_VERSION_CHECK_CURRENT) + message(FATAL_ERROR "CMake-Conan: Required parameter CURRENT not set!") + endif() + + if(CONAN_VERSION_CHECK_CURRENT VERSION_LESS CONAN_VERSION_CHECK_MINIMUM) + message(FATAL_ERROR "CMake-Conan: Conan version must be ${CONAN_VERSION_CHECK_MINIMUM} or later") + endif() +endfunction() + + +macro(conan_provide_dependency package_name) + get_property(CONAN_INSTALL_SUCCESS GLOBAL PROPERTY CONAN_INSTALL_SUCCESS) + if(NOT CONAN_INSTALL_SUCCESS) + find_program(CONAN_COMMAND "conan" REQUIRED) + conan_get_version(${CONAN_COMMAND} CONAN_CURRENT_VERSION) + conan_version_check(MINIMUM ${CONAN_MINIMUM_VERSION} CURRENT ${CONAN_CURRENT_VERSION}) + message(STATUS "CMake-Conan: first find_package() found. Installing dependencies with Conan") + conan_profile_detect_default() + detect_host_profile(${CMAKE_BINARY_DIR}/conan_host_profile) + if(NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "CMake-Conan: Installing single configuration ${CMAKE_BUILD_TYPE}") + conan_install(-pr ${CMAKE_BINARY_DIR}/conan_host_profile --build=missing -g CMakeDeps) + else() + message(STATUS "CMake-Conan: Installing both Debug and Release") + conan_install(-pr ${CMAKE_BINARY_DIR}/conan_host_profile -s build_type=Release --build=missing -g CMakeDeps) + conan_install(-pr ${CMAKE_BINARY_DIR}/conan_host_profile -s build_type=Debug --build=missing -g CMakeDeps) + endif() + else() + message(STATUS "CMake-Conan: find_package(${ARGV1}) found, 'conan install' already ran") + endif() + + get_property(CONAN_GENERATORS_FOLDER GLOBAL PROPERTY CONAN_GENERATORS_FOLDER) + list(FIND CMAKE_PREFIX_PATH "${CONAN_GENERATORS_FOLDER}" index) + if(${index} EQUAL -1) + list(PREPEND CMAKE_PREFIX_PATH "${CONAN_GENERATORS_FOLDER}") + endif() + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) + find_package(${ARGN} BYPASS_PROVIDER) +endmacro() + + +cmake_language( + SET_DEPENDENCY_PROVIDER conan_provide_dependency + SUPPORTED_METHODS FIND_PACKAGE +) \ No newline at end of file diff --git a/conanfile.txt b/conanfile.txt new file mode 100644 index 0000000..0bd9342 --- /dev/null +++ b/conanfile.txt @@ -0,0 +1,11 @@ +[requires] +openssl/1.1.1t +keychain/1.2.1 +spdlog/1.11.0 +pybind11/2.10.4 + +[generators] +CMakeDeps + +[options] +openssl*:shared=True \ No newline at end of file diff --git a/deps/Catch2 b/deps/Catch2 deleted file mode 160000 index 97c48e0..0000000 --- a/deps/Catch2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 97c48e0c343d26d50764fafdc90b1e630fbd10ce diff --git a/deps/cpp-httplib b/deps/cpp-httplib deleted file mode 160000 index ff813bf..0000000 --- a/deps/cpp-httplib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ff813bf99d3402adafd4141b660ed2313d27f7a6 diff --git a/deps/keychain b/deps/keychain deleted file mode 160000 index 502312f..0000000 --- a/deps/keychain +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 502312f59fdc44fa1103e67f8f17cec3affb82d9 diff --git a/deps/pybind11 b/deps/pybind11 deleted file mode 160000 index b2c1978..0000000 --- a/deps/pybind11 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b2c1978caaa6627095e3326f7ecba84b43037869 diff --git a/deps/python-cmake-wheel b/deps/python-cmake-wheel deleted file mode 160000 index 3be3c0d..0000000 --- a/deps/python-cmake-wheel +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3be3c0d71fd6fefcdfd5b1b0b9dbd00c2bd0cff8 diff --git a/deps/yaml-cpp b/deps/yaml-cpp deleted file mode 160000 index a6bbe0e..0000000 --- a/deps/yaml-cpp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a6bbe0e50ac4074f0b9b44188c28cf00caf1a723 diff --git a/deps/zserio b/deps/zserio deleted file mode 160000 index 7845e38..0000000 --- a/deps/zserio +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7845e3807dfc6758589c2328ad15a752a3c4e0bc diff --git a/deps/zserio-cmake-helper b/deps/zserio-cmake-helper deleted file mode 160000 index 78b39ea..0000000 --- a/deps/zserio-cmake-helper +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 78b39ea9b34e7033b7613e3bad0d5749dd6f9be9 diff --git a/libs/httpcl/CMakeLists.txt b/libs/httpcl/CMakeLists.txt index 8c8b06a..7301238 100644 --- a/libs/httpcl/CMakeLists.txt +++ b/libs/httpcl/CMakeLists.txt @@ -3,6 +3,8 @@ project(httpcl) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +find_package(spdlog CONFIG REQUIRED) + add_library(httpcl STATIC include/httpcl/http-client.hpp include/httpcl/http-settings.hpp @@ -21,7 +23,7 @@ target_link_libraries(httpcl PRIVATE stx PUBLIC - spdlog + spdlog::spdlog httplib::httplib yaml-cpp ) @@ -35,7 +37,7 @@ target_include_directories(httpcl if (ZSWAG_KEYCHAIN_SUPPORT) target_compile_definitions(httpcl PRIVATE ZSWAG_KEYCHAIN_SUPPORT) - target_link_libraries(httpcl PUBLIC keychain) + target_link_libraries(httpcl PUBLIC keychain::keychain) endif() add_subdirectory(test) diff --git a/libs/pyzswagcl/CMakeLists.txt b/libs/pyzswagcl/CMakeLists.txt index 022076b..5640fb6 100644 --- a/libs/pyzswagcl/CMakeLists.txt +++ b/libs/pyzswagcl/CMakeLists.txt @@ -22,13 +22,20 @@ target_compile_features(pyzswagcl if (MSVC) # Required because cpp-httplib speaks https via OpenSSL set (DEPLOY_FILES - "${OPENSSL_INCLUDE_DIR}/../libcrypto-1_1-x64.dll" - "${OPENSSL_INCLUDE_DIR}/../libssl-1_1-x64.dll") + "${OPENSSL_INCLUDE_DIR}/../bin/libcrypto-1_1-x64.dll" + "${OPENSSL_INCLUDE_DIR}/../bin/libssl-1_1-x64.dll") +endif() + +if (APPLE) + # Required because cpp-httplib speaks https via OpenSSL + set (DEPLOY_FILES + "${OPENSSL_INCLUDE_DIR}/../lib/libcrypto.1.1.dylib" + "${OPENSSL_INCLUDE_DIR}/../lib/libssl.1.1.dylib") endif() add_wheel(pyzswagcl - AUTHOR "Klebert Engineering" - URL "https://github.com/klebert-engineering/zswag" + AUTHOR "Navigation Data Standard e.V." + URL "https://github.com/ndsev/zswag" VERSION "${ZSWAG_VERSION}" DESCRIPTION "Python bindings for the zswag client library." TARGET_DEPENDENCIES diff --git a/libs/zswagcl/test/src/openapi-parameter-helper.cpp b/libs/zswagcl/test/src/openapi-parameter-helper.cpp index 12a489b..b19b77d 100644 --- a/libs/zswagcl/test/src/openapi-parameter-helper.cpp +++ b/libs/zswagcl/test/src/openapi-parameter-helper.cpp @@ -6,10 +6,10 @@ using namespace zswagcl; using Parameter = OpenAPIConfig::Parameter; using Format = Parameter::Format; -using Style = Parameter::Style; +using PStyle = Parameter::Style; static auto makeParameter(std::string ident, - Style style, + PStyle style, bool explode, Format format = Format::String) { @@ -46,7 +46,7 @@ const auto object = std::map{ TEST_CASE("openapi path parameters", "[zswagcl::open-api-format-helper]") { SECTION("Style Simple") { - auto style = Style::Simple; + auto style =PStyle::Simple; SECTION("Primitive Value") { auto explode = GENERATE(false, true); @@ -89,7 +89,7 @@ TEST_CASE("openapi path parameters", "[zswagcl::open-api-format-helper]") { } SECTION("Style Label") { - auto style = Style::Label; + auto style =PStyle::Label; SECTION("Primitive Value") { auto explode = GENERATE(false, true); @@ -135,7 +135,7 @@ TEST_CASE("openapi path parameters", "[zswagcl::open-api-format-helper]") { } SECTION("Style Matrix") { - auto style = Style::Matrix; + auto style =PStyle::Matrix; SECTION("Primitive Value") { auto explode = GENERATE(false, true); @@ -186,7 +186,7 @@ TEST_CASE("openapi path parameters", "[zswagcl::open-api-format-helper]") { TEST_CASE("openapi path parameters - formats", "[zswagcl::open-api-format-helper]") { SECTION("Style Simple") { - auto style = Style::Simple; + auto style =PStyle::Simple; SECTION("Format Hex") { auto format = Format::Hex; @@ -262,7 +262,7 @@ TEST_CASE("openapi path parameters - formats", "[zswagcl::open-api-format-helper TEST_CASE("openapi query parameters", "[zswagcl::open-api-format-helper]") { SECTION("Style Form") { - auto style = Style::Form; + auto style =PStyle::Form; SECTION("Primitive Value") { auto explode = GENERATE(false, true);