

include(FindPackageHandleStandardArgs)

message(STATUS "Conan: Using autogenerated FindBZip2.cmake")
# Global approach
set(BZip2_FOUND 1)
set(BZip2_VERSION "1.0.8")

find_package_handle_standard_args(BZip2 REQUIRED_VARS BZip2_VERSION VERSION_VAR BZip2_VERSION)
mark_as_advanced(BZip2_FOUND BZip2_VERSION)



set(BZip2_INCLUDE_DIRS "/root/.conan/data/bzip2/1.0.8/_/_/package/b27e2b40bcb70be2e7d6f0e0c6e43e35c530f8d3/include")
set(BZip2_INCLUDE_DIR "/root/.conan/data/bzip2/1.0.8/_/_/package/b27e2b40bcb70be2e7d6f0e0c6e43e35c530f8d3/include")
set(BZip2_INCLUDES "/root/.conan/data/bzip2/1.0.8/_/_/package/b27e2b40bcb70be2e7d6f0e0c6e43e35c530f8d3/include")
set(BZip2_RES_DIRS )
set(BZip2_DEFINITIONS )
set(BZip2_LINKER_FLAGS_LIST "" "")
set(BZip2_COMPILE_DEFINITIONS )
set(BZip2_COMPILE_OPTIONS_LIST "" "")
set(BZip2_LIBRARIES_TARGETS "") # Will be filled later, if CMake 3
set(BZip2_LIBRARIES "") # Will be filled later
set(BZip2_LIBS "") # Same as BZip2_LIBRARIES
set(BZip2_SYSTEM_LIBS )
set(BZip2_FRAMEWORK_DIRS )
set(BZip2_FRAMEWORKS )
set(BZip2_FRAMEWORKS_FOUND "") # Will be filled later
set(BZip2_BUILD_MODULES_PATHS )

# Apple frameworks
if(APPLE)
    foreach(_FRAMEWORK ${BZip2_FRAMEWORKS})
        # https://cmake.org/pipermail/cmake-developers/2017-August/030199.html
        find_library(CONAN_FRAMEWORK_${_FRAMEWORK}_FOUND NAME ${_FRAMEWORK} PATHS ${BZip2_FRAMEWORK_DIRS})
        if(CONAN_FRAMEWORK_${_FRAMEWORK}_FOUND)
            list(APPEND BZip2_FRAMEWORKS_FOUND ${CONAN_FRAMEWORK_${_FRAMEWORK}_FOUND})
        else()
            message(FATAL_ERROR "Framework library ${_FRAMEWORK} not found in paths: ${BZip2_FRAMEWORK_DIRS}")
        endif()
    endforeach()
endif()

mark_as_advanced(BZip2_INCLUDE_DIRS
                 BZip2_INCLUDE_DIR
                 BZip2_INCLUDES
                 BZip2_DEFINITIONS
                 BZip2_LINKER_FLAGS_LIST
                 BZip2_COMPILE_DEFINITIONS
                 BZip2_COMPILE_OPTIONS_LIST
                 BZip2_LIBRARIES
                 BZip2_LIBS
                 BZip2_LIBRARIES_TARGETS)

# Find the real .lib/.a and add them to BZip2_LIBS and BZip2_LIBRARY_LIST
set(BZip2_LIBRARY_LIST bz2)
set(BZip2_LIB_DIRS "/root/.conan/data/bzip2/1.0.8/_/_/package/b27e2b40bcb70be2e7d6f0e0c6e43e35c530f8d3/lib")
foreach(_LIBRARY_NAME ${BZip2_LIBRARY_LIST})
    unset(CONAN_FOUND_LIBRARY CACHE)
    find_library(CONAN_FOUND_LIBRARY NAME ${_LIBRARY_NAME} PATHS ${BZip2_LIB_DIRS}
                 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
    if(CONAN_FOUND_LIBRARY)
        list(APPEND BZip2_LIBRARIES ${CONAN_FOUND_LIBRARY})
        if(NOT ${CMAKE_VERSION} VERSION_LESS "3.0")
            # Create a micro-target for each lib/a found
            set(_LIB_NAME CONAN_LIB::BZip2_${_LIBRARY_NAME})
            if(NOT TARGET ${_LIB_NAME})
                # Create a micro-target for each lib/a found
                add_library(${_LIB_NAME} UNKNOWN IMPORTED)
                set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION ${CONAN_FOUND_LIBRARY})
            else()
                message(STATUS "Skipping already existing target: ${_LIB_NAME}")
            endif()
            list(APPEND BZip2_LIBRARIES_TARGETS ${_LIB_NAME})
        endif()
        message(STATUS "Found: ${CONAN_FOUND_LIBRARY}")
    else()
        message(STATUS "Library ${_LIBRARY_NAME} not found in package, might be system one")
        list(APPEND BZip2_LIBRARIES_TARGETS ${_LIBRARY_NAME})
        list(APPEND BZip2_LIBRARIES ${_LIBRARY_NAME})
    endif()
endforeach()
set(BZip2_LIBS ${BZip2_LIBRARIES})

foreach(_FRAMEWORK ${BZip2_FRAMEWORKS_FOUND})
    list(APPEND BZip2_LIBRARIES_TARGETS ${_FRAMEWORK})
    list(APPEND BZip2_LIBRARIES ${_FRAMEWORK})
endforeach()

foreach(_SYSTEM_LIB ${BZip2_SYSTEM_LIB})
    list(APPEND BZip2_LIBRARIES_TARGETS ${_SYSTEM_LIB})
    list(APPEND BZip2_LIBRARIES ${_SYSTEM_LIB})
endforeach()

set(CMAKE_MODULE_PATH "/root/.conan/data/bzip2/1.0.8/_/_/package/b27e2b40bcb70be2e7d6f0e0c6e43e35c530f8d3/" ${CMAKE_MODULE_PATH})
set(CMAKE_PREFIX_PATH "/root/.conan/data/bzip2/1.0.8/_/_/package/b27e2b40bcb70be2e7d6f0e0c6e43e35c530f8d3/" ${CMAKE_PREFIX_PATH})

foreach(_BUILD_MODULE_PATH ${BZip2_BUILD_MODULES_PATHS})
    include(${_BUILD_MODULE_PATH})
endforeach()

if(NOT ${CMAKE_VERSION} VERSION_LESS "3.0")
    # Target approach
    if(NOT TARGET BZip2::BZip2)
        add_library(BZip2::BZip2 INTERFACE IMPORTED)
        
    if(BZip2_INCLUDE_DIRS)
      set_target_properties(BZip2::BZip2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${BZip2_INCLUDE_DIRS}")
    endif()
    set_property(TARGET BZip2::BZip2 PROPERTY INTERFACE_LINK_LIBRARIES ${BZip2_LIBRARIES_TARGETS} ${BZip2_SYSTEM_LIBS} "${BZip2_LINKER_FLAGS_LIST}")
    set_property(TARGET BZip2::BZip2 PROPERTY INTERFACE_COMPILE_DEFINITIONS ${BZip2_COMPILE_DEFINITIONS})
    set_property(TARGET BZip2::BZip2 PROPERTY INTERFACE_COMPILE_OPTIONS "${BZip2_COMPILE_OPTIONS_LIST}")

        
    endif()
endif()
