Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cmake_minimum_required(VERSION 3.5.1)
cmake_policy(SET CMP0069 NEW)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate on why this policy is used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really need this, it could go but is a nice to have. This policy allows to use the cmake variable to enable Link Time Optimization easily, by passing the -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON option. Those options help the compiler generated better code (usually smarter inlining) when there are multiple compilation units, so here potentially the http.c and api.c and llhttp.c files would produce better code when optimized in an 'inter-proceduraled' way.

https://www.llvm.org/docs/LinkTimeOptimization.html
https://cmake.org/cmake/help/latest/policy/CMP0069.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so when this policy is present - cmake will detect the compiler support and use -flto if it might?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON is passed on.


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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

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)
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ release: generate
cp -rf src/native/*.c release/src/
cp -rf src/llhttp.gyp release/
cp -rf src/common.gypi release/
cp -rf CMakeLists.txt release/
cp -rf README.md release/
cp -rf LICENSE-MIT release/

Expand All @@ -58,7 +59,7 @@ postversion: release
git checkout release --
cp -rf release/* ./
rm -rf release
git add include src *.gyp *.gypi README.md LICENSE-MIT
git add include src *.gyp *.gypi CMakeLists.txt README.md LICENSE-MIT
git commit -a -m "release: $(TAG)"
git tag "release/v$(TAG)"
git push && git push --tags
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down