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

[C++] Support Windows Debug mode build #11302

Merged
merged 13 commits into from
Jul 13, 2021

Conversation

BewareMyPower
Copy link
Contributor

@BewareMyPower BewareMyPower commented Jul 13, 2021

Fixes #11081

Motivation

The current CMakeLists.txt doesn't work well for Windows build. If the dependencies were installed by Vcpkg, CMake would always find the release version libraries under vcpkg_installed/<triplet>/lib and could not find the debug version libraries under vcpkg_installed/<triplet>/debug/lib. If pulsar.dll was built in release mode while the application was built in debug mode, some link errors might happen.

Modifications

Use find_package with config mode to find curl and protobuf instead of find_library with the explicit library names. For example, after Protobuf was found successfully, the Protobuf_LITE_LIBRARIES would be set with

optimized;./vcpkg_installed/x64-windows/bin/libprotobuf-lite.dll;debug;./vcpkg_installed/x64-windows/debug/bin/libprotobuf-lited.dll

ZLIB and OpenSSL don't support config mode for find_package, so here we set hint path like ZLIB_ROOT to force CMake find debug version libraries when CMAKE_BUILD_TYPE is Debug.

For ZSTD and Snappy, use the correct name for MSVC with Debug mode.

In addition, this PR doesn't handle the case when LINK_STATIC=ON so it still doesn't support LINK_STATIC=ON on Windows currently.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.

It's hard to test in CI because it's something with linking in runtime. We can test the fixed CMakeLists.txt on Windows local machine with Visual Studio 2017 x64 compiler tools CMD window.

vcpkg install --feature-flags=manifests --triplet x64-windows
cmake -B ./build -A x64 -DBUILD_PYTHON_WRAPPER=OFF -DBUILD_TESTS=OFF -DVCPKG_TRIPLET=x64-windows -DCMAKE_BUILD_TYPE=Debug -S .
cmake --build ./build --config Debug
set PATH=%CD%\vcpkg_installed\x64-windows\debug\bin;%CD%\build\lib\Debug;%PATH%

@BewareMyPower
Copy link
Contributor Author

It looks like CMakeLists.txt is not compatible with apachepulsar/pulsar-build:manylinux-cp37-cp37m image, I'll fix it soon.

@BewareMyPower BewareMyPower changed the title [C++] Support Windows Debug mode build [WIP][C++] Support Windows Debug mode build Jul 13, 2021
@BewareMyPower BewareMyPower changed the title [WIP][C++] Support Windows Debug mode build [C++] Support Windows Debug mode build Jul 13, 2021
@merlimat merlimat merged commit 878cc44 into apache:master Jul 13, 2021
@BewareMyPower BewareMyPower deleted the bewaremypower/cpp-debug-mode branch July 14, 2021 01:54
codelipenghui pushed a commit that referenced this pull request Jul 14, 2021
* Use find_package for CURL

* Add version check for findCurl

* Use find_package for Protobuf

* Find snappyd and zstdd for MSVC Debug mode

* Restore the Protobuf variables name

* Remove predefined Protobuf_LITE_LIBRARIES variable

* Add comments for why use CONFIG mode for find_package

* Update C++ client README

* Minor fix

* Fix ZLIB debug libraries path error

* Fix build error when LINK_STATIC is ON

* Fix Windows x86 link error

* Fix ZSTD and Snappy not found on Windows x86 platform

(cherry picked from commit 878cc44)
@codelipenghui codelipenghui added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Jul 14, 2021
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
* Use find_package for CURL

* Add version check for findCurl

* Use find_package for Protobuf

* Find snappyd and zstdd for MSVC Debug mode

* Restore the Protobuf variables name

* Remove predefined Protobuf_LITE_LIBRARIES variable

* Add comments for why use CONFIG mode for find_package

* Update C++ client README

* Minor fix

* Fix ZLIB debug libraries path error

* Fix build error when LINK_STATIC is ON

* Fix Windows x86 link error

* Fix ZSTD and Snappy not found on Windows x86 platform
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build cherry-picked/branch-2.8 Archived: 2.8 is end of life doc-not-needed Your PR changes do not impact docs release/2.8.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[C++] Support Windows Debug mode build
3 participants