From 7fc6e2b3b5ef766ba0c88beb99d52e3979fb94eb Mon Sep 17 00:00:00 2001 From: neptoess Date: Mon, 2 Nov 2020 08:43:44 -0500 Subject: [PATCH 01/22] Build static librdkafka_windows.a with travis --- .../mingw-w64/configure-build-msys2-mingw.sh | 29 +++++++++++++++++-- packaging/mingw-w64/travis-before-install.sh | 11 ++++++- packaging/nuget/packaging.py | 8 ++++- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/packaging/mingw-w64/configure-build-msys2-mingw.sh b/packaging/mingw-w64/configure-build-msys2-mingw.sh index f26c10b5b5..58e9e52841 100644 --- a/packaging/mingw-w64/configure-build-msys2-mingw.sh +++ b/packaging/mingw-w64/configure-build-msys2-mingw.sh @@ -10,15 +10,38 @@ cmake \ -D RDKAFKA_BUILD_TESTS=ON \ -D WITH_LIBDL=OFF \ -D WITH_PLUGINS=OFF \ - -D WITH_SASL=ON \ + -D WITH_SASL=OFF \ -D WITH_SSL=ON \ -D WITH_ZLIB=OFF \ - -D RDKAFKA_BUILD_STATIC=OFF \ - -D CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE . + -D RDKAFKA_BUILD_STATIC=ON \ + . $mingw64 mingw32-make $mingw64 mingw32-make install +# Bundle all the static dependencies with the static lib we just built +mkdir mergescratch +pushd mergescratch +cp /mingw64/lib/libzstd.a ./ +cp /mingw64/lib/libcrypto.a ./ +cp /mingw64/lib/liblz4.a ./ +cp /mingw64/lib/libssl.a ./ +cp ../src/librdkafka.a ./ +ar -M << EOF +create librdkafka_windows.a +addlib librdkafka.a +addlib libzstd.a +addlib libcrypto.a +addlib liblz4.a +addlib libssl.a +save +end +EOF + +cp ./librdkafka_windows.a ../dest/ +popd +rm -rf ./mergescratch + export PATH="$PWD/dest/bin:/mingw64/bin/:${PATH}" cd tests ./test-runner.exe -l -Q -p1 diff --git a/packaging/mingw-w64/travis-before-install.sh b/packaging/mingw-w64/travis-before-install.sh index 2f75694973..f6d58f37c4 100644 --- a/packaging/mingw-w64/travis-before-install.sh +++ b/packaging/mingw-w64/travis-before-install.sh @@ -20,9 +20,18 @@ case $TRAVIS_OS_NAME in # to zstd instead of xz compression $msys2 pacman -Sy --noconfirm pacman choco upgrade --no-progress -y msys2 - $msys2 pacman --sync --noconfirm --needed mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-openssl mingw-w64-x86_64-cyrus-sasl ## Install more MSYS2 packages from https://packages.msys2.org/base here + $msys2 pacman --sync --noconfirm --needed mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-openssl mingw-w64-x86_64-lz4 mingw-w64-x86_64-zstd + + # Removing the DLLs so cmake links against the static libs + $msys2 \ + cd /mingw64/lib && \ + rm libzstd.dll.a && \ + rm libcrypto.dll.a && \ + rm liblz4.dll.a && \ + rm libssl.dll.a + taskkill //IM gpg-agent.exe //F || true # https://travis-ci.community/t/4967 export PATH=/C/tools/msys64/mingw64/bin:$PATH export MAKE=mingw32-make # so that Autotools can find it diff --git a/packaging/nuget/packaging.py b/packaging/nuget/packaging.py index cc2de31c30..207cb8800b 100755 --- a/packaging/nuget/packaging.py +++ b/packaging/nuget/packaging.py @@ -508,6 +508,10 @@ def build (self, buildtype): # osx static lib and pkg-config file [{'arch': 'x64', 'plat': 'osx', 'fname_glob': 'librdkafka-clang.tar.gz'}, './lib/librdkafka-static.a', 'librdkafka_darwin.a'], [{'arch': 'x64', 'plat': 'osx', 'fname_glob': 'librdkafka-clang.tar.gz'}, './lib/pkgconfig/rdkafka-static.pc', 'librdkafka_darwin.pc'], + + # win static lib and pkg-config file + [{'arch': 'x64', 'plat': 'win', 'fname_glob': 'librdkafka-mingw.tar.gz'}, './lib/librdkafka-static.a', 'librdkafka_windows.a'], + [{'arch': 'x64', 'plat': 'win', 'fname_glob': 'librdkafka-mingw.tar.gz'}, './lib/pkgconfig/rdkafka-static.pc', 'librdkafka_windows.pc'], ] for m in mappings: @@ -573,7 +577,9 @@ def verify (self, path): "./librdkafka_musl_linux.a", "./librdkafka_musl_linux.pc", "./librdkafka_darwin.a", - "./librdkafka_darwin.pc"] + "./librdkafka_darwin.pc", + "./librdkafka_windows.a", + "./librdkafka_windows.pc"] missing = list() with zfile.ZFile(path, 'r') as zf: From 6aedc13d736aa73d50887540c1232caa43c11c55 Mon Sep 17 00:00:00 2001 From: neptoess Date: Mon, 2 Nov 2020 09:01:47 -0500 Subject: [PATCH 02/22] Update paths to match Travis MinGW build script --- packaging/nuget/packaging.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/nuget/packaging.py b/packaging/nuget/packaging.py index 207cb8800b..ccf94e60b9 100755 --- a/packaging/nuget/packaging.py +++ b/packaging/nuget/packaging.py @@ -510,8 +510,8 @@ def build (self, buildtype): [{'arch': 'x64', 'plat': 'osx', 'fname_glob': 'librdkafka-clang.tar.gz'}, './lib/pkgconfig/rdkafka-static.pc', 'librdkafka_darwin.pc'], # win static lib and pkg-config file - [{'arch': 'x64', 'plat': 'win', 'fname_glob': 'librdkafka-mingw.tar.gz'}, './lib/librdkafka-static.a', 'librdkafka_windows.a'], - [{'arch': 'x64', 'plat': 'win', 'fname_glob': 'librdkafka-mingw.tar.gz'}, './lib/pkgconfig/rdkafka-static.pc', 'librdkafka_windows.pc'], + [{'arch': 'x64', 'plat': 'win', 'fname_glob': 'librdkafka-mingw.tar.gz'}, './librdkafka_windows.a', 'librdkafka_windows.a'], + [{'arch': 'x64', 'plat': 'win', 'fname_glob': 'librdkafka-mingw.tar.gz'}, './generated/rdkafka-static.pc', 'librdkafka_windows.pc'], ] for m in mappings: From 914740e0866b3fec658ccddf625e4b8118b4f698 Mon Sep 17 00:00:00 2001 From: neptoess Date: Mon, 2 Nov 2020 11:16:13 -0500 Subject: [PATCH 03/22] Update DLL paths --- packaging/mingw-w64/configure-build-msys2-mingw.sh | 8 ++++---- packaging/mingw-w64/travis-before-install.sh | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packaging/mingw-w64/configure-build-msys2-mingw.sh b/packaging/mingw-w64/configure-build-msys2-mingw.sh index 58e9e52841..c5a0a099e5 100644 --- a/packaging/mingw-w64/configure-build-msys2-mingw.sh +++ b/packaging/mingw-w64/configure-build-msys2-mingw.sh @@ -22,10 +22,10 @@ $mingw64 mingw32-make install # Bundle all the static dependencies with the static lib we just built mkdir mergescratch pushd mergescratch -cp /mingw64/lib/libzstd.a ./ -cp /mingw64/lib/libcrypto.a ./ -cp /mingw64/lib/liblz4.a ./ -cp /mingw64/lib/libssl.a ./ +cp /C/tools/msys64/mingw64/lib/libzstd.a ./ +cp /C/tools/msys64/mingw64/lib/libcrypto.a ./ +cp /C/tools/msys64/mingw64/lib/liblz4.a ./ +cp /C/tools/msys64/mingw64/lib/libssl.a ./ cp ../src/librdkafka.a ./ ar -M << EOF create librdkafka_windows.a diff --git a/packaging/mingw-w64/travis-before-install.sh b/packaging/mingw-w64/travis-before-install.sh index f6d58f37c4..6a335bc6d5 100644 --- a/packaging/mingw-w64/travis-before-install.sh +++ b/packaging/mingw-w64/travis-before-install.sh @@ -26,11 +26,11 @@ case $TRAVIS_OS_NAME in # Removing the DLLs so cmake links against the static libs $msys2 \ - cd /mingw64/lib && \ + cd /C/tools/msys64/mingw64/lib && \ rm libzstd.dll.a && \ rm libcrypto.dll.a && \ rm liblz4.dll.a && \ - rm libssl.dll.a + rm libssl.dll.a taskkill //IM gpg-agent.exe //F || true # https://travis-ci.community/t/4967 export PATH=/C/tools/msys64/mingw64/bin:$PATH From fa37b375d39d14f059e50e4c5404beab04369150 Mon Sep 17 00:00:00 2001 From: neptoess Date: Mon, 2 Nov 2020 11:20:42 -0500 Subject: [PATCH 04/22] Replace tabs with spaces --- packaging/mingw-w64/travis-before-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/mingw-w64/travis-before-install.sh b/packaging/mingw-w64/travis-before-install.sh index 6a335bc6d5..f7900563e3 100644 --- a/packaging/mingw-w64/travis-before-install.sh +++ b/packaging/mingw-w64/travis-before-install.sh @@ -30,7 +30,7 @@ case $TRAVIS_OS_NAME in rm libzstd.dll.a && \ rm libcrypto.dll.a && \ rm liblz4.dll.a && \ - rm libssl.dll.a + rm libssl.dll.a taskkill //IM gpg-agent.exe //F || true # https://travis-ci.community/t/4967 export PATH=/C/tools/msys64/mingw64/bin:$PATH From 3202c0030dbc5dc4d665f0cf61bd379befc25e0b Mon Sep 17 00:00:00 2001 From: neptoess Date: Mon, 2 Nov 2020 14:40:58 -0500 Subject: [PATCH 05/22] Don't use msys2 rm, just use regular travis one --- packaging/mingw-w64/travis-before-install.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packaging/mingw-w64/travis-before-install.sh b/packaging/mingw-w64/travis-before-install.sh index f7900563e3..8212e4ecd9 100644 --- a/packaging/mingw-w64/travis-before-install.sh +++ b/packaging/mingw-w64/travis-before-install.sh @@ -25,12 +25,10 @@ case $TRAVIS_OS_NAME in $msys2 pacman --sync --noconfirm --needed mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-openssl mingw-w64-x86_64-lz4 mingw-w64-x86_64-zstd # Removing the DLLs so cmake links against the static libs - $msys2 \ - cd /C/tools/msys64/mingw64/lib && \ - rm libzstd.dll.a && \ - rm libcrypto.dll.a && \ - rm liblz4.dll.a && \ - rm libssl.dll.a + rm /C/tools/msys64/mingw64/lib/libzstd.dll.a + rm /C/tools/msys64/mingw64/lib/libcrypto.dll.a + rm /C/tools/msys64/mingw64/lib/liblz4.dll.a + rm /C/tools/msys64/mingw64/lib/libssl.dll.a taskkill //IM gpg-agent.exe //F || true # https://travis-ci.community/t/4967 export PATH=/C/tools/msys64/mingw64/bin:$PATH From b6923bd3933b92cd34d21150e525dedc18599e3e Mon Sep 17 00:00:00 2001 From: neptoess Date: Mon, 2 Nov 2020 16:15:51 -0500 Subject: [PATCH 06/22] Add Win32 DLLs to MinGW C++ pkg-config --- src-cpp/CMakeLists.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src-cpp/CMakeLists.txt b/src-cpp/CMakeLists.txt index a7b3e83e41..59e7d46f46 100644 --- a/src-cpp/CMakeLists.txt +++ b/src-cpp/CMakeLists.txt @@ -71,9 +71,15 @@ if(RDKAFKA_BUILD_STATIC) set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library (static)" ) - set(PKG_CONFIG_LIBS - "-L\${libdir} \${libdir}/librdkafka++.a" - ) + if(WIN32) + set(PKG_CONFIG_LIBS + "-lws2_32 -lsecur32 -lcrypt32 -L\${libdir} \${libdir}/librdkafka++.a" + ) + else() + set(PKG_CONFIG_LIBS + "-L\${libdir} \${libdir}/librdkafka++.a" + ) + endif() configure_file( "../packaging/cmake/rdkafka.pc.in" "${GENERATED_DIR}/rdkafka++-static.pc" From 2fa3a830f83f7f17d772896a9f3e414978ef64fc Mon Sep 17 00:00:00 2001 From: neptoess Date: Mon, 2 Nov 2020 17:58:53 -0500 Subject: [PATCH 07/22] Relocate MinGW target_link_libraries to allow building executables --- src/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 70aef4e3d8..f8fbaad820 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -182,12 +182,6 @@ if(RDKAFKA_BUILD_STATIC) target_compile_definitions(rdkafka PUBLIC LIBRDKAFKA_STATICLIB) endif() -if(MINGW) - message(STATUS "Detected MinGW build") - # MinGW ignores `#pragma comment(lib, ...)` so we need to specify link libs - target_link_libraries(rdkafka PUBLIC crypt32 ws2_32 secur32) -endif(MINGW) - if(WIN32) if(RDKAFKA_BUILD_STATIC) target_link_libraries(rdkafka PUBLIC crypt32) @@ -253,6 +247,12 @@ if(WITH_LZ4_EXT) target_link_libraries(rdkafka PUBLIC LZ4::LZ4) endif() +if(MINGW) + message(STATUS "Detected MinGW build") + # MinGW ignores `#pragma comment(lib, ...)` so we need to specify link libs + target_link_libraries(rdkafka PUBLIC crypt32 ws2_32 secur32) +endif(MINGW) + # Set up path to these sources for other sub-projects (tests, examples) # to be able to reach them. #set(rdkafka_SRC_DIR ${PROJECT_SOURCE_DIR} From 3d714b76e4db000f1c92be72b3e12b28b561dd8e Mon Sep 17 00:00:00 2001 From: neptoess Date: Mon, 2 Nov 2020 18:10:02 -0500 Subject: [PATCH 08/22] Update CMakeLists.txt to include pkg-config for Windows DLLs for static MinGW builds --- src-cpp/CMakeLists.txt | 12 +++--------- src/CMakeLists.txt | 12 +++++++++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src-cpp/CMakeLists.txt b/src-cpp/CMakeLists.txt index 59e7d46f46..a7b3e83e41 100644 --- a/src-cpp/CMakeLists.txt +++ b/src-cpp/CMakeLists.txt @@ -71,15 +71,9 @@ if(RDKAFKA_BUILD_STATIC) set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library (static)" ) - if(WIN32) - set(PKG_CONFIG_LIBS - "-lws2_32 -lsecur32 -lcrypt32 -L\${libdir} \${libdir}/librdkafka++.a" - ) - else() - set(PKG_CONFIG_LIBS - "-L\${libdir} \${libdir}/librdkafka++.a" - ) - endif() + set(PKG_CONFIG_LIBS + "-L\${libdir} \${libdir}/librdkafka++.a" + ) configure_file( "../packaging/cmake/rdkafka.pc.in" "${GENERATED_DIR}/rdkafka++-static.pc" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f8fbaad820..104f7dc762 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -318,9 +318,15 @@ if(RDKAFKA_BUILD_STATIC) set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library (static)" ) - set(PKG_CONFIG_LIBS - "-L\${libdir} \${libdir}/librdkafka.a" - ) + if(WIN32) + set(PKG_CONFIG_LIBS + "-L\${libdir} \${libdir}/librdkafka.a -lws2_32 -lsecur32 -lcrypt32" + ) + else() + set(PKG_CONFIG_LIBS + "-L\${libdir} \${libdir}/librdkafka.a" + ) + endif() configure_file( "../packaging/cmake/rdkafka.pc.in" "${GENERATED_DIR}/rdkafka-static.pc" From 1a589f6997d52ee4f2383217ba399f7b7274b245 Mon Sep 17 00:00:00 2001 From: neptoess Date: Tue, 3 Nov 2020 09:17:29 -0500 Subject: [PATCH 09/22] Write to librdkafka.a instead of librdkafka_windows.a Update CMakeLists.txt to only generate -static .pc files when building static lib Run cmake-format on CMakeLists.txt --- CMakeLists.txt | 68 ++++---- examples/CMakeLists.txt | 18 ++- .../mingw-w64/configure-build-msys2-mingw.sh | 14 +- src-cpp/CMakeLists.txt | 103 +++++------- src/CMakeLists.txt | 152 +++++++----------- tests/CMakeLists.txt | 10 +- tests/interceptor_test/CMakeLists.txt | 11 +- 7 files changed, 161 insertions(+), 215 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 414fe586e8..4b1988b1cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,13 +5,14 @@ parseversion("src/rdkafka.h") project(RdKafka VERSION ${RDKAFKA_VERSION}) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/packaging/cmake/Modules/") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} + "${CMAKE_CURRENT_SOURCE_DIR}/packaging/cmake/Modules/") # Options. No 'RDKAFKA_' prefix to match old C++ code. { -# This option doesn't affect build in fact, only C code -# (see 'rd_kafka_version_str'). In CMake the build type feature usually used -# (like Debug, Release, etc.). +# This option doesn't affect build in fact, only C code (see +# 'rd_kafka_version_str'). +# In CMake the build type feature usually used (like Debug, Release, etc.). option(WITHOUT_OPTIMIZATION "Disable optimization" OFF) option(ENABLE_DEVEL "Enable development asserts, checks, etc" OFF) @@ -36,7 +37,7 @@ endif() include(CheckLibraryExists) check_library_exists(m pow "" WITH_HDRHISTOGRAM) if(WITH_HDRHISTOGRAM) - list(APPEND BUILT_WITH "HDRHISTOGRAM") + list(APPEND BUILT_WITH "HDRHISTOGRAM") endif() # } @@ -68,11 +69,10 @@ endif() # LibDL { try_compile( - WITH_LIBDL - "${CMAKE_CURRENT_BINARY_DIR}/try_compile" - "${TRYCOMPILE_SRC_DIR}/dlopen_test.c" - LINK_LIBRARIES "${CMAKE_DL_LIBS}" -) + WITH_LIBDL + "${CMAKE_CURRENT_BINARY_DIR}/try_compile" + "${TRYCOMPILE_SRC_DIR}/dlopen_test.c" + LINK_LIBRARIES "${CMAKE_DL_LIBS}") if(WITH_LIBDL) list(APPEND BUILT_WITH "LIBDL") endif() @@ -117,11 +117,10 @@ else() set(with_sasl_default ON) else() try_compile( - WITH_SASL_CYRUS_BOOL - "${CMAKE_CURRENT_BINARY_DIR}/try_compile" - "${TRYCOMPILE_SRC_DIR}/libsasl2_test.c" - LINK_LIBRARIES "-lsasl2" - ) + WITH_SASL_CYRUS_BOOL + "${CMAKE_CURRENT_BINARY_DIR}/try_compile" + "${TRYCOMPILE_SRC_DIR}/libsasl2_test.c" + LINK_LIBRARIES "-lsasl2") if(WITH_SASL_CYRUS_BOOL) set(with_sasl_default ON) set(SASL_LIBRARIES "-lsasl2") @@ -163,7 +162,8 @@ option(RDKAFKA_BUILD_STATIC "Build static rdkafka library" OFF) option(RDKAFKA_BUILD_EXAMPLES "Build examples" ON) option(RDKAFKA_BUILD_TESTS "Build tests" ON) if(WIN32) - option(WITHOUT_WIN32_CONFIG "Avoid including win32_config.h on cmake builds" ON) + option(WITHOUT_WIN32_CONFIG "Avoid including win32_config.h on cmake builds" + ON) endif(WIN32) # In: @@ -226,35 +226,27 @@ set(namespace "${PROJECT_NAME}::") include(CMakePackageConfigHelpers) # In: -# * targets_export_name -# * PROJECT_NAME +# * targets_export_name +# * PROJECT_NAME configure_package_config_file( - "packaging/cmake/Config.cmake.in" - "${project_config}" - INSTALL_DESTINATION "${config_install_dir}" -) + "packaging/cmake/Config.cmake.in" "${project_config}" + INSTALL_DESTINATION "${config_install_dir}") write_basic_package_version_file( - "${project_version}" - VERSION ${PROJECT_VERSION} - COMPATIBILITY AnyNewerVersion -) + "${project_version}" + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion) -install( - FILES "${project_config}" "${project_version}" "packaging/cmake/Modules/FindLZ4.cmake" - DESTINATION "${config_install_dir}" -) +install(FILES "${project_config}" "${project_version}" + "packaging/cmake/Modules/FindLZ4.cmake" + DESTINATION "${config_install_dir}") install( - EXPORT "${targets_export_name}" - NAMESPACE "${namespace}" - DESTINATION "${config_install_dir}" -) + EXPORT "${targets_export_name}" + NAMESPACE "${namespace}" + DESTINATION "${config_install_dir}") -install( - FILES LICENSES.txt - DESTINATION "share/licenses/librdkafka" -) +install(FILES LICENSES.txt DESTINATION "share/licenses/librdkafka") # } diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 9c3178184c..d9e328ec15 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,5 +1,5 @@ if(WIN32) - set(win32_sources ../win32/wingetopt.c ../win32/wingetopt.h) + set(win32_sources ../win32/wingetopt.c ../win32/wingetopt.h) endif(WIN32) add_executable(producer producer.c ${win32_sources}) @@ -17,17 +17,19 @@ target_link_libraries(rdkafka_performance PUBLIC rdkafka) add_executable(rdkafka_example_cpp rdkafka_example.cpp ${win32_sources}) target_link_libraries(rdkafka_example_cpp PUBLIC rdkafka++) -add_executable(rdkafka_complex_consumer_example_cpp rdkafka_complex_consumer_example.cpp ${win32_sources}) +add_executable(rdkafka_complex_consumer_example_cpp + rdkafka_complex_consumer_example.cpp ${win32_sources}) target_link_libraries(rdkafka_complex_consumer_example_cpp PUBLIC rdkafka++) # The targets below has Unix include dirs and do not compile on Windows. if(NOT WIN32) - add_executable(rdkafka_example rdkafka_example.c) - target_link_libraries(rdkafka_example PUBLIC rdkafka) + add_executable(rdkafka_example rdkafka_example.c) + target_link_libraries(rdkafka_example PUBLIC rdkafka) - add_executable(rdkafka_complex_consumer_example rdkafka_complex_consumer_example.c) - target_link_libraries(rdkafka_complex_consumer_example PUBLIC rdkafka) + add_executable(rdkafka_complex_consumer_example + rdkafka_complex_consumer_example.c) + target_link_libraries(rdkafka_complex_consumer_example PUBLIC rdkafka) - add_executable(kafkatest_verifiable_client kafkatest_verifiable_client.cpp) - target_link_libraries(kafkatest_verifiable_client PUBLIC rdkafka++) + add_executable(kafkatest_verifiable_client kafkatest_verifiable_client.cpp) + target_link_libraries(kafkatest_verifiable_client PUBLIC rdkafka++) endif(NOT WIN32) diff --git a/packaging/mingw-w64/configure-build-msys2-mingw.sh b/packaging/mingw-w64/configure-build-msys2-mingw.sh index c5a0a099e5..d3ebac4ce2 100644 --- a/packaging/mingw-w64/configure-build-msys2-mingw.sh +++ b/packaging/mingw-w64/configure-build-msys2-mingw.sh @@ -27,8 +27,9 @@ cp /C/tools/msys64/mingw64/lib/libcrypto.a ./ cp /C/tools/msys64/mingw64/lib/liblz4.a ./ cp /C/tools/msys64/mingw64/lib/libssl.a ./ cp ../src/librdkafka.a ./ +cp ../src-cpp/librdkafka++.a ./librdkafkapp.a ar -M << EOF -create librdkafka_windows.a +create librdkafka_merge.a addlib librdkafka.a addlib libzstd.a addlib libcrypto.a @@ -38,7 +39,16 @@ save end EOF -cp ./librdkafka_windows.a ../dest/ +ar -M << EOF +create librdkafkapp_merge.a +addlib librdkafka_merge.a +addlib librdkafkapp.a +save +end +EOF + +cp ./librdkafka_merge.a ../dest/lib/librdkafka.a +cp ./librdkafkapp_merge.a ../dest/lib/librdkafka++.a popd rm -rf ./mergescratch diff --git a/src-cpp/CMakeLists.txt b/src-cpp/CMakeLists.txt index a7b3e83e41..ebf2828b8e 100644 --- a/src-cpp/CMakeLists.txt +++ b/src-cpp/CMakeLists.txt @@ -1,7 +1,6 @@ set(LIBVER 1) -set( - sources +set(sources ConfImpl.cpp ConsumerImpl.cpp HandleImpl.cpp @@ -13,8 +12,7 @@ set( QueueImpl.cpp RdKafka.cpp TopicImpl.cpp - TopicPartitionImpl.cpp -) + TopicPartitionImpl.cpp) if(RDKAFKA_BUILD_STATIC) set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -31,69 +29,50 @@ endif() target_link_libraries(rdkafka++ PUBLIC rdkafka) # Support '#include ' -target_include_directories(rdkafka++ PUBLIC "$") +target_include_directories( + rdkafka++ PUBLIC "$") if(NOT RDKAFKA_BUILD_STATIC) - target_compile_definitions(rdkafka++ PRIVATE LIBRDKAFKACPP_EXPORTS) + target_compile_definitions(rdkafka++ PRIVATE LIBRDKAFKACPP_EXPORTS) endif() # Generate pkg-config file -set(PKG_CONFIG_NAME - "librdkafka++" -) -set(PKG_CONFIG_DESCRIPTION - "The Apache Kafka C/C++ library" -) -set(PKG_CONFIG_VERSION - "${PROJECT_VERSION}" -) -set(PKG_CONFIG_REQUIRES "rdkafka") -set(PKG_CONFIG_CFLAGS - "-I\${includedir}" -) -set(PKG_CONFIG_LIBS - "-L\${libdir} -lrdkafka++" -) -set(PKG_CONFIG_LIBS_PRIVATE - "-lrdkafka" -) -configure_file( - "../packaging/cmake/rdkafka.pc.in" - "${GENERATED_DIR}/rdkafka++.pc" - @ONLY -) -install(FILES ${GENERATED_DIR}/rdkafka++.pc - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" -) -if(RDKAFKA_BUILD_STATIC) - set(PKG_CONFIG_NAME - "librdkafka++-static" - ) - set(PKG_CONFIG_DESCRIPTION - "The Apache Kafka C/C++ library (static)" - ) - set(PKG_CONFIG_LIBS - "-L\${libdir} \${libdir}/librdkafka++.a" - ) - configure_file( - "../packaging/cmake/rdkafka.pc.in" - "${GENERATED_DIR}/rdkafka++-static.pc" - @ONLY - ) - install(FILES ${GENERATED_DIR}/rdkafka.pc - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" - ) +set(PKG_CONFIG_VERSION "${PROJECT_VERSION}") +if(NOT RDKAFKA_BUILD_STATIC) + set(PKG_CONFIG_NAME "librdkafka++") + set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library") + set(PKG_CONFIG_REQUIRES "rdkafka") + set(PKG_CONFIG_CFLAGS "-I\${includedir}") + set(PKG_CONFIG_LIBS "-L\${libdir} -lrdkafka++") + set(PKG_CONFIG_LIBS_PRIVATE "-lrdkafka") + configure_file("../packaging/cmake/rdkafka.pc.in" + "${GENERATED_DIR}/rdkafka++.pc" @ONLY) + install(FILES ${GENERATED_DIR}/rdkafka++.pc + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +else() + set(PKG_CONFIG_NAME "librdkafka++-static") + set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library (static)") + set(PKG_CONFIG_REQUIRES "") + set(PKG_CONFIG_CFLAGS "-I\${includedir} -DLIBRDKAFKA_STATICLIB") + if(WIN32) + set(PKG_CONFIG_LIBS + "-L\${libdir} \${libdir}/librdkafka++.a -lws2_32 -lsecur32 -lcrypt32") + else() + set(PKG_CONFIG_LIBS "-L\${libdir} \${libdir}/librdkafka++.a") + endif() + configure_file("../packaging/cmake/rdkafka.pc.in" + "${GENERATED_DIR}/rdkafka++-static.pc" @ONLY) + install(FILES ${GENERATED_DIR}/rdkafka++-static.pc + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") endif() install( - TARGETS rdkafka++ - EXPORT "${targets_export_name}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" -) + TARGETS rdkafka++ + EXPORT "${targets_export_name}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + INCLUDES + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") -install( - FILES "rdkafkacpp.h" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/librdkafka" -) +install(FILES "rdkafkacpp.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/librdkafka") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 104f7dc762..c302ca59ac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,6 @@ set(LIBVER 1) -set( - sources +set(sources crc32c.c rdaddr.c rdavl.c @@ -64,8 +63,7 @@ set( snappy.c tinycthread.c tinycthread_extra.c - rdxxhash.c -) + rdxxhash.c) if(WITH_SSL) list(APPEND sources rdkafka_ssl.c) @@ -176,13 +174,14 @@ if(MINGW) endif(MINGW) # Support '#include ' -target_include_directories(rdkafka PUBLIC "$") +target_include_directories( + rdkafka PUBLIC "$") target_compile_definitions(rdkafka PUBLIC ${rdkafka_compile_definitions}) if(RDKAFKA_BUILD_STATIC) target_compile_definitions(rdkafka PUBLIC LIBRDKAFKA_STATICLIB) endif() -if(WIN32) +if(WIN32) if(RDKAFKA_BUILD_STATIC) target_link_libraries(rdkafka PUBLIC crypt32) else() @@ -253,100 +252,69 @@ if(MINGW) target_link_libraries(rdkafka PUBLIC crypt32 ws2_32 secur32) endif(MINGW) -# Set up path to these sources for other sub-projects (tests, examples) -# to be able to reach them. -#set(rdkafka_SRC_DIR ${PROJECT_SOURCE_DIR} -# CACHE INTERNAL "${PROJECT_NAME} source dir" FORCE) - # Generate pkg-config file -set(PKG_CONFIG_NAME - "librdkafka" -) -set(PKG_CONFIG_DESCRIPTION - "The Apache Kafka C/C++ library" -) -set(PKG_CONFIG_VERSION - "${PROJECT_VERSION}" -) -set(PKG_CONFIG_REQUIRES "") -if(WITH_ZLIB) - string(APPEND PKG_CONFIG_REQUIRES "zlib ") -endif() -if(WITH_SSL) +set(PKG_CONFIG_VERSION "${PROJECT_VERSION}") +if(NOT RDKAFKA_BUILD_STATIC) + set(PKG_CONFIG_NAME "librdkafka") + set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library") + set(PKG_CONFIG_REQUIRES "") + if(WITH_ZLIB) + string(APPEND PKG_CONFIG_REQUIRES "zlib ") + endif() + if(WITH_SSL) string(APPEND PKG_CONFIG_REQUIRES "libssl ") -endif() -if(WITH_SASL_CYRUS) - string(APPEND PKG_CONFIG_REQUIRES "libsasl2 ") -endif() -if(WITH_ZSTD) + endif() + if(WITH_SASL_CYRUS) + string(APPEND PKG_CONFIG_REQUIRES "libsasl2 ") + endif() + if(WITH_ZSTD) string(APPEND PKG_CONFIG_REQUIRES "libzstd ") -endif() -if(WITH_LZ4_EXT) + endif() + if(WITH_LZ4_EXT) string(APPEND PKG_CONFIG_REQUIRES "liblz4 ") -endif() -set(PKG_CONFIG_CFLAGS - "-I\${includedir}" -) -set(PKG_CONFIG_LIBS - "-L\${libdir} -lrdkafka" -) -set(PKG_CONFIG_LIBS_PRIVATE - "-lpthread" -) -find_library(RT_LIBRARY rt) -if(RT_LIBRARY) - string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lrt") -endif() -if(WITH_PLUGINS) - string(APPEND PKG_CONFIG_LIBS_PRIVATE " -ldl") -endif() -if(WITH_HDRHISTOGRAM) - string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lm") -endif() -configure_file( - "../packaging/cmake/rdkafka.pc.in" - "${GENERATED_DIR}/rdkafka.pc" - @ONLY -) -install(FILES ${GENERATED_DIR}/rdkafka.pc - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" -) -if(RDKAFKA_BUILD_STATIC) - set(PKG_CONFIG_NAME - "librdkafka-static" - ) - set(PKG_CONFIG_DESCRIPTION - "The Apache Kafka C/C++ library (static)" - ) + endif() + set(PKG_CONFIG_CFLAGS "-I\${includedir}") + set(PKG_CONFIG_LIBS "-L\${libdir} -lrdkafka") + set(PKG_CONFIG_LIBS_PRIVATE "-lpthread") + find_library(RT_LIBRARY rt) + if(RT_LIBRARY) + string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lrt") + endif() + if(WITH_PLUGINS) + string(APPEND PKG_CONFIG_LIBS_PRIVATE " -ldl") + endif() + if(WITH_HDRHISTOGRAM) + string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lm") + endif() + configure_file("../packaging/cmake/rdkafka.pc.in" + "${GENERATED_DIR}/rdkafka.pc" @ONLY) + install(FILES ${GENERATED_DIR}/rdkafka.pc + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") +else() + set(PKG_CONFIG_REQUIRES "") + set(PKG_CONFIG_NAME "librdkafka-static") + set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library (static)") + set(PKG_CONFIG_CFLAGS "-I\${includedir} -DLIBRDKAFKA_STATICLIB") if(WIN32) set(PKG_CONFIG_LIBS - "-L\${libdir} \${libdir}/librdkafka.a -lws2_32 -lsecur32 -lcrypt32" - ) + "-L\${libdir} \${libdir}/librdkafka.a -lws2_32 -lsecur32 -lcrypt32") else() - set(PKG_CONFIG_LIBS - "-L\${libdir} \${libdir}/librdkafka.a" - ) + set(PKG_CONFIG_LIBS "-L\${libdir} \${libdir}/librdkafka.a") endif() - configure_file( - "../packaging/cmake/rdkafka.pc.in" - "${GENERATED_DIR}/rdkafka-static.pc" - @ONLY - ) - install(FILES ${GENERATED_DIR}/rdkafka.pc - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" - ) + configure_file("../packaging/cmake/rdkafka.pc.in" + "${GENERATED_DIR}/rdkafka-static.pc" @ONLY) + install(FILES ${GENERATED_DIR}/rdkafka-static.pc + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") endif() install( - TARGETS rdkafka - EXPORT "${targets_export_name}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" -) - -install( - FILES "rdkafka.h" "rdkafka_mock.h" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/librdkafka" -) + TARGETS rdkafka + EXPORT "${targets_export_name}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + INCLUDES + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") + +install(FILES "rdkafka.h" "rdkafka_mock.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/librdkafka") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9d3569a98e..b03924edc0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,4 @@ -set( - sources +set(sources 0000-unittests.c 0001-multiobj.c 0002-unkpart.c @@ -114,13 +113,12 @@ set( 8000-idle.cpp test.c testcpp.cpp - rusage.c -) + rusage.c) if(NOT WIN32) - list(APPEND sources sockem.c sockem_ctrl.c) + list(APPEND sources sockem.c sockem_ctrl.c) else() - list(APPEND sources ../src/tinycthread.c ../src/tinycthread_extra.c) + list(APPEND sources ../src/tinycthread.c ../src/tinycthread_extra.c) endif() add_executable(test-runner ${sources}) diff --git a/tests/interceptor_test/CMakeLists.txt b/tests/interceptor_test/CMakeLists.txt index c606bc4266..ddf8bd039f 100644 --- a/tests/interceptor_test/CMakeLists.txt +++ b/tests/interceptor_test/CMakeLists.txt @@ -1,8 +1,4 @@ -set( - sources - interceptor_test.c -) - +set(sources interceptor_test.c) add_library(interceptor_test SHARED ${sources}) @@ -12,5 +8,6 @@ target_link_libraries(interceptor_test PUBLIC rdkafka) # Remove "lib" prefix set_target_properties(interceptor_test PROPERTIES PREFIX "") -set_target_properties(interceptor_test PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${tests_OUTPUT_DIRECTORY}/interceptor_test/) +set_target_properties( + interceptor_test PROPERTIES LIBRARY_OUTPUT_DIRECTORY + ${tests_OUTPUT_DIRECTORY}/interceptor_test/) From 7bfe9b64884d67698c4f6b40ae5386ac6e92dfe1 Mon Sep 17 00:00:00 2001 From: neptoess Date: Tue, 3 Nov 2020 10:54:56 -0500 Subject: [PATCH 10/22] Update packing script for different .a file name --- packaging/nuget/packaging.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/nuget/packaging.py b/packaging/nuget/packaging.py index ccf94e60b9..322dc76277 100755 --- a/packaging/nuget/packaging.py +++ b/packaging/nuget/packaging.py @@ -510,8 +510,8 @@ def build (self, buildtype): [{'arch': 'x64', 'plat': 'osx', 'fname_glob': 'librdkafka-clang.tar.gz'}, './lib/pkgconfig/rdkafka-static.pc', 'librdkafka_darwin.pc'], # win static lib and pkg-config file - [{'arch': 'x64', 'plat': 'win', 'fname_glob': 'librdkafka-mingw.tar.gz'}, './librdkafka_windows.a', 'librdkafka_windows.a'], - [{'arch': 'x64', 'plat': 'win', 'fname_glob': 'librdkafka-mingw.tar.gz'}, './generated/rdkafka-static.pc', 'librdkafka_windows.pc'], + [{'arch': 'x64', 'plat': 'win', 'fname_glob': 'librdkafka-mingw.tar.gz'}, './lib/librdkafka.a', 'librdkafka_windows.a'], + [{'arch': 'x64', 'plat': 'win', 'fname_glob': 'librdkafka-mingw.tar.gz'}, './lib/pkgconfig/rdkafka-static.pc', 'librdkafka_windows.pc'], ] for m in mappings: From 8b1233c9fc2ecf623567c02f6d20b752a66afdb8 Mon Sep 17 00:00:00 2001 From: neptoess Date: Tue, 10 Nov 2020 13:57:49 -0500 Subject: [PATCH 11/22] Separate MinGW static build and dynamic build Turn WITH_SASL=ON for Windows build so OATHBEARER SASL can be used --- .travis.yml | 10 +++- .../configure-build-msys2-mingw-static.sh | 59 +++++++++++++++++++ .../mingw-w64/configure-build-msys2-mingw.sh | 39 +----------- packaging/nuget/packaging.py | 2 +- 4 files changed, 72 insertions(+), 38 deletions(-) create mode 100644 packaging/mingw-w64/configure-build-msys2-mingw-static.sh diff --git a/.travis.yml b/.travis.yml index 78c180f4de..fef48fac79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,7 +56,7 @@ matrix: env: LINKAGE=static HOMEBREW_NO_AUTO_UPDATE=1 before_script: - ./configure --install-deps --disable-lz4-ext --prefix="$PWD/dest" --enable-static --disable-syslog - - name: "Windows MinGW-w64" + - name: "Windows MinGW-w64 Dynamic" os: windows env: - SKIP_MAKE=y @@ -64,6 +64,14 @@ matrix: - source ./packaging/mingw-w64/travis-before-install.sh before_script: - ./packaging/mingw-w64/configure-build-msys2-mingw.sh + - name: "Windows MinGW-w64 Static" + os: windows + env: + - SKIP_MAKE=y + before_install: + - source ./packaging/mingw-w64/travis-before-install.sh + before_script: + - ./packaging/mingw-w64/configure-build-msys2-mingw-static.sh - name: "Linux GCC: +integration-tests +copyright-check +doc-check" os: linux dist: xenial diff --git a/packaging/mingw-w64/configure-build-msys2-mingw-static.sh b/packaging/mingw-w64/configure-build-msys2-mingw-static.sh new file mode 100644 index 0000000000..b06a74c08c --- /dev/null +++ b/packaging/mingw-w64/configure-build-msys2-mingw-static.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +set -e + +cmake \ + -G "MinGW Makefiles" \ + -D CMAKE_INSTALL_PREFIX="$PWD/dest/" \ + -D WITHOUT_WIN32_CONFIG=ON \ + -D RDKAFKA_BUILD_EXAMPLES=ON \ + -D RDKAFKA_BUILD_TESTS=ON \ + -D WITH_LIBDL=OFF \ + -D WITH_PLUGINS=OFF \ + -D WITH_SASL=ON \ + -D WITH_SSL=ON \ + -D WITH_ZLIB=OFF \ + -D RDKAFKA_BUILD_STATIC=ON \ + . + +$mingw64 mingw32-make +$mingw64 mingw32-make install + +# Bundle all the static dependencies with the static lib we just built +mkdir mergescratch +pushd mergescratch +cp /C/tools/msys64/mingw64/lib/libzstd.a ./ +cp /C/tools/msys64/mingw64/lib/libcrypto.a ./ +cp /C/tools/msys64/mingw64/lib/liblz4.a ./ +cp /C/tools/msys64/mingw64/lib/libssl.a ./ +cp ../src/librdkafka.a ./ + +# Have to rename because ar won't work with + in the name +cp ../src-cpp/librdkafka++.a ./librdkafkacpp.a +ar -M << EOF +create librdkafka-static.a +addlib librdkafka.a +addlib libzstd.a +addlib libcrypto.a +addlib liblz4.a +addlib libssl.a +save +end +EOF + +ar -M << EOF +create librdkafkacpp-static.a +addlib librdkafka-static.a +addlib librdkafkacpp.a +save +end +EOF + +cp ./librdkafka-static.a ../dest/lib/ +cp ./librdkafkacpp-static.a ../dest/lib/librdkafka++-static.a +popd +rm -rf ./mergescratch + +export PATH="$PWD/dest/bin:/mingw64/bin/:${PATH}" +cd tests +./test-runner.exe -l -Q -p1 diff --git a/packaging/mingw-w64/configure-build-msys2-mingw.sh b/packaging/mingw-w64/configure-build-msys2-mingw.sh index d3ebac4ce2..f26c10b5b5 100644 --- a/packaging/mingw-w64/configure-build-msys2-mingw.sh +++ b/packaging/mingw-w64/configure-build-msys2-mingw.sh @@ -10,48 +10,15 @@ cmake \ -D RDKAFKA_BUILD_TESTS=ON \ -D WITH_LIBDL=OFF \ -D WITH_PLUGINS=OFF \ - -D WITH_SASL=OFF \ + -D WITH_SASL=ON \ -D WITH_SSL=ON \ -D WITH_ZLIB=OFF \ - -D RDKAFKA_BUILD_STATIC=ON \ - . + -D RDKAFKA_BUILD_STATIC=OFF \ + -D CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE . $mingw64 mingw32-make $mingw64 mingw32-make install -# Bundle all the static dependencies with the static lib we just built -mkdir mergescratch -pushd mergescratch -cp /C/tools/msys64/mingw64/lib/libzstd.a ./ -cp /C/tools/msys64/mingw64/lib/libcrypto.a ./ -cp /C/tools/msys64/mingw64/lib/liblz4.a ./ -cp /C/tools/msys64/mingw64/lib/libssl.a ./ -cp ../src/librdkafka.a ./ -cp ../src-cpp/librdkafka++.a ./librdkafkapp.a -ar -M << EOF -create librdkafka_merge.a -addlib librdkafka.a -addlib libzstd.a -addlib libcrypto.a -addlib liblz4.a -addlib libssl.a -save -end -EOF - -ar -M << EOF -create librdkafkapp_merge.a -addlib librdkafka_merge.a -addlib librdkafkapp.a -save -end -EOF - -cp ./librdkafka_merge.a ../dest/lib/librdkafka.a -cp ./librdkafkapp_merge.a ../dest/lib/librdkafka++.a -popd -rm -rf ./mergescratch - export PATH="$PWD/dest/bin:/mingw64/bin/:${PATH}" cd tests ./test-runner.exe -l -Q -p1 diff --git a/packaging/nuget/packaging.py b/packaging/nuget/packaging.py index 322dc76277..207cb8800b 100755 --- a/packaging/nuget/packaging.py +++ b/packaging/nuget/packaging.py @@ -510,7 +510,7 @@ def build (self, buildtype): [{'arch': 'x64', 'plat': 'osx', 'fname_glob': 'librdkafka-clang.tar.gz'}, './lib/pkgconfig/rdkafka-static.pc', 'librdkafka_darwin.pc'], # win static lib and pkg-config file - [{'arch': 'x64', 'plat': 'win', 'fname_glob': 'librdkafka-mingw.tar.gz'}, './lib/librdkafka.a', 'librdkafka_windows.a'], + [{'arch': 'x64', 'plat': 'win', 'fname_glob': 'librdkafka-mingw.tar.gz'}, './lib/librdkafka-static.a', 'librdkafka_windows.a'], [{'arch': 'x64', 'plat': 'win', 'fname_glob': 'librdkafka-mingw.tar.gz'}, './lib/pkgconfig/rdkafka-static.pc', 'librdkafka_windows.pc'], ] From fff9182deb21c9cfc0eac44f2819d1760c6c9910 Mon Sep 17 00:00:00 2001 From: neptoess Date: Tue, 10 Nov 2020 14:29:47 -0500 Subject: [PATCH 12/22] Restore previous whitespace style in CMakeLists.txt --- CMakeLists.txt | 25 +++++++-------- examples/CMakeLists.txt | 6 ++-- src-cpp/CMakeLists.txt | 44 +++++++++++++++++---------- src/CMakeLists.txt | 15 +++++---- tests/CMakeLists.txt | 6 ++-- tests/interceptor_test/CMakeLists.txt | 9 ++++-- 6 files changed, 62 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b1988b1cf..e7f60765f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,14 +5,13 @@ parseversion("src/rdkafka.h") project(RdKafka VERSION ${RDKAFKA_VERSION}) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} - "${CMAKE_CURRENT_SOURCE_DIR}/packaging/cmake/Modules/") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/packaging/cmake/Modules/") # Options. No 'RDKAFKA_' prefix to match old C++ code. { -# This option doesn't affect build in fact, only C code (see -# 'rd_kafka_version_str'). -# In CMake the build type feature usually used (like Debug, Release, etc.). +# This option doesn't affect build in fact, only C code +# (see 'rd_kafka_version_str'). In CMake the build type feature usually used +# (like Debug, Release, etc.). option(WITHOUT_OPTIMIZATION "Disable optimization" OFF) option(ENABLE_DEVEL "Enable development asserts, checks, etc" OFF) @@ -162,8 +161,7 @@ option(RDKAFKA_BUILD_STATIC "Build static rdkafka library" OFF) option(RDKAFKA_BUILD_EXAMPLES "Build examples" ON) option(RDKAFKA_BUILD_TESTS "Build tests" ON) if(WIN32) - option(WITHOUT_WIN32_CONFIG "Avoid including win32_config.h on cmake builds" - ON) + option(WITHOUT_WIN32_CONFIG "Avoid including win32_config.h on cmake builds" ON) endif(WIN32) # In: @@ -229,7 +227,8 @@ include(CMakePackageConfigHelpers) # * targets_export_name # * PROJECT_NAME configure_package_config_file( - "packaging/cmake/Config.cmake.in" "${project_config}" + "packaging/cmake/Config.cmake.in" + "${project_config}" INSTALL_DESTINATION "${config_install_dir}") write_basic_package_version_file( @@ -237,16 +236,18 @@ write_basic_package_version_file( VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion) -install(FILES "${project_config}" "${project_version}" - "packaging/cmake/Modules/FindLZ4.cmake" - DESTINATION "${config_install_dir}") +install( + FILES "${project_config}" "${project_version}" "packaging/cmake/Modules/FindLZ4.cmake" + DESTINATION "${config_install_dir}") install( EXPORT "${targets_export_name}" NAMESPACE "${namespace}" DESTINATION "${config_install_dir}") -install(FILES LICENSES.txt DESTINATION "share/licenses/librdkafka") +install( + FILES LICENSES.txt + DESTINATION "share/licenses/librdkafka") # } diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d9e328ec15..8fa0e56858 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -17,8 +17,7 @@ target_link_libraries(rdkafka_performance PUBLIC rdkafka) add_executable(rdkafka_example_cpp rdkafka_example.cpp ${win32_sources}) target_link_libraries(rdkafka_example_cpp PUBLIC rdkafka++) -add_executable(rdkafka_complex_consumer_example_cpp - rdkafka_complex_consumer_example.cpp ${win32_sources}) +add_executable(rdkafka_complex_consumer_example_cpp rdkafka_complex_consumer_example.cpp ${win32_sources}) target_link_libraries(rdkafka_complex_consumer_example_cpp PUBLIC rdkafka++) # The targets below has Unix include dirs and do not compile on Windows. @@ -26,8 +25,7 @@ if(NOT WIN32) add_executable(rdkafka_example rdkafka_example.c) target_link_libraries(rdkafka_example PUBLIC rdkafka) - add_executable(rdkafka_complex_consumer_example - rdkafka_complex_consumer_example.c) + add_executable(rdkafka_complex_consumer_example rdkafka_complex_consumer_example.c) target_link_libraries(rdkafka_complex_consumer_example PUBLIC rdkafka) add_executable(kafkatest_verifiable_client kafkatest_verifiable_client.cpp) diff --git a/src-cpp/CMakeLists.txt b/src-cpp/CMakeLists.txt index ebf2828b8e..0ec7acdf28 100644 --- a/src-cpp/CMakeLists.txt +++ b/src-cpp/CMakeLists.txt @@ -12,7 +12,8 @@ set(sources QueueImpl.cpp RdKafka.cpp TopicImpl.cpp - TopicPartitionImpl.cpp) + TopicPartitionImpl.cpp +) if(RDKAFKA_BUILD_STATIC) set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -29,8 +30,7 @@ endif() target_link_libraries(rdkafka++ PUBLIC rdkafka) # Support '#include ' -target_include_directories( - rdkafka++ PUBLIC "$") +target_include_directories(rdkafka++ PUBLIC "$") if(NOT RDKAFKA_BUILD_STATIC) target_compile_definitions(rdkafka++ PRIVATE LIBRDKAFKACPP_EXPORTS) endif() @@ -44,25 +44,34 @@ if(NOT RDKAFKA_BUILD_STATIC) set(PKG_CONFIG_CFLAGS "-I\${includedir}") set(PKG_CONFIG_LIBS "-L\${libdir} -lrdkafka++") set(PKG_CONFIG_LIBS_PRIVATE "-lrdkafka") - configure_file("../packaging/cmake/rdkafka.pc.in" - "${GENERATED_DIR}/rdkafka++.pc" @ONLY) - install(FILES ${GENERATED_DIR}/rdkafka++.pc - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + configure_file( + "../packaging/cmake/rdkafka.pc.in" + "${GENERATED_DIR}/rdkafka++.pc" + @ONLY + ) + install( + FILES ${GENERATED_DIR}/rdkafka++.pc + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" + ) else() set(PKG_CONFIG_NAME "librdkafka++-static") set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library (static)") set(PKG_CONFIG_REQUIRES "") set(PKG_CONFIG_CFLAGS "-I\${includedir} -DLIBRDKAFKA_STATICLIB") if(WIN32) - set(PKG_CONFIG_LIBS - "-L\${libdir} \${libdir}/librdkafka++.a -lws2_32 -lsecur32 -lcrypt32") + set(PKG_CONFIG_LIBS "-L\${libdir} \${libdir}/librdkafka++.a -lws2_32 -lsecur32 -lcrypt32") else() set(PKG_CONFIG_LIBS "-L\${libdir} \${libdir}/librdkafka++.a") endif() - configure_file("../packaging/cmake/rdkafka.pc.in" - "${GENERATED_DIR}/rdkafka++-static.pc" @ONLY) - install(FILES ${GENERATED_DIR}/rdkafka++-static.pc - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + configure_file( + "../packaging/cmake/rdkafka.pc.in" + "${GENERATED_DIR}/rdkafka++-static.pc" + @ONLY + ) + install( + FILES ${GENERATED_DIR}/rdkafka++-static.pc + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" + ) endif() install( @@ -72,7 +81,10 @@ install( ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" INCLUDES - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) -install(FILES "rdkafkacpp.h" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/librdkafka") +install( + FILES "rdkafkacpp.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/librdkafka" +) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c302ca59ac..7875129b84 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,7 +63,8 @@ set(sources snappy.c tinycthread.c tinycthread_extra.c - rdxxhash.c) + rdxxhash.c +) if(WITH_SSL) list(APPEND sources rdkafka_ssl.c) @@ -174,8 +175,7 @@ if(MINGW) endif(MINGW) # Support '#include ' -target_include_directories( - rdkafka PUBLIC "$") +target_include_directories(rdkafka PUBLIC "$") target_compile_definitions(rdkafka PUBLIC ${rdkafka_compile_definitions}) if(RDKAFKA_BUILD_STATIC) target_compile_definitions(rdkafka PUBLIC LIBRDKAFKA_STATICLIB) @@ -314,7 +314,10 @@ install( ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" INCLUDES - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) -install(FILES "rdkafka.h" "rdkafka_mock.h" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/librdkafka") +install( + FILES "rdkafka.h" "rdkafka_mock.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/librdkafka" +) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b03924edc0..13866d4a43 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,5 @@ -set(sources +set( + sources 0000-unittests.c 0001-multiobj.c 0002-unkpart.c @@ -113,7 +114,8 @@ set(sources 8000-idle.cpp test.c testcpp.cpp - rusage.c) + rusage.c +) if(NOT WIN32) list(APPEND sources sockem.c sockem_ctrl.c) diff --git a/tests/interceptor_test/CMakeLists.txt b/tests/interceptor_test/CMakeLists.txt index ddf8bd039f..2895bcc299 100644 --- a/tests/interceptor_test/CMakeLists.txt +++ b/tests/interceptor_test/CMakeLists.txt @@ -1,4 +1,7 @@ -set(sources interceptor_test.c) +set( + sources + interceptor_test.c +) add_library(interceptor_test SHARED ${sources}) @@ -9,5 +12,5 @@ target_link_libraries(interceptor_test PUBLIC rdkafka) # Remove "lib" prefix set_target_properties(interceptor_test PROPERTIES PREFIX "") set_target_properties( - interceptor_test PROPERTIES LIBRARY_OUTPUT_DIRECTORY - ${tests_OUTPUT_DIRECTORY}/interceptor_test/) + interceptor_test PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${tests_OUTPUT_DIRECTORY}/interceptor_test/) From 37794d5b0fe4a3ab70c358ddd4fb5d206dc215e2 Mon Sep 17 00:00:00 2001 From: neptoess Date: Tue, 10 Nov 2020 16:58:34 -0500 Subject: [PATCH 13/22] CMakeLists.txt formatting --- CMakeLists.txt | 23 ++-- src-cpp/CMakeLists.txt | 27 ++-- src/CMakeLists.txt | 178 +++++++++++++++----------- tests/interceptor_test/CMakeLists.txt | 3 +- 4 files changed, 134 insertions(+), 97 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7f60765f8..ce2f56af4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,7 +71,8 @@ try_compile( WITH_LIBDL "${CMAKE_CURRENT_BINARY_DIR}/try_compile" "${TRYCOMPILE_SRC_DIR}/dlopen_test.c" - LINK_LIBRARIES "${CMAKE_DL_LIBS}") + LINK_LIBRARIES "${CMAKE_DL_LIBS}" +) if(WITH_LIBDL) list(APPEND BUILT_WITH "LIBDL") endif() @@ -119,7 +120,8 @@ else() WITH_SASL_CYRUS_BOOL "${CMAKE_CURRENT_BINARY_DIR}/try_compile" "${TRYCOMPILE_SRC_DIR}/libsasl2_test.c" - LINK_LIBRARIES "-lsasl2") + LINK_LIBRARIES "-lsasl2" + ) if(WITH_SASL_CYRUS_BOOL) set(with_sasl_default ON) set(SASL_LIBRARIES "-lsasl2") @@ -229,27 +231,30 @@ include(CMakePackageConfigHelpers) configure_package_config_file( "packaging/cmake/Config.cmake.in" "${project_config}" - INSTALL_DESTINATION "${config_install_dir}") + INSTALL_DESTINATION "${config_install_dir}" +) write_basic_package_version_file( "${project_version}" VERSION ${PROJECT_VERSION} - COMPATIBILITY AnyNewerVersion) + COMPATIBILITY AnyNewerVersion +) install( FILES "${project_config}" "${project_version}" "packaging/cmake/Modules/FindLZ4.cmake" - DESTINATION "${config_install_dir}") + DESTINATION "${config_install_dir}" +) install( EXPORT "${targets_export_name}" NAMESPACE "${namespace}" - DESTINATION "${config_install_dir}") + DESTINATION "${config_install_dir}" +) install( FILES LICENSES.txt - DESTINATION "share/licenses/librdkafka") - -# } + DESTINATION "share/licenses/librdkafka" +) add_subdirectory(src) add_subdirectory(src-cpp) diff --git a/src-cpp/CMakeLists.txt b/src-cpp/CMakeLists.txt index 0ec7acdf28..295789394e 100644 --- a/src-cpp/CMakeLists.txt +++ b/src-cpp/CMakeLists.txt @@ -1,18 +1,19 @@ set(LIBVER 1) -set(sources - ConfImpl.cpp - ConsumerImpl.cpp - HandleImpl.cpp - HeadersImpl.cpp - KafkaConsumerImpl.cpp - MessageImpl.cpp - MetadataImpl.cpp - ProducerImpl.cpp - QueueImpl.cpp - RdKafka.cpp - TopicImpl.cpp - TopicPartitionImpl.cpp +set( + sources + ConfImpl.cpp + ConsumerImpl.cpp + HandleImpl.cpp + HeadersImpl.cpp + KafkaConsumerImpl.cpp + MessageImpl.cpp + MetadataImpl.cpp + ProducerImpl.cpp + QueueImpl.cpp + RdKafka.cpp + TopicImpl.cpp + TopicPartitionImpl.cpp ) if(RDKAFKA_BUILD_STATIC) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7875129b84..f84c8bf926 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,69 +1,70 @@ set(LIBVER 1) -set(sources - crc32c.c - rdaddr.c - rdavl.c - rdbuf.c - rdcrc32.c - rdfnv1a.c - rdkafka.c - rdkafka_assignor.c - rdkafka_broker.c - rdkafka_buf.c - rdkafka_cgrp.c - rdkafka_conf.c - rdkafka_event.c - rdkafka_feature.c - rdkafka_lz4.c - rdkafka_metadata.c - rdkafka_metadata_cache.c - rdkafka_msg.c - rdkafka_msgset_reader.c - rdkafka_msgset_writer.c - rdkafka_offset.c - rdkafka_op.c - rdkafka_partition.c - rdkafka_pattern.c - rdkafka_queue.c - rdkafka_range_assignor.c - rdkafka_request.c - rdkafka_roundrobin_assignor.c - rdkafka_sasl.c - rdkafka_sasl_plain.c - rdkafka_sticky_assignor.c - rdkafka_subscription.c - rdkafka_assignment.c - rdkafka_timer.c - rdkafka_topic.c - rdkafka_transport.c - rdkafka_interceptor.c - rdkafka_header.c - rdkafka_admin.c - rdkafka_aux.c - rdkafka_background.c - rdkafka_idempotence.c - rdkafka_txnmgr.c - rdkafka_cert.c - rdkafka_coord.c - rdkafka_mock.c - rdkafka_mock_handlers.c - rdkafka_mock_cgrp.c - rdkafka_error.c - rdlist.c - rdlog.c - rdmurmur2.c - rdports.c - rdrand.c - rdregex.c - rdstring.c - rdunittest.c - rdvarint.c - rdmap.c - snappy.c - tinycthread.c - tinycthread_extra.c - rdxxhash.c +set( + sources + crc32c.c + rdaddr.c + rdavl.c + rdbuf.c + rdcrc32.c + rdfnv1a.c + rdkafka.c + rdkafka_assignor.c + rdkafka_broker.c + rdkafka_buf.c + rdkafka_cgrp.c + rdkafka_conf.c + rdkafka_event.c + rdkafka_feature.c + rdkafka_lz4.c + rdkafka_metadata.c + rdkafka_metadata_cache.c + rdkafka_msg.c + rdkafka_msgset_reader.c + rdkafka_msgset_writer.c + rdkafka_offset.c + rdkafka_op.c + rdkafka_partition.c + rdkafka_pattern.c + rdkafka_queue.c + rdkafka_range_assignor.c + rdkafka_request.c + rdkafka_roundrobin_assignor.c + rdkafka_sasl.c + rdkafka_sasl_plain.c + rdkafka_sticky_assignor.c + rdkafka_subscription.c + rdkafka_assignment.c + rdkafka_timer.c + rdkafka_topic.c + rdkafka_transport.c + rdkafka_interceptor.c + rdkafka_header.c + rdkafka_admin.c + rdkafka_aux.c + rdkafka_background.c + rdkafka_idempotence.c + rdkafka_txnmgr.c + rdkafka_cert.c + rdkafka_coord.c + rdkafka_mock.c + rdkafka_mock_handlers.c + rdkafka_mock_cgrp.c + rdkafka_error.c + rdlist.c + rdlog.c + rdmurmur2.c + rdports.c + rdrand.c + rdregex.c + rdstring.c + rdunittest.c + rdvarint.c + rdmap.c + snappy.c + tinycthread.c + tinycthread_extra.c + rdxxhash.c ) if(WITH_SSL) @@ -120,36 +121,43 @@ if(WITHOUT_WIN32_CONFIG) else() list(APPEND rdkafka_compile_definitions WITH_SSL=0) endif(WITH_SSL) + if(WITH_ZLIB) list(APPEND rdkafka_compile_definitions WITH_ZLIB=1) else() list(APPEND rdkafka_compile_definitions WITH_ZLIB=0) endif(WITH_ZLIB) + if(WITH_SNAPPY) list(APPEND rdkafka_compile_definitions WITH_SNAPPY=1) else() list(APPEND rdkafka_compile_definitions WITH_SNAPPY=0) endif(WITH_SNAPPY) + if(WITH_ZSTD) list(APPEND rdkafka_compile_definitions WITH_ZSTD=1) else() list(APPEND rdkafka_compile_definitions WITH_ZSTD=0) endif(WITH_ZSTD) + if(WITH_SASL_SCRAM) list(APPEND rdkafka_compile_definitions WITH_SASL_SCRAM=1) else() list(APPEND rdkafka_compile_definitions WITH_SASL_SCRAM=0) endif(WITH_SASL_SCRAM) + if(WITH_SASL_OAUTHBEARER) list(APPEND rdkafka_compile_definitions WITH_SASL_OAUTHBEARER=1) else() list(APPEND rdkafka_compile_definitions WITH_SASL_OAUTHBEARER=0) endif(WITH_SASL_OAUTHBEARER) + if(ENABLE_DEVEL) list(APPEND rdkafka_compile_definitions ENABLE_DEVEL=1) else() list(APPEND rdkafka_compile_definitions ENABLE_DEVEL=0) endif(ENABLE_DEVEL) + if(WITH_PLUGINS) list(APPEND rdkafka_compile_definitions WITH_PLUGIN=1) else() @@ -215,6 +223,7 @@ if(WITH_SSL) if(NOT TARGET bundled-ssl) message(FATAL_ERROR "bundled-ssl target not exist") endif() + target_include_directories(rdkafka BEFORE PUBLIC ${BUNDLED_SSL_INCLUDE_DIR}) target_link_libraries(rdkafka PUBLIC ${BUNDLED_SSL_LIBRARIES}) add_dependencies(rdkafka bundled-ssl) @@ -261,18 +270,23 @@ if(NOT RDKAFKA_BUILD_STATIC) if(WITH_ZLIB) string(APPEND PKG_CONFIG_REQUIRES "zlib ") endif() + if(WITH_SSL) string(APPEND PKG_CONFIG_REQUIRES "libssl ") endif() + if(WITH_SASL_CYRUS) string(APPEND PKG_CONFIG_REQUIRES "libsasl2 ") endif() + if(WITH_ZSTD) string(APPEND PKG_CONFIG_REQUIRES "libzstd ") endif() + if(WITH_LZ4_EXT) string(APPEND PKG_CONFIG_REQUIRES "liblz4 ") endif() + set(PKG_CONFIG_CFLAGS "-I\${includedir}") set(PKG_CONFIG_LIBS "-L\${libdir} -lrdkafka") set(PKG_CONFIG_LIBS_PRIVATE "-lpthread") @@ -280,31 +294,47 @@ if(NOT RDKAFKA_BUILD_STATIC) if(RT_LIBRARY) string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lrt") endif() + if(WITH_PLUGINS) string(APPEND PKG_CONFIG_LIBS_PRIVATE " -ldl") endif() + if(WITH_HDRHISTOGRAM) string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lm") endif() - configure_file("../packaging/cmake/rdkafka.pc.in" - "${GENERATED_DIR}/rdkafka.pc" @ONLY) - install(FILES ${GENERATED_DIR}/rdkafka.pc - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + + configure_file( + "../packaging/cmake/rdkafka.pc.in" + "${GENERATED_DIR}/rdkafka.pc" + @ONLY + ) + install( + FILES ${GENERATED_DIR}/rdkafka.pc + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" + ) else() set(PKG_CONFIG_REQUIRES "") set(PKG_CONFIG_NAME "librdkafka-static") set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library (static)") set(PKG_CONFIG_CFLAGS "-I\${includedir} -DLIBRDKAFKA_STATICLIB") if(WIN32) - set(PKG_CONFIG_LIBS - "-L\${libdir} \${libdir}/librdkafka.a -lws2_32 -lsecur32 -lcrypt32") + set( + PKG_CONFIG_LIBS + "-L\${libdir} \${libdir}/librdkafka.a -lws2_32 -lsecur32 -lcrypt32" + ) else() set(PKG_CONFIG_LIBS "-L\${libdir} \${libdir}/librdkafka.a") endif() - configure_file("../packaging/cmake/rdkafka.pc.in" - "${GENERATED_DIR}/rdkafka-static.pc" @ONLY) - install(FILES ${GENERATED_DIR}/rdkafka-static.pc - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + + configure_file( + "../packaging/cmake/rdkafka.pc.in" + "${GENERATED_DIR}/rdkafka-static.pc" + @ONLY + ) + install( + FILES ${GENERATED_DIR}/rdkafka-static.pc + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" + ) endif() install( diff --git a/tests/interceptor_test/CMakeLists.txt b/tests/interceptor_test/CMakeLists.txt index 2895bcc299..aa0f0b99bf 100644 --- a/tests/interceptor_test/CMakeLists.txt +++ b/tests/interceptor_test/CMakeLists.txt @@ -13,4 +13,5 @@ target_link_libraries(interceptor_test PUBLIC rdkafka) set_target_properties(interceptor_test PROPERTIES PREFIX "") set_target_properties( interceptor_test PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${tests_OUTPUT_DIRECTORY}/interceptor_test/) + LIBRARY_OUTPUT_DIRECTORY ${tests_OUTPUT_DIRECTORY}/interceptor_test/ +) From b3d1dc669e0fc4c2caf720906710c535b19120d0 Mon Sep 17 00:00:00 2001 From: neptoess Date: Wed, 11 Nov 2020 08:56:09 -0500 Subject: [PATCH 14/22] Undo CMakeLists.txt whitespace-only changes Remove cmake options where we like the defaults Add libdl and libz to static MinGW build to support WITH_PLUGINS and WITH_ZLIB --- CMakeLists.txt | 50 +++--- examples/CMakeLists.txt | 14 +- .../configure-build-msys2-mingw-static.sh | 12 +- packaging/mingw-w64/travis-before-install.sh | 4 +- src-cpp/CMakeLists.txt | 45 +++--- src/CMakeLists.txt | 152 +++++++++--------- tests/CMakeLists.txt | 4 +- tests/interceptor_test/CMakeLists.txt | 10 +- 8 files changed, 139 insertions(+), 152 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce2f56af4c..7852a0df85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ endif() include(CheckLibraryExists) check_library_exists(m pow "" WITH_HDRHISTOGRAM) if(WITH_HDRHISTOGRAM) - list(APPEND BUILT_WITH "HDRHISTOGRAM") + list(APPEND BUILT_WITH "HDRHISTOGRAM") endif() # } @@ -68,10 +68,10 @@ endif() # LibDL { try_compile( - WITH_LIBDL - "${CMAKE_CURRENT_BINARY_DIR}/try_compile" - "${TRYCOMPILE_SRC_DIR}/dlopen_test.c" - LINK_LIBRARIES "${CMAKE_DL_LIBS}" + WITH_LIBDL + "${CMAKE_CURRENT_BINARY_DIR}/try_compile" + "${TRYCOMPILE_SRC_DIR}/dlopen_test.c" + LINK_LIBRARIES "${CMAKE_DL_LIBS}" ) if(WITH_LIBDL) list(APPEND BUILT_WITH "LIBDL") @@ -117,10 +117,10 @@ else() set(with_sasl_default ON) else() try_compile( - WITH_SASL_CYRUS_BOOL - "${CMAKE_CURRENT_BINARY_DIR}/try_compile" - "${TRYCOMPILE_SRC_DIR}/libsasl2_test.c" - LINK_LIBRARIES "-lsasl2" + WITH_SASL_CYRUS_BOOL + "${CMAKE_CURRENT_BINARY_DIR}/try_compile" + "${TRYCOMPILE_SRC_DIR}/libsasl2_test.c" + LINK_LIBRARIES "-lsasl2" ) if(WITH_SASL_CYRUS_BOOL) set(with_sasl_default ON) @@ -163,7 +163,7 @@ option(RDKAFKA_BUILD_STATIC "Build static rdkafka library" OFF) option(RDKAFKA_BUILD_EXAMPLES "Build examples" ON) option(RDKAFKA_BUILD_TESTS "Build tests" ON) if(WIN32) - option(WITHOUT_WIN32_CONFIG "Avoid including win32_config.h on cmake builds" ON) + option(WITHOUT_WIN32_CONFIG "Avoid including win32_config.h on cmake builds" ON) endif(WIN32) # In: @@ -226,34 +226,34 @@ set(namespace "${PROJECT_NAME}::") include(CMakePackageConfigHelpers) # In: -# * targets_export_name -# * PROJECT_NAME +# * targets_export_name +# * PROJECT_NAME configure_package_config_file( - "packaging/cmake/Config.cmake.in" - "${project_config}" - INSTALL_DESTINATION "${config_install_dir}" + "packaging/cmake/Config.cmake.in" + "${project_config}" + INSTALL_DESTINATION "${config_install_dir}" ) write_basic_package_version_file( - "${project_version}" - VERSION ${PROJECT_VERSION} - COMPATIBILITY AnyNewerVersion + "${project_version}" + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion ) install( - FILES "${project_config}" "${project_version}" "packaging/cmake/Modules/FindLZ4.cmake" - DESTINATION "${config_install_dir}" + FILES "${project_config}" "${project_version}" "packaging/cmake/Modules/FindLZ4.cmake" + DESTINATION "${config_install_dir}" ) install( - EXPORT "${targets_export_name}" - NAMESPACE "${namespace}" - DESTINATION "${config_install_dir}" + EXPORT "${targets_export_name}" + NAMESPACE "${namespace}" + DESTINATION "${config_install_dir}" ) install( - FILES LICENSES.txt - DESTINATION "share/licenses/librdkafka" + FILES LICENSES.txt + DESTINATION "share/licenses/librdkafka" ) add_subdirectory(src) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 8fa0e56858..9c3178184c 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,5 +1,5 @@ if(WIN32) - set(win32_sources ../win32/wingetopt.c ../win32/wingetopt.h) + set(win32_sources ../win32/wingetopt.c ../win32/wingetopt.h) endif(WIN32) add_executable(producer producer.c ${win32_sources}) @@ -22,12 +22,12 @@ target_link_libraries(rdkafka_complex_consumer_example_cpp PUBLIC rdkafka++) # The targets below has Unix include dirs and do not compile on Windows. if(NOT WIN32) - add_executable(rdkafka_example rdkafka_example.c) - target_link_libraries(rdkafka_example PUBLIC rdkafka) + add_executable(rdkafka_example rdkafka_example.c) + target_link_libraries(rdkafka_example PUBLIC rdkafka) - add_executable(rdkafka_complex_consumer_example rdkafka_complex_consumer_example.c) - target_link_libraries(rdkafka_complex_consumer_example PUBLIC rdkafka) + add_executable(rdkafka_complex_consumer_example rdkafka_complex_consumer_example.c) + target_link_libraries(rdkafka_complex_consumer_example PUBLIC rdkafka) - add_executable(kafkatest_verifiable_client kafkatest_verifiable_client.cpp) - target_link_libraries(kafkatest_verifiable_client PUBLIC rdkafka++) + add_executable(kafkatest_verifiable_client kafkatest_verifiable_client.cpp) + target_link_libraries(kafkatest_verifiable_client PUBLIC rdkafka++) endif(NOT WIN32) diff --git a/packaging/mingw-w64/configure-build-msys2-mingw-static.sh b/packaging/mingw-w64/configure-build-msys2-mingw-static.sh index b06a74c08c..160d3a0060 100644 --- a/packaging/mingw-w64/configure-build-msys2-mingw-static.sh +++ b/packaging/mingw-w64/configure-build-msys2-mingw-static.sh @@ -5,14 +5,6 @@ set -e cmake \ -G "MinGW Makefiles" \ -D CMAKE_INSTALL_PREFIX="$PWD/dest/" \ - -D WITHOUT_WIN32_CONFIG=ON \ - -D RDKAFKA_BUILD_EXAMPLES=ON \ - -D RDKAFKA_BUILD_TESTS=ON \ - -D WITH_LIBDL=OFF \ - -D WITH_PLUGINS=OFF \ - -D WITH_SASL=ON \ - -D WITH_SSL=ON \ - -D WITH_ZLIB=OFF \ -D RDKAFKA_BUILD_STATIC=ON \ . @@ -26,6 +18,8 @@ cp /C/tools/msys64/mingw64/lib/libzstd.a ./ cp /C/tools/msys64/mingw64/lib/libcrypto.a ./ cp /C/tools/msys64/mingw64/lib/liblz4.a ./ cp /C/tools/msys64/mingw64/lib/libssl.a ./ +cp /C/tools/msys64/mingw64/lib/libdl.a ./ +cp /C/tools/msys64/mingw64/lib/libz.a ./ cp ../src/librdkafka.a ./ # Have to rename because ar won't work with + in the name @@ -37,6 +31,8 @@ addlib libzstd.a addlib libcrypto.a addlib liblz4.a addlib libssl.a +addlib libdl.a +addlib libz.a save end EOF diff --git a/packaging/mingw-w64/travis-before-install.sh b/packaging/mingw-w64/travis-before-install.sh index 8212e4ecd9..584a114ad4 100644 --- a/packaging/mingw-w64/travis-before-install.sh +++ b/packaging/mingw-w64/travis-before-install.sh @@ -22,13 +22,15 @@ case $TRAVIS_OS_NAME in choco upgrade --no-progress -y msys2 ## Install more MSYS2 packages from https://packages.msys2.org/base here - $msys2 pacman --sync --noconfirm --needed mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-openssl mingw-w64-x86_64-lz4 mingw-w64-x86_64-zstd + $msys2 pacman --sync --noconfirm --needed mingw-w64-x86_64-gcc mingw-w64-x86_64-make mingw-w64-x86_64-cmake mingw-w64-x86_64-openssl mingw-w64-x86_64-lz4 mingw-w64-x86_64-zstd mingw-w64-x86_64-dlfcn # Removing the DLLs so cmake links against the static libs rm /C/tools/msys64/mingw64/lib/libzstd.dll.a rm /C/tools/msys64/mingw64/lib/libcrypto.dll.a rm /C/tools/msys64/mingw64/lib/liblz4.dll.a rm /C/tools/msys64/mingw64/lib/libssl.dll.a + rm /C/tools/msys64/mingw64/lib/libdl.dll.a + rm /C/tools/msys64/mingw64/lib/libz.dll.a taskkill //IM gpg-agent.exe //F || true # https://travis-ci.community/t/4967 export PATH=/C/tools/msys64/mingw64/bin:$PATH diff --git a/src-cpp/CMakeLists.txt b/src-cpp/CMakeLists.txt index 295789394e..09c9bbfcc2 100644 --- a/src-cpp/CMakeLists.txt +++ b/src-cpp/CMakeLists.txt @@ -1,19 +1,19 @@ set(LIBVER 1) set( - sources - ConfImpl.cpp - ConsumerImpl.cpp - HandleImpl.cpp - HeadersImpl.cpp - KafkaConsumerImpl.cpp - MessageImpl.cpp - MetadataImpl.cpp - ProducerImpl.cpp - QueueImpl.cpp - RdKafka.cpp - TopicImpl.cpp - TopicPartitionImpl.cpp + sources + ConfImpl.cpp + ConsumerImpl.cpp + HandleImpl.cpp + HeadersImpl.cpp + KafkaConsumerImpl.cpp + MessageImpl.cpp + MetadataImpl.cpp + ProducerImpl.cpp + QueueImpl.cpp + RdKafka.cpp + TopicImpl.cpp + TopicPartitionImpl.cpp ) if(RDKAFKA_BUILD_STATIC) @@ -33,7 +33,7 @@ target_link_libraries(rdkafka++ PUBLIC rdkafka) # Support '#include ' target_include_directories(rdkafka++ PUBLIC "$") if(NOT RDKAFKA_BUILD_STATIC) - target_compile_definitions(rdkafka++ PRIVATE LIBRDKAFKACPP_EXPORTS) + target_compile_definitions(rdkafka++ PRIVATE LIBRDKAFKACPP_EXPORTS) endif() # Generate pkg-config file @@ -76,16 +76,15 @@ else() endif() install( - TARGETS rdkafka++ - EXPORT "${targets_export_name}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - INCLUDES - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + TARGETS rdkafka++ + EXPORT "${targets_export_name}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) install( - FILES "rdkafkacpp.h" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/librdkafka" + FILES "rdkafkacpp.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/librdkafka" ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f84c8bf926..d5431f4055 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,70 +1,70 @@ set(LIBVER 1) set( - sources - crc32c.c - rdaddr.c - rdavl.c - rdbuf.c - rdcrc32.c - rdfnv1a.c - rdkafka.c - rdkafka_assignor.c - rdkafka_broker.c - rdkafka_buf.c - rdkafka_cgrp.c - rdkafka_conf.c - rdkafka_event.c - rdkafka_feature.c - rdkafka_lz4.c - rdkafka_metadata.c - rdkafka_metadata_cache.c - rdkafka_msg.c - rdkafka_msgset_reader.c - rdkafka_msgset_writer.c - rdkafka_offset.c - rdkafka_op.c - rdkafka_partition.c - rdkafka_pattern.c - rdkafka_queue.c - rdkafka_range_assignor.c - rdkafka_request.c - rdkafka_roundrobin_assignor.c - rdkafka_sasl.c - rdkafka_sasl_plain.c - rdkafka_sticky_assignor.c - rdkafka_subscription.c - rdkafka_assignment.c - rdkafka_timer.c - rdkafka_topic.c - rdkafka_transport.c - rdkafka_interceptor.c - rdkafka_header.c - rdkafka_admin.c - rdkafka_aux.c - rdkafka_background.c - rdkafka_idempotence.c - rdkafka_txnmgr.c - rdkafka_cert.c - rdkafka_coord.c - rdkafka_mock.c - rdkafka_mock_handlers.c - rdkafka_mock_cgrp.c - rdkafka_error.c - rdlist.c - rdlog.c - rdmurmur2.c - rdports.c - rdrand.c - rdregex.c - rdstring.c - rdunittest.c - rdvarint.c - rdmap.c - snappy.c - tinycthread.c - tinycthread_extra.c - rdxxhash.c + sources + crc32c.c + rdaddr.c + rdavl.c + rdbuf.c + rdcrc32.c + rdfnv1a.c + rdkafka.c + rdkafka_assignor.c + rdkafka_broker.c + rdkafka_buf.c + rdkafka_cgrp.c + rdkafka_conf.c + rdkafka_event.c + rdkafka_feature.c + rdkafka_lz4.c + rdkafka_metadata.c + rdkafka_metadata_cache.c + rdkafka_msg.c + rdkafka_msgset_reader.c + rdkafka_msgset_writer.c + rdkafka_offset.c + rdkafka_op.c + rdkafka_partition.c + rdkafka_pattern.c + rdkafka_queue.c + rdkafka_range_assignor.c + rdkafka_request.c + rdkafka_roundrobin_assignor.c + rdkafka_sasl.c + rdkafka_sasl_plain.c + rdkafka_sticky_assignor.c + rdkafka_subscription.c + rdkafka_assignment.c + rdkafka_timer.c + rdkafka_topic.c + rdkafka_transport.c + rdkafka_interceptor.c + rdkafka_header.c + rdkafka_admin.c + rdkafka_aux.c + rdkafka_background.c + rdkafka_idempotence.c + rdkafka_txnmgr.c + rdkafka_cert.c + rdkafka_coord.c + rdkafka_mock.c + rdkafka_mock_handlers.c + rdkafka_mock_cgrp.c + rdkafka_error.c + rdlist.c + rdlog.c + rdmurmur2.c + rdports.c + rdrand.c + rdregex.c + rdstring.c + rdunittest.c + rdvarint.c + rdmap.c + snappy.c + tinycthread.c + tinycthread_extra.c + rdxxhash.c ) if(WITH_SSL) @@ -121,37 +121,31 @@ if(WITHOUT_WIN32_CONFIG) else() list(APPEND rdkafka_compile_definitions WITH_SSL=0) endif(WITH_SSL) - if(WITH_ZLIB) list(APPEND rdkafka_compile_definitions WITH_ZLIB=1) else() list(APPEND rdkafka_compile_definitions WITH_ZLIB=0) endif(WITH_ZLIB) - if(WITH_SNAPPY) list(APPEND rdkafka_compile_definitions WITH_SNAPPY=1) else() list(APPEND rdkafka_compile_definitions WITH_SNAPPY=0) endif(WITH_SNAPPY) - if(WITH_ZSTD) list(APPEND rdkafka_compile_definitions WITH_ZSTD=1) else() list(APPEND rdkafka_compile_definitions WITH_ZSTD=0) endif(WITH_ZSTD) - if(WITH_SASL_SCRAM) list(APPEND rdkafka_compile_definitions WITH_SASL_SCRAM=1) else() list(APPEND rdkafka_compile_definitions WITH_SASL_SCRAM=0) endif(WITH_SASL_SCRAM) - if(WITH_SASL_OAUTHBEARER) list(APPEND rdkafka_compile_definitions WITH_SASL_OAUTHBEARER=1) else() list(APPEND rdkafka_compile_definitions WITH_SASL_OAUTHBEARER=0) endif(WITH_SASL_OAUTHBEARER) - if(ENABLE_DEVEL) list(APPEND rdkafka_compile_definitions ENABLE_DEVEL=1) else() @@ -223,7 +217,6 @@ if(WITH_SSL) if(NOT TARGET bundled-ssl) message(FATAL_ERROR "bundled-ssl target not exist") endif() - target_include_directories(rdkafka BEFORE PUBLIC ${BUNDLED_SSL_INCLUDE_DIR}) target_link_libraries(rdkafka PUBLIC ${BUNDLED_SSL_LIBRARIES}) add_dependencies(rdkafka bundled-ssl) @@ -338,16 +331,15 @@ else() endif() install( - TARGETS rdkafka - EXPORT "${targets_export_name}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - INCLUDES - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + TARGETS rdkafka + EXPORT "${targets_export_name}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) install( - FILES "rdkafka.h" "rdkafka_mock.h" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/librdkafka" + FILES "rdkafka.h" "rdkafka_mock.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/librdkafka" ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 13866d4a43..9d3569a98e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -118,9 +118,9 @@ set( ) if(NOT WIN32) - list(APPEND sources sockem.c sockem_ctrl.c) + list(APPEND sources sockem.c sockem_ctrl.c) else() - list(APPEND sources ../src/tinycthread.c ../src/tinycthread_extra.c) + list(APPEND sources ../src/tinycthread.c ../src/tinycthread_extra.c) endif() add_executable(test-runner ${sources}) diff --git a/tests/interceptor_test/CMakeLists.txt b/tests/interceptor_test/CMakeLists.txt index aa0f0b99bf..a58a3d626b 100644 --- a/tests/interceptor_test/CMakeLists.txt +++ b/tests/interceptor_test/CMakeLists.txt @@ -1,6 +1,6 @@ set( - sources - interceptor_test.c + sources + interceptor_test.c ) add_library(interceptor_test SHARED ${sources}) @@ -11,7 +11,5 @@ target_link_libraries(interceptor_test PUBLIC rdkafka) # Remove "lib" prefix set_target_properties(interceptor_test PROPERTIES PREFIX "") -set_target_properties( - interceptor_test PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${tests_OUTPUT_DIRECTORY}/interceptor_test/ -) +set_target_properties(interceptor_test PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${tests_OUTPUT_DIRECTORY}/interceptor_test/) From e266bbdfb2eb7501ecbf9905dbd5aa20eb437799 Mon Sep 17 00:00:00 2001 From: neptoess Date: Wed, 11 Nov 2020 09:00:51 -0500 Subject: [PATCH 15/22] Fix accidental tab characters in packaging/mingw-w64/travis-before-install.sh --- packaging/mingw-w64/travis-before-install.sh | 4 ++-- src/CMakeLists.txt | 1 - tests/interceptor_test/CMakeLists.txt | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packaging/mingw-w64/travis-before-install.sh b/packaging/mingw-w64/travis-before-install.sh index 584a114ad4..4dbd21e49c 100644 --- a/packaging/mingw-w64/travis-before-install.sh +++ b/packaging/mingw-w64/travis-before-install.sh @@ -29,8 +29,8 @@ case $TRAVIS_OS_NAME in rm /C/tools/msys64/mingw64/lib/libcrypto.dll.a rm /C/tools/msys64/mingw64/lib/liblz4.dll.a rm /C/tools/msys64/mingw64/lib/libssl.dll.a - rm /C/tools/msys64/mingw64/lib/libdl.dll.a - rm /C/tools/msys64/mingw64/lib/libz.dll.a + rm /C/tools/msys64/mingw64/lib/libdl.dll.a + rm /C/tools/msys64/mingw64/lib/libz.dll.a taskkill //IM gpg-agent.exe //F || true # https://travis-ci.community/t/4967 export PATH=/C/tools/msys64/mingw64/bin:$PATH diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d5431f4055..4402aaed6a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -151,7 +151,6 @@ if(WITHOUT_WIN32_CONFIG) else() list(APPEND rdkafka_compile_definitions ENABLE_DEVEL=0) endif(ENABLE_DEVEL) - if(WITH_PLUGINS) list(APPEND rdkafka_compile_definitions WITH_PLUGIN=1) else() diff --git a/tests/interceptor_test/CMakeLists.txt b/tests/interceptor_test/CMakeLists.txt index a58a3d626b..c606bc4266 100644 --- a/tests/interceptor_test/CMakeLists.txt +++ b/tests/interceptor_test/CMakeLists.txt @@ -3,6 +3,7 @@ set( interceptor_test.c ) + add_library(interceptor_test SHARED ${sources}) target_include_directories(interceptor_test PUBLIC ${PROJECT_SOURCE_DIR}/src) From fb17f940e89178e702ea885285c9e95a89143106 Mon Sep 17 00:00:00 2001 From: neptoess Date: Wed, 11 Nov 2020 09:32:27 -0500 Subject: [PATCH 16/22] Default WITH_PLUGINS to ON on Windows CMake builds Remove libdl from MinGW build Fix typo when WITHOUT_WIN32_CONFIG is ON --- CMakeLists.txt | 2 +- packaging/mingw-w64/configure-build-msys2-mingw-static.sh | 2 -- packaging/mingw-w64/travis-before-install.sh | 3 +-- src/CMakeLists.txt | 4 ++-- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7852a0df85..0ee941cf24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,7 +79,7 @@ endif() # } # WITH_PLUGINS { -if(WITH_LIBDL) +if(WITH_LIBDL OR WIN32) set(with_plugins_default ON) else() set(with_plugins_default OFF) diff --git a/packaging/mingw-w64/configure-build-msys2-mingw-static.sh b/packaging/mingw-w64/configure-build-msys2-mingw-static.sh index 160d3a0060..b8834413cf 100644 --- a/packaging/mingw-w64/configure-build-msys2-mingw-static.sh +++ b/packaging/mingw-w64/configure-build-msys2-mingw-static.sh @@ -18,7 +18,6 @@ cp /C/tools/msys64/mingw64/lib/libzstd.a ./ cp /C/tools/msys64/mingw64/lib/libcrypto.a ./ cp /C/tools/msys64/mingw64/lib/liblz4.a ./ cp /C/tools/msys64/mingw64/lib/libssl.a ./ -cp /C/tools/msys64/mingw64/lib/libdl.a ./ cp /C/tools/msys64/mingw64/lib/libz.a ./ cp ../src/librdkafka.a ./ @@ -31,7 +30,6 @@ addlib libzstd.a addlib libcrypto.a addlib liblz4.a addlib libssl.a -addlib libdl.a addlib libz.a save end diff --git a/packaging/mingw-w64/travis-before-install.sh b/packaging/mingw-w64/travis-before-install.sh index 4dbd21e49c..071dfb24c1 100644 --- a/packaging/mingw-w64/travis-before-install.sh +++ b/packaging/mingw-w64/travis-before-install.sh @@ -22,14 +22,13 @@ case $TRAVIS_OS_NAME in choco upgrade --no-progress -y msys2 ## Install more MSYS2 packages from https://packages.msys2.org/base here - $msys2 pacman --sync --noconfirm --needed mingw-w64-x86_64-gcc mingw-w64-x86_64-make mingw-w64-x86_64-cmake mingw-w64-x86_64-openssl mingw-w64-x86_64-lz4 mingw-w64-x86_64-zstd mingw-w64-x86_64-dlfcn + $msys2 pacman --sync --noconfirm --needed mingw-w64-x86_64-gcc mingw-w64-x86_64-make mingw-w64-x86_64-cmake mingw-w64-x86_64-openssl mingw-w64-x86_64-lz4 mingw-w64-x86_64-zstd # Removing the DLLs so cmake links against the static libs rm /C/tools/msys64/mingw64/lib/libzstd.dll.a rm /C/tools/msys64/mingw64/lib/libcrypto.dll.a rm /C/tools/msys64/mingw64/lib/liblz4.dll.a rm /C/tools/msys64/mingw64/lib/libssl.dll.a - rm /C/tools/msys64/mingw64/lib/libdl.dll.a rm /C/tools/msys64/mingw64/lib/libz.dll.a taskkill //IM gpg-agent.exe //F || true # https://travis-ci.community/t/4967 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4402aaed6a..7fcc5d9b0d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -152,9 +152,9 @@ if(WITHOUT_WIN32_CONFIG) list(APPEND rdkafka_compile_definitions ENABLE_DEVEL=0) endif(ENABLE_DEVEL) if(WITH_PLUGINS) - list(APPEND rdkafka_compile_definitions WITH_PLUGIN=1) + list(APPEND rdkafka_compile_definitions WITH_PLUGINS=1) else() - list(APPEND rdkafka_compile_definitions WITH_PLUGIN=0) + list(APPEND rdkafka_compile_definitions WITH_PLUGINS=0) endif(WITH_PLUGINS) endif() From a2939dd86c7c97b1558392b6d4cb2126b83605b6 Mon Sep 17 00:00:00 2001 From: neptoess Date: Thu, 12 Nov 2020 06:47:39 -0500 Subject: [PATCH 17/22] Modify CMAKE_FIND_LIBRARY_SUFFIXES instead of deleting .dll.a files --- CMakeLists.txt | 5 +++++ packaging/mingw-w64/travis-before-install.sh | 7 ------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ee941cf24..4eaa5a0b4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,11 @@ list(APPEND BUILT_WITH "${CMAKE_C_COMPILER_ID}") list(APPEND BUILT_WITH "${CMAKE_CXX_COMPILER_ID}") # } +if (MINGW AND RDKAFKA_BUILD_STATIC) + # ".dll.a" takes precedence over ".a" by default + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") +endif() + # PkgConfig { find_package(PkgConfig QUIET) if(PkgConfig_FOUND) diff --git a/packaging/mingw-w64/travis-before-install.sh b/packaging/mingw-w64/travis-before-install.sh index 071dfb24c1..dd79961ba7 100644 --- a/packaging/mingw-w64/travis-before-install.sh +++ b/packaging/mingw-w64/travis-before-install.sh @@ -24,13 +24,6 @@ case $TRAVIS_OS_NAME in ## Install more MSYS2 packages from https://packages.msys2.org/base here $msys2 pacman --sync --noconfirm --needed mingw-w64-x86_64-gcc mingw-w64-x86_64-make mingw-w64-x86_64-cmake mingw-w64-x86_64-openssl mingw-w64-x86_64-lz4 mingw-w64-x86_64-zstd - # Removing the DLLs so cmake links against the static libs - rm /C/tools/msys64/mingw64/lib/libzstd.dll.a - rm /C/tools/msys64/mingw64/lib/libcrypto.dll.a - rm /C/tools/msys64/mingw64/lib/liblz4.dll.a - rm /C/tools/msys64/mingw64/lib/libssl.dll.a - rm /C/tools/msys64/mingw64/lib/libz.dll.a - taskkill //IM gpg-agent.exe //F || true # https://travis-ci.community/t/4967 export PATH=/C/tools/msys64/mingw64/bin:$PATH export MAKE=mingw32-make # so that Autotools can find it From 81428d0a7fc186446d382ee5bebd0d78f51fc210 Mon Sep 17 00:00:00 2001 From: neptoess Date: Thu, 12 Nov 2020 07:21:21 -0500 Subject: [PATCH 18/22] Make use of Libs.private --- src-cpp/CMakeLists.txt | 6 +++--- src/CMakeLists.txt | 44 +++++++++++++++++++----------------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src-cpp/CMakeLists.txt b/src-cpp/CMakeLists.txt index 09c9bbfcc2..a7335c30da 100644 --- a/src-cpp/CMakeLists.txt +++ b/src-cpp/CMakeLists.txt @@ -59,11 +59,11 @@ else() set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library (static)") set(PKG_CONFIG_REQUIRES "") set(PKG_CONFIG_CFLAGS "-I\${includedir} -DLIBRDKAFKA_STATICLIB") + set(PKG_CONFIG_LIBS "-L\${libdir} \${libdir}/librdkafka++.a") if(WIN32) - set(PKG_CONFIG_LIBS "-L\${libdir} \${libdir}/librdkafka++.a -lws2_32 -lsecur32 -lcrypt32") - else() - set(PKG_CONFIG_LIBS "-L\${libdir} \${libdir}/librdkafka++.a") + set(PKG_CONFIG_LIBS_PRIVATE "-lws2_32 -lsecur32 -lcrypt32") endif() + configure_file( "../packaging/cmake/rdkafka.pc.in" "${GENERATED_DIR}/rdkafka++-static.pc" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7fcc5d9b0d..3520613244 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -255,10 +255,28 @@ endif(MINGW) # Generate pkg-config file set(PKG_CONFIG_VERSION "${PROJECT_VERSION}") +set(PKG_CONFIG_REQUIRES "") +if (WIN32) + set(PKG_CONFIG_LIBS_PRIVATE "-lws2_32 -lsecur32 -lcrypt32") +else() + set(PKG_CONFIG_LIBS_PRIVATE "-lpthread") + find_library(RT_LIBRARY rt) + if(RT_LIBRARY) + string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lrt") + endif() + + if(WITH_PLUGINS) + string(APPEND PKG_CONFIG_LIBS_PRIVATE " -ldl") + endif() + + if(WITH_HDRHISTOGRAM) + string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lm") + endif() +endif() + if(NOT RDKAFKA_BUILD_STATIC) set(PKG_CONFIG_NAME "librdkafka") set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library") - set(PKG_CONFIG_REQUIRES "") if(WITH_ZLIB) string(APPEND PKG_CONFIG_REQUIRES "zlib ") endif() @@ -281,19 +299,6 @@ if(NOT RDKAFKA_BUILD_STATIC) set(PKG_CONFIG_CFLAGS "-I\${includedir}") set(PKG_CONFIG_LIBS "-L\${libdir} -lrdkafka") - set(PKG_CONFIG_LIBS_PRIVATE "-lpthread") - find_library(RT_LIBRARY rt) - if(RT_LIBRARY) - string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lrt") - endif() - - if(WITH_PLUGINS) - string(APPEND PKG_CONFIG_LIBS_PRIVATE " -ldl") - endif() - - if(WITH_HDRHISTOGRAM) - string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lm") - endif() configure_file( "../packaging/cmake/rdkafka.pc.in" @@ -305,19 +310,10 @@ if(NOT RDKAFKA_BUILD_STATIC) DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" ) else() - set(PKG_CONFIG_REQUIRES "") set(PKG_CONFIG_NAME "librdkafka-static") set(PKG_CONFIG_DESCRIPTION "The Apache Kafka C/C++ library (static)") set(PKG_CONFIG_CFLAGS "-I\${includedir} -DLIBRDKAFKA_STATICLIB") - if(WIN32) - set( - PKG_CONFIG_LIBS - "-L\${libdir} \${libdir}/librdkafka.a -lws2_32 -lsecur32 -lcrypt32" - ) - else() - set(PKG_CONFIG_LIBS "-L\${libdir} \${libdir}/librdkafka.a") - endif() - + set(PKG_CONFIG_LIBS "-L\${libdir} \${libdir}/librdkafka.a") configure_file( "../packaging/cmake/rdkafka.pc.in" "${GENERATED_DIR}/rdkafka-static.pc" From 3ff3cb8ba2f957d5fb5394509b3cd5b2fc97c4de Mon Sep 17 00:00:00 2001 From: neptoess Date: Tue, 6 Apr 2021 10:05:08 -0400 Subject: [PATCH 19/22] Fix a CMake check using WITH_PLUGINS when it should have been using WITH_LIBDL --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 683ff37bb8..b16eede883 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -269,7 +269,7 @@ else() string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lrt") endif() - if(WITH_PLUGINS) + if(WITH_LIBDL) string(APPEND PKG_CONFIG_LIBS_PRIVATE " -ldl") endif() From d393223a8b00a04021533efdf6e9c35dd223f12e Mon Sep 17 00:00:00 2001 From: neptoess Date: Tue, 6 Apr 2021 12:50:58 -0400 Subject: [PATCH 20/22] Add strip calls for MinGW static libraries --- packaging/mingw-w64/configure-build-msys2-mingw-static.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/mingw-w64/configure-build-msys2-mingw-static.sh b/packaging/mingw-w64/configure-build-msys2-mingw-static.sh index b8834413cf..8453065937 100644 --- a/packaging/mingw-w64/configure-build-msys2-mingw-static.sh +++ b/packaging/mingw-w64/configure-build-msys2-mingw-static.sh @@ -43,6 +43,8 @@ save end EOF +strip -g ./librdkafka-static.a +strip -g ./librdkafkacpp-static.a cp ./librdkafka-static.a ../dest/lib/ cp ./librdkafkacpp-static.a ../dest/lib/librdkafka++-static.a popd From cbf9b163f43966530f049d381fbc7a0c7cd56c8b Mon Sep 17 00:00:00 2001 From: neptoess Date: Tue, 6 Apr 2021 15:21:52 -0400 Subject: [PATCH 21/22] Slight CMakeLists.txt refactor per SpaceIm comment --- src/CMakeLists.txt | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b16eede883..826f21860e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -182,14 +182,6 @@ if(RDKAFKA_BUILD_STATIC) target_compile_definitions(rdkafka PUBLIC LIBRDKAFKA_STATICLIB) endif() -if(WIN32) - if(RDKAFKA_BUILD_STATIC) - target_link_libraries(rdkafka PUBLIC crypt32) - else() - target_compile_definitions(rdkafka PRIVATE LIBRDKAFKA_EXPORTS) - endif() -endif() - # We need 'dummy' directory to support `#include "../config.h"` path set(dummy "${GENERATED_DIR}/dummy") file(MAKE_DIRECTORY "${dummy}") @@ -251,11 +243,16 @@ if(WITH_LZ4_EXT) target_link_libraries(rdkafka PUBLIC LZ4::LZ4) endif() -if(MINGW) - message(STATUS "Detected MinGW build") - # MinGW ignores `#pragma comment(lib, ...)` so we need to specify link libs - target_link_libraries(rdkafka PUBLIC crypt32 ws2_32 secur32) -endif(MINGW) +if(WIN32) + if(WITH_SSL) + target_link_libraries(rdkafka PUBLIC crypt32) + endif() + + target_link_libraries(rdkafka PUBLIC ws2_32 secur32) + if(NOT RDKAFKA_BUILD_STATIC) + target_compile_definitions(rdkafka PRIVATE LIBRDKAFKA_EXPORTS) + endif() +endif() # Generate pkg-config file set(PKG_CONFIG_VERSION "${PROJECT_VERSION}") From cc1926582bb2feecb6dfb834f59321b79b8ac0b9 Mon Sep 17 00:00:00 2001 From: neptoess Date: Tue, 6 Apr 2021 15:59:12 -0400 Subject: [PATCH 22/22] Move CMAKE_FIND_LIBRARY_SUFFIXES from CMakeLists.txt to the Travis build script --- CMakeLists.txt | 5 ----- packaging/mingw-w64/configure-build-msys2-mingw-static.sh | 1 + 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 43f4753286..d1129bce9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,11 +24,6 @@ list(APPEND BUILT_WITH "${CMAKE_C_COMPILER_ID}") list(APPEND BUILT_WITH "${CMAKE_CXX_COMPILER_ID}") # } -if (MINGW AND RDKAFKA_BUILD_STATIC) - # ".dll.a" takes precedence over ".a" by default - set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") -endif() - # PkgConfig { find_package(PkgConfig QUIET) if(PkgConfig_FOUND) diff --git a/packaging/mingw-w64/configure-build-msys2-mingw-static.sh b/packaging/mingw-w64/configure-build-msys2-mingw-static.sh index 8453065937..fecbadb064 100644 --- a/packaging/mingw-w64/configure-build-msys2-mingw-static.sh +++ b/packaging/mingw-w64/configure-build-msys2-mingw-static.sh @@ -4,6 +4,7 @@ set -e cmake \ -G "MinGW Makefiles" \ + -D CMAKE_FIND_LIBRARY_SUFFIXES=".a" \ -D CMAKE_INSTALL_PREFIX="$PWD/dest/" \ -D RDKAFKA_BUILD_STATIC=ON \ .