Use CMake's FetchContent and remove git submodules

Submodules get included in the source tarball generated by meson dist,
making dpkg-source throw a lot of warnings.

Using FetchContent instead of submodules has a few advantages:
Solves packaging warnings
Faster git clone
External dependencies get downloaded only if needed
parent f3080e9e
[submodule "third-party/rapidjson"]
path = third-party/rapidjson
url = https://github.com/Tencent/rapidjson
branch = v1.1.0
[submodule "third-party/googletest"]
path = third-party/googletest
url = https://github.com/google/googletest.git
branch = release-1.7.0
......@@ -36,6 +36,7 @@ _apt_pkgs: &_apt_pkgs
- 'python3-setuptools'
- 'ninja-build'
- 'libblocksruntime-dev'
- 'rapidjson-dev'
_apt_srcs: &_apt_srcs
- 'ubuntu-toolchain-r-test'
......@@ -254,24 +255,24 @@ before_script:
- initctl list || true
# CMake debug build
- cmake -H.
-BBuild-Debug
- cmake -S .
-B cmake_build_debug
-DCMAKE_BUILD_TYPE=Debug
-DPISTACHE_BUILD_EXAMPLES=true
-DPISTACHE_BUILD_TESTS=true
-DPISTACHE_USE_SSL=true
# CMake debug build, no SSL
- cmake -H.
-BBuild-Debug-nossl
- cmake -S .
-B cmake_build_debug-nossl
-DCMAKE_BUILD_TYPE=Debug
-DPISTACHE_BUILD_EXAMPLES=true
-DPISTACHE_BUILD_TESTS=true
-DPISTACHE_USE_SSL=false
# CMake release build
- cmake -H.
-BBuild-Release
- cmake -S .
-B cmake_build_release
-DCMAKE_BUILD_TYPE=Release
-DPISTACHE_USE_SSL=true
......@@ -301,19 +302,19 @@ script:
- ulimit -c unlimited -S
# CMake debug build
- make -C Build-Debug --jobs 2 all test ARGS="-V"
- cmake --build cmake_build_debug --parallel 2 --target all test -- ARGS='-V'
# CMake debug build, no SSL
- make -C Build-Debug-nossl --jobs 2 all test ARGS="-V"
- cmake --build cmake_build_debug-nossl --parallel 2 --target all test -- ARGS='-V'
# CMake release build
- make -C Build-Release --jobs 2
- cmake --build cmake_build_release --parallel 2 -- ARGS='-V'
# Meson debug build
- meson compile -C meson_build_debug --jobs 2 && meson test -C meson_build_debug
- meson compile -C meson_build_debug --jobs 2 && meson test -C meson_build_debug || (cat meson_build_debug/meson-logs/testlog.txt && false)
# Meson debug build, no SSL
- meson compile -C meson_build_debug_nossl --jobs 2 && meson test -C meson_build_debug_nossl
- meson compile -C meson_build_debug_nossl --jobs 2 && meson test -C meson_build_debug_nossl || (cat meson_build_debug/meson-logs/testlog.txt && false)
# Meson release build
- meson compile -C meson_build_release --jobs 2
......@@ -330,6 +331,6 @@ after_failure:
after_success:
- sudo su -c "echo 'if [ \"\$1\" = \"-v\" ] ; then $COV_TOOL --version ; else $COV_TOOL $COV_TOOL_ARGS \$@ ; fi' > /usr/local/bin/cov-tool" && sudo chmod +x /usr/local/bin/cov-tool
- lcov --capture --gcov-tool cov-tool --directory . --output-file coverage.info
- lcov --remove coverage.info '/usr/*' '*tests/*' '*third-party/*' --output-file coverage.info
- lcov --remove coverage.info '/usr/*' '*tests/*' '*examples/*' '*subprojects/*' --output-file coverage.info
- lcov --list coverage.info
- bash <(curl -s https://codecov.io/bash) -f coverage.info || echo "Codecov did not collect coverage reports"
cmake_minimum_required (VERSION 3.9)
cmake_minimum_required (VERSION 3.11)
set(CMAKE_BUILD_TYPE_INIT Release)
......@@ -177,10 +177,20 @@ if (PISTACHE_BUILD_EXAMPLES)
endif()
if (PISTACHE_BUILD_TESTS)
find_package(GTest)
find_package(GTest QUIET)
if (NOT GTEST_FOUND)
ADD_SUBDIRECTORY (third-party/googletest)
set(GTEST_INCLUDE_DIRS ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_SHALLOW true
)
set(BUILD_GMOCK OFF CACHE BOOL "")
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif()
endif()
enable_testing()
......
#-------------------------------------------------------------------------------
# Copyright (c) 2013-2013, Lars Baehren <lbaehren@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#-------------------------------------------------------------------------------
# - Check for the presence of RAPIDJSON
#
# The following variables are set when RAPIDJSON is found:
# RAPIDJSON_FOUND = Set to true, if all components of RapidJSON have been
# found.
# RAPIDJSON_INCLUDES = Include path for the header files of RAPIDJSON
# RAPIDJSON_LIBRARIES = Link these to use RAPIDJSON
# RAPIDJSON_LFLAGS = Linker flags (optional)
if (NOT RAPIDJSON_FOUND)
if (NOT RAPIDJSON_ROOT_DIR)
set (RAPIDJSON_ROOT_DIR ${CMAKE_INSTALL_PREFIX})
endif (NOT RAPIDJSON_ROOT_DIR)
##____________________________________________________________________________
## Check for the header files
find_path (RAPIDJSON_INCLUDES
NAMES rapidjson/rapidjson.h rapidjson/reader.h rapidjson/writer.h
HINTS ${RAPIDJSON_ROOT_DIR} ${CMAKE_INSTALL_PREFIX}
PATH_SUFFIXES include
)
##____________________________________________________________________________
## Actions taken when all components have been found
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (RAPIDJSON DEFAULT_MSG RAPIDJSON_INCLUDES)
if (RAPIDJSON_FOUND)
## Update
get_filename_component (RAPIDJSON_ROOT_DIR ${RAPIDJSON_INCLUDES} PATH)
## Feedback
if (NOT RAPIDJSON_FIND_QUIETLY)
message (STATUS "Found components for RapidJSON")
message (STATUS "RAPIDJSON_ROOT_DIR = ${RAPIDJSON_ROOT_DIR}")
message (STATUS "RAPIDJSON_INCLUDES = ${RAPIDJSON_INCLUDES}")
endif (NOT RAPIDJSON_FIND_QUIETLY)
else (RAPIDJSON_FOUND)
if (RAPIDJSON_FIND_REQUIRED)
message (FATAL_ERROR "Could not find RapidJSON!")
endif (RAPIDJSON_FIND_REQUIRED)
endif (RAPIDJSON_FOUND)
##____________________________________________________________________________
## Mark advanced variables
mark_as_advanced (
RAPIDJSON_ROOT_DIR
RAPIDJSON_INCLUDES
)
endif (NOT RAPIDJSON_FOUND)
\ No newline at end of file
......@@ -14,7 +14,7 @@ We are still looking for a volunteer to document fully the API. In the mean time
Pistache has the following third party dependencies
- [CMake](https://cmake.org)
- [Meson](https://mesonbuild.com)
- [Doxygen](https://www.doxygen.nl/)
- [Googletest](https://github.com/google/googletest)
- [OpenSSL](https://www.openssl.org/)
......@@ -116,21 +116,6 @@ YOURPROJECT_CXXFLAGS="$YOURPROJECT_CXXFLAGS $libpistache_CFLAGS"
YOURPROJECT_LIBS="$YOURPROJECT_LIBS $libpistache_LIBS"
```
### CMake
To use with a CMake build environment, use the [FindPkgConfig](https://cmake.org/cmake/help/latest/module/FindPkgConfig.html) module. Here is an example:
```cmake
cmake_minimum_required(3.4 FATAL_ERROR)
project("MyPistacheProject")
# Find the library.
find_package(Pistache 0.0.2 REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} pistache_shared)
```
### Meson
To use with Meson, you just need to add `dependency('pistache')` as a dependency for your executable. If you have this repository as a submodule in the `subprojects` directory of your project, Meson will automatically build the library from source if it is not installed on the system.
......@@ -139,7 +124,7 @@ To use with Meson, you just need to add `dependency('pistache')` as a dependency
project(
'MyPistacheProject',
'cpp',
meson_version: '>=0.57.0'
meson_version: '>=0.55.0'
)
executable(
......@@ -155,6 +140,21 @@ If you're using a Meson version older than 0.55.0 you'll have to use the "older"
dependencies: dependency('pistache', fallback ['pistache', 'pistache_static_dep'])
```
### CMake
To use with a CMake build environment, use the [FindPkgConfig](https://cmake.org/cmake/help/latest/module/FindPkgConfig.html) module. Here is an example:
```cmake
cmake_minimum_required(3.4 FATAL_ERROR)
project("MyPistacheProject")
# Find the library.
find_package(Pistache 0.0.2 REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} pistache_shared)
```
### Makefile
To use within a vanilla makefile, you can call `pkg-config` directly to supply compiler and linker flags using shell substitution.
......@@ -172,44 +172,33 @@ LDFLAGS+= $(pkg-config --libs libpistache)
To download the latest available release, clone the repository over GitHub.
```sh
$ git clone https://github.com/pistacheio/pistache.git --recurse-submodules
$ git clone https://github.com/pistacheio/pistache.git
```
Now, compile the sources:
```sh
$ cd pistache
$ mkdir -p {build,prefix}
$ cd build
$ cmake -G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Release \
$ meson setup build \
--buildtype=release \
-DPISTACHE_USE_SSL=true \
-DPISTACHE_BUILD_EXAMPLES=true \
-DPISTACHE_BUILD_TESTS=true \
-DPISTACHE_BUILD_DOCS=false \
-DPISTACHE_USE_SSL=true \
-DCMAKE_INSTALL_PREFIX=$PWD/../prefix \
../
$ make -j
$ make install
```
If you chose to build the examples, then perform the following to build the examples.
```sh
$ cd examples
$ make -j
--prefix=$PWD/prefix
$ meson compile -C build
$ meson install -C build
```
Optionally, you can also build and run the tests (tests require the examples):
Optionally, you can also run the tests:
```sh
$ cmake -G "Unix Makefiles" -DPISTACHE_BUILD_EXAMPLES=true -DPISTACHE_BUILD_TESTS=true ..
$ make test test_memcheck
$ meson test -C build
```
Be patient, async_test can take some time before completing. And that's it, now you can start playing with your newly installed Pistache framework.
Some other CMake and Meson options:
Some other Meson and CMake options:
| Option | Default | Description |
|-------------------------------|-------------|------------------------------------------------|
......@@ -249,7 +238,7 @@ Generate a Pistache source package in the parent directory of `pistache_source`:
$ cd pistache_source
$ sudo apt build-dep pistache
$ ./debian/rules get-orig-source
$ debuild -S -sa -uc
$ debuild -S -sa -uc -us
```
Test the source package on the host architecture in QEMU with KVM support and 8GB of RAM and four CPUs:
......
......@@ -4,7 +4,6 @@ USE_MDFILE_AS_MAINPAGE = @CMAKE_SOURCE_DIR@/README.md
EXCLUDE_PATTERNS = */.git/*
EXCLUDE_PATTERNS += */subprojects/*
EXCLUDE_PATTERNS += */tests/*
EXCLUDE_PATTERNS += */third-party/*
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = @PROJECT_NAME@
......
......@@ -13,12 +13,25 @@ pistache_example(rest_server)
pistache_example(custom_header)
pistache_example(http_server_shutdown)
set(RAPIDJSON_ROOT_DIR PATH "${PROJECT_SOURCE_DIR}/third-party/rapidjson")
find_package(RapidJSON)
if (RAPIDJSON_FOUND)
include_directories(${RAPIDJSON_INCLUDES})
find_package(RapidJSON QUIET)
if (NOT RapidJSON_FOUND)
include(FetchContent)
FetchContent_Declare(
RapidJSON
GIT_REPOSITORY https://github.com/Tencent/rapidjson.git
GIT_TAG v1.1.0
GIT_SHALLOW true
)
set(RAPIDJSON_BUILD_DOC OFF CACHE BOOL "")
set(RAPIDJSON_BUILD_EXAMPLES OFF CACHE BOOL "")
set(RAPIDJSON_BUILD_TESTS OFF CACHE BOOL "")
if(NOT RapidJSON_POPULATED)
FetchContent_Populate(RapidJSON)
add_subdirectory(${rapidjson_SOURCE_DIR} ${rapidjson_BINARY_DIR})
endif()
pistache_example(rest_description)
target_include_directories(run_rest_description PRIVATE ${rapidjson_SOURCE_DIR}/include)
else()
message(FATAL_ERROR "RapidJSON not found. Could not build rest_description example.")
pistache_example(rest_description)
target_include_directories(run_rest_description PRIVATE ${RAPIDJSON_INCLUDE_DIRS})
endif()
......@@ -11,4 +11,3 @@ Requires:
Libs: -L'${libdir}/' @libs@
Libs.private:
Cflags: -I'${includedir}/'
Subproject commit c99458533a9b4c743ed51537e25989ea55944908
Subproject commit f54b0e47a08782a6131cc3d60f94d038fa6e0a51
......@@ -5,4 +5,3 @@ VERSION_GIT_DATE 20210107
SONAME_VERSION_MAJOR 0
SONAME_VERSION_MINOR 0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment