-
-
Notifications
You must be signed in to change notification settings - Fork 214
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
Merged
Merged
Add CMakeLists.txt #122
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
64896d0
Add CMakeLists.txt
bsergean b782f54
copy CMakeList.txt to release folder
bsergean 30fa9ac
handle CMakeLists.txt in postversion
bsergean 592f170
rever package.json change
bsergean 9d5d816
rever package-lock.json change
bsergean 33bad3e
update readme to mention cmake
bsergean 7f7c649
project is C only, not ASM, set lto policy
bsergean File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.