Skip to content

Commit de178d3

Browse files
committed
cmake: refactor http_parser selection
Move http_parser selection into its own cmake module.
1 parent 16b6e3a commit de178d3

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

cmake/SelectHTTPParser.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Optional external dependency: http-parser
2+
if(USE_HTTP_PARSER STREQUAL "system")
3+
find_package(HTTP_Parser)
4+
5+
if(HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
6+
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS})
7+
list(APPEND LIBGIT2_LIBS ${HTTP_PARSER_LIBRARIES})
8+
list(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
9+
add_feature_info(http-parser ON "http-parser support (system)")
10+
else()
11+
message(FATAL_ERROR "http-parser support was requested but not found")
12+
endif()
13+
else()
14+
message(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.")
15+
add_subdirectory("${libgit2_SOURCE_DIR}/deps/http-parser" "${libgit2_BINARY_DIR}/deps/http-parser")
16+
list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/http-parser")
17+
list(APPEND LIBGIT2_OBJECTS "$<TARGET_OBJECTS:http-parser>")
18+
add_feature_info(http-parser ON "http-parser support (bundled)")
19+
endif()

src/CMakeLists.txt

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ endif()
113113

114114
include(SelectHTTPSBackend)
115115
include(SelectHashes)
116+
include(SelectHTTPParser)
117+
116118
target_sources(git2internal PRIVATE ${SRC_SHA1})
117119

118120
# Specify regular expression implementation
@@ -167,26 +169,6 @@ else()
167169
message(FATAL_ERROR "The REGEX_BACKEND option provided is not supported")
168170
endif()
169171

170-
# Optional external dependency: http-parser
171-
if(USE_HTTP_PARSER STREQUAL "system")
172-
find_package(HTTPParser)
173-
174-
if(HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
175-
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS})
176-
list(APPEND LIBGIT2_LIBS ${HTTP_PARSER_LIBRARIES})
177-
list(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
178-
add_feature_info(http-parser ON "http-parser support (system)")
179-
else()
180-
message(FATAL_ERROR "http-parser support was requested but not found")
181-
endif()
182-
else()
183-
message(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.")
184-
add_subdirectory("${libgit2_SOURCE_DIR}/deps/http-parser" "${libgit2_BINARY_DIR}/deps/http-parser")
185-
list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/http-parser")
186-
list(APPEND LIBGIT2_OBJECTS "$<TARGET_OBJECTS:http-parser>")
187-
add_feature_info(http-parser ON "http-parser support (bundled)")
188-
endif()
189-
190172
# Optional external dependency: zlib
191173
SanitizeBool(USE_BUNDLED_ZLIB)
192174
if(USE_BUNDLED_ZLIB STREQUAL ON)

0 commit comments

Comments
 (0)