Skip to content

Commit ec0d6b7

Browse files
committed
- Extract version from library soname on conda-forge
- Skip Kafka adapter on Windows if avro-cpp < 1.12.1 - Update vcpkg submodule to 1.12.1 (has upstream fmt fix) - Rename CSP_AVRO_TARGET to AVRO_LIBRARIES Signed-off-by: Krzysztof Milde <Krzysztof.Milde@Point72.com>
1 parent fda0344 commit ec0d6b7

5 files changed

Lines changed: 40 additions & 24 deletions

File tree

cpp/cmake/modules/FindAvro.cmake

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,46 @@ find_path(Avro_INCLUDE_DIR NAMES avro/Encoder.hh)
22
find_library(Avro_LIBRARY NAMES avrocpp libavrocpp)
33

44
# =============================================================================
5-
# Check for conda-forge avro-cpp fmt::formatter incompatibility on Windows
5+
# Extract version from library soname and check compatibility on Windows
66
# =============================================================================
7-
# conda-forge's avro-cpp has fmt::formatter specializations with non-const
8-
# format() methods, but fmt v12+ requires const. This causes MSVC error C2766.
9-
#
10-
# If detected, Avro_FOUND is set to FALSE and Kafka adapter will be disabled.
7+
# avro-cpp versions <= 1.12.0 have fmt::formatter with non-const format()
8+
# methods, but fmt v12+ requires const. This causes MSVC error C2766.
9+
# Require avro-cpp >= 1.12.1 on Windows which has the fix.
1110
# =============================================================================
1211

1312
set(Avro_COMPATIBLE TRUE)
13+
set(Avro_VERSION "")
1414

15-
if(WIN32 AND Avro_INCLUDE_DIR AND NOT CSP_USE_VCPKG)
16-
set(_avro_node_hh "${Avro_INCLUDE_DIR}/avro/Node.hh")
17-
if(EXISTS "${_avro_node_hh}")
18-
file(READ "${_avro_node_hh}" _node_hh_content)
19-
string(FIND "${_node_hh_content}" "fmt::formatter<avro::Name>" _has_formatter)
20-
if(NOT _has_formatter EQUAL -1)
21-
# Check for non-const format() - the bug pattern
22-
string(REGEX MATCH "auto format\\([^)]+\\)[^c]*\\{" _buggy_pattern "${_node_hh_content}")
23-
if(_buggy_pattern)
24-
set(Avro_COMPATIBLE FALSE)
25-
message(WARNING
26-
"avro-cpp has incompatible fmt::formatter (non-const format()). "
27-
"Kafka adapter will be disabled. Update avro-cpp when conda-forge releases a fix.")
28-
endif()
15+
if(Avro_LIBRARY)
16+
get_filename_component(_avro_realpath "${Avro_LIBRARY}" REALPATH)
17+
if(_avro_realpath MATCHES "libavrocpp\\.so\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)")
18+
set(Avro_VERSION_MAJOR "${CMAKE_MATCH_1}")
19+
set(Avro_VERSION_MINOR "${CMAKE_MATCH_2}")
20+
set(Avro_VERSION_PATCH "${CMAKE_MATCH_3}")
21+
set(Avro_VERSION "${Avro_VERSION_MAJOR}.${Avro_VERSION_MINOR}.${Avro_VERSION_PATCH}")
22+
elseif(_avro_realpath MATCHES "avrocpp\\.dll")
23+
# Windows DLL doesn't have version in filename - try library name
24+
if(_avro_realpath MATCHES "([0-9]+)\\.([0-9]+)\\.([0-9]+)")
25+
set(Avro_VERSION_MAJOR "${CMAKE_MATCH_1}")
26+
set(Avro_VERSION_MINOR "${CMAKE_MATCH_2}")
27+
set(Avro_VERSION_PATCH "${CMAKE_MATCH_3}")
28+
set(Avro_VERSION "${Avro_VERSION_MAJOR}.${Avro_VERSION_MINOR}.${Avro_VERSION_PATCH}")
29+
endif()
30+
endif()
31+
32+
if(WIN32 AND NOT CSP_USE_VCPKG)
33+
if(NOT Avro_VERSION)
34+
# Could not detect version - assume buggy and skip
35+
set(Avro_COMPATIBLE FALSE)
36+
message(WARNING
37+
"Could not detect avro-cpp version on Windows. "
38+
"Kafka adapter will be disabled to avoid potential fmt::formatter incompatibility. "
39+
"Use vcpkg or upgrade to avro-cpp >= 1.12.1.")
40+
elseif(Avro_VERSION VERSION_LESS "1.12.1")
41+
set(Avro_COMPATIBLE FALSE)
42+
message(WARNING
43+
"avro-cpp ${Avro_VERSION} has incompatible fmt::formatter on Windows. "
44+
"Kafka adapter will be disabled. Upgrade to avro-cpp >= 1.12.1.")
2945
endif()
3046
endif()
3147
endif()

cpp/cmake/modules/FindDepsKafkaAdapter.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ if (CSP_USE_VCPKG)
88
# https://github.com/microsoft/vcpkg/issues/40320
99
link_directories(${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib)
1010
endif()
11-
set(CSP_AVRO_TARGET unofficial::avro-cpp::avrocpp CACHE INTERNAL "")
11+
set(AVRO_LIBRARIES unofficial::avro-cpp::avrocpp CACHE INTERNAL "")
1212
set(DepsKafkaAdapter_FOUND TRUE)
1313
else()
1414
find_package(RdKafka REQUIRED)
1515
find_package(Avro)
1616
if(NOT Avro_FOUND)
1717
set(DepsKafkaAdapter_FOUND FALSE)
1818
else()
19-
set(CSP_AVRO_TARGET Avro::avrocpp CACHE INTERNAL "")
19+
set(AVRO_LIBRARIES Avro::avrocpp CACHE INTERNAL "")
2020
set(DepsKafkaAdapter_FOUND TRUE)
2121
endif()
2222
endif()

cpp/csp/adapters/kafka/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ find_package(DepsKafkaAdapter REQUIRED)
2424

2525
target_link_libraries(csp_kafka_adapter PUBLIC csp_adapter_utils RdKafka::rdkafka RdKafka::rdkafka++)
2626

27-
target_link_libraries(csp_kafka_adapter PUBLIC ${CSP_AVRO_TARGET})
27+
target_link_libraries(csp_kafka_adapter PUBLIC ${AVRO_LIBRARIES})
2828

2929
install(TARGETS csp_kafka_adapter
3030
PUBLIC_HEADER DESTINATION include/csp/adapters/kafka

cpp/csp/adapters/utils/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ set_target_properties(csp_adapter_utils PROPERTIES PUBLIC_HEADER "${ADAPTER_UTIL
2525

2626
find_package(DepsKafkaAdapter REQUIRED)
2727

28-
target_link_libraries(csp_adapter_utils PUBLIC ${CSP_AVRO_TARGET})
28+
target_link_libraries(csp_adapter_utils PUBLIC ${AVRO_LIBRARIES})
2929

3030
install(TARGETS csp_adapter_utils
3131
PUBLIC_HEADER DESTINATION include/csp/adapters/utils

vcpkg

Submodule vcpkg updated 4505 files

0 commit comments

Comments
 (0)