Cleanup of cmake structure

This commit is contained in:
KjellKod 2014-10-03 00:56:13 -06:00
parent 73c6066c66
commit 19b17b9d94
5 changed files with 238 additions and 0 deletions

77
g2log/Build.cmake Normal file
View File

@ -0,0 +1,77 @@
SET(LOG_SRC ${g3log_SOURCE_DIR}/src)
include_directories(${LOG_SRC})
SET(ACTIVE_CPP0xx_DIR "Release")
#cmake -DCMAKE_CXX_COMPILER=clang++ ..
# WARNING: If Clang for Linux does not work with full C++11 support it might be your
# installation that is faulty. When I tested Clang on Ubuntu I followed the following
# description
# 1) http://kjellkod.wordpress.com/2013/09/23/experimental-g2log-with-clang/
# 2) https://github.com/maidsafe/MaidSafe/wiki/Hacking-with-Clang-llvm-abi-and-llvm-libc
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang")
MESSAGE("")
MESSAGE("cmake for Clang ")
IF (APPLE)
set(PLATFORM_LINK_LIBRIES c++abi)
ELSE()
set(PLATFORM_LINK_LIBRIES rt c++abi)
ENDIF()
SET(CMAKE_CXX_FLAGS "-Wall -std=c++11 -pthread -stdlib=libc++ -Wunused -D_GLIBCXX_USE_NANOSLEEP")
ELSEIF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
MESSAGE("cmake for GCC ")
IF (APPLE)
set(CMAKE_CXX_FLAGS "-Wall -Wunused -std=c++11 -pthread -D_GLIBCXX_USE_NANOSLEEP")
ELSE()
set(PLATFORM_LINK_LIBRIES rt)
set(CMAKE_CXX_FLAGS "-Wall -rdynamic -Wunused -std=c++11 -pthread -D_GLIBCXX_USE_NANOSLEEP -D_GLIBCXX_USE_SCHED_YIELD")
ENDIF()
ELSEIF(MSVC)
# VC11 bug: http://code.google.com/p/googletest/issues/detail?id=408
# add_definition(-D_VARIADIC_MAX=10)
# https://github.com/anhstudios/swganh/pull/186/files
ADD_DEFINITIONS (/D_VARIADIC_MAX=10)
MESSAGE(STATUS "- MSVC: Set variadic max to 10 for MSVC compatibility")
# 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")
MESSAGE("")
MESSAGE("Windows: Please run the command [cmake -DCMAKE_BUILD_TYPE=Release -G \"Visual Studio 11\" ..]")
MESSAGE("if cmake finishes OK, do 'msbuild g3log.sln /p:Configuration=Release'")
MESSAGE("then run 'Release\\g2log-FATAL-*' examples")
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)
MESSAGE(" HEADER FILES ARE: ${HEADER_FILES}")
IF (MSVC OR MINGW)
list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_unix.cpp)
ELSE()
list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_win.cpp)
ENDIF (MSVC OR MINGW)
set(SRC_FILES ${SRC_FILES} ${SRC_PLATFORM_SPECIFIC})
# Create the g2log library
include_directories(${LOG_SRC})
MESSAGE(" g3logger files: [${SRC_FILES}]")
add_library(g3logger ${SRC_FILES})
set_target_properties(g3logger PROPERTIES LINKER_LANGUAGE CXX)
add_library(g3logger_shared SHARED ${SRC_FILES})
set_target_properties(g3logger_shared PROPERTIES LINKER_LANGUAGE CXX)
SET(G3LOG_SHARED_LIBRARY g3logger_shared)
SET(G3LOG_LIBRARY g3logger)

18
g2log/Dynamic.cmake Normal file
View File

