mfontanini / cppkafka

Modern C++ Apache Kafka client library (wrapper for librdkafka)
BSD 2-Clause "Simplified" License
589 stars 207 forks source link

FindRdKafka.cmake incompatible with windows build #259

Closed jeeftor closed 4 years ago

jeeftor commented 4 years ago

The directions for windows building says to use nuget to install librdkafka.

This is what the expanded package list looks like:

│   .signature.p7s
│   CONFIGURATION.md
│   librdkafka.redist.1.5.0.nupkg
│   LICENSES.txt
│   README.md
│
├───build
│   │   librdkafka.redist.props
│   │
│   └───native
│       │   librdkafka.redist.targets
│       │
│       ├───include
│       │   └───librdkafka
│       │           rdkafka.h
│       │           rdkafkacpp.h
│       │           rdkafka_mock.h
│       │
│       └───lib
│           └───win
│               ├───x64
│               │   └───win-x64-Release
│               │       └───v120
│               │               librdkafka.lib
│               │               librdkafkacpp.lib
│               │
│               └───x86
│                   └───win-x86-Release
│                       └───v120
│                               librdkafka.lib
│                               librdkafkacpp.lib
│
└───runtimes
    ├───linux-x64
    │   └───native
    │           alpine-librdkafka.so
    │           centos7-librdkafka.so
    │           debian9-librdkafka.so
    │           librdkafka.so
    │
    ├───osx-x64
    │   └───native
    │           librdkafka.dylib
    │
    ├───win-x64
    │   └───native
    │           librdkafka.dll
    │           librdkafkacpp.dll
    │           libzstd.dll
    │           msvcp120.dll
    │           msvcr120.dll
    │           zlib.dll
    │
    └───win-x86
        └───native
                librdkafka.dll
                librdkafkacpp.dll
                libzstd.dll
                msvcp120.dll
                msvcr120.dll
                zlib.dll

On windows I'm finding that passing in -DRDKAFKA_ROOT=C:\cppkafka\packages\librdkafka.redist.1.5.0 in insufficient to actually find the correct libs.

jeeftor commented 4 years ago

The more I dig into things it really seems windows is pretty borked...

Additionally it doesn't appear that the definitions: add_definitions("-DNOMINMAX=1") for windows ever get set because there is always a CXX flags...

I dont know if I have time to dig into this further - but if anybody has successfully built a 32 and a 64 version of windows please reply to this thread

jeeftor commented 4 years ago

This is how I got windows build (64bit) working with Visual Studio 2017

Use vcpkg to install required libs:

# Install vcpkg if not already installed
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
bootstrap-vcpkg.bat
vcpkg integrate install

# Install librdkafka
vcpkg install librdkafka pthread  --triplet x64-windows

and then this:

git config --global http.sslVerify false
git clone https://github.com/mfontanini/cppkafka.git

cd cppkafka

# Download nuget and checkout boost
curl -sq -k -o nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
nuget install boost  -Version 1.72.0 -OutputDirectory packages

# build in the b64 directory (but clean it out before running)

del /s /q c:/cppkafka/b64 & cmake -S c:/cppkafka -B c:/cppkafka/b64 ^
-DBoost_DEBUG=OFF -DCMAKE_GENERATOR_PLATFORM=x64 ^
-DBOOST_ROOT=c:/cppkafka/packages/boost.1.72.0.0 ^
-DCPPKAFKA_RDKAFKA_STATIC_LIB=1 ^
-DBoost_INCLUDE_DIR=c:/cppkafka/packages/boost.1.72.0.0/lib/native/include ^
-DCPPKAFKA_CMAKE_VERBOSE=OFF ^
-DCMAKE_FIND_DEBUG_MODE=false ^
-DRDKAFKA_ROOT=c:/cppkafka/librdkafka/ ^
-DCPPKAFKA_DISABLE_EXAMPLES=ON ^
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake ^
-DCPPKAFKA_DISABLE_EXAMPLES=ON ^
-DCPPKAFKA_RDKAFKA_STATIC_LIB=ON ^
-G "Visual Studio 15 2017" & cmake --build c:/cppkafka/b64 --config Release & cmake --install c:/cppkafka/b64 --config Release