Skip to content

Commit 8218717

Browse files
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.
1 parent 234a55d commit 8218717

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

.github/workflows/ci-pr-validation.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ jobs:
114114
cmake . -DINTEGRATE_VCPKG=ON -DBUILD_TESTS=ON -DBUILD_PERF_TOOLS=ON
115115
cmake --build . -j8
116116
117+
- name: Verify custom vcpkg installation
118+
run: |
119+
mv vcpkg /tmp/
120+
cmake -B build -DINTEGRATE_VCPKG=ON -DCMAKE_TOOLCHAIN_FILE="/tmp/vcpkg/scripts/buildsystems/vcpkg.cmake"
121+
117122
cpp20-build:
118123
name: Build with the C++20 standard
119124
needs: formatting-check

CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ option(USE_ASIO "Use Asio instead of Boost.Asio" OFF)
2424
option(INTEGRATE_VCPKG "Integrate with Vcpkg" OFF)
2525
if (INTEGRATE_VCPKG)
2626
set(USE_ASIO ON)
27-
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
27+
if (NOT CMAKE_TOOLCHAIN_FILE)
28+
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
29+
endif ()
2830
endif ()
2931

3032
option(BUILD_TESTS "Build tests" ON)

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Since it's integrated with vcpkg, see [vcpkg#README](https://github.com/microsof
4747

4848
### How to build from source
4949

50+
The simplest way is to clone this project with the vcpkg submodule.
51+
5052
```bash
5153
git clone https://github.com/apache/pulsar-client-cpp.git
5254
cd pulsar-client-cpp
@@ -57,6 +59,17 @@ cmake --build build -j8
5759

5860
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.
5961

62+
> You can also add the CMAKE_TOOLCHAIN_FILE option if your system already have vcpkg installed.
63+
>
64+
> ```bash
65+
> git clone https://github.com/apache/pulsar-client-cpp.git
66+
> cd pulsar-client-cpp
67+
> # For example, you can install vcpkg in /tmp/vcpkg
68+
> cd /tmp && git clone https://github.com/microsoft/vcpkg.git && cd -
69+
> cmake -B build -DINTEGRATE_VCPKG=ON -DCMAKE_TOOLCHAIN_FILE="/tmp/vcpkg/scripts/buildsystems/vcpkg.cmake"
70+
> cmake --build build -j8
71+
> ```
72+
6073
After the build, the hierarchy of the `build` directory will be:
6174
6275
```

0 commit comments

Comments
 (0)