Skip to content

Commit a0e744f

Browse files
authored
fix: Fixed CMake integration. (#226)
1 parent 14d263c commit a0e744f

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ configure_file(
4747
function(config_library target)
4848
target_sources(${target} PRIVATE ${LLHTTP_SOURCES} ${LLHTTP_HEADERS})
4949

50-
target_include_directories(${target} PRIVATE
51-
${CMAKE_CURRENT_SOURCE_DIR}/include
50+
target_include_directories(${target} PUBLIC
51+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
52+
$<INSTALL_INTERFACE:include>
5253
)
5354

5455
set_target_properties(${target} PROPERTIES
@@ -72,9 +73,10 @@ function(config_library target)
7273

7374
# This is required to work with FetchContent
7475
install(EXPORT llhttp
75-
FILE llhttp-config.cmake
76-
NAMESPACE llhttp::
77-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/llhttp)
76+
FILE llhttp-config.cmake
77+
NAMESPACE llhttp::
78+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/llhttp
79+
)
7880
endfunction(config_library target)
7981

8082
if(BUILD_SHARED_LIBS)

README.md

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,33 +61,41 @@ checks could be performed to get even stricter verification of the llhttp.
6161
## Usage
6262

6363
```C
64+
#include "stdio.h"
6465
#include "llhttp.h"
66+
#include "string.h"
6567

66-
llhttp_t parser;
67-
llhttp_settings_t settings;
68+
int handle_on_message_complete(llhttp_t* parser) {
69+
fprintf(stdout, "Message completed!\n");
70+
return 0;
71+
}
72+
73+
int main() {
74+
llhttp_t parser;
75+
llhttp_settings_t settings;
6876

69-
/* Initialize user callbacks and settings */
70-
llhttp_settings_init(&settings);
77+
/*Initialize user callbacks and settings */
78+
llhttp_settings_init(&settings);
7179

72-
/* Set user callback */
73-
settings.on_message_complete = handle_on_message_complete;
80+
/*Set user callback */
81+
settings.on_message_complete = handle_on_message_complete;
7482

75-
/* Initialize the parser in HTTP_BOTH mode, meaning that it will select between
76-
* HTTP_REQUEST and HTTP_RESPONSE parsing automatically while reading the first
77-
* input.
78-
*/
79-
llhttp_init(&parser, HTTP_BOTH, &settings);
83+
/*Initialize the parser in HTTP_BOTH mode, meaning that it will select between
84+
*HTTP_REQUEST and HTTP_RESPONSE parsing automatically while reading the first
85+
*input.
86+
*/
87+
llhttp_init(&parser, HTTP_BOTH, &settings);
8088

81-
/* Parse request! */
82-
const char* request = "GET / HTTP/1.1\r\n\r\n";
83-
int request_len = strlen(request);
89+
/*Parse request! */
90+
const char* request = "GET / HTTP/1.1\r\n\r\n";
91+
int request_len = strlen(request);
8492

85-
enum llhttp_errno err = llhttp_execute(&parser, request, request_len);
86-
if (err == HPE_OK) {
87-
/* Successfully parsed! */
88-
} else {
89-
fprintf(stderr, "Parse error: %s %s\n", llhttp_errno_name(err),
90-
parser.reason);
93+
enum llhttp_errno err = llhttp_execute(&parser, request, request_len);
94+
if (err == HPE_OK) {
95+
fprintf(stdout, "Successfully parsed!\n");
96+
} else {
97+
fprintf(stderr, "Parse error: %s %s\n", llhttp_errno_name(err), parser.reason);
98+
}
9199
}
92100
```
93101
For more information on API usage, please refer to [src/native/api.h](https://github.com/nodejs/llhttp/blob/main/src/native/api.h).

0 commit comments

Comments
 (0)