Skip to content

Commit

Permalink
cmake: cpptoml allow usage of installed dependency (#40)
Browse files Browse the repository at this point in the history
* cmake: cpptoml allow usage of installed dependency

* CMakeLists.txt fix

* fixes build errors

* cmake: Added option "SPDLOG_SETUP_CPPTOML_EXTERNAL" to allow cpptoml library as installed dependency.

* build fix

* cmake: cleanup

* cmake: wrong option in "configure_file"

* unit_test.cpp fix

* cmake: travis and appveyor tests extended

* travis.yml : tabs removed

* fix travis test

* cmake: clear tab and newline characters.

* Additional description

* cmake: move cpptoml_config.h.in to cmake folder
cmake: add option SPDLOG_SETUP_INCLUDE_UNIT_TESTS
travis: build script adjusted

* fix travis

* travis: revert changes

* clang-format fix
  • Loading branch information
davidwed authored and guangie88 committed May 21, 2019
1 parent bb6bfe3 commit 9cf1693
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 4 deletions.
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
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ matrix:
- ubuntu-toolchain-r-test

# ubuntu 14.04, gcc-6
- env: ["VER=6"]
- env: ["VER=6", "EXT=YES"]
compiler: gcc
os: linux
dist: trusty
Expand Down Expand Up @@ -231,6 +231,11 @@ script:
-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: 4 additions & 2 deletions include/spdlog_setup/details/conf_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
#define FMT_HEADER_ONLY
#endif

#include "setup_error.h"

#include "third_party/cpptoml.h"
#if defined(SPDLOG_SETUP_CPPTOML_EXTERNAL)
#include "cpptoml.h"
#endif
#include "setup_error.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

0 comments on commit 9cf1693

Please sign in to comment.