diff --git a/.travis.yml b/.travis.yml index 85273844..3067c322 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,91 +1,103 @@ -# Adapted from various sources, including: -# - Louis Dionne's Hana: https://github.com/ldionne/hana -# - Paul Fultz II's FIT: https://github.com/pfultz2/Fit -# - Eric Niebler's range-v3: https://github.com/ericniebler/range-v3 -language: cpp - -# Test matrix: -# - Build matrix per compiler: C++11/C++14 + Debug/Release -# - Optionally: AddressSanitizer (ASAN) -# - Valgrind: all release builds are also tested with valgrind -# - clang 3.4, 3.5, 3.6, trunk -# - Note: 3.4 and trunk are tested with/without ASAN, -# the rest is only tested with ASAN=On. -# - gcc 4.9, 5.0 -# -matrix: - include: - -# Test gcc-4.8: C++11, Build=Debug/Release, ASAN=Off - - env: GCC_VERSION=4.8 BUILD_TYPE=Debug CPP=11 ASAN=Off LIBCXX=Off - os: linux - addons: &gcc48 - apt: - packages: - - g++-4.8 - - valgrind - sources: - - ubuntu-toolchain-r-test - - - env: GCC_VERSION=4.8 BUILD_TYPE=Release CPP=11 ASAN=Off LIBCXX=Off - os: linux - addons: *gcc48 - - # Test gcc-4.9: C++11, Build=Debug/Release, ASAN=Off - - env: GCC_VERSION=4.9 BUILD_TYPE=Debug CPP=11 ASAN=Off LIBCXX=Off - os: linux - addons: &gcc49 - apt: - packages: - - g++-4.9 - - valgrind - sources: - - ubuntu-toolchain-r-test - - - env: GCC_VERSION=4.9 BUILD_TYPE=Release CPP=11 ASAN=Off LIBCXX=Off - os: linux - addons: *gcc49 - -# Install dependencies -before_install: - - export CHECKOUT_PATH=`pwd`; - - if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi - - if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi - - if [ "$CLANG_VERSION" == "3.4" ]; then export CXX="/usr/local/clang-3.4/bin/clang++" CC="/usr/local/clang-3.4/bin/clang"; fi - - which $CXX - - which $CC - - which valgrind - - if [ -n "$CLANG_VERSION" ]; then sudo CXX=$CXX CC=$CC ./tests/install_libcxx.sh; fi - -install: - - cd $CHECKOUT_PATH - - # Workaround for valgrind bug: https://bugs.kde.org/show_bug.cgi?id=326469. - # It is fixed in valgrind 3.10 so this won't be necessary if someone - # replaces the current valgrind (3.7) with valgrind-3.10 - - sed -i 's/march=native/msse4.2/' example/Makefile - - - if [ ! -d build ]; then mkdir build; fi - - export CXX_FLAGS="-I${CHECKOUT_PATH}/include" - - export CXX_LINKER_FLAGS="" - - if [ -z "$BUILD_TYPE" ]; then export BUILD_TYPE=Release; fi - - if [ "$ASAN" == "On"]; then export CXX_FLAGS="${CXX_FLAGS} -fsanitize=address,undefined,integer -fno-omit-frame-pointer -fno-sanitize=unsigned-integer-overflow"; fi - - if [ -n "$CLANG_VERSION" ]; then CXX_FLAGS="${CXX_FLAGS} -D__extern_always_inline=inline"; fi - - if [ "$LIBCXX" == "On" ]; then CXX_FLAGS="${CXX_FLAGS} -stdlib=libc++ -I/usr/include/c++/v1/"; fi - - if [ "$LIBCXX" == "On" ]; then CXX_LINKER_FLAGS="${CXX_FLAGS} -L/usr/lib/ -lc++"; fi - - CXX_FLAGS="${CXX_FLAGS} -std=c++${CPP}" - - # Build examples - - cd example - - if [ "$BUILD_TYPE" == "Release" ]; then make rebuild CXXFLAGS="${CXX_FLAGS} ${CXX_LINKER_FLAGS}" VERBOSE=1; export BIN=example; fi - - if [ "$BUILD_TYPE" == "Debug" ]; then make rebuild debug CXXFLAGS="${CXX_FLAGS} ${CXX_LINKER_FLAGS}" VERBOSE=1; export BIN=example-debug; fi - - -script: - - ./"${BIN}" - - valgrind --trace-children=yes --leak-check=full ./"${BIN}" - - cd $CHECKOUT_PATH/tests; make rebuild; ./tests - - cd $CHECKOUT_PATH/tests; STYLE=printf make rebuild; ./tests - -notifications: - email: false +# Adapted from various sources, including: +# - Louis Dionne's Hana: https://github.com/ldionne/hana +# - Paul Fultz II's FIT: https://github.com/pfultz2/Fit +# - Eric Niebler's range-v3: https://github.com/ericniebler/range-v3 +sudo: required +language: cpp + +addons: &gcc48 + apt: + packages: + - g++-4.8 + - valgrind + sources: + - ubuntu-toolchain-r-test + +addons: &gcc7 + apt: + packages: + - g++-7 + - valgrind + sources: + - ubuntu-toolchain-r-test + +addons: &clang35 + apt: + packages: + - clang-3.5 + - valgrind + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.5 + +addons: &clang6 + apt: + packages: + - clang-6.0 + - valgrind + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-6.0 + +matrix: + include: + # Test gcc-4.8: C++11, Build=Debug/Release + - env: GCC_VERSION=4.8 BUILD_TYPE=Debug CPP=11 + os: linux + addons: *gcc48 + + - env: GCC_VERSION=4.8 BUILD_TYPE=Release CPP=11 + os: linux + addons: *gcc48 + + # Test gcc-7: C++11, Build=Debug/Release + - env: GCC_VERSION=7 BUILD_TYPE=Debug CPP=11 + os: linux + addons: *gcc7 + + - env: GCC_VERSION=7 BUILD_TYPE=Release CPP=11 + os: linux + addons: *gcc7 + + # Test clang-3.5: C++11, Build=Debug/Release + - env: CLANG_VERSION=3.5 BUILD_TYPE=Debug CPP=11 + os: linux + addons: *clang35 + + - env: CLANG_VERSION=3.5 BUILD_TYPE=Release CPP=11 + os: linux + addons: *clang35 + + # Test clang-6.0: C++11, Build=Debug, ASAN=On + - env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 ASAN=On + os: linux + addons: *clang6 + +before_install: + - if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi + - if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi + - which $CXX + - which $CC + - which valgrind + - $CXX --version + - cmake --version + - valgrind --version + +install: + - cd ${TRAVIS_BUILD_DIR} + - mkdir -p build && cd build + - | + cmake .. \ + --warn-uninitialized \ + -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ + -DCMAKE_CXX_STANDARD=$CPP \ + -DSPDLOG_BUILD_EXAMPLES=ON \ + -DSPDLOG_SANITIZE_ADDRESS=$ASAN + - VERBOSE=1 make -j2 + +script: + - if [ "$ASAN" != "On" ]; then CTEST_FLAGS="-DExperimentalMemCheck"; fi + - ctest -j2 -VV $CTEST_FLAGS + +notifications: + email: false diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d55b8ef..a5cceb70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,15 +14,19 @@ include(GNUInstallDirs) #--------------------------------------------------------------------------------------- set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") set(CMAKE_CXX_FLAGS "-Wall -O3 ${CMAKE_CXX_FLAGS}") endif() +include(cmake/sanitizers.cmake) + #--------------------------------------------------------------------------------------- # spdlog target #--------------------------------------------------------------------------------------- add_library(spdlog INTERFACE) +add_library(spdlog::spdlog ALIAS spdlog) option(SPDLOG_BUILD_EXAMPLES "Build examples" OFF) cmake_dependent_option(SPDLOG_BUILD_TESTING diff --git a/cmake/sanitizers.cmake b/cmake/sanitizers.cmake new file mode 100644 index 00000000..3b090835 --- /dev/null +++ b/cmake/sanitizers.cmake @@ -0,0 +1,21 @@ +if(SPDLOG_SANITIZE_THREAD AND SPDLOG_SANITIZE_ADDRESS) + message(FATAL_ERROR "AddressSanitizer is not compatible with ThreadSanitizer.") +endif() + +if(SPDLOG_SANITIZE_ADDRESS) + message(STATUS "AddressSanitizer enabled") + set(SANITIZER_FLAGS "-fsanitize=address,undefined") + add_compile_options("-fno-sanitize=signed-integer-overflow") +endif() + +if(SPDLOG_SANITIZE_THREAD) + message(STATUS "ThreadSanitizer enabled") + set(SANITIZER_FLAGS "-fsanitize=thread") +endif() + +if(SPDLOG_SANITIZE_THREAD OR SPDLOG_SANITIZE_ADDRESS) + add_compile_options(${SANITIZER_FLAGS}) + add_compile_options("-fno-sanitize-recover=all") + add_compile_options("-fno-omit-frame-pointer") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS} -fuse-ld=gold") +endif() diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index cc699729..11dc2d98 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -24,10 +24,7 @@ cmake_minimum_required(VERSION 3.1) project(SpdlogExamples CXX) -if(TARGET spdlog) - # Part of the main project - add_library(spdlog::spdlog ALIAS spdlog) -else() +if(NOT TARGET spdlog) # Stand-alone build find_package(spdlog CONFIG REQUIRED) endif() @@ -37,13 +34,10 @@ find_package(Threads REQUIRED) add_executable(example example.cpp) target_link_libraries(example spdlog::spdlog Threads::Threads) -add_executable(benchmark bench.cpp) -target_link_libraries(benchmark spdlog::spdlog Threads::Threads) - add_executable(multisink multisink.cpp) target_link_libraries(multisink spdlog::spdlog Threads::Threads) enable_testing() file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") -add_test(NAME RunExample COMMAND example) -add_test(NAME RunBenchmark COMMAND benchmark) +add_test(NAME example COMMAND example) +add_test(NAME multisink COMMAND multisink) diff --git a/example/multisink.cpp b/example/multisink.cpp index 4b3f2d9c..fefa3b39 100644 --- a/example/multisink.cpp +++ b/example/multisink.cpp @@ -1,4 +1,4 @@ -#include "spdlog/sinks/file_sinks.h" +#include "spdlog/sinks/basic_file_sink.h" #include "spdlog/sinks/stdout_sinks.h" #include "spdlog/spdlog.h" #include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ba8b7487..18af9770 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -18,7 +18,7 @@ set(SPDLOG_UTESTS_SOURCES add_executable(${PROJECT_NAME} ${SPDLOG_UTESTS_SOURCES}) target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) -target_link_libraries(${PROJECT_NAME} PRIVATE spdlog) +target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog) add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") diff --git a/tests/install_libcxx.sh b/tests/install_libcxx.sh deleted file mode 100755 index cee97692..00000000 --- a/tests/install_libcxx.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# -# Install libc++ under travis - -svn --quiet co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx -mkdir libcxx/build -(cd libcxx/build && cmake .. -DLIBCXX_CXX_ABI=libstdc++ -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.6;/usr/include/c++/4.6/x86_64-linux-gnu") -make -C libcxx/build cxx -j2 -sudo cp libcxx/build/lib/libc++.so.1.0 /usr/lib/ -sudo cp -r libcxx/build/include/c++/v1 /usr/include/c++/v1/ -sudo ln -sf /usr/lib/libc++.so.1.0 /usr/lib/libc++.so -sudo ln -sf /usr/lib/libc++.so.1.0 /usr/lib/libc++.so.1