Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 999f6ab

Browse files
authored
Fix for Cmake on systems without Git (yhirose#594)
If you didn't have Git installed, execute_process never declared the error variable, which led to it never parsing the header for a version. So if Git wasn't installed, the version variable never got declared, which caused errors. This fixes that.
1 parent 48da75d commit 999f6ab

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

CMakeLists.txt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[[
22
Build options:
3-
* BUILD_SHARED_LIBS (default off) builds as a static library (if HTTPLIB_COMPILE is ON)
3+
* BUILD_SHARED_LIBS (default off) builds as a shared library (if HTTPLIB_COMPILE is ON)
44
* HTTPLIB_USE_OPENSSL_IF_AVAILABLE (default on)
55
* HTTPLIB_USE_ZLIB_IF_AVAILABLE (default on)
66
* HTTPLIB_REQUIRE_OPENSSL (default off)
@@ -60,17 +60,21 @@
6060
]]
6161
cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)
6262

63-
# Gets the latest tag as a string like "v0.6.6"
64-
# Can silently fail if git isn't on the system
65-
execute_process(COMMAND git describe --tags --abbrev=0
66-
OUTPUT_VARIABLE _raw_version_string
67-
ERROR_VARIABLE _git_tag_error
68-
)
63+
# On systems without Git installed, there were errors since execute_process seemed to not throw an error without it?
64+
find_package(Git QUIET)
65+
if(Git_FOUND)
66+
# Gets the latest tag as a string like "v0.6.6"
67+
# Can silently fail if git isn't on the system
68+
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0
69+
OUTPUT_VARIABLE _raw_version_string
70+
ERROR_VARIABLE _git_tag_error
71+
)
72+
endif()
6973

7074
# execute_process can fail silenty, so check for an error
7175
# if there was an error, just use the user agent as a version
72-
if(_git_tag_error)
73-
message(WARNING "cpp-httplib failed to find the latest git tag, falling back to using user agent as the version.")
76+
if(_git_tag_error OR NOT Git_FOUND)
77+
message(WARNING "cpp-httplib failed to find the latest Git tag, falling back to using user agent as the version.")
7478
# Get the user agent and use it as a version
7579
# This gets the string with the user agent from the header.
7680
# This is so the maintainer doesn't actually need to update this manually.
@@ -101,7 +105,7 @@ if(HTTPLIB_COMPILE)
101105
endif()
102106

103107
option(HTTPLIB_REQUIRE_BROTLI "Requires Brotli to be found & linked, or fails build." OFF)
104-
option(HTTPLIB_USE_BROTLI_IF_AVAILABLE "Uses Brotli (if available) to enable Brotli compression support." ON)
108+
option(HTTPLIB_USE_BROTLI_IF_AVAILABLE "Uses Brotli (if available) to enable Brotli decompression support." ON)
105109
# Defaults to static library
106110
option(BUILD_SHARED_LIBS "Build the library as a shared library instead of static. Has no effect if using header-only." OFF)
107111
if (BUILD_SHARED_LIBS AND WIN32 AND HTTPLIB_COMPILE)

0 commit comments

Comments
 (0)