2013-11-08 10:47:43 +01:00
# CMakeLists.txt cmake configuration for g2log test
2011-11-10 22:23:33 +01:00
# g2log is a KjellKod Logger
2012-10-14 01:54:56 +02:00
# 2011 @author Kjell Hedström, hedstrom@kjellkod.cc
2011-11-23 16:18:18 +01:00
# ==================================================================
2011-11-22 00:04:02 +01:00
# 2010 by KjellKod.cc. This is PUBLIC DOMAIN to use at your own
2012-10-14 01:54:56 +02:00
# risk and comes with no warranties.
#
2011-11-22 00:04:02 +01:00
# This code is yours to share, use and modify with no strings attached
# and no restrictions or obligations.
2011-11-23 16:18:18 +01:00
# ===================================================================
2011-11-10 22:23:33 +01:00
2011-11-17 11:26:02 +01:00
# Below are details for compiling on Windows and Linux
# by default only an example g2log binary is created
# the performance and unit tests creation can be enabled by switching their
# OPTIONs from OFF to ON --- See below at around line 110
2011-11-10 22:23:33 +01:00
2012-06-02 22:04:28 +02:00
# 2012-05-29: justthread is no longer necessary on Windows (vs2011) and
# linux (gcc4.7.1)
2011-11-10 22:23:33 +01:00
# WINDOWS == README: Example how to setup environment + running an example
2012-10-14 01:54:56 +02:00
# Below written for VS11 (2012)
# 1. please use the "Visual Studio Command Prompt 11 (2012)"
2011-11-10 22:23:33 +01:00
# 2. from the g2log folder
# mkdir build
# cd build;
2014-01-14 07:18:38 +01:00
# 3. cmake -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 12" ..
2012-06-02 22:04:28 +02:00
# 4. msbuild g2log_by_kjellkod.sln /p:Configuration=Release
2013-12-20 06:51:47 +01:00
# 5. Release\g2log-FATAL-contract.exe
2011-11-05 17:36:07 +01:00
#
#
2013-07-13 18:21:00 +02:00
# >>. LINUX:To try this out from folder g2log:
2011-11-05 17:36:07 +01:00
# mkdir build
# cd build
2013-07-13 18:21:00 +02:00
# >> create makefiles in g2log/build directory
# cmake .. // for debug builds OR
# >> Alternatively: for release cmake -DCMAKE_BUILD_TYPE=Release ..
# make # links active, g2log and example code: g2log-FATAL-example
2011-11-05 17:36:07 +01:00
# ============================================================================
2012-06-02 22:04:28 +02:00
cmake_minimum_required ( VERSION 2.8 )
ENABLE_LANGUAGE ( CXX )
set ( CMAKE_BUILD_TYPE Release )
2011-11-10 22:23:33 +01:00
project ( g2log_by_kjellkod )
set ( LOG_SRC ${ g2log_by_kjellkod_SOURCE_DIR } /src )
2011-11-17 11:26:02 +01:00
set ( DIR_UNIT_TEST ${ g2log_by_kjellkod_SOURCE_DIR } /test_unit )
set ( DIR_EXAMPLE ${ g2log_by_kjellkod_SOURCE_DIR } /test_example )
set ( DIR_PERFORMANCE ${ g2log_by_kjellkod_SOURCE_DIR } /test_performance )
2011-11-05 17:36:07 +01:00
MESSAGE ( " LOG_SRC = : ${LOG_SRC}" )
2011-11-10 22:23:33 +01:00
include_directories ( ${ LOG_SRC } )
SET ( ACTIVE_CPP0xx_DIR "Release" )
2012-10-14 01:54:56 +02:00
# Detect 64 or 32 bit
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
# 64-bit project
SET ( 64_BIT_OS TRUE )
MESSAGE ( "A 64-bit OS detected" )
else ( )
SET ( 64_BIT_OS FALSE )
MESSAGE ( "A 32-bit OS detected" )
endif ( )
2011-11-10 22:23:33 +01:00
2011-11-05 17:36:07 +01:00
IF ( UNIX )
2011-11-10 22:23:33 +01:00
MESSAGE ( "" )
MESSAGE ( "cmake for *NIX " )
MESSAGE ( "if cmake finishes OK, do make" )
2012-06-02 22:04:28 +02:00
MESSAGE ( "then run './g2log-FATAL-example' or whatever performance test you feel like trying" )
2011-11-10 22:23:33 +01:00
MESSAGE ( "" )
2012-06-02 22:04:28 +02:00
set ( PLATFORM_LINK_LIBRIES rt )
2011-11-17 00:51:28 +01:00
# -rdynamic is needed for correct stack dumps with demangling
2012-06-02 22:04:28 +02:00
# -D_GLIBCXX_USE_NANOSLEEP is needed for this_thread sleep (unit testing)
set ( CMAKE_CXX_FLAGS "-Wall -rdynamic -Wunused -std=c++11 ${CMAKE_CXX_FLAGS_DEBUG} -pthread -D_GLIBCXX_USE_NANOSLEEP" )
2011-11-17 11:26:02 +01:00
set ( SRC_PLATFORM_SPECIFIC ${ LOG_SRC } /crashhandler_unix.cpp )
2013-12-13 20:39:50 +01:00
ENDIF ( UNIX )
2011-11-10 22:23:33 +01:00
2013-12-13 20:39:50 +01:00
IF ( MINGW )
MESSAGE ( "" )
MESSAGE ( "cmake for MinGW " )
MESSAGE ( "if cmake finishes OK, do make" )
MESSAGE ( "then run './g2log-FATAL-example' or whatever performance test you feel like trying" )
MESSAGE ( "" )
# -D_GLIBCXX_USE_NANOSLEEP is needed for this_thread sleep (unit testing)
set ( CMAKE_CXX_FLAGS "-Wall -Wunused -std=c++11 ${CMAKE_CXX_FLAGS_DEBUG} -pthread -D_GLIBCXX_USE_NANOSLEEP" )
set ( SRC_PLATFORM_SPECIFIC ${ LOG_SRC } /crashhandler_win.cpp )
ENDIF ( MINGW )
2013-07-14 03:33:00 +02:00
# Visual Studio 2011 -- std::thread etc are included with the Visual Studio package, so justthread dependencies are removed
IF ( MSVC )
2012-06-24 21:43:23 +02:00
# VC11 bug: http://code.google.com/p/googletest/issues/detail?id=408
# add_definition(-D_VARIADIC_MAX=10)
2013-07-14 03:33:00 +02:00
# https://github.com/anhstudios/swganh/pull/186/files
2012-06-24 21:43:23 +02:00
ADD_DEFINITIONS ( /D_VARIADIC_MAX=10 )
MESSAGE ( STATUS "- MSVC: Set variadic max to 10 for MSVC compatibility" )
2013-07-14 03:33:00 +02:00
# Remember to set set target properties if using GTEST similar to done below on target "unit_test"
# "set_target_properties(unit_test PROPERTIES COMPILE_DEFINITIONS "GTEST_USE_OWN_TR1_TUPLE=0")
2012-03-04 01:18:11 +01:00
MESSAGE ( "" )
2012-06-02 22:04:28 +02:00
MESSAGE ( "Windows: Please run the command [cmake -DCMAKE_BUILD_TYPE=Release -G \" Visual Studio 11\ " ..]" )
MESSAGE ( "if cmake finishes OK, do 'msbuild g2log_by_kjellkod.sln /p:Configuration=Release'" )
MESSAGE ( "then run 'Release\\g2log-FATAL-example.exe' or whatever performance test you feel like trying" )
2012-03-04 01:18:11 +01:00
MESSAGE ( "" )
set ( SRC_PLATFORM_SPECIFIC ${ LOG_SRC } /crashhandler_win.cpp )
2013-07-14 03:33:00 +02:00
ENDIF ( MSVC )
2011-11-05 17:36:07 +01:00
2013-07-14 01:56:38 +02:00
2013-07-14 03:33:00 +02:00
# GENERIC STEPS
2013-07-30 06:43:33 +02:00
file ( GLOB SRC_FILES ${ LOG_SRC } /*.h ${ LOG_SRC } /*.hpp ${ LOG_SRC } /*.cpp ${ LOG_SRC } /*.ipp )
2013-12-13 20:39:50 +01:00
if ( MSVC OR MINGW )
2013-07-14 03:33:00 +02:00
list ( REMOVE_ITEM SRC_FILES ${ LOG_SRC } /crashhandler_unix.cpp )
else ( )
list ( REMOVE_ITEM SRC_FILES ${ LOG_SRC } /crashhandler_win.cpp )
2013-12-13 20:39:50 +01:00
endif ( MSVC OR MINGW )
2011-11-17 11:26:02 +01:00
2013-07-14 03:33:00 +02:00
set ( SRC_FILES ${ SRC_FILES } ${ SRC_PLATFORM_SPECIFIC } )
2013-12-10 22:57:04 +01:00
2013-07-14 03:33:00 +02:00
# Create the g2log library
include_directories ( ${ LOG_SRC } )
2013-12-10 22:57:04 +01:00
MESSAGE ( " g3logger files: [${SRC_FILES}]" )
add_library ( lib_g3logger ${ SRC_FILES } )
set_target_properties ( lib_g3logger PROPERTIES LINKER_LANGUAGE CXX )
2011-11-10 22:23:33 +01:00
2013-12-10 22:57:04 +01:00
# ============================================================================
# G2LOG OPTIONS: Turn OFF the ones that is of no interest to you
# ============================================================================
option ( USE_DYNAMIC_LOGGING_LEVELS
" T u r n O N / O F F l o g l e v e l s . A n d i s a b l e d l e v e l w i l l n o t p u s h l o g s o f t h a t l e v e l t o t h e s i n k . B y d e f a u l t d y n a m i c l o g g i n g i s d i s a b l e d " O F F )
2013-12-20 06:51:47 +01:00
# Do 'cmake -DUSE_DYNAMIC_LOGGING_LEVELS=ON -DCMAKE_BUILD_TYPE=Release .. ' to enable this
2013-12-10 22:57:04 +01:00
# (or change the default option above)
if ( USE_DYNAMIC_LOGGING_LEVELS )
add_definitions ( -DG2_DYNAMIC_LOGGING )
2013-12-13 20:39:03 +01:00
MESSAGE ( "\nUSE_DYNAMIC_LOGGING_LEVELS is turned on\n\tUse g2::setLogLevel(LEVEL boolean) to enable/disable logging on specified levels.\n\tAll levels are by default turn ON\n\n" )
2013-12-10 22:57:04 +01:00
endif ( USE_DYNAMIC_LOGGING_LEVELS )
2011-11-05 17:36:07 +01:00
2011-11-23 16:18:18 +01:00
# ============================================================================
2013-12-10 22:57:04 +01:00
# TEST OPTIONS: Turn OFF the ones that is of no interest to you
2012-06-02 22:04:28 +02:00
# ---- by default all is OFF: except 'g2log-FATAL-example -----
2012-10-14 01:54:56 +02:00
# ---- the reason for this is that
2011-11-23 16:18:18 +01:00
# ----- 1) the performance tests were only thoroughly tested on Ubuntu, not windows-
# (g2log windows/linux, but Google's glog only on linux)
#
# 2) The unit test were tested windows/linux,. but must be unzipped
# before it can be "cmake'd" and compiled --- leaving it as OFF for now
# ============================================================================
2013-12-10 22:57:04 +01:00
2013-12-20 06:51:47 +01:00
# 1. a simple test example 'g2log-FATAL-*'
# Do 'cmake -DUSE_SIMPLE_EXAMPLE=ON' to enable this
option ( USE_SIMPLE_EXAMPLE "Simple (fatal-crash/contract) examples " ON )
2011-11-05 17:36:07 +01:00
2011-11-17 11:26:02 +01:00
# 2. performance test (average + worst case) for KjellKod's g2log
2013-12-20 06:51:47 +01:00
# Do 'cmake -DUSE_G2LOG_PERFORMANCE=ON' to enable this
2013-07-14 03:33:00 +02:00
option ( USE_G2LOG_PERFORMANCE "g2log performance test" OFF )
2011-11-05 17:36:07 +01:00
2011-11-17 11:26:02 +01:00
# 3. performance test for Google's glog
2013-07-14 03:33:00 +02:00
# remember to install glog, snapshot available at g2log/3rdParty/glog
option ( USE_GOOGLE_GLOG_PERFORMANCE "Google's glog performance test" OFF )
2011-11-05 17:36:07 +01:00
2014-01-09 06:48:18 +01:00
# 4. unit test for g2log (cmake -DUSE_G2LOG_UNIT_TEST=ON ..)
2013-07-14 03:33:00 +02:00
# remember to unzip gtest at g2log/3rdParty/gtest
2013-12-16 06:29:26 +01:00
option ( USE_G2LOG_UNIT_TEST "g2log unit tests" OFF )
2011-11-17 11:26:02 +01:00
2012-06-02 22:04:28 +02:00
# ===============================================================================================
2011-11-05 17:36:07 +01:00
#
2011-11-17 11:26:02 +01:00
# BELOW : Creating executables depending on OPTIONS above
2011-11-05 17:36:07 +01:00
#
2012-06-02 22:04:28 +02:00
# ==============================================================================================
2011-11-17 11:26:02 +01:00
# 1. create the the example EXECUTABLE - hook in the test_example's CMakeLists.txt file
2013-07-13 18:21:00 +02:00
# =========================
2011-11-17 11:26:02 +01:00
if ( USE_SIMPLE_EXAMPLE )
2013-12-20 06:51:47 +01:00
MESSAGE ( " g2log-FATAL-* examples option ON" )
2011-11-17 11:26:02 +01:00
include_directories ( ${ DIR_EXAMPLE } )
2013-12-20 06:51:47 +01:00
add_executable ( g2log-FATAL-contract ${ DIR_EXAMPLE } /main_contract.cpp )
add_executable ( g2log-FATAL-sigsegv ${ DIR_EXAMPLE } /main_sigsegv.cpp )
target_link_libraries ( g2log-FATAL-contract lib_g3logger ${ PLATFORM_LINK_LIBRIES } )
target_link_libraries ( g2log-FATAL-sigsegv lib_g3logger ${ PLATFORM_LINK_LIBRIES } )
2012-10-14 01:54:56 +02:00
endif ( USE_SIMPLE_EXAMPLE )
2013-07-13 18:21:00 +02:00
2011-11-17 11:26:02 +01:00
# 2. create the g2log's performance tests
2013-07-13 18:21:00 +02:00
# =========================
2011-11-17 11:26:02 +01:00
if ( USE_G2LOG_PERFORMANCE )
2011-11-17 22:46:38 +01:00
MESSAGE ( " g2log performance tests option ON" )
2012-10-14 01:54:56 +02:00
include_directories ( ${ DIR_PERFORMANCE } )
2011-11-17 11:26:02 +01:00
# MEAN PERFORMANCE TEST
2012-10-14 01:54:56 +02:00
add_executable ( g2log-performance-threaded_mean
2011-11-17 11:26:02 +01:00
$ { D I R _ P E R F O R M A N C E } / m a i n _ t h r e a d e d _ m e a n . c p p $ { D I R _ P E R F O R M A N C E } / p e r f o r m a n c e . h )
# Turn on G2LOG performance flag
set_target_properties ( g2log-performance-threaded_mean PROPERTIES COMPILE_DEFINITIONS "G2LOG_PERFORMANCE=1" )
2013-12-10 22:57:04 +01:00
target_link_libraries ( g2log-performance-threaded_mean lib_g3logger ${ PLATFORM_LINK_LIBRIES } )
2011-11-17 11:26:02 +01:00
# WORST CASE PERFORMANCE TEST
2013-07-13 18:21:00 +02:00
add_executable ( g2log-performance-threaded_worst ${ DIR_PERFORMANCE } /main_threaded_worst.cpp ${ DIR_PERFORMANCE } /performance.h )
2011-11-17 11:26:02 +01:00
# Turn on G2LOG performance flag
set_target_properties ( g2log-performance-threaded_worst PROPERTIES COMPILE_DEFINITIONS "G2LOG_PERFORMANCE=1" )
2013-12-10 22:57:04 +01:00
target_link_libraries ( g2log-performance-threaded_worst lib_g3logger ${ PLATFORM_LINK_LIBRIES } )
2011-11-17 11:26:02 +01:00
endif ( USE_G2LOG_PERFORMANCE )
# 3. create the Google glog's performance test
2013-07-13 18:21:00 +02:00
# =========================
2012-10-14 01:54:56 +02:00
if ( USE_GOOGLE_GLOG_PERFORMANCE )
2011-11-17 22:46:38 +01:00
MESSAGE ( " Google's glog performance tests option ON" )
2012-10-14 01:54:56 +02:00
include_directories ( ${ DIR_PERFORMANCE } )
#Linux is easy!
2011-11-18 01:51:34 +01:00
if ( UNIX )
set ( GLOG_LIB glog )
2013-07-14 03:33:00 +02:00
# create the the GOOGLE MEAN_PERFORMANCE executable
2011-11-18 01:51:34 +01:00
add_executable ( google_glog-performance-threaded_mean ${ DIR_PERFORMANCE } /main_threaded_mean.cpp ${ DIR_PERFORMANCE } /performance.h )
set_target_properties ( google_glog-performance-threaded_mean PROPERTIES COMPILE_DEFINITIONS "GOOGLE_GLOG_PERFORMANCE=1" )
2013-07-14 03:33:00 +02:00
target_link_libraries ( google_glog-performance-threaded_mean ${ GLOG_LIB } ${ PLATFORM_LINK_LIBRIES } )
2012-10-14 01:54:56 +02:00
2011-11-18 01:51:34 +01:00
# create the the GOOGLE MEAN_PERFORMANCE executable
add_executable ( google_glog-performance-threaded_worst ${ DIR_PERFORMANCE } /main_threaded_worst.cpp ${ DIR_PERFORMANCE } /performance.h )
set_target_properties ( google_glog-performance-threaded_worst PROPERTIES COMPILE_DEFINITIONS "GOOGLE_GLOG_PERFORMANCE=1" )
2013-07-14 03:33:00 +02:00
target_link_libraries ( google_glog-performance-threaded_worst ${ GLOG_LIB } ${ PLATFORM_LINK_LIBRIES } )
endif ( UNIX )
2012-10-14 01:54:56 +02:00
2013-07-14 03:33:00 +02:00
# GLOG on Linux is easy - but for Windows trickier,. and it doesn't work (as of yet)
2011-11-18 01:51:34 +01:00
if ( WIN32 )
MESSAGE ( "******************************************************" )
2013-07-14 03:33:00 +02:00
MESSAGE ( "*** SORRY- Google glog on windows is not preconfigured" )
MESSAGE ( "*** You have to do this yourself: ref CMakeLists.txt" )
2011-11-18 01:51:34 +01:00
MESSAGE ( "******************************************************" )
2013-07-14 03:33:00 +02:00
MESSAGE ( "" )
2012-10-14 01:54:56 +02:00
endif ( WIN32 )
2011-11-17 11:26:02 +01:00
endif ( USE_GOOGLE_GLOG_PERFORMANCE )
2011-11-05 17:36:07 +01:00
2011-11-17 11:26:02 +01:00
# 4. create the unit tests for g2log --- ONLY TESTED THE UNIT TEST ON LINUX
2013-07-13 18:21:00 +02:00
# =========================
2012-10-14 01:54:56 +02:00
if ( USE_G2LOG_UNIT_TEST )
2011-11-17 22:46:38 +01:00
MESSAGE ( " g2log unit testing option ON" )
2011-11-17 11:26:02 +01:00
set ( GTEST_DIR ../3rdParty/gtest/gtest-1.6.0__stripped )
set ( GTEST_INCLUDE_DIRECTORIES ${ GTEST_DIR } /include ${ GTEST_DIR } ${ GTEST_DIR } /src )
include_directories ( ${ GTEST_INCLUDE_DIRECTORIES } )
add_library ( gtest_160_lib ${ GTEST_DIR } /src/gtest-all.cc ${ GTEST_DIR } /src/gtest_main.cc )
enable_testing ( true )
2011-11-05 17:36:07 +01:00
2013-07-14 03:33:00 +02:00
# obs see this: http://stackoverflow.com/questions/9589192/how-do-i-change-the-number-of-template-arguments-supported-by-msvcs-stdtupl
2013-07-13 18:21:00 +02:00
# and this: http://stackoverflow.com/questions/2257464/google-test-and-visual-studio-2010-rc
2013-08-21 07:40:39 +02:00
SET ( tests_to_run test_filechange test_io test_configuration test_concept_sink test_sink )
2013-07-14 01:56:38 +02:00
SET ( helper ${ DIR_UNIT_TEST } /testing_helpers.h ${ DIR_UNIT_TEST } /testing_helpers.cpp )
2013-07-14 03:33:00 +02:00
include_directories ( ${ DIR_UNIT_TEST } )
2013-07-13 18:21:00 +02:00
FOREACH ( test ${ tests_to_run } )
2013-07-14 03:33:00 +02:00
SET ( all_tests ${ all_tests } ${ DIR_UNIT_TEST } / ${ test } .cpp )
2013-08-21 07:40:39 +02:00
IF ( ${ test } STREQUAL "test_filechange" )
2013-07-14 03:33:00 +02:00
add_executable ( ${ test } ${ DIR_UNIT_TEST } / ${ test } .cpp ${ helper } )
2013-08-21 07:40:39 +02:00
ELSEIF ( ${ test } STREQUAL "test_sink" )
add_executable ( ${ test } ${ DIR_UNIT_TEST } / ${ test } .cpp ${ helper } )
MESSAGE ( "*****************************************************" )
2013-07-13 18:21:00 +02:00
ELSE ( )
2013-07-14 03:33:00 +02:00
add_executable ( ${ test } ../test_main/test_main.cpp ${ DIR_UNIT_TEST } / ${ test } .cpp ${ helper } )
2013-07-13 18:21:00 +02:00
ENDIF ( ${ test } STREQUAL "test_filechange" )
2013-08-21 07:40:39 +02:00
2013-07-13 18:21:00 +02:00
set_target_properties ( ${ test } PROPERTIES COMPILE_DEFINITIONS "_VARIADIC_MAX=10" )
set_target_properties ( ${ test } PROPERTIES COMPILE_DEFINITIONS "GTEST_USE_OWN_TR1_TUPLE=0" )
2013-12-10 22:57:04 +01:00
target_link_libraries ( ${ test } lib_g3logger gtest_160_lib ${ PLATFORM_LINK_LIBRIES } )
2013-07-13 18:21:00 +02:00
ENDFOREACH ( test )
2013-07-14 03:33:00 +02:00
2013-08-21 07:40:39 +02:00
#add_executable(test_ALL ${all_tests} ${DIR_UNIT_TEST}/test_filechange.cpp ${helper})
#set_target_properties(test_ALL PROPERTIES COMPILE_DEFINITIONS "_VARIADIC_MAX=10")
#set_target_properties(test_ALL PROPERTIES COMPILE_DEFINITIONS "GTEST_USE_OWN_TR1_TUPLE=0")
2013-12-10 22:57:04 +01:00
#target_link_libraries(test_ALL lib_g3logger gtest_160_lib ${PLATFORM_LINK_LIBRIES})
2013-07-14 03:33:00 +02:00
2013-07-13 18:21:00 +02:00
# add_executable(test_ALL ${all_tests})
#
# set_target_properties(${test_ALL} PROPERTIES COMPILE_DEFINITIONS "_VARIADIC_MAX=10")
# set_target_properties(${test_ALL} PROPERTIES COMPILE_DEFINITIONS "GTEST_USE_OWN_TR1_TUPLE=0")
2013-12-10 22:57:04 +01:00
# target_link_libraries(${test_ALL} lib_g3logger gtest_160_lib ${PLATFORM_LINK_LIBRIES})
2012-10-14 01:54:56 +02:00
2013-07-13 18:21:00 +02:00
endif ( USE_G2LOG_UNIT_TEST )
2012-10-14 01:54:56 +02:00
2011-11-05 17:36:07 +01:00
2011-11-10 22:23:33 +01:00
2011-11-17 11:26:02 +01:00
2011-11-05 17:36:07 +01:00