Commit 73c0efbe authored by jan.koester's avatar jan.koester
Browse files

test

parent 88c9eb3e
Loading
Loading
Loading
Loading
+121 −27
Changes for cmake/FindBrotli.cmake: 121 added lines, 27 removed lines.
Original line number Diff line number Diff line
#***************************************************************************
#                                  _   _ ____  _
#  Project                     ___| | | |  _ \| |
#                             / __| | | | |_) | |
#                            | (__| |_| |  _ <| |___
#                             \___|\___/|_| \_\_____|
#=============================================================================
# FindBrotli.cmake
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
# Finds the Brotli compression library.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.se/docs/copyright.html.
# Defines the following variables:
#  BROTLI_FOUND           - True if Brotli was found.
#  BROTLI_INCLUDE_DIR     - The directory containing the Brotli headers.
#  BROTLICOMMON_LIBRARY   - The path to the brotlicommon link library.
#  BROTLIDEC_LIBRARY      - The path to the brotlidec link library.
#  BROTLIENC_LIBRARY      - The path to the brotlienc link library.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
# Defines the following imported targets:
#  Brotli::Dec            - The decoder library target.
#  Brotli::Enc            - The encoder library target.
#  Brotli::Common         - The common library target.
#  Brotli::Brotli         - An interface target linking to Dec, Enc, and Common.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
# Usage:
#   find_package(Brotli REQUIRED)
#   target_link_libraries(MyTarget PRIVATE Brotli::Brotli)
#
# SPDX-License-Identifier: curl
#
###########################################################################
# NOTE on Windows: This script assumes that if the .lib (Import Library) is found,
# the corresponding .dll (Runtime Library) is in a discoverable location.
#=============================================================================

# Include standard CMake modules
include(FindPackageHandleStandardArgs)

find_path(BROTLI_INCLUDE_DIR "brotli/decode.h")
# -----------------------------------------------------------------------------
# 1. Find Header and Link Libraries
# -----------------------------------------------------------------------------

# Find the common header file
find_path(BROTLI_INCLUDE_DIR "brotli/decode.h"
    HINTS ENV BROTLI_ROOT
    PATH_SUFFIXES include
)

# Find the link libraries (.lib or .so/.a)
# We prioritize SHARED library names in the find_library calls
find_library(BROTLICOMMON_LIBRARY NAMES brotlicommon)
find_library(BROTLIDEC_LIBRARY NAMES brotlidec)
find_library(BROTLIENC_LIBRARY NAMES brotlienc)

# -----------------------------------------------------------------------------
# 2. Handle Required Arguments
# -----------------------------------------------------------------------------

find_package_handle_standard_args(Brotli
    FOUND_VAR
      BROTLI_FOUND
    REQUIRED_VARS
    FOUND_VAR           BROTLI_FOUND
    REQUIRED_VARS       BROTLI_INCLUDE_DIR
                        BROTLIDEC_LIBRARY
                        BROTLIENC_LIBRARY
                        BROTLICOMMON_LIBRARY
      BROTLI_INCLUDE_DIR
    FAIL_MESSAGE
      "Could NOT find Brotli"
    FAIL_MESSAGE        "Could NOT find Brotli. Set BROTLI_ROOT or check library/header paths."
)

# -----------------------------------------------------------------------------
# 3. Define Imported Targets (Modern CMake)
# -----------------------------------------------------------------------------

if(BROTLI_FOUND)
    # Determine the type of library found (Shared or Static)
    # This is a heuristic. On Windows, if find_library found a .lib and 
    # we expect DLLs, we must define it as SHARED.
    if(WIN32)
        # Check if we are linking against an MSVC-style import library (.lib)
        # Assuming that if a library is found, it is either the static lib 
        # or the shared import lib. We default to SHARED for runtime path support.
        set(_BROTLI_LIB_TYPE SHARED)
        set(_BROTLI_IMPLIB_PROPERTY IMPORTED_IMPLIB)
        set(_BROTLI_LOCATION_PROPERTY IMPORTED_LOCATION)

        # Helper to get the base directory of the link library
        function(get_lib_dir LIB_VAR OUT_VAR)
            get_filename_component(_path ${${LIB_VAR}} DIRECTORY)
            set(${OUT_VAR} "${_path}" PARENT_SCOPE)
        endfunction()
    else()
        # Non-Windows systems typically don't separate link and runtime files
        set(_BROTLI_LIB_TYPE SHARED)
        set(_BROTLI_IMPLIB_PROPERTY) # Not used on non-Windows for SHARED
        set(_BROTLI_LOCATION_PROPERTY IMPORTED_LOCATION)
    endif()


    # ------------------ BROTLI::DEC Target ------------------
    get_lib_dir(BROTLIDEC_LIBRARY BROTLIDEC_LIB_DIR)
    add_library(Brotli::Dec ${_BROTLI_LIB_TYPE} IMPORTED)
    set_target_properties(Brotli::Dec PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES "${BROTLI_INCLUDE_DIR}"
        # Set link file (.lib or .so/.a)
        ${_BROTLI_IMPLIB_PROPERTY} "${BROTLIDEC_LIBRARY}"
        # Set the runtime file (DLL on Windows, or the .so on others)
        # On Windows, we assume the DLL is in the same directory as the .lib, 
        # using the DLL naming convention.
        IMPORTED_LOCATION_RELEASE "$<IF:$<BOOL:${_BROTLI_IMPLIB_PROPERTY}>,${BROTLIDEC_LIB_DIR}/brotlidec.dll,${BROTLIDEC_LIBRARY}>"
    )
    
