From 64896d0c2ddac01e53fd6b53d00e2815e0f2e257 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Thu, 24 Jun 2021 20:26:28 -0700 Subject: [PATCH 1/9] Add CMakeLists.txt --- CMakeLists.txt | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..547fdd9f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,52 @@ +cmake_minimum_required(VERSION 3.5.1) + +project(llhttp C ASM) + +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 + $ + $ +) + +set_target_properties(llhttp PROPERTIES PUBLIC_HEADER "include/llhttp.h") + +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) From b782f5436e43095e11d0a605afbc0135c8b68507 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Thu, 24 Jun 2021 20:27:30 -0700 Subject: [PATCH 2/9] copy CMakeList.txt to release folder --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index b0f3d643..27602ba8 100644 --- a/Makefile +++ b/Makefile @@ -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/ From 30fa9acf8833a2767395e174d5466d554a724bb9 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Thu, 24 Jun 2021 20:30:03 -0700 Subject: [PATCH 3/9] handle CMakeLists.txt in postversion --- Makefile | 2 +- package-lock.json | 29 ++++++++++++++++++++++++++++- package.json | 3 ++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 27602ba8..586f345a 100644 --- a/Makefile +++ b/Makefile @@ -59,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 diff --git a/package-lock.json b/package-lock.json index 7a774761..0d05c791 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "dependencies": { "@types/semver": "^5.5.0", "llparse": "^7.1.1", - "semver": "^5.7.1" + "semver": "^5.7.1", + "ts-core": "^0.6.4" }, "devDependencies": { "@types/mocha": "^5.2.7", @@ -1556,6 +1557,14 @@ "node": ">=8.0" } }, + "node_modules/ts-core": { + "version": "0.6.4", + "resolved": "https://registry.npmjs.org/ts-core/-/ts-core-0.6.4.tgz", + "integrity": "sha1-RseXaDc+7amAu4EeyaIujLkJBAM=", + "dependencies": { + "underscore": "^1.8.3" + } + }, "node_modules/ts-node": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz", @@ -1669,6 +1678,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/underscore": { + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.1.tgz", + "integrity": "sha512-hzSoAVtJF+3ZtiFX0VgfFPHEDRm7Y/QPjGyNo4TVdnDTdft3tr8hEkD25a1jC+TjTuE7tkHGKkhwCgs9dgBB2g==" + }, "node_modules/which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", @@ -3243,6 +3257,14 @@ "is-number": "^7.0.0" } }, + "ts-core": { + "version": "0.6.4", + "resolved": "https://registry.npmjs.org/ts-core/-/ts-core-0.6.4.tgz", + "integrity": "sha1-RseXaDc+7amAu4EeyaIujLkJBAM=", + "requires": { + "underscore": "^1.8.3" + } + }, "ts-node": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz", @@ -3327,6 +3349,11 @@ "which-boxed-primitive": "^1.0.2" } }, + "underscore": { + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.1.tgz", + "integrity": "sha512-hzSoAVtJF+3ZtiFX0VgfFPHEDRm7Y/QPjGyNo4TVdnDTdft3tr8hEkD25a1jC+TjTuE7tkHGKkhwCgs9dgBB2g==" + }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", diff --git a/package.json b/package.json index 224bef3d..5ce68632 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "dependencies": { "@types/semver": "^5.5.0", "llparse": "^7.1.1", - "semver": "^5.7.1" + "semver": "^5.7.1", + "ts-core": "^0.6.4" } } From 592f1703bc88889dcf44b7ef26d04c34d94cf6c7 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Thu, 24 Jun 2021 20:52:42 -0700 Subject: [PATCH 4/9] rever package.json change --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 5ce68632..224bef3d 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ "dependencies": { "@types/semver": "^5.5.0", "llparse": "^7.1.1", - "semver": "^5.7.1", - "ts-core": "^0.6.4" + "semver": "^5.7.1" } } From 9d5d81677fec3dd896cb488bdabcb9f8c2ba5147 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Thu, 24 Jun 2021 20:54:01 -0700 Subject: [PATCH 5/9] rever package-lock.json change --- package-lock.json | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0d05c791..7a774761 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,7 @@ "dependencies": { "@types/semver": "^5.5.0", "llparse": "^7.1.1", - "semver": "^5.7.1", - "ts-core": "^0.6.4" + "semver": "^5.7.1" }, "devDependencies": { "@types/mocha": "^5.2.7", @@ -1557,14 +1556,6 @@ "node": ">=8.0" } }, - "node_modules/ts-core": { - "version": "0.6.4", - "resolved": "https://registry.npmjs.org/ts-core/-/ts-core-0.6.4.tgz", - "integrity": "sha1-RseXaDc+7amAu4EeyaIujLkJBAM=", - "dependencies": { - "underscore": "^1.8.3" - } - }, "node_modules/ts-node": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz", @@ -1678,11 +1669,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/underscore": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.1.tgz", - "integrity": "sha512-hzSoAVtJF+3ZtiFX0VgfFPHEDRm7Y/QPjGyNo4TVdnDTdft3tr8hEkD25a1jC+TjTuE7tkHGKkhwCgs9dgBB2g==" - }, "node_modules/which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", @@ -3257,14 +3243,6 @@ "is-number": "^7.0.0" } }, - "ts-core": { - "version": "0.6.4", - "resolved": "https://registry.npmjs.org/ts-core/-/ts-core-0.6.4.tgz", - "integrity": "sha1-RseXaDc+7amAu4EeyaIujLkJBAM=", - "requires": { - "underscore": "^1.8.3" - } - }, "ts-node": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz", @@ -3349,11 +3327,6 @@ "which-boxed-primitive": "^1.0.2" } }, - "underscore": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.1.tgz", - "integrity": "sha512-hzSoAVtJF+3ZtiFX0VgfFPHEDRm7Y/QPjGyNo4TVdnDTdft3tr8hEkD25a1jC+TjTuE7tkHGKkhwCgs9dgBB2g==" - }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", From 33bad3e123d47f65d7e6d118cc48fe1ffd606f12 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Thu, 24 Jun 2021 21:01:23 -0700 Subject: [PATCH 6/9] update readme to mention cmake --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index fcbf86c1..1c37cf66 100644 --- a/README.md +++ b/README.md @@ -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. From 7f7c649e10d5dcd42b270c617566503918af88fa Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Fri, 25 Jun 2021 10:41:17 -0700 Subject: [PATCH 7/9] project is C only, not ASM, set lto policy --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 547fdd9f..41d2000e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.5.1) +cmake_policy(SET CMP0069 NEW) -project(llhttp C ASM) +project(llhttp C) set(CMAKE_C_STANDARD 99) @@ -37,7 +38,7 @@ target_include_directories(llhttp PUBLIC $ ) -set_target_properties(llhttp PROPERTIES PUBLIC_HEADER "include/llhttp.h") +set_target_properties(llhttp PROPERTIES PUBLIC_HEADER ${LLHTTP_HEADERS}) install(TARGETS llhttp EXPORT llhttp From 067e45eba422d083ad544352b65cbe8531fdc2aa Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Tue, 29 Jun 2021 22:00:49 -0700 Subject: [PATCH 8/9] Update README to use v6.0.5 in the CMake example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1c37cf66..de0bba0b 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ 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 + URL "https://github.com/nodejs/llhttp/releases/download/v6.0.5/llhttp-release-v6.0.5.tar.gz") # Using version 6.0.4 FetchContent_MakeAvailable(llhttp) From c5d425f04fe96a87f4e113f0d940e8406bb34671 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Tue, 29 Jun 2021 22:03:38 -0700 Subject: [PATCH 9/9] 6.0.4 -> 6.0.5 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index de0bba0b..aa6b8e78 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ 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.5/llhttp-release-v6.0.5.tar.gz") # Using version 6.0.4 + URL "https://github.com/nodejs/llhttp/releases/download/v6.0.5/llhttp-release-v6.0.5.tar.gz") # Using version 6.0.5 FetchContent_MakeAvailable(llhttp)