@@ -2,30 +2,46 @@ find_path(Avro_INCLUDE_DIR NAMES avro/Encoder.hh)
22find_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
1312set (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 ()
3147endif ()
0 commit comments