Skip to content

Commit

Permalink
CMake: Fix configuration on Windows
Browse files Browse the repository at this point in the history
- Remove WITHOUT_WIN32_CONFIG option
- Fix hdr histogram check
- Fix WITH_PLUGINS check
- Specify _CRT_SECURE_NO_WARNINGS
- Fix MSVC ARM64 check
- Fix __ARM_ARCH_6KZ__ typo
  • Loading branch information
myd7349 committed Jun 14, 2019
1 parent b25436e commit e46df0c
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 47 deletions.
27 changes: 20 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ endif()
# }

# LIBM {
include(CheckLibraryExists)
check_library_exists(m pow "" WITH_HDRHISTOGRAM)
if(MSVC)
set(WITH_HDRHISTOGRAM ON)
set(HAVE_LIBM OFF)
else()
include(CheckLibraryExists)
check_library_exists(m pow "" HAVE_LIBM)
set(WITH_HDRHISTOGRAM ${HAVE_LIBM})
if(NOT WITH_HDRHISTOGRAM)
include(CheckFunctionExists)
check_function_exists(pow WITH_HDRHISTOGRAM)
endif()
endif()
if(WITH_HDRHISTOGRAM)
list(APPEND BUILT_WITH "HDRHISTOGRAM")
endif()
Expand Down Expand Up @@ -80,7 +90,7 @@ endif()
# }

# WITH_PLUGINS {
if(WITH_LIBDL)
if(WITH_LIBDL OR MSVC)
set(with_plugins_default ON)
else()
set(with_plugins_default OFF)
Expand Down Expand Up @@ -163,9 +173,6 @@ endif()
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)
endif(WIN32)

