diff --git a/bindings/cpp/CMakeLists.txt b/bindings/cpp/CMakeLists.txt index 7abce03bd021..0d8ce89dfed6 100644 --- a/bindings/cpp/CMakeLists.txt +++ b/bindings/cpp/CMakeLists.txt @@ -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) @@ -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}) @@ -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}) diff --git a/bindings/cpp/CONTRIBUTING.md b/bindings/cpp/CONTRIBUTING.md index 8182ea987f0b..cc06ed1f714e 100644 --- a/bindings/cpp/CONTRIBUTING.md +++ b/bindings/cpp/CONTRIBUTING.md @@ -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). @@ -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 ``` @@ -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 ``` diff --git a/bindings/cpp/README.md b/bindings/cpp/README.md index 8b264d4968d3..e0a5414d03a9 100644 --- a/bindings/cpp/README.md +++ b/bindings/cpp/README.md @@ -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