cmake_minimum_required(VERSION 3.16)

project({{{commonLibraryName}}} VERSION 0.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt6 REQUIRED COMPONENTS Core Network)
{{#contentCompression}}
find_package(ZLIB REQUIRED)
{{/contentCompression}}
qt_standard_project_setup()

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

qt_add_library(${PROJECT_NAME}
    {{prefixLowerCase}}baseapi.h
    {{prefixLowerCase}}helpers.h
    {{prefixLowerCase}}httprequest.h
    {{prefixLowerCase}}object.h
    {{prefixLowerCase}}enum.h
    {{prefixLowerCase}}httpfileelement.h
    {{prefixLowerCase}}serverconfiguration.h
    {{prefixLowerCase}}servervariable.h
    {{prefixLowerCase}}baseapi.cpp
    {{prefixLowerCase}}helpers.cpp
    {{prefixLowerCase}}httprequest.cpp
    {{prefixLowerCase}}object.cpp
    {{prefixLowerCase}}enum.cpp
    {{prefixLowerCase}}httpfileelement.cpp
    {{prefixLowerCase}}serverconfiguration.cpp
    {{prefixLowerCase}}servervariable.cpp
)

target_include_directories(${PROJECT_NAME}
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
{{#contentCompression}}
    PRIVATE
        ${ZLIB_INCLUDE_DIRS}
{{/contentCompression}}
)

get_target_property(target_type ${PROJECT_NAME} TYPE)
if(target_type STREQUAL "SHARED_LIBRARY" OR target_type STREQUAL "MODULE_LIBRARY")
    target_compile_definitions(${PROJECT_NAME} PRIVATE {{prefix}}_COMMON_LIB_SHARED)
elseif(target_type STREQUAL "STATIC_LIBRARY")
    target_compile_definitions(${PROJECT_NAME} PRIVATE {{prefix}}_COMMON_LIB_STATIC)
endif()
target_compile_definitions(${PROJECT_NAME} PRIVATE {{prefix}}_BUILD_COMMON_LIB)

target_link_libraries(${PROJECT_NAME}
    PUBLIC
        Qt::Core
        Qt::Network
{{#contentCompression}}
    PRIVATE
        ZLIB::ZLIB
{{/contentCompression}}
)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.in
    "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
    INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

install(
    TARGETS ${PROJECT_NAME}
    EXPORT ${PROJECT_NAME}Targets
    LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
    ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
    RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
    INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
)

install(
    FILES ${HEADER_FILES}
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)

install(
    FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)

install(
    EXPORT ${PROJECT_NAME}Targets
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
