Debian Codegraph @

coeurl/CMakeLists.txt

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
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 if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
35 message(FATAL_ERROR "The CMake build for coeurl is not intended for installation or usage outside of FetchContent. Use meson instead.")
36 endif()
37
38 add_library(coeurl lib/client.cpp lib/request.cpp lib/errors.cpp)
39 add_library(coeurl::coeurl ALIAS coeurl)
40 target_include_directories(coeurl PUBLIC
41 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
42 $<INSTALL_INTERFACE:include>)
43
44 find_package(Threads REQUIRED)
45 target_link_libraries(coeurl PUBLIC Threads::Threads)
46
47
48 # libevent
49 if (USE_BUNDLED_LIBEVENT)
50 hunter_add_package(Libevent)
51 if (WIN32)
52 find_package(Libevent 2.2 REQUIRED COMPONENTS core)
53 target_link_libraries(coeurl PUBLIC libevent::core)
54 else()
55 find_package(Libevent 2.2 REQUIRED COMPONENTS core pthreads)
56 target_link_libraries(coeurl PUBLIC libevent::core libevent::pthreads)
57 endif()
58 else()
59 find_package(PkgConfig REQUIRED)
60 pkg_check_modules(libevent_core REQUIRED IMPORTED_TARGET libevent_core)
61 target_link_libraries(coeurl PUBLIC PkgConfig::libevent_core)
62 if (WIN32)
63 pkg_check_modules(libevent_windows REQUIRED IMPORTED_TARGET libevent_windows)
64 target_link_libraries(coeurl PUBLIC PkgConfig::libevent_windows)
65 else()
66 pkg_check_modules(libevent_pthreads REQUIRED IMPORTED_TARGET
67 libevent_pthreads)
68 target_link_libraries(coeurl PUBLIC PkgConfig::libevent_pthreads)
69 endif()
70 endif()
71
72 # curl
73 if (USE_BUNDLED_ZLIB)
74 hunter_add_package(ZLIB)
75 endif()
76 if (USE_BUNDLED_LIBCURL)
77 hunter_add_package(CURL)
78 find_package(CURL CONFIG REQUIRED)
79 target_link_libraries(coeurl PUBLIC CURL::libcurl)
80 else()
81 find_package(PkgConfig REQUIRED)
82 pkg_check_modules(libcurl REQUIRED IMPORTED_TARGET libcurl)
83 target_link_libraries(coeurl PUBLIC PkgConfig::libcurl)
84 endif()
85
86 # spdlog
87 if(USE_BUNDLED_SPDLOG)
88 hunter_add_package(spdlog)
89 endif()
90 find_package(spdlog 1.0.0 CONFIG REQUIRED)
91 target_link_libraries(coeurl PUBLIC spdlog::spdlog)
92
93 IF(MSVC)
94 add_compile_definitions(NOMINMAX WIN32_LEAN_AND_MEAN)
95 target_link_libraries(coeurl PUBLIC wsock32 ws2_32)
96 target_link_libraries(coeurl PUBLIC iphlpapi)
97 ENDIF()
98
99
100 # INSTALL MAGIC
101 include(GNUInstallDirs)
102 set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/coeurl)
103
104 # Include module with fuction 'write_basic_package_version_file'
105 include(CMakePackageConfigHelpers)
106 write_basic_package_version_file(
107 "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion
108 )
109
110 configure_package_config_file(
111 ${CMAKE_CURRENT_LIST_DIR}/cmake/coeurl.cmake.in
112 ${CMAKE_CURRENT_BINARY_DIR}/coeurlConfig.cmake
113 INSTALL_DESTINATION "${INSTALL_CONFIGDIR}"
114 )
115
116 install(
117 TARGETS coeurl
118 EXPORT "${PROJECT_NAME}Targets"
119 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
120 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
121 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
122 INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
123 )
124
125 export(
126 EXPORT "${PROJECT_NAME}Targets"
127 FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake
128 NAMESPACE coeurl::)
129 export(PACKAGE coeurl)
130
131 install(
132 DIRECTORY "include/"
133 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
134 FILES_MATCHING PATTERN "*.hpp"
135 )
136
137 install(
138 FILES ${CMAKE_CURRENT_BINARY_DIR}/coeurlConfig.cmake
139 DESTINATION "${INSTALL_CONFIGDIR}"
140 )
141
142 install(
143 EXPORT "${PROJECT_NAME}Targets"
144 NAMESPACE "${PROJECT_NAME}"
145 DESTINATION "${INSTALL_CONFIGDIR}"
146 )
147