-
-
Notifications
You must be signed in to change notification settings - Fork 213
Add CMakeLists.txt #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CMakeLists.txt #122
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
FYI I added a gist with 2 files showing how to use this. https://gist.github.com/bsergean/20322145cc4fcb3de4aa2f366621fc62 |
Thanks a lot! Merged. |
PR-URL: nodejs/llhttp#122 Reviewed-By: Fedor Indutny <[email protected]>
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.