You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by xy...@apache.org on 2024/03/28 02:45:20 UTC

(pulsar-client-cpp) 01/05: Support customize vcpkg directory when INTEGRATE_VCPKG is ON (#417)

This is an automated email from the ASF dual-hosted git repository.

xyz pushed a commit to branch branch-3.5
in repository https://gitbox.apache.org/repos/asf/pulsar-client-cpp.git

commit e7793d6752a6bbfd5f526ecf207bd3738179f29e
Author: Yunze Xu <xy...@163.com>
AuthorDate: Thu Mar 14 20:11:26 2024 +0800

    Support customize vcpkg directory when INTEGRATE_VCPKG is ON (#417)
    
    ### Motivation
    
    Currently when INTEGRATE_VCPKG is ON, the CMAKE_TOOLCHAIN_FILE variable
    is always a subdirectory of `${CMAKE_SOURCE_DIR}/vcpkg`. We can only
    customize the vcpkg directory when INTEGRATE_VCPKG is OFF, while the
    legacy CMake logic is incompatible with this way.
    
    ### Modifications
    
    When INTEGRATE_VCPKG is ON, only set CMAKE_TOOLCHAIN_FILE if it's not
    defined. The workflow and README are updated for it.
    
    (cherry picked from commit 821871777e247e1ccbfa323ea0d5136cf0e18711)
---
 .github/workflows/ci-pr-validation.yaml |  5 +++++
 CMakeLists.txt                          |  4 +++-
 README.md                               | 13 +++++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/ci-pr-validation.yaml b/.github/workflows/ci-pr-validation.yaml
index d9dc2ca..5010411 100644
--- a/.github/workflows/ci-pr-validation.yaml
+++ b/.github/workflows/ci-pr-validation.yaml
@@ -114,6 +114,11 @@ jobs:
           cmake . -DINTEGRATE_VCPKG=ON -DBUILD_TESTS=ON -DBUILD_PERF_TOOLS=ON
           cmake --build . -j8
 
+      - name: Verify custom vcpkg installation
+        run: |
+          mv vcpkg /tmp/
+          cmake -B build -DINTEGRATE_VCPKG=ON -DCMAKE_TOOLCHAIN_FILE="/tmp/vcpkg/scripts/buildsystems/vcpkg.cmake"
+
   cpp20-build:
     name: Build with the C++20 standard
     needs: formatting-check
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 662e84a..b004653 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,7 +24,9 @@ option(USE_ASIO "Use Asio instead of Boost.Asio" OFF)
 option(INTEGRATE_VCPKG "Integrate with Vcpkg" OFF)
 if (INTEGRATE_VCPKG)
     set(USE_ASIO ON)
-    set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
+    if (NOT CMAKE_TOOLCHAIN_FILE)
+        set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
+    endif ()
 endif ()
 
 option(BUILD_TESTS "Build tests" ON)
diff --git a/README.md b/README.md
index f0c13f0..4c86b63 100644
--- a/README.md
+++ b/README.md
@@ -47,6 +47,8 @@ Since it's integrated with vcpkg, see [vcpkg#README](https://github.com/microsof
 
 ### How to build from source
 
+The simplest way is to clone this project with the vcpkg submodule.
+
 ```bash
 git clone https://github.com/apache/pulsar-client-cpp.git
 cd pulsar-client-cpp
@@ -57,6 +59,17 @@ cmake --build build -j8
 
 The 1st step will download vcpkg and then install all dependencies according to the version description in [vcpkg.json](./vcpkg.json). The 2nd step will build the Pulsar C++ libraries under `./build/lib/`, where `./build` is the CMake build directory.
 
+> You can also add the CMAKE_TOOLCHAIN_FILE option if your system already have vcpkg installed.
+>
+> ```bash
+> git clone https://github.com/apache/pulsar-client-cpp.git
+> cd pulsar-client-cpp
+> # For example, you can install vcpkg in /tmp/vcpkg
+> cd /tmp && git clone https://github.com/microsoft/vcpkg.git && cd -
+> cmake -B build -DINTEGRATE_VCPKG=ON -DCMAKE_TOOLCHAIN_FILE="/tmp/vcpkg/scripts/buildsystems/vcpkg.cmake"
+> cmake --build build -j8
+> ```
+
 After the build, the hierarchy of the `build` directory will be:
 
 ```