diff --git a/.gitmodules b/.gitmodules index 5427cc30..a6936c8c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/.travis.yml b/.travis.yml index 1ca64923..0ba4cac6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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 \ diff --git a/CMakeLists.txt b/CMakeLists.txt index d4c0584a..cd6482bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) @@ -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) @@ -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 @@ -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 @@ -88,6 +113,12 @@ if(SPDLOG_SETUP_INCLUDE_UNIT_TESTS) PRIVATE $) + if(SPDLOG_SETUP_CPPTOML_EXTERNAL) + target_include_directories(spdlog_setup_unit_test + PRIVATE + $) + endif() + target_link_libraries(spdlog_setup_unit_test PRIVATE spdlog_setup diff --git a/appveyor.yml b/appveyor.yml index 32118442..f72992da 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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 diff --git a/cmake/cpptoml_config.h.in b/cmake/cpptoml_config.h.in new file mode 100644 index 00000000..277636ae --- /dev/null +++ b/cmake/cpptoml_config.h.in @@ -0,0 +1,4 @@ +#pragma once + +// define to 1 if you use external cpptoml library +#cmakedefine SPDLOG_SETUP_CPPTOML_EXTERNAL 1 diff --git a/deps/cpptoml b/deps/cpptoml new file mode 160000 index 00000000..fededad7 --- /dev/null +++ b/deps/cpptoml @@ -0,0 +1 @@ +Subproject commit fededad7169e538ca47e11a9ee9251bc361a9a65 diff --git a/include/spdlog_setup/details/conf_impl.h b/include/spdlog_setup/details/conf_impl.h index cd7cbe59..2bd4533a 100644 --- a/include/spdlog_setup/details/conf_impl.h +++ b/include/spdlog_setup/details/conf_impl.h @@ -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" diff --git a/src/unit_test/unit_test.cpp b/src/unit_test/unit_test.cpp index ed9cb697..571619f0 100644 --- a/src/unit_test/unit_test.cpp +++ b/src/unit_test/unit_test.cpp @@ -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 #include