Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(bindings/cpp): fetch and build dependencies instead of finding system libs #5188

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading