| 1 |
cmake_minimum_required(VERSION 3.12...3.13) |
| 2 |
|
| 3 |
|
| 4 |
set( |
| 5 |
CMAKE_TOOLCHAIN_FILE |
| 6 |
"${CMAKE_CURRENT_LIST_DIR}/toolchain.cmake" |
| 7 |
CACHE |
| 8 |
FILEPATH |
| 9 |
"Default toolchain" |
| 10 |
) |
| 11 |
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard") |
| 12 |
set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE BOOL "Require C++ standard to be supported") |
| 13 |
set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "compile as PIC by default") |
| 14 |
|
| 15 |
option(HUNTER_ENABLED "Enable Hunter package manager" OFF) |
| 16 |
include("cmake/HunterGate.cmake") |
| 17 |
HunterGate( |
| 18 |
URL "https://github.com/cpp-pm/hunter/archive/v0.26.6.tar.gz" |
| 19 |
SHA1 "e70c29f878f5d5f5cdf1b9ccd628fb872e8624a8" |
| 20 |
LOCAL |
| 21 |
) |
| 22 |
|
| 23 |
option(USE_BUNDLED_SPDLOG "Use the bundled version of spdlog." ${HUNTER_ENABLED}) |
| 24 |
option(USE_BUNDLED_LIBEVENT "Use the bundled version of libevent." ${HUNTER_ENABLED}) |
| 25 |
option(USE_BUNDLED_LIBCURL "Use the bundled version of curl." ${HUNTER_ENABLED}) |
| 26 |
option(USE_BUNDLED_ZLIB "Use the bundled version of zlib (for curl)." ${HUNTER_ENABLED}) |
| 27 |
|
| 28 |
project(coeurl |
| 29 |
VERSION 0.3.2 |
| 30 |
DESCRIPTION "Simple library to do http requests asynchronously via CURL in C++." |
| 31 |
HOMEPAGE_URL "https://nheko.im/nheko-reborn/cocurl" |
| 32 |
LANGUAGES CXX) |
| 33 |
|
| 34 |
add_library(coeurl lib/client.cpp lib/request.cpp lib/errors.cpp) |
| 35 |
add_library(coeurl::coeurl ALIAS coeurl) |
| 36 |
target_include_directories(coeurl PUBLIC |
| 37 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 38 |
$<INSTALL_INTERFACE:include>) |
| 39 |
|
| 40 |
find_package(Threads REQUIRED) |
| 41 |
target_link_libraries(coeurl PUBLIC Threads::Threads) |
| 42 |
|
| 43 |
|
| 44 |
# libevent |
| 45 |
if (USE_BUNDLED_LIBEVENT) |
| 46 |
hunter_add_package(Libevent) |
| 47 |
if (WIN32) |
| 48 |
find_package(Libevent 2.2 REQUIRED COMPONENTS core) |
| 49 |
target_link_libraries(coeurl PUBLIC libevent::core) |
| 50 |
else() |
| 51 |
find_package(Libevent 2.2 REQUIRED COMPONENTS core pthreads) |
| 52 |
target_link_libraries(coeurl PUBLIC libevent::core libevent::pthreads) |
| 53 |
endif() |
| 54 |
else() |
| 55 |
find_package(PkgConfig REQUIRED) |
| 56 |
pkg_check_modules(libevent_core REQUIRED IMPORTED_TARGET libevent_core) |
| 57 |
target_link_libraries(coeurl PUBLIC PkgConfig::libevent_core) |
| 58 |
if (WIN32) |
| 59 |
pkg_check_modules(libevent_windows REQUIRED IMPORTED_TARGET libevent_windows) |
| 60 |
target_link_libraries(coeurl PUBLIC PkgConfig::libevent_windows) |
| 61 |
else() |
| 62 |
pkg_check_modules(libevent_pthreads REQUIRED IMPORTED_TARGET |
| 63 |
libevent_pthreads) |
| 64 |
target_link_libraries(coeurl PUBLIC PkgConfig::libevent_pthreads) |
| 65 |
endif() |
| 66 |
endif() |
| 67 |
|
| 68 |
# curl |
| 69 |
if (USE_BUNDLED_ZLIB) |
| 70 |
hunter_add_package(ZLIB) |
| 71 |
endif() |
| 72 |
if (USE_BUNDLED_LIBCURL) |
| 73 |
hunter_add_package(CURL) |
| 74 |
find_package(CURL CONFIG REQUIRED) |
| 75 |
target_link_libraries(coeurl PUBLIC CURL::libcurl) |
| 76 |
else() |
| 77 |
find_package(PkgConfig REQUIRED) |
| 78 |
pkg_check_modules(libcurl REQUIRED IMPORTED_TARGET libcurl) |
| 79 |
target_link_libraries(coeurl PUBLIC PkgConfig::libcurl) |
| 80 |
endif() |
| 81 |
|
| 82 |
# spdlog |
| 83 |
if(USE_BUNDLED_SPDLOG) |
| 84 |
hunter_add_package(spdlog) |
| 85 |
endif() |
| 86 |
find_package(spdlog 1.0.0 CONFIG REQUIRED) |
| 87 |
target_link_libraries(coeurl PUBLIC spdlog::spdlog) |
| 88 |
|
| 89 |
IF(MSVC) |
| 90 |
add_compile_definitions(NOMINMAX WIN32_LEAN_AND_MEAN) |
| 91 |
target_link_libraries(coeurl PUBLIC wsock32 ws2_32) |
| 92 |
target_link_libraries(coeurl PUBLIC iphlpapi) |
| 93 |
ENDIF() |
| 94 |
|
| 95 |
|
| 96 |
# INSTALL MAGIC |
| 97 |
include(GNUInstallDirs) |
| 98 |
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/coeurl) |
| 99 |
|
| 100 |
# Include module with fuction 'write_basic_package_version_file' |
| 101 |
include(CMakePackageConfigHelpers) |
| 102 |
write_basic_package_version_file( |
| 103 |
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion |
| 104 |
) |
| 105 |
|
| 106 |
configure_package_config_file( |
| 107 |
${CMAKE_CURRENT_LIST_DIR}/cmake/coeurl.cmake.in |
| 108 |
${CMAKE_CURRENT_BINARY_DIR}/coeurlConfig.cmake |
| 109 |
INSTALL_DESTINATION "${INSTALL_CONFIGDIR}" |
| 110 |
) |
| 111 |
|
| 112 |
install( |
| 113 |
TARGETS coeurl |
| 114 |
EXPORT "${PROJECT_NAME}Targets" |
| 115 |
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 116 |
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" |
| 117 |
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" |
| 118 |
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| 119 |
) |
| 120 |
|
| 121 |
export( |
| 122 |
EXPORT "${PROJECT_NAME}Targets" |
| 123 |
FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake |
| 124 |
NAMESPACE coeurl::) |
| 125 |
export(PACKAGE coeurl) |
| 126 |
|
| 127 |
install( |
| 128 |
DIRECTORY "include/" |
| 129 |
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
| 130 |
FILES_MATCHING PATTERN "*.hpp" |
| 131 |
) |
| 132 |
|
| 133 |
install( |
| 134 |
FILES ${CMAKE_CURRENT_BINARY_DIR}/coeurlConfig.cmake |
| 135 |
DESTINATION "${INSTALL_CONFIGDIR}" |
| 136 |
) |
| 137 |
|
| 138 |
install( |
| 139 |
EXPORT "${PROJECT_NAME}Targets" |
| 140 |
NAMESPACE "${PROJECT_NAME}" |
| 141 |
DESTINATION "${INSTALL_CONFIGDIR}" |
| 142 |
) |
| 143 |
|