From b2e4fd54cd5608879bcdedcaef24501f87cfa6f5 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Mon, 12 Mar 2018 09:43:25 -0400 Subject: [PATCH 1/3] Add CMake build --- CMakeLists.txt | 84 +++++++++++++++++++++++++++++++++++++++++++ cmake/Config.cmake.in | 4 +++ 2 files changed, 88 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..c4d9f6f0 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,84 @@ +cmake_minimum_required(VERSION 3.1) + +project(http-parser VERSION 2.8.0) + +add_library(http_parser "http_parser.c" "http_parser.h") +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + target_compile_definitions(http_parser PRIVATE HTTP_PARSER_STRICT=1) +else() + target_compile_definitions(http_parser PRIVATE HTTP_PARSER_STRICT=0) +endif() + +# Installation (https://github.com/forexample/package-example) + +# Layout. This works for all platforms: +# * /lib/cmake/ +# * /lib/ +# * /include/ +set(config_install_dir "lib/cmake/${PROJECT_NAME}") +set(include_install_dir "include") + +set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") + +# Configuration +set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") +set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") +set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") +set(namespace "${PROJECT_NAME}::") + +# Include module with fuction 'write_basic_package_version_file' +include(CMakePackageConfigHelpers) + +# Configure 'ConfigVersion.cmake' +# Use: +# * PROJECT_VERSION +write_basic_package_version_file( + "${version_config}" COMPATIBILITY SameMajorVersion +) + +# Configure 'Config.cmake' +# Use variables: +# * TARGETS_EXPORT_NAME +# * PROJECT_NAME +configure_package_config_file( + "cmake/Config.cmake.in" + "${project_config}" + INSTALL_DESTINATION "${config_install_dir}" +) + +# Targets: +# * /lib/libhttp_parser.a +# * header location after install: /include/http_parser.h +# * headers can be included by C++ code `#include ` +install( + TARGETS http_parser + EXPORT "${TARGETS_EXPORT_NAME}" + LIBRARY DESTINATION "lib" + ARCHIVE DESTINATION "lib" + RUNTIME DESTINATION "bin" + INCLUDES DESTINATION "${include_install_dir}" +) + +# Headers: +# * http_parser.h -> /include/http_parser.h +install( + DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + DESTINATION "${include_install_dir}" + FILES_MATCHING PATTERN "*.h" +) + +# Config +# * /lib/cmake/http-parser/http-parserConfig.cmake +# * /lib/cmake/http-parser/http-parserConfigVersion.cmake +install( + FILES "${project_config}" "${version_config}" + DESTINATION "${config_install_dir}" +) + +# Config +# * /lib/cmake/http-parser/http-parserTargets.cmake +install( + EXPORT "${TARGETS_EXPORT_NAME}" + NAMESPACE "${namespace}" + DESTINATION "${config_install_dir}" +) diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 00000000..38bbde7b --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") +check_required_components("@PROJECT_NAME@") From b3aea873bbadf8e03303a43734580c749fb7c192 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Mon, 12 Mar 2018 09:51:11 -0400 Subject: [PATCH 2/3] Fix install --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4d9f6f0..9ddd4a31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,9 +62,8 @@ install( # Headers: # * http_parser.h -> /include/http_parser.h install( - DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + FILES "${CMAKE_CURRENT_SOURCE_DIR}/http_parser.h" DESTINATION "${include_install_dir}" - FILES_MATCHING PATTERN "*.h" ) # Config From 754ffbb12537360a283ade196e980714ad44af61 Mon Sep 17 00:00:00 2001 From: Isaac Hier Date: Mon, 12 Mar 2018 11:50:00 -0400 Subject: [PATCH 3/3] Use generator expression for debug macro --- CMakeLists.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ddd4a31..17951560 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,11 +3,8 @@ cmake_minimum_required(VERSION 3.1) project(http-parser VERSION 2.8.0) add_library(http_parser "http_parser.c" "http_parser.h") -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - target_compile_definitions(http_parser PRIVATE HTTP_PARSER_STRICT=1) -else() - target_compile_definitions(http_parser PRIVATE HTTP_PARSER_STRICT=0) -endif() +target_compile_definitions(http_parser PRIVATE + "HTTP_PARSER_STRICT=$") # Installation (https://github.com/forexample/package-example)