Skip to content

Instantly share code, notes, and snippets.

@00-matt
Created October 3, 2019 14:43
Show Gist options
  • Save 00-matt/b4cc8b83a5312c65618174c42273fdbb to your computer and use it in GitHub Desktop.
Save 00-matt/b4cc8b83a5312c65618174c42273fdbb to your computer and use it in GitHub Desktop.
find_path(HTTP_PARSER_INCLUDE_DIR NAMES http_parser.h)
mark_as_advanced(HTTP_PARSER_INCLUDE_DIR)
find_library(HTTP_PARSER_LIBRARY NAMES http_parser libhttp_parser)
mark_as_advanced(HTTP_PARSER_LIBRARY)
if(DEFINED HTTP_PARSER_INCLUDE_DIR)
file(STRINGS "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h" _HTTP_PARSER_H REGEX
"#define HTTP_PARSER_VERSION_(MAJOR|MINOR|PATCH) [0-9]+")
foreach(c MAJOR MINOR PATCH)
if(_HTTP_PARSER_H MATCHES "#define HTTP_PARSER_VERSION_${c} ([0-9]+)")
set(HTTP_PARSER_VERSION_${c} "${CMAKE_MATCH_1}")
endif()
endforeach()
unset(_HTTP_PARSER_H)
set(HTTP_PARSER_VERSION "${HTTP_PARSER_VERSION_MAJOR}.${HTTP_PARSER_VERSION_MINOR}.${HTTP_PARSER_VERSION_PATCH}")
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(http_parser
REQUIRED_VARS HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY
VERSION_VAR HTTP_PARSER_VERSION)
if(HTTP_PARSER_FOUND)
set(HTTP_PARSER_INCLUDE_DIRS "${HTTP_PARSER_INCLUDE_DIR}")
set(HTTP_PARSER_LIBRARIES "${HTTP_PARSER_LIBRARY}")
if(NOT TARGET http_parser::http_parser)
add_library(http_parser::http_parser UNKNOWN IMPORTED)
set_target_properties(http_parser::http_parser PROPERTIES
IMPORTED_LOCATION "${HTTP_PARSER_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${HTTP_PARSER_INCLUDE_DIRS}")
endif()
endif()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment