diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 754b2ec4..832d9f1d 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -69,14 +69,13 @@ jobs: platform: x64 - name: Configure CMake - run: cmake -B ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}} -G"Ninja" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNUI_BUILD_EXAMPLES=off -DCMAKE_CXX_EXTENSIONS=on -DCMAKE_CXX_COMPILER=c++ -DCMAKE_C_COMPILER=cc -DCMAKE_CXX_STANDARD=20 + run: cmake -B ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}} -G"Ninja" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_EXTENSIONS=on -DCMAKE_CXX_COMPILER=c++ -DCMAKE_C_COMPILER=cc -DCMAKE_CXX_STANDARD=20 env: BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }} - name: Build run: cmake --build ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}} --config ${{env.BUILD_TYPE}} - windows-msys2: runs-on: windows-2022 defaults: @@ -95,7 +94,41 @@ jobs: run: echo "WSPACE=$(cygpath '${{github.workspace}}')" >> $GITHUB_ENV - name: Configure CMake - run: cmake -B ${{env.WSPACE}}/build/clang_${{env.BUILD_TYPE}} -G"Ninja" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNUI_BUILD_EXAMPLES=off -DCMAKE_CXX_EXTENSIONS=on -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_LINKER=lld -DCMAKE_CXX_STANDARD=20 + run: cmake -B ${{env.WSPACE}}/build/clang_${{env.BUILD_TYPE}} -G"Ninja" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_EXTENSIONS=on -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_LINKER=lld -DCMAKE_CXX_STANDARD=20 - name: Build run: cmake --build ${{env.WSPACE}}/build/clang_${{env.BUILD_TYPE}} --config ${{env.BUILD_TYPE}} + + macos: + runs-on: macos-13 + + steps: + - uses: actions/checkout@v3 + + - run: brew install ninja boost cryptopp curl llvm@16 + + - name: Get Brew Prefix + run: | + echo "BREW_PREFIX=$(brew --prefix)" >> $GITHUB_ENV + + - name: Set Env Vars + run: | + echo "export LDFLAGS=-L$BREW_PREFIX/lib" >> $GITHUB_ENV + echo "export CPPFLAGS=-I$BREW_PREFIX/include" >> $GITHUB_ENV + + - name: Configure CMake + run: > + cmake + -DCMAKE_C_COMPILER=$BREW_PREFIX/opt/llvm@16/bin/clang + -DCMAKE_CXX_COMPILER=$BREW_PREFIX/opt/llvm@16/bin/clang++ + -DCMAKE_LINKER=$BREW_PREFIX/opt/llvm@16/bin/lld + -S ${{github.workspace}} + -B ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}} + -G"Ninja" + -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + -DBREW_PREFIX="$BREW_PREFIX" + -DCMAKE_CXX_EXTENSIONS=on + -DCMAKE_CXX_STANDARD=20 + + - name: Build + run: cmake --build ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}} --config ${{env.BUILD_TYPE}} diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ae5f004..10ffc3f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,14 +10,20 @@ if(PROJECT_IS_TOP_LEVEL) endif() endif() -include (./cmake/warnings.cmake) -include (./cmake/example_target.cmake) -include (./cmake/options.cmake) - -include (./cmake/xhawk18_promise.cmake) +include(./cmake/warnings.cmake) +include(./cmake/example_target.cmake) +include(./cmake/options.cmake) +include(./cmake/brew.cmake) + +# Deps +include(./cmake/dependencies/boost.cmake) +include(./cmake/dependencies/ssl.cmake) +include(./cmake/dependencies/curl.cmake) +include(./cmake/dependencies/cryptopp.cmake) +include(./cmake/dependencies/xhawk18_promise.cmake) if (${ROAR_ENABLE_NLOHMANN_JSON}) - include(./cmake/nlohmann_json.cmake) + include(./cmake/dependencies/nlohmann_json.cmake) endif() add_subdirectory(src/roar) diff --git a/README.md b/README.md index 03afb640..77a8f9fa 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,15 @@ This is a network library that has: - cryptopp - libcurl +### MacOS + +Dependencies are expected to be installed via brew. +If this does not work for you, please open an issue. + +brew install ninja boost cryptopp curl llvm@16 + +### Windows + Use vcpkg on windows for these dependencies when building with Visual Studio & cmake. https://vcpkg.io/en/getting-started.html diff --git a/cmake/brew.cmake b/cmake/brew.cmake new file mode 100644 index 00000000..43ff32a7 --- /dev/null +++ b/cmake/brew.cmake @@ -0,0 +1 @@ +set(BREW_PREFIX "/opt/homebrew" CACHE STRING "Homebrew install prefix") \ No newline at end of file diff --git a/cmake/dependencies/boost.cmake b/cmake/dependencies/boost.cmake new file mode 100644 index 00000000..4e24fd68 --- /dev/null +++ b/cmake/dependencies/boost.cmake @@ -0,0 +1 @@ +find_package(Boost 1.81.0 REQUIRED COMPONENTS system) \ No newline at end of file diff --git a/cmake/dependencies/cryptopp.cmake b/cmake/dependencies/cryptopp.cmake new file mode 100644 index 00000000..dcc84fcc --- /dev/null +++ b/cmake/dependencies/cryptopp.cmake @@ -0,0 +1,25 @@ +if (UNIX) + find_package(PkgConfig REQUIRED) +endif() + +add_library(roar-cryptopp INTERFACE) + +if (WIN32) + find_package(CryptoPP REQUIRED) + if (${MSVC}) + target_link_libraries(roar-cryptopp INTERFACE cryptopp::cryptopp) + else() + target_link_libraries(roar-cryptopp INTERFACE cryptopp-static) + endif() +elseif(APPLE) + find_library(CRYPTOPP_LIB libcryptopp.a HINTS ${BREW_PREFIX}/lib) + target_include_directories(roar-cryptopp INTERFACE ${BREW_PREFIX}/include) + target_link_libraries(roar-cryptopp INTERFACE ${CRYPTOPP_LIB}) +elseif(UNIX) + pkg_check_modules(cryptopp IMPORTED_TARGET libcrypto++) + if ("${cryptopp_FOUND}" STREQUAL "1") + else() + pkg_check_modules(cryptopp IMPORTED_TARGET libcryptopp) + endif() + target_link_libraries(roar-cryptopp INTERFACE PkgConfig::cryptopp) +endif() \ No newline at end of file diff --git a/cmake/dependencies/curl.cmake b/cmake/dependencies/curl.cmake new file mode 100644 index 00000000..d0c9bca1 --- /dev/null +++ b/cmake/dependencies/curl.cmake @@ -0,0 +1 @@ +find_package(CURL REQUIRED) \ No newline at end of file diff --git a/cmake/dependencies/nlohmann_json.cmake b/cmake/dependencies/nlohmann_json.cmake new file mode 100644 index 00000000..64b50595 --- /dev/null +++ b/cmake/dependencies/nlohmann_json.cmake @@ -0,0 +1,15 @@ +option(ROAR_EXTERNAL_NLOHMANN_JSON "Use an external nlohmann_json library (provide it manually)" OFF) +set(ROAR_NLOHMANN_JSON_GIT_REPOSITORY "https://github.com/nlohmann/json.git" CACHE STRING "The URL from which to clone the nlohmann_json repository") +set(ROAR_NLOHMANN_JSON_GIT_TAG "9dfa7226693012ed5bcf5ab3bc5d8e69d58006ab" CACHE STRING "The git tag or commit hash to checkout from the nlohmann_json repository") + +if (ROAR_EXTERNAL_NLOHMANN_JSON) +else() + include(FetchContent) + FetchContent_Declare( + nlohmann_json + GIT_REPOSITORY ${ROAR_NLOHMANN_JSON_GIT_REPOSITORY} + GIT_TAG ${ROAR_NLOHMANN_JSON_GIT_TAG} + ) + + FetchContent_MakeAvailable(nlohmann_json) +endif() \ No newline at end of file diff --git a/cmake/dependencies/ssl.cmake b/cmake/dependencies/ssl.cmake new file mode 100644 index 00000000..274c7921 --- /dev/null +++ b/cmake/dependencies/ssl.cmake @@ -0,0 +1 @@ +find_package(OpenSSL COMPONENTS SSL Crypto) \ No newline at end of file diff --git a/cmake/dependencies/xhawk18_promise.cmake b/cmake/dependencies/xhawk18_promise.cmake new file mode 100644 index 00000000..96ad0ec3 --- /dev/null +++ b/cmake/dependencies/xhawk18_promise.cmake @@ -0,0 +1,22 @@ +set(PROMISE_BUILD_EXAMPLES off CACHE BOOL "Promise build examples" FORCE) +set(PROMISE_MULTITHREAD on CACHE BOOL "Promise multithreading on") + +option(ROAR_EXTERNAL_PROMISE "Use an external promise library (provide it manually)" OFF) +set(ROAR_PROMISE_GIT_REPOSITORY "https://github.com/5cript/promise-cpp.git" CACHE STRING "The URL from which to clone the promiselib repository") +set(ROAR_PROMISE_GIT_TAG "affb386031896805c198485f10fd56215b1a4460" CACHE STRING "The git tag or commit hash to checkout from the promiselib repository") + +if (ROAR_EXTERNAL_PROMISE) +else() + include(FetchContent) + FetchContent_Declare( + promise + GIT_REPOSITORY ${ROAR_PROMISE_GIT_REPOSITORY} + GIT_TAG ${ROAR_PROMISE_GIT_TAG} + ) + FetchContent_MakeAvailable(promise) + + if (WIN32) + # MS SOCK + target_link_libraries(promise PUBLIC -lws2_32 -lmswsock -lbcrypt) + endif() +endif() \ No newline at end of file diff --git a/cmake/nlohmann_json.cmake b/cmake/nlohmann_json.cmake deleted file mode 100644 index 5df633ac..00000000 --- a/cmake/nlohmann_json.cmake +++ /dev/null @@ -1,10 +0,0 @@ -project(nlohmann_json-git NONE) - -include(FetchContent) -FetchContent_Declare( - nlohmann_json - GIT_REPOSITORY https://github.com/nlohmann/json.git - GIT_TAG 9dfa7226693012ed5bcf5ab3bc5d8e69d58006ab -) - -FetchContent_MakeAvailable(nlohmann_json) \ No newline at end of file diff --git a/cmake/xhawk18_promise.cmake b/cmake/xhawk18_promise.cmake deleted file mode 100644 index d55ee2b6..00000000 --- a/cmake/xhawk18_promise.cmake +++ /dev/null @@ -1,17 +0,0 @@ -project(promise-git NONE) - -set(PROMISE_BUILD_EXAMPLES off CACHE BOOL "Promise build examples" FORCE) -set(PROMISE_MULTITHREAD on CACHE BOOL "Promise multithreading on") -include(FetchContent) -FetchContent_Declare( - promise - GIT_REPOSITORY https://github.com/5cript/promise-cpp.git - GIT_TAG affb386031896805c198485f10fd56215b1a4460 -) - -FetchContent_MakeAvailable(promise) - -if (WIN32) - # MS SOCK - target_link_libraries(promise PUBLIC -lws2_32 -lmswsock -lbcrypt) -endif() \ No newline at end of file diff --git a/src/roar/CMakeLists.txt b/src/roar/CMakeLists.txt index cfe1eb4b..0f472255 100644 --- a/src/roar/CMakeLists.txt +++ b/src/roar/CMakeLists.txt @@ -33,39 +33,18 @@ add_library( include(../../cmake/warnings.cmake) -if (UNIX) - find_package(PkgConfig REQUIRED) -endif() -find_package(CURL REQUIRED) -find_package(Boost 1.81.0 REQUIRED COMPONENTS system) -find_package(OpenSSL COMPONENTS SSL Crypto) - +target_compile_features(roar PUBLIC cxx_std_20) target_include_directories(roar PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include ${CURL_INCLUDE_DIR}) target_link_libraries( roar PUBLIC Boost::system promise + roar-cryptopp CURL::libcurl OpenSSL::SSL OpenSSL::Crypto ) -if (WIN32) - find_package(CryptoPP REQUIRED) - if (${MSVC}) - target_link_libraries(roar PUBLIC cryptopp::cryptopp) - else() - target_link_libraries(roar PUBLIC cryptopp-static) - endif() -else() - pkg_check_modules(cryptopp IMPORTED_TARGET libcrypto++) - if ("${cryptopp_FOUND}" STREQUAL "1") - else() - pkg_check_modules(cryptopp IMPORTED_TARGET libcryptopp) - endif() - target_link_libraries(roar PUBLIC PkgConfig::cryptopp) -endif() -target_compile_features(roar PUBLIC cxx_std_20) set_target_warnings(roar)