@ -0,0 +1,18 @@
# -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)
add_definitions(-DG2_DYNAMIC_LOGGING)
MESSAGE("-DUSE_DYNAMIC_LOGGING_LEVELS=ON
\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")
ELSE()
MESSAGE("-DUSE_DYNAMIC_LOGGING_LEVELS=OFF")
ENDIF(USE_DYNAMIC_LOGGING_LEVELS)

View File

@ -0,0 +1,27 @@
# ==============================================================
# -DUSE_SIMPLE_EXAMPLE=OFF : to turn off the fatal examples
#
#
# Leaving it to ON will create
# g3log-FATAL-sigsegv
# g3log-FATAL-contract
#
# ==============================================================
set(DIR_EXAMPLE ${g3log_SOURCE_DIR}/example)
option (USE_SIMPLE_EXAMPLE "Simple (fatal-crash/contract) examples " ON)
IF (USE_SIMPLE_EXAMPLE)
MESSAGE("-DUSE_SIMPLE_EXAMPLE=ON")
MESSAGE("\tg3log-FATAL-contract and g3log-FATAL-sigsegv shows fatal 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)
target_link_libraries(g3log-FATAL-contract ${G3LOG_LIBRARY} ${PLATFORM_LINK_LIBRIES})
target_link_libraries(g3log-FATAL-sigsegv ${G3LOG_LIBRARY} ${PLATFORM_LINK_LIBRIES})
ELSE()
MESSAGE("-DUSE_SIMPLE_EXAMPLE=OFF")
ENDIF (USE_SIMPLE_EXAMPLE)

View File

@ -0,0 +1,40 @@
# 2. performance test (average + worst case) for KjellKod's g2log
# Do 'cmake -DUSE_G2LOG_PERFORMANCE=ON' to enable this
option (USE_G2LOG_PERFORMANCE "g2log performance test" OFF)
# 2. create the g2log's performance tests
# =========================
IF (USE_G2LOG_PERFORMANCE)
set(DIR_PERFORMANCE ${g3log_SOURCE_DIR}/test_performance)
MESSAGE("-DUSE_G2LOG_PERFORMANCE=ON")
include_directories (${DIR_PERFORMANCE})
# MEAN PERFORMANCE TEST
add_executable(g2log-performance-threaded_mean
${DIR_PERFORMANCE}/main_threaded_mean.cpp
${DIR_PERFORMANCE}/performance.h)
# Turn on G2LOG performance flag
set_target_properties(g2log-performance-threaded_mean PROPERTIES
COMPILE_DEFINITIONS "G2LOG_PERFORMANCE=1")
target_link_libraries(g2log-performance-threaded_mean
${G3LOG_LIBRARY} ${PLATFORM_LINK_LIBRIES})
# WORST CASE PERFORMANCE TEST
add_executable(g2log-performance-threaded_worst
${DIR_PERFORMANCE}/main_threaded_worst.cpp ${DIR_PERFORMANCE}/performance.h)
# Turn on G2LOG performance flag
set_target_properties(g2log-performance-threaded_worst PROPERTIES
COMPILE_DEFINITIONS "G2LOG_PERFORMANCE=1")
target_link_libraries(g2log-performance-threaded_worst
${G3LOG_LIBRARY} ${PLATFORM_LINK_LIBRIES})
ELSE()
MESSAGE("-DUSE_G2LOG_PERFORMANCE=OFF")
ENDIF(USE_G2LOG_PERFORMANCE)

View File

@ -0,0 +1,76 @@
# -DUSE_G2LOG_UNIT_TEST=ON : unit tests
#
#
option (USE_G2LOG_UNIT_TEST
"Turn ON/OFF unit tests for G3Log" OFF)
# ============================================================================
# TEST OPTIONS: Turn OFF the ones that is of no interest to you
# ---- by default all is OFF: except 'g2log-FATAL-example -----
# ---- the reason for this is that
# ----- 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
# ============================================================================
# Unit test for g2log (cmake -DUSE_G2LOG_UNIT_TEST=ON ..)
# remember to unzip gtest at g2log/3rdParty/gtest
option (USE_G2LOG_UNIT_TEST "g2log unit tests" OFF)
# 4. create the unit tests for g2log --- ONLY TESTED THE UNIT TEST ON LINUX
# =========================
IF (USE_G2LOG_UNIT_TEST)
set(DIR_UNIT_TEST ${g3log_SOURCE_DIR}/test_unit)
MESSAGE("-DUSE_G2LOG_UNIT_TEST=ON")
set(GTEST_DIR ../3rdParty/gtest/gtest-1.7.0)
set(GTEST_INCLUDE_DIRECTORIES ${GTEST_DIR}/include ${GTEST_DIR} ${GTEST_DIR}/src)
include_directories(${GTEST_INCLUDE_DIRECTORIES})
add_library(gtest_170_lib ${GTEST_DIR}/src/gtest-all.cc)
set_target_properties(gtest_170_lib PROPERTIES COMPILE_DEFINITIONS "GTEST_HAS_RTTI=0")
enable_testing(true)
# obs see this: http://stackoverflow.com/questions/9589192/how-do-i-change-the-number-of-template-arguments-supported-by-msvcs-stdtupl
# and this: http://stackoverflow.com/questions/2257464/google-test-and-visual-studio-2010-rc
SET(tests_to_run test_filechange test_io test_configuration test_concept_sink test_sink)
SET(helper ${DIR_UNIT_TEST}/testing_helpers.h ${DIR_UNIT_TEST}/testing_helpers.cpp)
include_directories(${DIR_UNIT_TEST})
FOREACH(test ${tests_to_run} )
SET(all_tests ${all_tests} ${DIR_UNIT_TEST}/${test}.cpp )
IF(${test} STREQUAL "test_filechange")
add_executable(${test} ${DIR_UNIT_TEST}/${test}.cpp ${helper})
ELSE()
add_executable(${test} ../test_main/test_main.cpp ${DIR_UNIT_TEST}/${test}.cpp ${helper})
ENDIF(${test} STREQUAL "test_filechange")
set_target_properties(${test} PROPERTIES COMPILE_DEFINITIONS "GTEST_HAS_TR1_TUPLE=0")
set_target_properties(${test} PROPERTIES COMPILE_DEFINITIONS "GTEST_HAS_RTTI=0")
IF( NOT(MSVC))
set_target_properties(${test} PROPERTIES COMPILE_FLAGS "-isystem -pthread ")
ENDIF( NOT(MSVC))
target_link_libraries(${test} g3logger gtest_170_lib ${PLATFORM_LINK_LIBRIES})
ENDFOREACH(test)
#
# Test for Linux, runtime loading of dynamic libraries
#
IF (NOT WIN32 AND NOT ("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang"))
add_library(tester_sharedlib SHARED ${DIR_UNIT_TEST}/tester_sharedlib.h ${DIR_UNIT_TEST}/tester_sharedlib.cpp)
target_link_libraries(tester_sharedlib ${G3LOG_SHARED_LIBRARY})
add_executable(test_dynamic_loaded_shared_lib ../test_main/test_main.cpp ${DIR_UNIT_TEST}/test_linux_dynamic_loaded_sharedlib.cpp)
set_target_properties(test_dynamic_loaded_shared_lib PROPERTIES COMPILE_DEFINITIONS "GTEST_HAS_TR1_TUPLE=0")
set_target_properties(test_dynamic_loaded_shared_lib PROPERTIES COMPILE_DEFINITIONS "GTEST_HAS_RTTI=0")
target_link_libraries(test_dynamic_loaded_shared_lib ${G3LOG_SHARED_LIBRARY} -ldl gtest_170_lib )
ENDIF()
ELSE()
MESSAGE("-DUSE_G2LOG_UNIT_TEST=OFF")
ENDIF (USE_G2LOG_UNIT_TEST)