set(BROTLI_INCLUDE_DIRS ${BROTLI_INCLUDE_DIR})
set(BROTLI_LIBRARIES ${BROTLICOMMON_LIBRARY} ${BROTLIDEC_LIBRARY} ${BROTLIENC_LIBRARY})
    # ------------------ BROTLI::ENC Target ------------------
    get_lib_dir(BROTLIENC_LIBRARY BROTLIENC_LIB_DIR)
    add_library(Brotli::Enc ${_BROTLI_LIB_TYPE} IMPORTED)
    set_target_properties(Brotli::Enc PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES "${BROTLI_INCLUDE_DIR}"
        ${_BROTLI_IMPLIB_PROPERTY} "${BROTLIENC_LIBRARY}"
        IMPORTED_LOCATION_RELEASE "$<IF:$<BOOL:${_BROTLI_IMPLIB_PROPERTY}>,${BROTLIENC_LIB_DIR}/brotlienc.dll,${BROTLIENC_LIBRARY}>"
    )

    # ------------------ BROTLI::COMMON Target ------------------
    get_lib_dir(BROTLICOMMON_LIBRARY BROTLICOMMON_LIB_DIR)
    add_library(Brotli::Common ${_BROTLI_LIB_TYPE} IMPORTED)
    set_target_properties(Brotli::Common PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES "${BROTLI_INCLUDE_DIR}"
        ${_BROTLI_IMPLIB_PROPERTY} "${BROTLICOMMON_LIBRARY}"
        IMPORTED_LOCATION_RELEASE "$<IF:$<BOOL:${_BROTLI_IMPLIB_PROPERTY}>,${BROTLICOMMON_LIB_DIR}/brotlicommon.dll,${BROTLICOMMON_LIBRARY}>"
    )

    # ------------------ BROTLI::BROTLI Interface Target ------------------
    # Provides a single target for users to link against all components
    add_library(Brotli::Brotli INTERFACE IMPORTED)
    target_link_libraries(Brotli::Brotli INTERFACE
        Brotli::Common
        Brotli::Dec
        Brotli::Enc
    )
    # The interface target inherits the include directory
    target_include_directories(Brotli::Brotli INTERFACE "${BROTLI_INCLUDE_DIR}")
    
endif()

# Hide internal variables from the CMake GUI
mark_as_advanced(
    BROTLI_FOUND
    BROTLI_INCLUDE_DIR
    BROTLICOMMON_LIBRARY
    BROTLIDEC_LIBRARY
    BROTLIENC_LIBRARY
)
 No newline at end of file
+7 −3
Changes for src/CMakeLists.txt: 7 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ target_link_libraries(blogidev PUBLIC
    httppp::httppp
    netplus::netplus
    cmdplus::cmdplus
    ${BROTLI_LIBRARIES}
    Brotli::Brotli
    json-c::json-c
    authdb::client
    confplus::confplus
@@ -47,7 +47,6 @@ add_executable(blogi
include_directories(
    ${CMAKE_SOURCE_DIR}/data
    ${CMAKE_SOURCE_DIR}/src/database
    ${BROTLI_INCLUDE_DIRS}
)


@@ -74,9 +73,14 @@ install(
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows" )
    install(
        RUNTIME_DEPENDENCY_SET blogidyn 
        DIRECTORIES 
            "$<TARGET_FILE_DIR:htmlpp::htmlpp>" 
            "$<TARGET_FILE_DIR:httppp::httppp>"
            "$<TARGET_FILE_DIR:uuidp::uuidp>"
            "$<TARGET_FILE_DIR:json-c::json-c>"
            "$<TARGET_FILE_DIR:Brotli::Enc>"
        DESTINATION bin
        PRE_EXCLUDE_REGEXES "((api|ext)-ms-.*|.*azureattest.*|vcruntime.*|ucrtbase.*|msvcrt.*|wpaxholder.*|hvsifiletrust.*|pdmutilities.*)\\.dll"
        POST_INSTALL_SCRIPT "brotlicommon.dll|fback.dll|httppp.dll|json-c.dll|uuidp.dll|brotlienc.dll|htmlpp.dll"
    )

    set(CPACK_GENERATOR WIX)
+1
Changes for src/plugin.cpp: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -248,6 +248,7 @@ blogi::Plugin::PluginData::~PluginData(){
}

blogi::Plugin::PluginData::PluginData(){
    pldata = nullptr;
    next=nullptr;
    ins=nullptr;
}