32
32
33
33
-------------------------------------------------------------------------------
34
34
35
- These three variables are available after you run find_package(httplib)
36
- * HTTPLIB_HEADER_PATH - this is the full path to the installed header.
35
+ These variables are available after you run find_package(httplib)
36
+ * HTTPLIB_HEADER_PATH - this is the full path to the installed header (e.g. /usr/include/httplib.h) .
37
37
* HTTPLIB_IS_USING_OPENSSL - a bool for if OpenSSL support is enabled.
38
38
* HTTPLIB_IS_USING_ZLIB - a bool for if ZLIB support is enabled.
39
- * HTTPLIB_IS_COMPILED - a bool for if the library is header-only or compiled.
39
+ * HTTPLIB_IS_COMPILED - a bool for if the library is compiled, or otherwise header-only.
40
+ * HTTPLIB_INCLUDE_DIR - the root path to httplib's header (e.g. /usr/include).
41
+ * HTTPLIB_LIBRARY - the full path to the library if compiled (e.g. /usr/lib/libhttplib.so).
42
+ * HTTPLIB_VERSION - the project's version string.
43
+ * HTTPLIB_FOUND - a bool for if the target was found.
40
44
41
45
Want to use precompiled headers (Cmake feature since v3.16)?
42
46
It's as simple as doing the following (before linking):
48
52
FindPython3 requires Cmake v3.12
49
53
]]
50
54
cmake_minimum_required (VERSION 3.12.0 FATAL_ERROR )
51
- project (httplib LANGUAGES CXX )
55
+
56
+ # Get the user agent and use it as a version
57
+ # This gets the string with the user agent from the header.
58
+ # This is so the maintainer doesn't actually need to update this manually.
59
+ file (STRINGS httplib.h _user_agent_match REGEX "User\- Agent.*cpp\- httplib/([0-9]+\. ?)+" )
60
+ # Need to pull out just the version for use
61
+ string (REGEX MATCH "([0-9]+\\ .?)+" _httplib_version "${_user_agent_match} " )
62
+
63
+ project (httplib VERSION ${_httplib_version} LANGUAGES CXX )
52
64
53
65
# Change as needed to set an OpenSSL minimum version.
54
66
# This is used in the installed Cmake config file.
@@ -205,6 +217,23 @@ configure_package_config_file("${PROJECT_NAME}Config.cmake.in"
205
217
NO_CHECK_REQUIRED_COMPONENTS_MACRO
206
218
)
207
219
220
+ if (HTTPLIB_COMPILE )
221
+ write_basic_package_version_file ("${PROJECT_NAME} ConfigVersion.cmake"
222
+ # Example: if you find_package(httplib 0.5.4)
223
+ # then anything >= 0.5 and <= 1.0 is accepted
224
+ COMPATIBILITY SameMajorVersion
225
+ )
226
+ else ()
227
+ write_basic_package_version_file ("${PROJECT_NAME} ConfigVersion.cmake"
228
+ # Example: if you find_package(httplib 0.5.4)
229
+ # then anything >= 0.5 and <= 1.0 is accepted
230
+ COMPATIBILITY SameMajorVersion
231
+ # Tells Cmake that it's a header-only lib
232
+ # Mildly useful for end-users :)
233
+ ARCH_INDEPENDENT
234
+ )
235
+ endif ()
236
+
208
237
# Creates the export httplibTargets.cmake
209
238
# This is strictly what holds compilation requirements
210
239
# and linkage information (doesn't find deps though).
@@ -218,6 +247,7 @@ install(FILES "${_httplib_build_includedir}/httplib.h" DESTINATION ${CMAKE_INSTA
218
247
219
248
install (FILES
220
249
"${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} Config.cmake"
250
+ "${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} ConfigVersion.cmake"
221
251
DESTINATION ${_TARGET_INSTALL_CMAKEDIR}
222
252
)
223
253
0 commit comments