Skip to content

Commit

Permalink
build(bindings/cpp): fetch and build dependencies instead of finding …
Browse files Browse the repository at this point in the history
…system libs (#5188)
  • Loading branch information
PragmaTwice authored Oct 16, 2024
1 parent b692223 commit f4e1ce7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
37 changes: 33 additions & 4 deletions bindings/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
# specific language governing permissions and limitations
# under the License.

cmake_minimum_required(VERSION 3.10)
project(opendal-cpp VERSION 0.45.10 LANGUAGES CXX)
cmake_minimum_required(VERSION 3.22)
project(opendal-cpp LANGUAGES CXX)

include(FetchContent)
set(OPENDAL_GOOGLETEST_VERSION 1.15.2 CACHE STRING "version of GoogleTest, 'external' to fallback to find_package()")
set(OPENDAL_BOOST_VERSION 1.86.0 CACHE STRING "version of Boost, 'external' to fallback to find_package()")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down Expand Up @@ -94,7 +98,19 @@ else()
)
endif()

find_package(Boost REQUIRED COMPONENTS date_time iostreams)
if(OPENDAL_BOOST_VERSION STREQUAL "external")
find_package(Boost REQUIRED COMPONENTS date_time iostreams)
else()
# fetch Boost
FetchContent_Declare(
Boost
URL https://github.com/boostorg/boost/releases/download/boost-${OPENDAL_BOOST_VERSION}/boost-${OPENDAL_BOOST_VERSION}-cmake.zip
)

set(BOOST_INCLUDE_LIBRARIES date_time iostreams system)
set(BOOST_ENABLE_CMAKE ON)
FetchContent_MakeAvailable(Boost)
endif()

add_library(opendal_cpp STATIC ${CPP_SOURCE_FILE} ${RUST_BRIDGE_CPP})
target_sources(opendal_cpp PUBLIC ${CPP_HEADER_FILE})
Expand Down Expand Up @@ -126,7 +142,20 @@ endif()
# Tests
if (OPENDAL_ENABLE_TESTING)
enable_testing()
find_package(GTest REQUIRED)

if(OPENDAL_GOOGLETEST_VERSION STREQUAL "external")
find_package(GTest REQUIRED)
else()
# fetch GoogleTest
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v${OPENDAL_GOOGLETEST_VERSION}.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()

file(GLOB_RECURSE TEST_SOURCE_FILE tests/*.cpp)
add_executable(opendal_cpp_test ${TEST_SOURCE_FILE})
target_include_directories(opendal_cpp_test PUBLIC ${CPP_INCLUDE_DIR} ${GTEST_INCLUDE_DIRS})
Expand Down
16 changes: 2 additions & 14 deletions bindings/cpp/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ To build OpenDAL C++ binding, the following is all you need:

- To format the code, you need to install **clang-format**

- **GTest(Google Test)**. It is used to run the tests. To see how to build, check [here](https://github.com/google/googletest).
- **GTest(Google Test)**. It is used to run the tests. You do NOT need to build it manually.

- **Boost**. It is one dependency of this library. To see how to build, check [here](https://www.boost.org/doc/libs/1_76_0/more/getting_started/unix-variants.html).
- **Boost**. It is one dependency of this library. You do NOT need to build it manually.

- **Doxygen**. It is used to generate the documentation. To see how to build, check [here](https://www.doxygen.nl/manual/install.html).

Expand All @@ -50,12 +50,6 @@ sudo apt install cmake ninja-build
# install clang-format
sudo apt install clang-format

# install GTest library
sudo apt-get install libgtest-dev

# install Boost library
sudo apt install libboost-all-dev

# install Doxygen and Graphviz
sudo apt install doxygen graphviz
```
Expand All @@ -72,12 +66,6 @@ brew install cmake ninja
# install clang-format
brew install clang-format

# install GTest library
brew install googletest

# install Boost library
brew install boost

# install Doxygen and Graphviz
brew install doxygen graphviz
```
Expand Down
3 changes: 1 addition & 2 deletions bindings/cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ Support for more package managers is coming soon!

### Prerequisites

- CMake >= 3.10
- CMake >= 3.22
- C++ compiler with C++17 support
- The boost library

### Build

Expand Down

0 comments on commit f4e1ce7

Please sign in to comment.