Skip to content
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

cmake: cpptoml allow usage of installed dependency #40

Merged
merged 17 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from 15 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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "deps/Catch2"]
path = deps/Catch2
url = https://github.com/catchorg/Catch2.git
[submodule "deps/cpptoml"]
path = deps/cpptoml
url = https://github.com/skystrife/cpptoml.git
39 changes: 25 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ git:
matrix:
include:
# ubuntu 14.04, gcc-4.9
- env: ["VER=4.9"]
- env: ["VER=4.9", "EXT=YES"]
compiler: gcc
os: linux
dist: trusty
Expand All @@ -20,7 +20,7 @@ matrix:
- ubuntu-toolchain-r-test

# ubuntu 14.04, gcc-5
- env: ["VER=5", "COV=YES"]
- env: ["VER=5", "COV=YES", "EXT=YES"]
compiler: gcc
os: linux
dist: trusty
Expand All @@ -33,7 +33,7 @@ matrix:
- ubuntu-toolchain-r-test

# ubuntu 14.04, gcc-6
- env: ["VER=6"]
- env: ["VER=6", "EXT=YES"]
davidwed marked this conversation as resolved.
Show resolved Hide resolved
compiler: gcc
os: linux
dist: trusty
Expand All @@ -46,7 +46,7 @@ matrix:
- ubuntu-toolchain-r-test

# ubuntu 14.04, gcc-7
- env: ["VER=7"]
- env: ["VER=7", "EXT=YES"]
compiler: gcc
os: linux
dist: trusty
Expand All @@ -59,7 +59,7 @@ matrix:
- ubuntu-toolchain-r-test

# ubuntu 14.04, clang-3.4
- env: ["VER=3.4"]
- env: ["VER=3.4", "EXT=YES"]
compiler: clang
os: linux
dist: trusty
Expand All @@ -74,7 +74,7 @@ matrix:
key_url: http://apt.llvm.org/llvm-snapshot.gpg.key

# ubuntu 14.04, clang-3.5
- env: ["VER=3.5"]
- env: ["VER=3.5", "EXT=YES"]
compiler: clang
os: linux
dist: trusty
Expand All @@ -89,7 +89,7 @@ matrix:
key_url: http://apt.llvm.org/llvm-snapshot.gpg.key

# ubuntu 14.04, clang-3.6
- env: ["VER=3.6"]
- env: ["VER=3.6", "EXT=YES"]
compiler: clang
os: linux
dist: trusty
Expand All @@ -104,7 +104,7 @@ matrix:
key_url: http://apt.llvm.org/llvm-snapshot.gpg.key

# ubuntu 14.04, clang-3.7
- env: ["VER=3.7"]
- env: ["VER=3.7", "EXT=YES"]
compiler: clang
os: linux
dist: trusty
Expand All @@ -119,7 +119,7 @@ matrix:
key_url: http://apt.llvm.org/llvm-snapshot.gpg.key

# ubuntu 14.04, clang-3.8
- env: ["VER=3.8"]
- env: ["VER=3.8", "EXT=YES"]
compiler: clang
os: linux
dist: trusty
Expand All @@ -134,7 +134,7 @@ matrix:
key_url: http://apt.llvm.org/llvm-snapshot.gpg.key

# ubuntu 14.04, clang-3.9
- env: ["VER=3.9"]
- env: ["VER=3.9", "EXT=YES"]
compiler: clang
os: linux
dist: trusty
Expand All @@ -149,7 +149,7 @@ matrix:
key_url: http://apt.llvm.org/llvm-snapshot.gpg.key

# ubuntu 14.04, clang-4.0
- env: ["VER=4.0"]
- env: ["VER=4.0", "EXT=YES"]
compiler: clang
os: linux
dist: trusty
Expand All @@ -164,7 +164,7 @@ matrix:
key_url: http://apt.llvm.org/llvm-snapshot.gpg.key

# ubuntu 14.04, clang-5.0
- env: ["VER=5.0"]
- env: ["VER=5.0", "EXT=YES"]
compiler: clang
os: linux
dist: trusty
Expand All @@ -179,7 +179,7 @@ matrix:
key_url: http://apt.llvm.org/llvm-snapshot.gpg.key

# ubuntu 14.04, clang-6.0
- env: ["VER=6.0"]
- env: ["VER=6.0", "EXT=YES"]
compiler: clang
os: linux
dist: trusty
Expand Down Expand Up @@ -226,11 +226,22 @@ script:
(
set -x

if [ "${COV}" = "YES" ] && [ "${BUILD}" = "Debug" ]; then
if [ "${EXT}" = "YES" ] && [ "${COV}" = "YES" ] && [ "${BUILD}" = "Debug" ]; then
cmake -DCMAKE_BUILD_TYPE="${BUILD}" \
-DCMAKE_INSTALL_PREFIX:PATH=install \
-DSPDLOG_SETUP_INCLUDE_UNIT_TESTS=ON \
-DSPDLOG_SETUP_INCLUDE_TEST_COVERAGE=ON \
-DSPDLOG_SETUP_CPPTOML_EXTERNAL=ON ..
elif [ "${COV}" = "YES" ] && [ "${BUILD}" = "Debug" ]; then
cmake -DCMAKE_BUILD_TYPE="${BUILD}" \
-DCMAKE_INSTALL_PREFIX:PATH=install \
-DSPDLOG_SETUP_INCLUDE_UNIT_TESTS=ON \
-DSPDLOG_SETUP_INCLUDE_TEST_COVERAGE=ON ..
elif [ "${EXT}" = "YES" ] && [ "${BUILD}" = "Debug" ]; then
cmake -DCMAKE_BUILD_TYPE="${BUILD}" \
-DCMAKE_INSTALL_PREFIX:PATH=install \
-DSPDLOG_SETUP_INCLUDE_UNIT_TESTS=ON \
-DSPDLOG_SETUP_CPPTOML_EXTERNAL=ON ..
else
cmake -DCMAKE_BUILD_TYPE="${BUILD}" \
-DCMAKE_INSTALL_PREFIX:PATH=install \
Expand Down
33 changes: 32 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.3)
# project variables
project(spdlog_setup VERSION 0.3.0 LANGUAGES CXX)
set(SPDLOG_MIN_VERSION "1.0.0")
set(CPPTOML_MIN_VERSION "0.1.0")

