2015-07-13 15:49:44 +02:00
|
|
|
# g3log is a KjellKod Logger
|
2016-01-24 13:27:52 +01:00
|
|
|
# 2015 @author Kjell Hedström, hedstrom@kjellkod.cc
|
2015-07-13 15:49:44 +02:00
|
|
|
# ==================================================================
|
|
|
|
# 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.
|
|
|
|
# ===================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-03 08:56:13 +02:00
|
|
|
SET(LOG_SRC ${g3log_SOURCE_DIR}/src)
|
|
|
|
include_directories(${LOG_SRC})
|
2017-05-09 18:26:48 +02:00
|
|
|
include_directories("${CMAKE_CURRENT_BINARY_DIR}/include")
|
2014-10-03 08:56:13 +02:00
|
|
|
SET(ACTIVE_CPP0xx_DIR "Release")
|
|
|
|
|
|
|
|
#cmake -DCMAKE_CXX_COMPILER=clang++ ..
|
2017-03-31 06:52:09 +02:00
|
|
|
# WARNING: If Clang for Linux does not work with full c++14 support it might be your
|
2014-10-03 08:56:13 +02:00
|
|
|
# installation that is faulty. When I tested Clang on Ubuntu I followed the following
|
2016-01-24 13:27:52 +01:00
|
|
|
# description
|
2015-07-20 07:10:56 +02:00
|
|
|
# 1) http://kjellkod.wordpress.com/2013/09/23/experimental-g3log-with-clang/
|
2014-10-03 08:56:13 +02:00
|
|
|
# 2) https://github.com/maidsafe/MaidSafe/wiki/Hacking-with-Clang-llvm-abi-and-llvm-libc
|
2017-03-31 06:52:09 +02:00
|
|
|
IF (${CMAKE_CXX_COMPILER_ID} MATCHES ".*Clang")
|
2017-05-17 22:31:19 +02:00
|
|
|
message( STATUS "" )
|
|
|
|
message( STATUS "cmake for Clang " )
|
2017-03-31 06:52:09 +02:00
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++14 -Wunused -D_GLIBCXX_USE_NANOSLEEP")
|
2016-02-02 22:30:44 +01:00
|
|
|
IF (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++ -pthread")
|
|
|
|
ELSE()
|
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
|
|
ENDIF()
|
2015-09-21 04:23:38 +02:00
|
|
|
IF (${CMAKE_SYSTEM} MATCHES "FreeBSD-([0-9]*)\\.(.*)")
|
|
|
|
IF (${CMAKE_MATCH_1} GREATER 9)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
|
|
|
set(PLATFORM_LINK_LIBRIES execinfo)
|
|
|
|
ENDIF()
|
|
|
|
ELSEIF (APPLE)
|
2014-10-03 08:56:13 +02:00
|
|
|
set(PLATFORM_LINK_LIBRIES c++abi)
|
2016-02-02 22:30:44 +01:00
|
|
|
ELSEIF (NOT (${CMAKE_SYSTEM_NAME} STREQUAL "Linux"))
|
2015-09-21 04:23:38 +02:00
|
|
|
set(PLATFORM_LINK_LIBRIES rt c++abi)
|
2016-02-02 22:30:44 +01:00
|
|
|
ELSE()
|
|
|
|
set(PLATFORM_LINK_LIBRIES rt)
|
2014-10-03 08:56:13 +02:00
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-03-31 06:52:09 +02:00
|
|
|
ELSEIF(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
2017-05-17 22:31:19 +02:00
|
|
|
message( STATUS "cmake for GCC " )
|
2014-10-03 08:56:13 +02:00
|
|
|
IF (APPLE)
|
2017-03-31 06:52:09 +02:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wunused -std=c++14 -pthread -D_GLIBCXX_USE_NANOSLEEP")
|
2015-03-29 14:29:07 +02:00
|
|
|
ELSEIF (MINGW)
|
2017-03-31 06:52:09 +02:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wunused -std=c++14 -pthread -D_GLIBCXX_USE_NANOSLEEP -D_GLIBCXX_USE_SCHED_YIELD")
|
|
|
|
set(PLATFORM_LINK_LIBRIES dbghelp)
|
|
|
|
|
|
|
|
# deal with ERROR level conflicts with windows.h
|
|
|
|
ADD_DEFINITIONS (-DNOGDI)
|
2014-10-03 08:56:13 +02:00
|
|
|
ELSE()
|
|
|
|
set(PLATFORM_LINK_LIBRIES rt)
|
2017-03-31 06:52:09 +02:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -rdynamic -Wunused -std=c++14 -pthread -lrt -D_GLIBCXX_USE_NANOSLEEP -D_GLIBCXX_USE_SCHED_YIELD")
|
2014-10-03 08:56:13 +02:00
|
|
|
ENDIF()
|
2017-02-19 18:50:58 +01:00
|
|
|
ELSEIF(MSVC)
|
2017-03-31 06:52:09 +02:00
|
|
|
set(PLATFORM_LINK_LIBRIES dbghelp)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") # source code already in utf-8, force it for compilers in non-utf8_windows_locale
|
|
|
|
# ERROR level conflicts with windows.h
|
|
|
|
ADD_DEFINITIONS (-DNOGDI)
|
|
|
|
# support AMD proc on vc2015
|
|
|
|
if(${CMAKE_CL_64} STREQUAL "0")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:IA32")
|
|
|
|
endif()
|
|
|
|
endif()
|
2014-10-03 08:56:13 +02:00
|
|
|
|
2015-03-29 14:29:07 +02:00
|
|
|
IF (MSVC OR MINGW)
|
2014-10-03 08:56:13 +02:00
|
|
|
# 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")
|
2017-05-17 22:31:19 +02:00
|
|
|
message( STATUS "" )
|
|
|
|
message( STATUS "Windows: Run cmake with the appropriate Visual Studio generator" )
|
|
|
|
message( STATUS "The generator is one number below the official version number. I.e. VS2013 -> Generator 'Visual Studio 12'" )
|
|
|
|
MESSAGE( STATUS "I.e. if VS2013: Please run the command [cmake -DCMAKE_BUILD_TYPE=Release -G \"Visual Studio 12\" ..]")
|
|
|
|
message( STATUS "if cmake finishes OK, do 'msbuild g3log.sln /p:Configuration=Release'" )
|
|
|
|
message( STATUS "then run 'Release\\g3log-FATAL-*' examples" )
|
|
|
|
message( STATUS "" )
|
2014-10-03 08:56:13 +02:00
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
# GENERIC STEPS
|
2015-07-20 07:10:56 +02:00
|
|
|
file(GLOB SRC_FILES ${LOG_SRC}/g3log/*.h ${LOG_SRC}/g3log/*.hpp ${LOG_SRC}/*.cpp ${LOG_SRC}/*.ipp)
|
2015-07-16 09:55:23 +02:00
|
|
|
file(GLOB HEADER_FILES ${LOG_SRC}/g3log/*.hpp ${LOG_SRC}/*.hpp)
|
2017-03-31 06:52:09 +02:00
|
|
|
|
2017-05-09 18:26:48 +02:00
|
|
|
list( APPEND HEADER_FILES ${GENERATED_G3_DEFINITIONS} )
|
|
|
|
list( APPEND SRC_FILES ${GENERATED_G3_DEFINITIONS} )
|
2014-10-03 08:56:13 +02:00
|
|
|
|
2016-01-24 13:27:52 +01:00
|
|
|
IF (MSVC OR MINGW)
|
2017-05-09 18:26:48 +02:00
|
|
|
list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_unix.cpp)
|
2015-07-21 12:21:31 +02:00
|
|
|
ELSE()
|
2017-05-09 18:26:48 +02:00
|
|
|
list(REMOVE_ITEM SRC_FILES ${LOG_SRC}/crashhandler_windows.cpp ${LOG_SRC}/g3log/stacktrace_windows.hpp ${LOG_SRC}/stacktrace_windows.cpp)
|
2014-10-03 08:56:13 +02:00
|
|
|
ENDIF (MSVC OR MINGW)
|
|
|
|
|
|
|
|
set(SRC_FILES ${SRC_FILES} ${SRC_PLATFORM_SPECIFIC})
|
2016-01-24 13:27:52 +01:00
|
|
|
|
2014-10-03 09:53:21 +02:00
|
|
|
# Create the g3log library
|
2017-03-31 06:52:09 +02:00
|
|
|
INCLUDE_DIRECTORIES(${LOG_SRC})
|
2017-05-09 18:26:48 +02:00
|
|
|
SET(G3LOG_LIBRARY g3logger)
|
|
|
|
|
|
|
|
IF( G3_SHARED_LIB )
|
2017-05-17 22:24:11 +02:00
|
|
|
IF( WIN32 )
|
2017-12-20 18:32:36 +01:00
|
|
|
IF(NOT(${CMAKE_VERSION} VERSION_LESS "3.4"))
|
2017-05-17 22:24:11 +02:00
|
|
|
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
|
|
|
ELSE()
|
|
|
|
message( FATAL_ERROR "Need CMake version >=3.4 to build shared windows library!" )
|
|
|
|
ENDIF()
|
2017-05-09 18:26:48 +02:00
|
|
|
ENDIF()
|
|
|
|
ADD_LIBRARY(${G3LOG_LIBRARY} SHARED ${SRC_FILES})
|
|
|
|
ELSE()
|
|
|
|
ADD_LIBRARY(${G3LOG_LIBRARY} STATIC ${SRC_FILES})
|
|
|
|
ENDIF()
|
2015-02-02 08:31:43 +01:00
|
|
|
|
2017-03-31 06:52:09 +02:00
|
|
|
SET(${G3LOG_LIBRARY}_VERSION_STRING ${VERSION})
|
2017-05-17 22:31:19 +02:00
|
|
|
MESSAGE( STATUS "Creating ${G3LOG_LIBRARY} VERSION: ${VERSION}" )
|
2017-03-31 06:52:09 +02:00
|
|
|
SET_TARGET_PROPERTIES(g3logger PROPERTIES LINKER_LANGUAGE CXX SOVERSION ${VERSION})
|
|
|
|
|
|
|
|
set_target_properties(${G3LOG_LIBRARY} PROPERTIES
|
2016-01-24 13:27:52 +01:00
|
|
|
LINKER_LANGUAGE CXX
|
|
|
|
OUTPUT_NAME g3logger
|
|
|
|
CLEAN_DIRECT_OUTPUT 1)
|
2017-03-31 06:52:09 +02:00
|
|
|
|
2015-09-01 08:02:36 +02:00
|
|
|
IF(APPLE)
|
2017-03-31 06:52:09 +02:00
|
|
|
set_target_properties(${G3LOG_LIBRARY} PROPERTIES MACOSX_RPATH TRUE)
|
|
|
|
ENDIF()
|
2015-09-06 13:22:04 +02:00
|
|
|
|
2017-03-31 06:52:09 +02:00
|
|
|
TARGET_LINK_LIBRARIES(${G3LOG_LIBRARY} ${PLATFORM_LINK_LIBRIES})
|
2014-10-03 08:56:13 +02:00
|
|
|
|
2017-03-31 06:52:09 +02:00
|
|
|
# Kjell: This is likely not necessary, except for Windows?
|
|
|
|
TARGET_INCLUDE_DIRECTORIES(${G3LOG_LIBRARY} PUBLIC ${LOG_SRC})
|
2014-10-03 08:56:13 +02:00
|
|
|
|
|
|
|
|