@@ -111,28 +111,40 @@ else()
111111endif ()
112112
113113# Try to find system lz4 first, fetch if not found
114- find_package (PkgConfig QUIET )
115- if (PkgConfig_FOUND)
116- pkg_check_modules (LZ4 QUIET liblz4 )
114+ # Prefer CMake config (gives proper targets with full paths on all platforms)
115+ find_package (lz4 CONFIG QUIET )
116+ if (lz4_FOUND)
117+ message (STATUS "Found lz4 via CMake config" )
118+ if (CARQUET_BUILD_SHARED AND TARGET LZ4::lz4_shared)
119+ set (LZ4_LIBRARIES LZ4::lz4_shared)
120+ elseif (TARGET LZ4::lz4_static)
121+ set (LZ4_LIBRARIES LZ4::lz4_static)
122+ elseif (TARGET LZ4::lz4_shared)
123+ set (LZ4_LIBRARIES LZ4::lz4_shared)
124+ elseif (TARGET lz4::lz4)
125+ set (LZ4_LIBRARIES lz4::lz4)
126+ endif ()
127+ # Only mark as found if we actually resolved a target
128+ if (LZ4_LIBRARIES)
129+ set (LZ4_FOUND TRUE )
130+ else ()
131+ message (STATUS "lz4 CMake config found but no known target — trying pkg-config" )
132+ set (LZ4_FOUND FALSE )
133+ endif ()
117134endif ()
118135
119- if (LZ4_FOUND)
120- message (STATUS "Found system liblz4" )
121- else ()
122- # Try CMake config (vcpkg, conda, etc.)
123- find_package (lz4 CONFIG QUIET )
124- if (lz4_FOUND)
125- message (STATUS "Found lz4 via CMake config" )
126- if (CARQUET_BUILD_SHARED AND TARGET LZ4::lz4_shared)
127- set (LZ4_LIBRARIES LZ4::lz4_shared)
128- elseif (TARGET LZ4::lz4_static)
129- set (LZ4_LIBRARIES LZ4::lz4_static)
130- elseif (TARGET LZ4::lz4_shared)
131- set (LZ4_LIBRARIES LZ4::lz4_shared)
132- elseif (TARGET lz4::lz4)
133- set (LZ4_LIBRARIES lz4::lz4)
136+ if (NOT LZ4_FOUND)
137+ find_package (PkgConfig QUIET )
138+ if (PkgConfig_FOUND)
139+ pkg_check_modules (LZ4 QUIET liblz4 )
140+ if (LZ4_FOUND)
141+ message (STATUS "Found system liblz4 via pkg-config" )
142+ # Use LINK_LIBRARIES (full paths) instead of LIBRARIES (bare names)
143+ # to avoid MSVC linker failing to locate the .lib file
144+ if (LZ4_LINK_LIBRARIES)
145+ set (LZ4_LIBRARIES ${LZ4_LINK_LIBRARIES} )
146+ endif ()
134147 endif ()
135- set (LZ4_FOUND TRUE )
136148 endif ()
137149endif ()
138150
@@ -407,7 +419,7 @@ endif()
407419# Create library
408420if (CARQUET_BUILD_SHARED)
409421 add_library (carquet SHARED ${CARQUET_SOURCES} )
410- target_compile_definitions (carquet PRIVATE CARQUET_BUILD_SHARED )
422+ target_compile_definitions (carquet PRIVATE CARQUET_BUILD_SHARED CARQUET_BUILDING_DLL )
411423else ()
412424 add_library (carquet STATIC ${CARQUET_SOURCES} )
413425endif ()
0 commit comments