Merge pull request #796 from DanielChabrowski/cmake-refactor

Little cmake and tests refactor
This commit is contained in:
Gabi Melman 2018-08-14 23:21:11 +03:00 committed by GitHub
commit e8927dc75f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 26 deletions

View File

@ -12,13 +12,11 @@ include(GNUInstallDirs)
#--------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------
# set default build to release # set default build to release
#--------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------
if (NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
endif() endif()
message("Build type: " ${CMAKE_BUILD_TYPE}) message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
#--------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------
# compiler config # compiler config
@ -28,10 +26,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "-Wall -Wextra ${CMAKE_CXX_FLAGS}") add_compile_options("-Wall")
add_compile_options("-Wextra")
endif() endif()
#--------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------
# address sanitizers check # address sanitizers check
#--------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------

View File

@ -24,10 +24,6 @@
cmake_minimum_required(VERSION 3.1) cmake_minimum_required(VERSION 3.1)
project(SpdlogBench CXX) project(SpdlogBench CXX)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
if(NOT TARGET spdlog) if(NOT TARGET spdlog)
# Stand-alone build # Stand-alone build
find_package(spdlog CONFIG REQUIRED) find_package(spdlog CONFIG REQUIRED)
@ -44,7 +40,4 @@ target_link_libraries(async_bench spdlog::spdlog Threads::Threads)
add_executable(latency latency.cpp) add_executable(latency latency.cpp)
target_link_libraries(latency spdlog::spdlog Threads::Threads) target_link_libraries(latency spdlog::spdlog Threads::Threads)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs")

View File

@ -37,6 +37,7 @@ target_link_libraries(example spdlog::spdlog Threads::Threads)
add_executable(multisink multisink.cpp) add_executable(multisink multisink.cpp)
target_link_libraries(multisink spdlog::spdlog Threads::Threads) target_link_libraries(multisink spdlog::spdlog Threads::Threads)
enable_testing()
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs") file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs")
enable_testing()
add_test(NAME example COMMAND example) add_test(NAME example COMMAND example)

View File

@ -4,7 +4,6 @@
#include <iostream> #include <iostream>
#include <memory> #include <memory>
namespace spd = spdlog;
int main(int, char *[]) int main(int, char *[])
{ {
bool enable_debug = true; bool enable_debug = true;
@ -39,7 +38,7 @@ int main(int, char *[])
spdlog::drop_all(); spdlog::drop_all();
} }
// Exceptions will only be thrown upon failed logger or sink construction (not during logging) // Exceptions will only be thrown upon failed logger or sink construction (not during logging)
catch (const spd::spdlog_ex &ex) catch (const spdlog::spdlog_ex &ex)
{ {
std::cout << "Log init failed: " << ex.what() << std::endl; std::cout << "Log init failed: " << ex.what() << std::endl;
return 1; return 1;

View File

@ -1,5 +1,5 @@
project(spdlog-utests CXX) project(spdlog-utests CXX)
enable_testing()
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
set(SPDLOG_UTESTS_SOURCES set(SPDLOG_UTESTS_SOURCES
@ -7,18 +7,23 @@ set(SPDLOG_UTESTS_SOURCES
file_helper.cpp file_helper.cpp
file_log.cpp file_log.cpp
test_misc.cpp test_misc.cpp
test_pattern_formatter.cpp test_pattern_formatter.cpp
test_async.cpp test_async.cpp
includes.h includes.h
registry.cpp registry.cpp
test_macros.cpp test_macros.cpp
utils.cpp utils.cpp
utils.h utils.h
main.cpp test_mpmc_q.cpp) main.cpp
test_mpmc_q.cpp
test_sink.h
)
add_executable(${PROJECT_NAME} ${SPDLOG_UTESTS_SOURCES}) add_executable(${PROJECT_NAME} ${SPDLOG_UTESTS_SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)
target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::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") file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs")
enable_testing()
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})

View File

@ -9,15 +9,15 @@ class failing_sink : public spdlog::sinks::base_sink<std::mutex>
{ {
public: public:
failing_sink() = default; failing_sink() = default;
~failing_sink() = default; ~failing_sink() final = default;
protected: protected:
void sink_it_(const spdlog::details::log_msg &) override void sink_it_(const spdlog::details::log_msg &) final
{ {
throw std::runtime_error("some error happened during log"); throw std::runtime_error("some error happened during log");
} }
void flush_() override void flush_() final
{ {
throw std::runtime_error("some error happened during flush"); throw std::runtime_error("some error happened during flush");
} }
@ -25,7 +25,6 @@ protected:
TEST_CASE("default_error_handler", "[errors]]") TEST_CASE("default_error_handler", "[errors]]")
{ {
prepare_logdir(); prepare_logdir();
std::string filename = "logs/simple_log.txt"; std::string filename = "logs/simple_log.txt";

View File

@ -9,7 +9,7 @@ TEST_CASE("register_drop", "[registry]")
spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name); spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name);
REQUIRE(spdlog::get(tested_logger_name) != nullptr); REQUIRE(spdlog::get(tested_logger_name) != nullptr);
// Throw if registring existing name // Throw if registring existing name
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), spdlog::spdlog_ex); REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), const spdlog::spdlog_ex&);
} }
TEST_CASE("explicit register" TEST_CASE("explicit register"
@ -20,7 +20,7 @@ TEST_CASE("explicit register"
spdlog::register_logger(logger); spdlog::register_logger(logger);
REQUIRE(spdlog::get(tested_logger_name) != nullptr); REQUIRE(spdlog::get(tested_logger_name) != nullptr);
// Throw if registring existing name // Throw if registring existing name
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), spdlog::spdlog_ex); REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), const spdlog::spdlog_ex&);
} }
TEST_CASE("apply_all" TEST_CASE("apply_all"