# general fixed compiler settings
if(${MSVC})
Expand All @@ -17,6 +18,13 @@ else()
set(DEBUG_FLAGS -Wall)
endif()

option(SPDLOG_SETUP_INCLUDE_UNIT_TESTS "Build with unittests" OFF)

option(SPDLOG_SETUP_CPPTOML_EXTERNAL "Use external CPPTOML library instead of bundled" OFF)
if(SPDLOG_SETUP_CPPTOML_EXTERNAL)
configure_file(cmake/cpptoml_config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/spdlog_setup/details/third_party/cpptoml.h" @ONLY)
endif()

# allow thread library to be used for linking
set(THREADS_PREFER_PTHREAD_FLAG ON)
set(THREADS_PTHREAD_ARG "0" CACHE STRING "Result from TRY_RUN" FORCE)
Expand All @@ -30,7 +38,17 @@ if (EXISTS ${CMAKE_SOURCE_DIR}/deps/spdlog/CMakeLists.txt)
else()
# allow usage of installed dependency
find_package(spdlog ${SPDLOG_MIN_VERSION} REQUIRED)
add_library(spdlog INTERFACE IMPORTED)
add_library(${PROJECT_NAME}_spdlog INTERFACE IMPORTED)
endif()

if(SPDLOG_SETUP_CPPTOML_EXTERNAL)
if (EXISTS ${CMAKE_SOURCE_DIR}/deps/cpptoml/CMakeLists.txt)
add_subdirectory(deps/cpptoml)
else()
# allow usage of installed dependency
find_package(cpptoml ${CPPTOML_MIN_VERSION} REQUIRED)
add_library(${PROJECT_NAME}_cpptoml INTERFACE IMPORTED)
endif()
endif()

# spdlog_setup
Expand Down Expand Up @@ -73,6 +91,13 @@ install(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/spdlog_setup-config-version.cmake"
DESTINATION lib/cmake/spdlog_setup)

if(SPDLOG_SETUP_CPPTOML_EXTERNAL)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/include/spdlog_setup/details/third_party/cpptoml.h"
DESTINATION include/spdlog_setup/details/third_party)
endif()

# spdlog_setup_unit_test
if(SPDLOG_SETUP_INCLUDE_UNIT_TESTS)
add_executable(spdlog_setup_unit_test
Expand All @@ -88,6 +113,12 @@ if(SPDLOG_SETUP_INCLUDE_UNIT_TESTS)
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/Catch2/single_include>)

if(SPDLOG_SETUP_CPPTOML_EXTERNAL)
target_include_directories(spdlog_setup_unit_test
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/cpptoml/include>)
endif()

target_link_libraries(spdlog_setup_unit_test
PRIVATE
spdlog_setup
Expand Down
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ build_script:
- cmake .. -G "%CMAKE_GENERATOR_NAME%" -DSPDLOG_SETUP_INCLUDE_UNIT_TESTS=ON -DCMAKE_INSTALL_PREFIX:PATH=install
- cmake --build . --config %CONFIGURATION% --target install
- ctest -R spdlog_setup_unit_test -V
- cmake .. -G "%CMAKE_GENERATOR_NAME%" -DSPDLOG_SETUP_INCLUDE_UNIT_TESTS=ON -DSPDLOG_SETUP_CPPTOML_EXTERNAL=ON -DCMAKE_INSTALL_PREFIX:PATH=install
- cmake --build . --config %CONFIGURATION% --target install
- ctest -R spdlog_setup_unit_test -V
4 changes: 4 additions & 0 deletions cmake/cpptoml_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

// define to 1 if you use external cpptoml library
#cmakedefine SPDLOG_SETUP_CPPTOML_EXTERNAL 1
1 change: 1 addition & 0 deletions deps/cpptoml
Submodule cpptoml added at fededa
6 changes: 5 additions & 1 deletion include/spdlog_setup/details/conf_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
#define FMT_HEADER_ONLY
#endif

#include "third_party/cpptoml.h"
#if defined(SPDLOG_SETUP_CPPTOML_EXTERNAL)
#include "cpptoml.h"
#endif
#include "setup_error.h"

#include "third_party/cpptoml.h"


// Just so that it works for v1.3.0
#include "spdlog/spdlog.h"
Expand Down
3 changes: 3 additions & 0 deletions src/unit_test/unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#include "spdlog_setup/conf.h"
#include "spdlog_setup/details/third_party/cpptoml.h"
#if defined(SPDLOG_SETUP_CPPTOML_EXTERNAL)
#include "cpptoml.h"
#endif

#include <fstream>
#include <iostream>
Expand Down