# In:
# * TRYCOMPILE_SRC_DIR
Expand Down Expand Up @@ -199,12 +206,18 @@ set(GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
# * HAVE_ATOMICS_64
# * HAVE_ATOMICS_64_SYNC
# * WITH_ZLIB
# * WITH_SOCKEM
# * WITH_SSL
# * WITH_SASL
# * HAVE_REGEX
# * HAVE_STRNDUP
list(APPEND BUILT_WITH "SNAPPY")
list(APPEND BUILT_WITH "SOCKEM")
if(WIN32)
set(WITH_SOCKEM OFF)
else()
set(WITH_SOCKEM ON)
list(APPEND BUILT_WITH "SOCKEM")
endif()
string(REPLACE ";" " " BUILT_WITH "${BUILT_WITH}")
configure_file("packaging/cmake/config.h.in" "${GENERATED_DIR}/config.h")

Expand Down
1 change: 1 addition & 0 deletions packaging/cmake/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if(@WITH_SSL@)
endif()

if(@WITH_LZ4_EXT@)
include("${CMAKE_CURRENT_LIST_DIR}/FindLZ4.cmake")
find_dependency(LZ4)
endif()

Expand Down
2 changes: 1 addition & 1 deletion packaging/cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#cmakedefine01 WITH_LIBDL
#cmakedefine01 WITH_PLUGINS
#define WITH_SNAPPY 1
#define WITH_SOCKEM 1
#cmakedefine01 WITH_SOCKEM
#cmakedefine01 WITH_SSL
#cmakedefine01 WITH_SASL
#cmakedefine01 WITH_SASL_SCRAM
Expand Down
42 changes: 9 additions & 33 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,35 +103,6 @@ if(NOT HAVE_REGEX)
list(APPEND sources regexp.c)
endif()

# Define flags with cmake instead of by defining them on win32_config.h
if(WITHOUT_WIN32_CONFIG)
list(APPEND rdkafka_compile_definitions WITHOUT_WIN32_CONFIG)
if(WITH_SSL)
list(APPEND rdkafka_compile_definitions WITH_SSL)
endif(WITH_SSL)
if(WITH_ZLIB)
list(APPEND rdkafka_compile_definitions WITH_ZLIB)
endif(WITH_ZLIB)
if(WITH_SNAPPY)
list(APPEND rdkafka_compile_definitions WITH_SNAPPY)
endif(WITH_SNAPPY)
if(WITH_ZSTD)
list(APPEND rdkafka_compile_definitions WITH_ZSTD)
endif(WITH_ZSTD)
if(WITH_SASL_SCRAM)
list(APPEND rdkafka_compile_definitions WITH_SASL_SCRAM)
endif(WITH_SASL_SCRAM)
if(WITH_SASL_OAUTHBEARER)
list(APPEND rdkafka_compile_definitions WITH_SASL_OAUTHBEARER)
endif(WITH_SASL_OAUTHBEARER)
if(ENABLE_DEVEL)
list(APPEND rdkafka_compile_definitions ENABLE_DEVEL)
endif(ENABLE_DEVEL)
if(WITH_PLUGINS)
list(APPEND rdkafka_compile_definitions WITH_PLUGINS)
endif(WITH_PLUGINS)
endif()

if(RDKAFKA_BUILD_STATIC)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(RDKAFKA_BUILD_MODE STATIC)
Expand All @@ -146,12 +117,17 @@ endif()

# Support '#include <rdkafka.h>'
target_include_directories(rdkafka PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>")
target_compile_definitions(rdkafka PUBLIC ${rdkafka_compile_definitions})
if(WIN32)
target_compile_definitions(rdkafka PRIVATE WITHOUT_WIN32_CONFIG)
endif()
if(RDKAFKA_BUILD_STATIC)
target_compile_definitions(rdkafka PUBLIC LIBRDKAFKA_STATICLIB)
endif()

if(WIN32)
if(WIN32)
if(MSVC)
target_compile_definitions(rdkafka PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
if(RDKAFKA_BUILD_STATIC)
target_link_libraries(rdkafka PUBLIC crypt32)
else()
Expand All @@ -164,7 +140,7 @@ set(dummy "${GENERATED_DIR}/dummy")
file(MAKE_DIRECTORY "${dummy}")
target_include_directories(rdkafka PUBLIC "$<BUILD_INTERFACE:${dummy}>")

if(WITH_HDRHISTOGRAM)
if(HAVE_LIBM)
target_link_libraries(rdkafka PUBLIC m)
endif()

Expand Down Expand Up @@ -259,7 +235,7 @@ endif()
if(WITH_PLUGINS)
string(APPEND PKG_CONFIG_LIBS_PRIVATE " -ldl")
endif()
if(WITH_HDRHISTOGRAM)
if(HAVE_LIBM)
string(APPEND PKG_CONFIG_LIBS_PRIVATE " -lm")
endif()
configure_file(
Expand Down
3 changes: 2 additions & 1 deletion src/rd.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
#include "tinycthread.h"
#include "rdsysqueue.h"

#ifdef _MSC_VER
/* WITHOUT_WIN32_CONFIG is defined when configuring with CMake */
#if defined(_MSC_VER) && !defined(WITHOUT_WIN32_CONFIG)
/* Visual Studio */
#include "win32_config.h"
#else
Expand Down
3 changes: 2 additions & 1 deletion src/snappy_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct iovec {
// x86, PowerPC, and ARM64 can simply do these loads and stores native.
#if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || \
defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || \
defined(__aarch64__)
defined(__arm64) || defined(__aarch64__) || defined(__AARCH64EL__) || defined(_M_ARM64)

#define get_unaligned get_unaligned_direct
#define put_unaligned put_unaligned_direct
Expand All @@ -115,6 +115,7 @@ struct iovec {
!defined(__ARM_ARCH_6J__) && \
!defined(__ARM_ARCH_6K__) && \
!defined(__ARM_ARCH_6Z__) && \
!defined(__ARM_ARCH_6KZ__) && \
!defined(__ARM_ARCH_6ZK__) && \
!defined(__ARM_ARCH_6T2__)

Expand Down
4 changes: 2 additions & 2 deletions src/tinycthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ freely, subject to the following restrictions:
#ifndef _TINYCTHREAD_H_
#define _TINYCTHREAD_H_

/* Include config to know if C11 threads are available */
#ifdef _MSC_VER
/* WITHOUT_WIN32_CONFIG is defined when configuring with CMake */
#if defined(_MSC_VER) && !defined(WITHOUT_WIN32_CONFIG)
#include "win32_config.h"
#else
#include "../config.h"
Expand Down
3 changes: 1 addition & 2 deletions src/win32_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef _RD_WIN32_CONFIG_H_
#define _RD_WIN32_CONFIG_H_

#ifndef WITHOUT_WIN32_CONFIG
#define WITH_SSL 1
#define WITH_ZLIB 1
#define WITH_SNAPPY 1
Expand All @@ -45,7 +44,7 @@
#define ENABLE_DEVEL 0
#define WITH_PLUGINS 1
#define WITH_HDRHISTOGRAM 1
#endif

#define SOLIB_EXT ".dll"

/* Notice: Keep up to date */
Expand Down
3 changes: 3 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ else()
endif()

add_executable(rdkafka_test ${sources})
if(MSVC)
target_compile_definitions(rdkafka_test PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
target_link_libraries(rdkafka_test PUBLIC rdkafka++)

add_test(NAME RdKafkaTestInParallel COMMAND rdkafka_test -p5)
Expand Down

0 comments on commit e46df0c

Please sign in to comment.