From 3ed90c156947ae766b940ec7fa3ec409ab540983 Mon Sep 17 00:00:00 2001 From: bergmann Date: Sat, 10 Aug 2019 01:26:36 +0200 Subject: [PATCH] * Updated project structure --- CMakeLists.txt | 14 ++++++++++---- cmake/cpplogging-const.cmake | 28 ++++++++++++++++++++++++++++ cmake/cpplogging-options.cmake | 5 +++++ cmake/cpplogging-var.cmake | 24 +++--------------------- cmake/modules | 2 +- src/CMakeLists.txt | 4 ++++ test/CMakeLists.txt | 5 ----- test/cpplogging/cpplogging_tests.cpp | 25 +++++++++++++------------ 8 files changed, 64 insertions(+), 43 deletions(-) create mode 100644 cmake/cpplogging-const.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 760a7b7..fa290c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,19 +20,25 @@ EndIf ( ) # Project ######################################################################################### +Include ( CTest ) +Include ( GNUInstallDirs ) Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cpplogging-options.cmake ) +Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cpplogging-const.cmake ) Include ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cpplogging-var.cmake ) -Project ( cpplogging - DESCRIPTION "A simple library" +Project ( ${CPPLOGGING_PROJECT_NAME} + DESCRIPTION "${CPPLOGGING_PROJECT_DESCRIPTION}" VERSION "${CPPLOGGING_VERSION}" ) -Include ( CTest ) -Include ( GNUInstallDirs ) # Subdirectories Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/src ) Add_SubDirectory ( ${CMAKE_CURRENT_SOURCE_DIR}/test ) # Install +If ( NOT CPPLOGGING_HAS_EXPORT + OR NOT CPPLOGGING_INSTALL_PACKAGE ) + Return ( ) +EndIf ( ) + Include ( CMakePackageConfigHelpers ) Write_Basic_Package_Version_File ( "${CMAKE_CURRENT_BINARY_DIR}/cmake/cpplogging-config-version.cmake" VERSION ${CPPLOGGING_VERSION} diff --git a/cmake/cpplogging-const.cmake b/cmake/cpplogging-const.cmake new file mode 100644 index 0000000..f52cc2a --- /dev/null +++ b/cmake/cpplogging-const.cmake @@ -0,0 +1,28 @@ +# This file contains constant variables that are fixed to this project + +# Version +Set ( CPPLOGGING_VERSION_MAJOR 1 ) +Set ( CPPLOGGING_VERSION_MINOR 0 ) +Set ( CPPLOGGING_VERSION_PATCH 0 ) +Set ( CPPLOGGING_VERSION_BUILD 0 ) +Set ( CPPLOGGING_VERSION_HASH "" ) +Set ( CPPLOGGING_VERSION_BEHIND 0 ) +Set ( CPPLOGGING_VERSION_DIRTY 0 ) + +# Names +Set ( CPPLOGGING_PROJECT_NAME "cpplogging" ) +Set ( CPPLOGGING_PROJECT_DESCRIPTION "A simple hello world library" ) + +# Include generated variables for further usage +Include ( ${CMAKE_CURRENT_LIST_DIR}/cpplogging-var.cmake ) + +# Install directories +Set ( CPPLOGGING_INSTALL_DIR_INCLUDE "${CMAKE_INSTALL_INCLUDEDIR}/${CPPLOGGING_NAME}" ) +Set ( CPPLOGGING_INSTALL_DIR_LIB "${CMAKE_INSTALL_LIBDIR}" ) +Set ( CPPLOGGING_INSTALL_DIR_SHARE "${CMAKE_INSTALL_DATAROOTDIR}/${CPPLOGGING_NAME}" ) + +# C Standard +Set ( CMAKE_C_STANDARD 11 ) +Set ( CMAKE_CXX_STANDARD 17 ) +Set ( CMAKE_C_STANDARD_REQUIRED ON ) +Set ( CMAKE_CXX_STANDARD_REQUIRED ON ) diff --git a/cmake/cpplogging-options.cmake b/cmake/cpplogging-options.cmake index 9488532..78bc915 100644 --- a/cmake/cpplogging-options.cmake +++ b/cmake/cpplogging-options.cmake @@ -1,3 +1,5 @@ +# This file contains options that can be passed to the cmake command + Option ( CPPLOGGING_INSTALL_HEADER "Install headers of cpplogging." ON ) @@ -10,6 +12,9 @@ Option ( CPPLOGGING_INSTALL_SHARED Option ( CPPLOGGING_INSTALL_DEBUG "Install the stripped debug informations of cpplogging." OFF ) +Option ( CPPLOGGING_INSTALL_PACKAGE + "Install the cmake package of cpplogging." + ON ) Option ( CPPLOGGING_NO_STRIP "Do not strip debug symbols from binary." OFF ) diff --git a/cmake/cpplogging-var.cmake b/cmake/cpplogging-var.cmake index dbb3c25..8e3f806 100644 --- a/cmake/cpplogging-var.cmake +++ b/cmake/cpplogging-var.cmake @@ -1,11 +1,4 @@ -# Version -Set ( CPPLOGGING_VERSION_MAJOR 1 ) -Set ( CPPLOGGING_VERSION_MINOR 0 ) -Set ( CPPLOGGING_VERSION_PATCH 0 ) -Set ( CPPLOGGING_VERSION_BUILD 0 ) -Set ( CPPLOGGING_VERSION_HASH "" ) -Set ( CPPLOGGING_VERSION_BEHIND 0 ) -Set ( CPPLOGGING_VERSION_DIRTY 0 ) +# This file contains generated variables that are needed for the project # Git Version If ( CPPLOGGING_USE_GIT_VERSION ) @@ -26,19 +19,8 @@ EndIf ( ) Set ( CPPLOGGING_VERSION_SHORT "${CPPLOGGING_VERSION_MAJOR}.${CPPLOGGING_VERSION_MINOR}" ) Set ( CPPLOGGING_VERSION "${CPPLOGGING_VERSION_SHORT}.${CPPLOGGING_VERSION_PATCH}.${CPPLOGGING_VERSION_BUILD}" ) Set ( CPPLOGGING_VERSION_COMPLETE "${CPPLOGGING_VERSION}" ) -Set ( CPPLOGGING_NAME "cpplogging-${CPPLOGGING_VERSION_SHORT}" ) -Set ( CPPLOGGING_OUTPUTNAME "cpplogging" ) +Set ( CPPLOGGING_NAME "${CPPLOGGING_PROJECT_NAME}-${CPPLOGGING_VERSION_SHORT}" ) +Set ( CPPLOGGING_OUTPUTNAME "${CPPLOGGING_PROJECT_NAME}" ) If ( CPPLOGGING_VERSION_BEHIND ) Set ( CPPLOGGING_VERSION_COMPLETE "${CPPLOGGING_VERSION_COMPLETE}+${CPPLOGGING_VERSION_BEHIND}" ) EndIf ( ) - -# Install directories -Set ( CPPLOGGING_INSTALL_DIR_INCLUDE "include/${CPPLOGGING_NAME}" ) -Set ( CPPLOGGING_INSTALL_DIR_LIB "lib" ) -Set ( CPPLOGGING_INSTALL_DIR_SHARE "share/${CPPLOGGING_NAME}" ) - -# C Standard -Set ( CMAKE_C_STANDARD 11 ) -Set ( CMAKE_CXX_STANDARD 17 ) -Set ( CMAKE_C_STANDARD_REQUIRED ON ) -Set ( CMAKE_CXX_STANDARD_REQUIRED ON ) diff --git a/cmake/modules b/cmake/modules index 4953cd4..ebbae4f 160000 --- a/cmake/modules +++ b/cmake/modules @@ -1 +1 @@ -Subproject commit 4953cd4cc849afdfa02a6057b5a2011fb62e91a6 +Subproject commit ebbae4fbb42d671331b4c6e9d1d142f41dcacc1b diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e20145b..11ab077 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -80,6 +80,8 @@ EndIf ( ) # Install ######################################################################################### +Set ( CPPLOGGING_HAS_EXPORT False PARENT_SCOPE ) + # Header If ( CPPLOGGING_INSTALL_HEADER ) Install ( DIRECTORY ${CPPLOGGING_INCLUDE_DIR}/cpplogging @@ -90,6 +92,7 @@ EndIf ( ) # Static If ( CPPLOGGING_INSTALL_STATIC ) + Set ( CPPLOGGING_HAS_EXPORT True PARENT_SCOPE ) Install ( TARGETS cpplogging-static EXPORT cpplogging DESTINATION ${CPPLOGGING_INSTALL_DIR_LIB} ) @@ -97,6 +100,7 @@ EndIf ( ) # Shared If ( CPPLOGGING_INSTALL_SHARED ) + Set ( CPPLOGGING_HAS_EXPORT True PARENT_SCOPE ) Install ( TARGETS cpplogging-shared EXPORT cpplogging DESTINATION ${CPPLOGGING_INSTALL_DIR_LIB} ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 91ee56e..427a008 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -43,11 +43,6 @@ ForEach ( FILE IN LISTS CPPLOGGING_TEST_SOURCE_FILES ) Pedantic_Apply_Flags_Target ( ${TEST_NAME} ALL ) EndIf ( ) - # optimization - If ( HAS_COTIRE ) - Cotire ( ${TEST_NAME} ) - EndIf ( ) - # test If ( HAS_CMAKE_TESTS ) Add_CMake_Test ( NAME ${TEST_NAME} TARGET ${TEST_NAME} ) diff --git a/test/cpplogging/cpplogging_tests.cpp b/test/cpplogging/cpplogging_tests.cpp index 4115f11..b3b26bd 100644 --- a/test/cpplogging/cpplogging_tests.cpp +++ b/test/cpplogging/cpplogging_tests.cpp @@ -1,6 +1,7 @@ #include #include #include +#include using namespace ::testing; using namespace ::cpplogging; @@ -84,7 +85,7 @@ TEST(LoggingTests, matcher_regex) EXPECT_TRUE (matcher0.match(c0)); EXPECT_FALSE(matcher0.match(c1)); - EXPECT_FALSE(matcher1.match(l0)); + EXPECT_TRUE (matcher1.match(l0)); EXPECT_TRUE (matcher1.match(l1)); } @@ -117,15 +118,15 @@ TEST(LoggingTests, log_base) auto& l0 = logger::get("logger0"); auto& l1 = logger::get("logger1"); - cpplogging_log(l0, debug).sender((void*)0x11).message("test1") << " debug"; - cpplogging_log(l0, info ).sender((void*)0x12).message("test1") << " info"; - cpplogging_log(l0, warn ).sender((void*)0x13).message("test1") << " warn"; - cpplogging_log(l0, error).sender((void*)0x14).message("test1") << " error"; + cpplogging_log(l0, debug) << cpplogging::sender((void*)0x11) << "test1" << " debug"; + cpplogging_log(l0, info ) << cpplogging::sender((void*)0x12) << "test1" << " info"; + cpplogging_log(l0, warn ) << cpplogging::sender((void*)0x13) << "test1" << " warn"; + cpplogging_log(l0, error) << cpplogging::sender((void*)0x14) << "test1" << " error"; - cpplogging_log(l1, debug).sender((void*)0x21).message("test2") << " debug"; - cpplogging_log(l1, info ).sender((void*)0x22).message("test2") << " info"; - cpplogging_log(l1, warn ).sender((void*)0x23).message("test2") << " warn"; - cpplogging_log(l1, error).sender((void*)0x24).message("test2") << " error"; + cpplogging_log(l1, debug) << cpplogging::sender((void*)0x21) << "test2" << " debug"; + cpplogging_log(l1, info ) << cpplogging::sender((void*)0x22) << "test2" << " info"; + cpplogging_log(l1, warn ) << cpplogging::sender((void*)0x23) << "test2" << " warn"; + cpplogging_log(l1, error) << cpplogging::sender((void*)0x24) << "test2" << " error"; } TEST(LoggingTests, log_inverted_regex) @@ -150,9 +151,9 @@ TEST(LoggingTests, log_inverted_regex) auto& l1 = logger::get("logger1"); auto& l2 = logger::get("logger2"); - cpplogging_log(l0, debug).sender((void*)0x10) << "test0"; - cpplogging_log(l1, debug).sender((void*)0x11) << "test1"; - cpplogging_log(l2, debug).sender((void*)0x12) << "test2"; + cpplogging_log(l0, debug) << cpplogging::sender((void*)0x10) << "test0"; + cpplogging_log(l1, debug) << cpplogging::sender((void*)0x11) << "test1"; + cpplogging_log(l2, debug) << cpplogging::sender((void*)0x12) << "test2"; } #ifdef CPPLOGGING_HAS_LOAD_CONFIG