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
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ endif()
# Options
#
# Generic option
option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so)" ON)
option(BUILD_STATIC_LIBS "Build static libraries (.lib/.a)" OFF)
option(LLHTTP_BUILD_SHARED_LIBS "Build shared libraries (.dll/.so)" ON)
option(LLHTTP_BUILD_STATIC_LIBS "Build static libraries (.lib/.a)" OFF)

# Source code
set(LLHTTP_SOURCES
Expand Down Expand Up @@ -80,19 +80,19 @@ function(config_library target)
)
endfunction(config_library target)

if(BUILD_SHARED_LIBS)
if(LLHTTP_BUILD_SHARED_LIBS)
add_library(llhttp_shared SHARED
${llhttp_src}
)
add_library(llhttp::llhttp ALIAS llhttp_shared)
config_library(llhttp_shared)
endif()

if(BUILD_STATIC_LIBS)
if(LLHTTP_BUILD_STATIC_LIBS)
add_library(llhttp_static STATIC
${llhttp_src}
)
if(NOT BUILD_SHARED_LIBS)
if(NOT LLHTTP_BUILD_SHARED_LIBS)
add_library(llhttp::llhttp ALIAS llhttp_static)
endif()
config_library(llhttp_static)
Expand All @@ -111,6 +111,6 @@ message(STATUS "Project configure summary:")
message(STATUS "")
message(STATUS " CMake build type .................: ${CMAKE_BUILD_TYPE}")
message(STATUS " Install prefix ...................: ${CMAKE_INSTALL_PREFIX}")
message(STATUS " Build shared library .............: ${BUILD_SHARED_LIBS}")
message(STATUS " Build static library .............: ${BUILD_STATIC_LIBS}")
message(STATUS " Build shared library .............: ${LLHTTP_BUILD_SHARED_LIBS}")
message(STATUS " Build static library .............: ${LLHTTP_BUILD_STATIC_LIBS}")
message(STATUS "")
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,16 @@ If you want to use this library in a CMake project as a static library, you can
FetchContent_Declare(llhttp
URL "https://github.com/nodejs/llhttp/archive/refs/tags/release/v8.1.0.tar.gz")

set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
set(BUILD_STATIC_LIBS ON CACHE INTERNAL "")
set(LLHTTP_BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
set(LLHTTP_BUILD_STATIC_LIBS ON CACHE INTERNAL "")
FetchContent_MakeAvailable(llhttp)

# Link with the llhttp_static target
target_link_libraries(${EXAMPLE_PROJECT_NAME} ${PROJECT_LIBRARIES} llhttp_static ${PROJECT_NAME})
```

If using a version prior to 9.3.0, the `LLHTTP_BUILD_SHARED_LIBS` and `LLHTTP_BUILD_STATIC_LIBS` options are known as `BUILD_SHARED_LIBS` and `BUILD_STATIC_LIBS` and should be used instead.

_Note that using the git repo directly (e.g., via a git repo url and tag) will not work with FetchContent_Declare because [CMakeLists.txt](./CMakeLists.txt) requires string replacements (e.g., `_RELEASE_`) before it will build._

## Building on Windows
Expand Down
Loading