Skip to content

Commit 7e9668b

Browse files
authored
build: add CMakeLists.txt
PR-URL: #122 Reviewed-By: Fedor Indutny <[email protected]>
1 parent e353c59 commit 7e9668b

3 files changed

Lines changed: 69 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
cmake_minimum_required(VERSION 3.5.1)
2+
cmake_policy(SET CMP0069 NEW)
3+
4+
project(llhttp C)
5+
6+
set(CMAKE_C_STANDARD 99)
7+
8+
#
9+
# Options
10+
#
11+
# Generic option
12+
option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF)
13+
14+
# Source code
15+
set(LLHTTP_SOURCES
16+
src/llhttp.c
17+
src/http.c
18+
src/api.c
19+
)
20+
21+
set(LLHTTP_HEADERS
22+
include/llhttp.h
23+
)
24+
25+
add_library(llhttp)
26+
add_library(llhttp::llhttp ALIAS llhttp)
27+
28+
target_sources(llhttp PRIVATE ${LLHTTP_SOURCES} ${LLHTTP_HEADERS})
29+
30+
# On windows with Visual Studio, add a debug postfix so that release
31+
# and debug libraries can coexist.
32+
if(MSVC)
33+
set(CMAKE_DEBUG_POSTFIX "d")
34+
endif()
35+
36+
target_include_directories(llhttp PUBLIC
37+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
38+
$<INSTALL_INTERFACE:include>
39+
)
40+
41+
set_target_properties(llhttp PROPERTIES PUBLIC_HEADER ${LLHTTP_HEADERS})
42+
43+
install(TARGETS llhttp
44+
EXPORT llhttp
45+
ARCHIVE DESTINATION lib
46+
PUBLIC_HEADER DESTINATION include/
47+
)
48+
49+
# This is required to work with FetchContent
50+
install(EXPORT llhttp
51+
FILE llhttp-config.cmake
52+
NAMESPACE llhttp::
53+
DESTINATION lib/cmake/llhttp)

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ release: generate
5050
cp -rf src/native/*.c release/src/
5151
cp -rf src/llhttp.gyp release/
5252
cp -rf src/common.gypi release/
53+
cp -rf CMakeLists.txt release/
5354
cp -rf README.md release/
5455
cp -rf LICENSE-MIT release/
5556

@@ -58,7 +59,7 @@ postversion: release
5859
git checkout release --
5960
cp -rf release/* ./
6061
rm -rf release
61-
git add include src *.gyp *.gypi README.md LICENSE-MIT
62+
git add include src *.gyp *.gypi CMakeLists.txt README.md LICENSE-MIT
6263
git commit -a -m "release: $(TAG)"
6364
git tag "release/v$(TAG)"
6465
git push && git push --tags

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ For more information on API usage, please refer to [src/native/api.h](https://gi
9999
* Python: [pallas/pyllhttp][8]
100100
* Ruby: [metabahn/llhttp][9]
101101
102+
103+
### Using with CMake
104+
105+
If you want to use this library in a CMake project you can use the snippet below.
106+
107+
```
108+
FetchContent_Declare(llhttp
109+
URL "https://github.com/nodejs/llhttp/releases/download/v6.0.4/llhttp-release-v6.0.4.tar.gz") # Using version 6.0.4
110+
111+
FetchContent_MakeAvailable(llhttp)
112+
113+
target_link_libraries(${EXAMPLE_PROJECT_NAME} ${PROJECT_LIBRARIES} llhttp ${PROJECT_NAME})
114+
```
115+
102116
#### LICENSE
103117
104118
This software is licensed under the MIT License.

0 commit comments

Comments
 (0)