From 78103cb41593bc55e7ae3f707a09fa99395f7672 Mon Sep 17 00:00:00 2001 From: Kjell Hedstrom Date: Mon, 13 Jul 2015 07:49:44 -0600 Subject: [PATCH] Auto generate macro defintions in a file. This way you don't have to re-state them in your library if no options are given a blank file will be generated --- .hgignore => .gitignore | 1 + Build.cmake | 15 +++++++-- CMakeLists.txt | 34 ++++++++++--------- GenerateMacroDefinitionsFile.cmake | 28 ++++++++++++++++ Options.cmake | 54 ++++++++++++++++++++++++------ example/Example.cmake | 27 +++++++++++---- test_performance/Performance.cmake | 27 +++++++++++---- test_unit/Test.cmake | 23 +++++++------ 8 files changed, 155 insertions(+), 54 deletions(-) rename .hgignore => .gitignore (85%) create mode 100644 GenerateMacroDefinitionsFile.cmake diff --git a/.hgignore b/.gitignore similarity index 85% rename from .hgignore rename to .gitignore index 5fb7b4f..642b0fa 100644 --- a/.hgignore +++ b/.gitignore @@ -6,4 +6,5 @@ nbproject/* build_clang build_travis gtest-1.7.0 +definitions.hpp *~ diff --git a/Build.cmake b/Build.cmake index 5b71179..c9240cb 100644 --- a/Build.cmake +++ b/Build.cmake @@ -1,3 +1,15 @@ +# g3log is a KjellKod Logger +# 2015 @author Kjell Hedström, hedstrom@kjellkod.cc +# ================================================================== +# 2015 by KjellKod.cc. This is PUBLIC DOMAIN to use at your own +# risk and comes with no warranties. +# +# This code is yours to share, use and modify with no strings attached +# and no restrictions or obligations. +# =================================================================== + + + SET(LOG_SRC ${g3log_SOURCE_DIR}/src) include_directories(${LOG_SRC}) SET(ACTIVE_CPP0xx_DIR "Release") @@ -51,9 +63,6 @@ IF (MSVC OR MINGW) MESSAGE("") ENDIF() - - - # GENERIC STEPS file(GLOB SRC_FILES ${LOG_SRC}/*.h ${LOG_SRC}/*.hpp ${LOG_SRC}/*.cpp ${LOG_SRC}/*.ipp) file(GLOB HEADER_FILES ${LOG_SRC}/*.h ${LOG_SRC}/*.hpp) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9180e58..2110975 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # g3log is a KjellKod Logger -# 2011 @author Kjell Hedström, hedstrom@kjellkod.cc +# 2010 @author Kjell Hedström, hedstrom@kjellkod.cc # ================================================================== # 2010 by KjellKod.cc. This is PUBLIC DOMAIN to use at your own # risk and comes with no warranties. @@ -47,7 +47,7 @@ # # ============================================================================ -cmake_minimum_required (VERSION 2.8) +cmake_minimum_required (VERSION 3.2) ENABLE_LANGUAGE(CXX) set(CMAKE_BUILD_TYPE Release) @@ -67,28 +67,30 @@ endif() + # ============================================================================ + # G3LOG OPTIONAL FEATURES + # ============================================================================ + INCLUDE (${g3log_SOURCE_DIR}/Options.cmake) + + + # ========================================================================= + # G3 Macro definitions in Options.cmake are written to file + # this avoids having to re-state your definitions in your source code + # or compile options + #========================================================================== + INCLUDE (${g3log_SOURCE_DIR}/GenerateMacroDefinitionsFile.cmake) + # ========================================================================= # G3LOG BUILD #========================================================================== INCLUDE (${g3log_SOURCE_DIR}/Build.cmake) - - - - # ============================================================================ - # G3LOG OPTIONAL FEATURES - # ============================================================================ - # Dynamic logging: ENABLE WITH: -DUSE_DYNAMIC_LOGGING_LEVELS=ON : run-type turn on/off levels - # DBUG instead of DEBUG logging level: ENABLE WITH: -DCHANGE_G3LOG_DEBUG_TO_DBUG=ON - INCLUDE (${g3log_SOURCE_DIR}/Options.cmake) - - # ============================================================================ # EXAMPLE OPTIONS: By defauls is ON. This will create 'g3log-FATAL-* examples' # ============================================================================ - # DISABLE WITH: -DUSE_FATAL_EXAMPLE=OFF + # DISABLE WITH: -DADD_FATAL_EXAMPLE=OFF INCLUDE (${g3log_SOURCE_DIR}/example/Example.cmake) @@ -96,7 +98,7 @@ endif() # ============================================================================ # PERFORMANCE TEST OPTIONS: Performance operations for g3log # ============================================================================ - # ENABLE WITH: -USE_G3LOG_PERFORMANCE=ON + # ENABLE WITH: -DADD_G3LOG_PERFORMANCE=ON INCLUDE (${g3log_SOURCE_DIR}/test_performance/Performance.cmake) @@ -104,7 +106,7 @@ endif() # ========================================================================== # UNIT TEST OPTIONS: # ============================================================================ - # ENABLE WITH: -DUSE_G2LOG_UNIT_TEST=ON + # ENABLE WITH: -DADD_G2LOG_UNIT_TEST=ON INCLUDE (${g3log_SOURCE_DIR}/test_unit/Test.cmake) diff --git a/GenerateMacroDefinitionsFile.cmake b/GenerateMacroDefinitionsFile.cmake new file mode 100644 index 0000000..db5a0a3 --- /dev/null +++ b/GenerateMacroDefinitionsFile.cmake @@ -0,0 +1,28 @@ +# Prerequisite : Options.cmake should run first + + SET(HEADER "/** ========================================================================== + * Original code made by Robert Engeln. Given as a PUBLIC DOMAIN dedication for + * the benefit of g3log. It was originally published at: + * http://code-freeze.blogspot.com/2012/01/generating-stack-traces-from-c.html + + * 2014-2015: adapted for g3log by Kjell Hedstrom (KjellKod). + * + * This is PUBLIC DOMAIN to use at your own risk and comes + * with no warranties. This code is yours to share, use and modify with no + * strings attached and no restrictions or obligations. + * + * For more information see g3log/LICENSE or refer refer to http://unlicense.org + * ============================================================================*/") + + + + +MESSAGE("COMPILE_DEFINITIONS: ${G3_DEFINITIONS}") +MESSAGE("End of COMPILE_DEFINITIONS") +FILE(WRITE g3log/definitions.hpp "// AUTO GENERATED MACRO DEFINITIONS FOR G3LOG\n\n") +FILE(APPEND g3log/definitions.hpp ${HEADER}"\n") +FILE(APPEND g3log/definitions.hpp "#pragma once\n\n") + +FOREACH(definition ${G3_DEFINITIONS} ) + FILE(APPEND g3log/definitions.hpp "#define ${definition}\n") +ENDFOREACH(definition) diff --git a/Options.cmake b/Options.cmake index f125b50..d9a73fa 100644 --- a/Options.cmake +++ b/Options.cmake @@ -1,11 +1,32 @@ +# g3log is a KjellKod Logger +# 2015 @author Kjell Hedström, hedstrom@kjellkod.cc +# ================================================================== +# 2015 by KjellKod.cc. This is PUBLIC DOMAIN to use at your own +# risk and comes with no warranties. +# +# This code is yours to share, use and modify with no strings attached +# and no restrictions or obligations. +# =================================================================== + + + + + +# Used for generating a macro definitions file that is to be included +# that way you do not have to re-state the Options.cmake definitions when +# compiling your binary (if done in a separate build step from the g3log library) +SET(G3_DEFINITIONS "") + + # -DUSE_DYNAMIC_LOGGING_LEVELS=ON : run-type turn on/off levels option (USE_DYNAMIC_LOGGING_LEVELS "Turn ON/OFF log levels. An disabled level will not push logs of that level to the sink. By default dynamic logging is disabled" OFF) IF(USE_DYNAMIC_LOGGING_LEVELS) + LIST(APPEND G3_DEFINITIONS G2_DYNAMIC_LOGGING) add_definitions(-DG2_DYNAMIC_LOGGING) MESSAGE("-DUSE_DYNAMIC_LOGGING_LEVELS=ON") - MESSAGE("\tDynamic logging levels can be turned on. Make sure to have \n\t\t[#define G2_DYNAMIC_LOGGING 1] in your source code") - MESSAGE("\t\tUse [g2::setLogLevel(LEVEL boolean)] to enable/disable logging on specified levels") + MESSAGE("\tDynamic logging levels can be turned on. Make sure to have [#define G2_DYNAMIC_LOGGING 1] in your source code") + MESSAGE("\tUse [g2::setLogLevel(LEVEL boolean)] to enable/disable logging on specified levels\n\n") ELSE() MESSAGE("-DUSE_DYNAMIC_LOGGING_LEVELS=OFF") ENDIF(USE_DYNAMIC_LOGGING_LEVELS) @@ -18,12 +39,12 @@ ENDIF(USE_DYNAMIC_LOGGING_LEVELS) option (CHANGE_G3LOG_DEBUG_TO_DBUG "Use DBUG logging level instead of DEBUG. By default DEBUG is the debugging level" OFF) IF(CHANGE_G3LOG_DEBUG_TO_DBUG) + LIST(APPEND G3_DEFINITIONS CHANGE_G3LOG_DEBUG_TO_DBUG) add_definitions(-DCHANGE_G3LOG_DEBUG_TO_DBUG) - MESSAGE("-DCHANGE_G3LOG_DEBUG_TO_DBUG=ON") - MESSAGE("\tDBUG instead of DEBUG logging level can be used. Make sure to have \n\t\t[#define CHANGE_G3LOG_DEBUG_TO_DBUG 1] in your source code") + MESSAGE("-DCHANGE_G3LOG_DEBUG_TO_DBUG=ON DBUG instead of DEBUG logging level can be used. Make sure to have:") + MESSAGE(" [#define CHANGE_G3LOG_DEBUG_TO_DBUG 1] in your source code") ELSE() - MESSAGE("-DCHANGE_G3LOG_DEBUG_TO_DBUG=OFF") - MESSAGE("\tDebuggin logging level is 'DEBUG'") + MESSAGE("-DCHANGE_G3LOG_DEBUG_TO_DBUG=OFF \t(Debuggin logging level is 'DEBUG')") ENDIF(CHANGE_G3LOG_DEBUG_TO_DBUG) @@ -35,13 +56,14 @@ option (ENABLE_FATAL_SIGNALHANDLING "Vectored exception / crash handling with improved stack trace" ON) IF(NOT ENABLE_FATAL_SIGNALHANDLING) + LIST(APPEND G3_DEFINITIONS DISABLE_FATAL_SIGNALHANDLING) add_definitions(-DDISABLE_FATAL_SIGNALHANDLING) - MESSAGE("-DENABLE_FATAL_SIGNALHANDLING=OFF\t\t\tFatal signal handler is disabled. Make sure to have \n\t\t[#define DISABLE_FATAL_SIGNALHANDLING 1] in your source code") + MESSAGE("-DENABLE_FATAL_SIGNALHANDLING=OFF Fatal signal handler is disabled. Make sure to have:") + MESSAGE(" [#define DISABLE_FATAL_SIGNALHANDLING 1] in your source code") ELSE() - MESSAGE("-DENABLE_FATAL_SIGNALHANDLING=ON\t\t\tFatal signal handler is enabled") + MESSAGE("-DENABLE_FATAL_SIGNALHANDLING=ON\tFatal signal handler is enabled") ENDIF(NOT ENABLE_FATAL_SIGNALHANDLING) - # WINDOWS OPTIONS IF (MSVC OR MINGW) # -DENABLE_VECTORED_EXCEPTIONHANDLING=ON : defualt change the @@ -52,8 +74,10 @@ IF (MSVC OR MINGW) "Vectored exception / crash handling with improved stack trace" ON) IF(NOT ENABLE_VECTORED_EXCEPTIONHANDLING) + LIST(APPEND G3_DEFINITIONS DISABLE_VECTORED_EXCEPTIONHANDLING) add_definitions(-DDISABLE_VECTORED_EXCEPTIONHANDLING) - MESSAGE("-DENABLE_VECTORED_EXCEPTIONHANDLING=OFF\t\t\tVectored exception handling is disabled. Make sure to have \n\t\t[#define DISABLE_VECTORED_EXCEPTIONHANDLING 1] in your source code") + MESSAGE("-DENABLE_VECTORED_EXCEPTIONHANDLING=OFF Vectored exception handling is disabled. Make sure to have:") + MESSaGE(" [#define DISABLE_VECTORED_EXCEPTIONHANDLING 1] in your source code") ELSE() MESSAGE("-DENABLE_VECTORED_EXCEPTIONHANDLING=ON\t\t\tVectored exception handling is enabled") @@ -68,12 +92,20 @@ IF (MSVC OR MINGW) option (DEBUG_BREAK_AT_FATAL_SIGNAL "Enable Visual Studio break point when receiving a fatal exception. In __DEBUG mode only" ON) IF(DEBUG_BREAK_AT_FATAL_SIGNAL) + LIST(APPEND G3_DEFINITIONS DEBUG_BREAK_AT_FATAL_SIGNAL) add_definitions(-DDEBUG_BREAK_AT_FATAL_SIGNAL) - MESSAGE("-DDEBUG_BREAK_AT_FATAL_SIGNAL=ON\t\t\tBreak point for fatal signal is enabled for __DEBUG.Make sure to have \n\t\t[#define DEBUG_BREAK_AT_FATAL_SIGNAL 1] in your source code") + MESSAGE("-DDEBUG_BREAK_AT_FATAL_SIGNAL=ON Break point for fatal signal is enabled for __DEBUG.Make sure to have:") + MESSAGE(" [#define DEBUG_BREAK_AT_FATAL_SIGNAL 1] in your source code") ELSE() MESSAGE("-DDEBUG_BREAK_AT_FATAL_SIGNAL=OFF\t\t\tBreak point for fatal signal is disabled") ENDIF(DEBUG_BREAK_AT_FATAL_SIGNAL) ENDIF (MSVC OR MINGW) +MESSAGE("\n\n\n") + + + + + diff --git a/example/Example.cmake b/example/Example.cmake index c23fb27..629afcf 100644 --- a/example/Example.cmake +++ b/example/Example.cmake @@ -1,4 +1,18 @@ - # ============================================================== +# g3log is a KjellKod Logger +# 2015 @author Kjell Hedström, hedstrom@kjellkod.cc +# ================================================================== +# 2015 by KjellKod.cc. This is PUBLIC DOMAIN to use at your own +# risk and comes with no warranties. +# +# This code is yours to share, use and modify with no strings attached +# and no restrictions or obligations. +# =================================================================== + + + + + +# ============================================================== # -DUSE_SIMPLE_EXAMPLE=OFF : to turn off the fatal examples # # @@ -10,12 +24,11 @@ set(DIR_EXAMPLE ${g3log_SOURCE_DIR}/example) - option (USE_FATAL_EXAMPLE "Fatal (fatal-crashes/contract) examples " ON) + option (ADD_FATAL_EXAMPLE "Fatal (fatal-crashes/contract) examples " ON) - IF (USE_FATAL_EXAMPLE) - - MESSAGE("-DUSE_FATAL_EXAMPLE=ON\t\t\tg3log-FATAL- [contract][sigsegv][choice] are examples of when g3log comes in handy") + IF (ADD_FATAL_EXAMPLE) + MESSAGE("-DADD_FATAL_EXAMPLE=ON\t\t[contract][sigsegv][fatal choice] are examples of when g3log comes in handy") include_directories (${DIR_EXAMPLE}) add_executable(g3log-FATAL-contract ${DIR_EXAMPLE}/main_contract.cpp) add_executable(g3log-FATAL-sigsegv ${DIR_EXAMPLE}/main_sigsegv.cpp) @@ -25,5 +38,5 @@ target_link_libraries(g3log-FATAL-sigsegv ${G3LOG_LIBRARY}) target_link_libraries(g3log-FATAL-choice ${G3LOG_LIBRARY}) ELSE() - MESSAGE("-DUSE_SIMPLE_EXAMPLE=OFF") - ENDIF (USE_FATAL_EXAMPLE) \ No newline at end of file + MESSAGE("-DADD_SIMPLE_EXAMPLE=OFF") + ENDIF (ADD_FATAL_EXAMPLE) diff --git a/test_performance/Performance.cmake b/test_performance/Performance.cmake index f8314f8..a783d13 100644 --- a/test_performance/Performance.cmake +++ b/test_performance/Performance.cmake @@ -1,16 +1,29 @@ - # 2. performance test (average + worst case) for KjellKod's g3log +# g3log is a KjellKod Logger +# 2015 @author Kjell Hedström, hedstrom@kjellkod.cc +# ================================================================== +# 2015 by KjellKod.cc. This is PUBLIC DOMAIN to use at your own +# risk and comes with no warranties. +# +# This code is yours to share, use and modify with no strings attached +# and no restrictions or obligations. +# =================================================================== + + + + + # . performance test (average + worst case) for KjellKod's g3log # Do 'cmake -DUSE_G3LOG_PERFORMANCE=ON' to enable this - option (USE_G3LOG_PERFORMANCE "g3log performance test" OFF) + option (ADD_G3LOG_PERFORMANCE "g3log performance test" OFF) - # 2. create the g3log's performance tests + # create the g3log's performance tests # ========================= - IF (USE_G3LOG_PERFORMANCE) + IF (ADD_G3LOG_BENCH_PERFORMANCE) set(DIR_PERFORMANCE ${g3log_SOURCE_DIR}/test_performance) - MESSAGE("-DUSE_G3LOG_PERFORMANCE=ON") + MESSAGE("-DADD_G3LOG_BENCH_PERFORMANCE=ON") include_directories (${DIR_PERFORMANCE}) # MEAN PERFORMANCE TEST @@ -33,8 +46,8 @@ ${G3LOG_LIBRARY} ${PLATFORM_LINK_LIBRIES}) ELSE() - MESSAGE("-DUSE_G3LOG_PERFORMANCE=OFF") - ENDIF(USE_G3LOG_PERFORMANCE) + MESSAGE("-DADD_G3LOG_BENCH_PERFORMANCE=OFF") + ENDIF(ADD_G3LOG_BENCH_PERFORMANCE) diff --git a/test_unit/Test.cmake b/test_unit/Test.cmake index 7c9ef24..c5f26fb 100644 --- a/test_unit/Test.cmake +++ b/test_unit/Test.cmake @@ -1,9 +1,12 @@ -# -DUSE_G3LOG_UNIT_TEST=ON : unit tests +# g3log is a KjellKod Logger +# 2015 @author Kjell Hedström, hedstrom@kjellkod.cc +# ================================================================== +# 2015 by KjellKod.cc. This is PUBLIC DOMAIN to use at your own +# risk and comes with no warranties. # -# -option (USE_G3LOG_UNIT_TEST - "Turn ON/OFF unit tests for G3Log" OFF) - +# This code is yours to share, use and modify with no strings attached +# and no restrictions or obligations. +# =================================================================== # ============================================================================ @@ -20,14 +23,14 @@ option (USE_G3LOG_UNIT_TEST # Unit test for g3log (cmake -DUSE_G3LOG_UNIT_TEST=ON ..) # remember to unzip gtest at g3log/3rdParty/gtest - option (USE_G3LOG_UNIT_TEST "g3log unit tests" OFF) + option (ADD_G3LOG_UNIT_TEST "g3log unit tests" OFF) # 4. create the unit tests for g3log --- ONLY TESTED THE UNIT TEST ON LINUX # ========================= - IF (USE_G3LOG_UNIT_TEST) + IF (ADD_G3LOG_UNIT_TEST) set(DIR_UNIT_TEST ${g3log_SOURCE_DIR}/test_unit) - MESSAGE("-DUSE_G3LOG_UNIT_TEST=ON") + MESSAGE("-DADD_G3LOG_UNIT_TEST=ON") set(GTEST_DIR ${g3log_SOURCE_DIR}/3rdParty/gtest/gtest-1.7.0) set(GTEST_INCLUDE_DIRECTORIES ${GTEST_DIR}/include ${GTEST_DIR} ${GTEST_DIR}/src) include_directories(${GTEST_INCLUDE_DIRECTORIES}) @@ -76,5 +79,5 @@ option (USE_G3LOG_UNIT_TEST target_link_libraries(test_dynamic_loaded_shared_lib ${G3LOG_SHARED_LIBRARY} -ldl gtest_170_lib ) ENDIF() ELSE() - MESSAGE("-DUSE_G3LOG_UNIT_TEST=OFF") -ENDIF (USE_G3LOG_UNIT_TEST) + MESSAGE("-DADD_G3LOG_UNIT_TEST=OFF") +ENDIF (ADD_G3LOG_UNIT_TEST)