From c31f68bded52c6cc6992f75ea63dda4f0152b685 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Thu, 12 Jun 2025 22:54:58 +0200 Subject: [PATCH] FindBZip2: Fix check for 1.0.1 and earlier versions Changes: - BZip2 versions before 1.0.2 required `` header file to be included before `bzlib.h` for the FILE definition. - Described `BZIP2_NEED_PREFIX` in more details. --- Modules/FindBZip2.cmake | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Modules/FindBZip2.cmake b/Modules/FindBZip2.cmake index 37d44247a7..0b9f3fe716 100644 --- a/Modules/FindBZip2.cmake +++ b/Modules/FindBZip2.cmake @@ -5,7 +5,11 @@ FindBZip2 --------- -Finds the BZip2 data compression library (libbz2). +Finds the BZip2 data compression library (libbz2): + +.. code-block:: cmake + + find_package(BZip2 [] [...]) Imported Targets ^^^^^^^^^^^^^^^^ @@ -55,7 +59,9 @@ The following cache variables may also be set: The path to the BZip2 library for debug configurations. ``BZIP2_NEED_PREFIX`` - Boolean indicating if the BZip2 functions are prefixed with ``BZ2_``. + Boolean indicating whether BZip2 functions are prefixed with ``BZ2_`` + (e.g., ``BZ2_bzCompressInit()``). Versions of BZip2 prior to 1.0.0 used + unprefixed function names (e.g., ``bzCompressInit()``). Legacy Variables ^^^^^^^^^^^^^^^^ @@ -117,7 +123,15 @@ if (BZip2_FOUND) set(CMAKE_REQUIRED_QUIET ${BZip2_FIND_QUIETLY}) set(CMAKE_REQUIRED_INCLUDES ${BZIP2_INCLUDE_DIR}) set(CMAKE_REQUIRED_LIBRARIES ${BZIP2_LIBRARIES}) - check_symbol_exists(BZ2_bzCompressInit "bzlib.h" BZIP2_NEED_PREFIX) + + # Versions before 1.0.2 required for the FILE definition. + set(BZip2_headers "bzlib.h") + if(BZIP2_VERSION VERSION_LESS "1.0.2") + list(PREPEND BZip2_headers "stdio.h") + endif() + check_symbol_exists(BZ2_bzCompressInit "${BZip2_headers}" BZIP2_NEED_PREFIX) + unset(BZip2_headers) + cmake_pop_check_state() if(NOT TARGET BZip2::BZip2)