diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..41d2000e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,53 @@ +cmake_minimum_required(VERSION 3.5.1) +cmake_policy(SET CMP0069 NEW) + +project(llhttp C) + +set(CMAKE_C_STANDARD 99) + +# +# Options +# +# Generic option +option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF) + +# Source code +set(LLHTTP_SOURCES + src/llhttp.c + src/http.c + src/api.c +) + +set(LLHTTP_HEADERS + include/llhttp.h +) + +add_library(llhttp) +add_library(llhttp::llhttp ALIAS llhttp) + +target_sources(llhttp PRIVATE ${LLHTTP_SOURCES} ${LLHTTP_HEADERS}) + +# On windows with Visual Studio, add a debug postfix so that release +# and debug libraries can coexist. +if(MSVC) + set(CMAKE_DEBUG_POSTFIX "d") +endif() + +target_include_directories(llhttp PUBLIC + $ + $ +) + +set_target_properties(llhttp PROPERTIES PUBLIC_HEADER ${LLHTTP_HEADERS}) + +install(TARGETS llhttp + EXPORT llhttp + ARCHIVE DESTINATION lib + PUBLIC_HEADER DESTINATION include/ +) + +# This is required to work with FetchContent +install(EXPORT llhttp + FILE llhttp-config.cmake + NAMESPACE llhttp:: + DESTINATION lib/cmake/llhttp) diff --git a/README.md b/README.md index fcbf86c1..1c37cf66 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,20 @@ For more information on API usage, please refer to [src/native/api.h](https://gi * Python: [pallas/pyllhttp][8] * Ruby: [metabahn/llhttp][9] + +### Using with CMake + +If you want to use this library in a CMake project you can use the snippet below. + +``` +FetchContent_Declare(llhttp + URL "https://github.com/nodejs/llhttp/releases/download/v6.0.4/llhttp-release-v6.0.4.tar.gz") # Using version 6.0.4 + +FetchContent_MakeAvailable(llhttp) + +target_link_libraries(${EXAMPLE_PROJECT_NAME} ${PROJECT_LIBRARIES} llhttp ${PROJECT_NAME}) +``` + #### LICENSE This software is licensed under the MIT License. diff --git a/include/llhttp.h b/include/llhttp.h index 336234c6..b7510720 100644 --- a/include/llhttp.h +++ b/include/llhttp.h @@ -3,7 +3,7 @@ #define LLHTTP_VERSION_MAJOR 6 #define LLHTTP_VERSION_MINOR 0 -#define LLHTTP_VERSION_PATCH 4 +#define LLHTTP_VERSION_PATCH 5 #ifndef LLHTTP_STRICT_MODE # define LLHTTP_STRICT_MODE 0