11cb0ef41Sopenharmony_cicmake_minimum_required(VERSION 3.5.1) 21cb0ef41Sopenharmony_cicmake_policy(SET CMP0069 NEW) 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciproject(llhttp VERSION 6.1.1) 51cb0ef41Sopenharmony_ciinclude(GNUInstallDirs) 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciset(CMAKE_C_STANDARD 99) 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci# By default build in relwithdebinfo type, supports both lowercase and uppercase 101cb0ef41Sopenharmony_ciif(NOT CMAKE_CONFIGURATION_TYPES) 111cb0ef41Sopenharmony_ci set(allowableBuildTypes DEBUG RELEASE RELWITHDEBINFO MINSIZEREL) 121cb0ef41Sopenharmony_ci set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowableBuildTypes}") 131cb0ef41Sopenharmony_ci if(NOT CMAKE_BUILD_TYPE) 141cb0ef41Sopenharmony_ci set(CMAKE_BUILD_TYPE RELWITHDEBINFO CACHE STRING "" FORCE) 151cb0ef41Sopenharmony_ci else() 161cb0ef41Sopenharmony_ci string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE) 171cb0ef41Sopenharmony_ci if(NOT CMAKE_BUILD_TYPE IN_LIST allowableBuildTypes) 181cb0ef41Sopenharmony_ci message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}") 191cb0ef41Sopenharmony_ci endif() 201cb0ef41Sopenharmony_ci endif() 211cb0ef41Sopenharmony_ciendif() 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci# 241cb0ef41Sopenharmony_ci# Options 251cb0ef41Sopenharmony_ci# 261cb0ef41Sopenharmony_ci# Generic option 271cb0ef41Sopenharmony_cioption(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so)" ON) 281cb0ef41Sopenharmony_cioption(BUILD_STATIC_LIBS "Build static libraries (.lib/.a)" OFF) 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci# Source code 311cb0ef41Sopenharmony_ciset(LLHTTP_SOURCES 321cb0ef41Sopenharmony_ci ${CMAKE_CURRENT_SOURCE_DIR}/src/llhttp.c 331cb0ef41Sopenharmony_ci ${CMAKE_CURRENT_SOURCE_DIR}/src/http.c 341cb0ef41Sopenharmony_ci ${CMAKE_CURRENT_SOURCE_DIR}/src/api.c 351cb0ef41Sopenharmony_ci) 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ciset(LLHTTP_HEADERS 381cb0ef41Sopenharmony_ci ${CMAKE_CURRENT_SOURCE_DIR}/include/llhttp.h 391cb0ef41Sopenharmony_ci) 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ciconfigure_file( 421cb0ef41Sopenharmony_ci ${CMAKE_CURRENT_SOURCE_DIR}/libllhttp.pc.in 431cb0ef41Sopenharmony_ci ${CMAKE_CURRENT_SOURCE_DIR}/libllhttp.pc 441cb0ef41Sopenharmony_ci @ONLY 451cb0ef41Sopenharmony_ci) 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_cifunction(config_library target) 481cb0ef41Sopenharmony_ci target_sources(${target} PRIVATE ${LLHTTP_SOURCES} ${LLHTTP_HEADERS}) 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci target_include_directories(${target} PRIVATE 511cb0ef41Sopenharmony_ci ${CMAKE_CURRENT_SOURCE_DIR}/include 521cb0ef41Sopenharmony_ci ) 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci set_target_properties(${target} PROPERTIES 551cb0ef41Sopenharmony_ci OUTPUT_NAME llhttp 561cb0ef41Sopenharmony_ci VERSION ${PROJECT_VERSION} 571cb0ef41Sopenharmony_ci SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 581cb0ef41Sopenharmony_ci PUBLIC_HEADER ${LLHTTP_HEADERS} 591cb0ef41Sopenharmony_ci ) 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci install(TARGETS ${target} 621cb0ef41Sopenharmony_ci EXPORT llhttp 631cb0ef41Sopenharmony_ci LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 641cb0ef41Sopenharmony_ci ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 651cb0ef41Sopenharmony_ci PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 661cb0ef41Sopenharmony_ci ) 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci install(FILES 691cb0ef41Sopenharmony_ci ${CMAKE_CURRENT_SOURCE_DIR}/libllhttp.pc 701cb0ef41Sopenharmony_ci DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig 711cb0ef41Sopenharmony_ci ) 721cb0ef41Sopenharmony_ci 731cb0ef41Sopenharmony_ci # This is required to work with FetchContent 741cb0ef41Sopenharmony_ci install(EXPORT llhttp 751cb0ef41Sopenharmony_ci FILE llhttp-config.cmake 761cb0ef41Sopenharmony_ci NAMESPACE llhttp:: 771cb0ef41Sopenharmony_ci DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/llhttp) 781cb0ef41Sopenharmony_ciendfunction(config_library target) 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ciif(BUILD_SHARED_LIBS) 811cb0ef41Sopenharmony_ci add_library(llhttp_shared SHARED 821cb0ef41Sopenharmony_ci ${llhttp_src} 831cb0ef41Sopenharmony_ci ) 841cb0ef41Sopenharmony_ci add_library(llhttp::llhttp ALIAS llhttp_shared) 851cb0ef41Sopenharmony_ci config_library(llhttp_shared) 861cb0ef41Sopenharmony_ciendif() 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_ciif(BUILD_STATIC_LIBS) 891cb0ef41Sopenharmony_ci add_library(llhttp_static STATIC 901cb0ef41Sopenharmony_ci ${llhttp_src} 911cb0ef41Sopenharmony_ci ) 921cb0ef41Sopenharmony_ci if(BUILD_SHARED_LIBS) 931cb0ef41Sopenharmony_ci add_library(llhttp::llhttp ALIAS llhttp_shared) 941cb0ef41Sopenharmony_ci else() 951cb0ef41Sopenharmony_ci add_library(llhttp::llhttp ALIAS llhttp_static) 961cb0ef41Sopenharmony_ci endif() 971cb0ef41Sopenharmony_ci config_library(llhttp_static) 981cb0ef41Sopenharmony_ciendif() 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci# On windows with Visual Studio, add a debug postfix so that release 1011cb0ef41Sopenharmony_ci# and debug libraries can coexist. 1021cb0ef41Sopenharmony_ciif(MSVC) 1031cb0ef41Sopenharmony_ci set(CMAKE_DEBUG_POSTFIX "d") 1041cb0ef41Sopenharmony_ciendif() 1051cb0ef41Sopenharmony_ci 1061cb0ef41Sopenharmony_ci# Print project configure summary 1071cb0ef41Sopenharmony_cimessage(STATUS "") 1081cb0ef41Sopenharmony_cimessage(STATUS "") 1091cb0ef41Sopenharmony_cimessage(STATUS "Project configure summary:") 1101cb0ef41Sopenharmony_cimessage(STATUS "") 1111cb0ef41Sopenharmony_cimessage(STATUS " CMake build type .................: ${CMAKE_BUILD_TYPE}") 1121cb0ef41Sopenharmony_cimessage(STATUS " Install prefix ...................: ${CMAKE_INSTALL_PREFIX}") 1131cb0ef41Sopenharmony_cimessage(STATUS " Build shared library .............: ${BUILD_SHARED_LIBS}") 1141cb0ef41Sopenharmony_cimessage(STATUS " Build static library .............: ${BUILD_STATIC_LIBS}") 1151cb0ef41Sopenharmony_cimessage(STATUS "") 116