Skip to content

SASL_SCRAM build inconsistency between mklove and CMake #5143

@JackKelly-Bellroy

Description

@JackKelly-Bellroy

When built with mklove, WITH_SASL_SCRAM is set if WITH_SSL is set:

librdkafka/configure.self

Lines 143 to 145 in c56a3e6

if [[ "$WITH_SSL" == "y" ]]; then
# SASL SCRAM requires base64 encoding from OpenSSL
mkl_allvar_set WITH_SASL_SCRAM WITH_SASL_SCRAM y

When built with cmake, WITH_SASL is set (by default) only if libsasl2 (cyrus-sasl) is found by pkg-config, or if a test program successfully links against -lsasl2:

librdkafka/CMakeLists.txt

Lines 127 to 145 in c56a3e6

if(PkgConfig_FOUND)
pkg_check_modules(SASL libsasl2)
if(SASL_FOUND)
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"
)
if(WITH_SASL_CYRUS_BOOL)
set(with_sasl_default ON)
set(SASL_LIBRARIES "-lsasl2")
else()
set(with_sasl_default OFF)
endif()
endif()
endif()

WITH_SASL_SCRAM is then only enabled if WITH_SASL is set:

librdkafka/CMakeLists.txt

Lines 148 to 156 in c56a3e6

if(WITH_SASL)
if(SASL_FOUND)
link_directories(${SASL_LIBRARY_DIRS})
endif()
if(WITH_SSL)
set(WITH_SASL_SCRAM ON)
set(WITH_SASL_OAUTHBEARER ON)
list(APPEND BUILT_WITH "SASL_SCRAM SASL_OAUTHBEARER")
endif()

This means that when building with cmake, you need to either override -DWITH_SASL=ON or you'll never get SASL support that isn't SASL_CYRUS.

My suggestions:

  1. The check for libsasl2 should have the try_compile() outside of the if(WITH_PKGCONFIG) guard:
    if(WITH_PKGCONFIG)
      pkg_check_modules(SASL libsasl2)
      if(SASL_FOUND)
        set(with_sasl_default ON)
      endif()
    else()
      try_compile(WITH_SASL_CYRUS_BOOL ...)
      if(WITH_SASL_CYRUS_BOOL)
        set(with_sasl_default ON)
        set(SASL_LIBRARIES "-lsasl2")
      endif()
    endif()
  2. The check for if(WITH_SSL) should be hoisted outside of the if(WITH_SASL) guard, so that if OpenSSL is present, SASL_SCRAM and SASL_OATHBEARER can be used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions