Skip to content

Conversation

bsergean
Copy link
Contributor

This will make it easier for cmake users (which is a bunch of C++ users those days) to use llhttp.

This is an example cmake snippet to bring in your library in a CMake project.

FetchContent_Declare(llhttp
  URL "https://github.com/bsergean/llhttp/releases/download/v6.0.3/llhttp-release-v6.0.3.tar.gz")

FetchContent_MakeAvailable(llhttp)

target_link_libraries(${EXAMPLE_PROJECT_NAME} ${PROJECT_LIBRARIES} llhttp ${PROJECT_NAME})

@bsergean bsergean mentioned this pull request Jun 25, 2021
Copy link
Member

@indutny indutny left a comment

Choose a reason for hiding this comment

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

LGTM with a question. Thanks for submitting it!

@@ -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.

Copy link
Member

@indutny indutny left a comment

Choose a reason for hiding this comment

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

LGTM

@bsergean
Copy link
Contributor Author

FYI I added a gist with 2 files showing how to use this.

https://gist.github.com/bsergean/20322145cc4fcb3de4aa2f366621fc62

@indutny indutny merged commit 7e9668b into nodejs:master Jun 27, 2021
@indutny
Copy link
Member

indutny commented Jun 27, 2021

Thanks a lot! Merged.

alex-dev-2012 added a commit to alex-dev-2012/llhttp that referenced this pull request Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants