-
-
Notifications
You must be signed in to change notification settings - Fork 933
/
CMakeLists.txt
103 lines (80 loc) · 3.38 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
cmake_minimum_required(VERSION 2.8.7)
project(Easyloggingpp CXX)
macro(require_cpp14)
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.0)
# CMake 3.1 has built-in CXX standard checks.
message("-- Setting C++14")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED on)
else()
if (CMAKE_CXX_COMPILER_ID MATCHES "GCC")
message ("-- GNU CXX (-std=c++14)")
list(APPEND CMAKE_CXX_FLAGS "-std=c++14")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message ("-- CLang CXX (-std=c++14)")
list(APPEND CMAKE_CXX_FLAGS "-std=c++14")
else()
message ("-- Easylogging++ requires C++14. Your compiler does not support it.")
endif()
endif()
endmacro()
option(test "Build all tests" OFF)
option(build_static_lib "Build easyloggingpp as a static library" OFF)
option(lib_utc_datetime "Build library with UTC date/time logging" OFF)
set(ELPP_MAJOR_VERSION "9")
set(ELPP_MINOR_VERSION "96")
set(ELPP_PATCH_VERSION "7")
set(ELPP_VERSION_STRING "${ELPP_MAJOR_VERSION}.${ELPP_MINOR_VERSION}.${ELPP_PATCH_VERSION}")
set(ELPP_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The directory the headers are installed in")
set(ELPP_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
install(FILES
src/easylogging++.h
src/easylogging++.cc
DESTINATION "${ELPP_INCLUDE_INSTALL_DIR}"
COMPONENT dev)
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/easyloggingpp.pc.cmakein
${CMAKE_CURRENT_BINARY_DIR}/easyloggingpp.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/easyloggingpp.pc DESTINATION "${ELPP_PKGCONFIG_INSTALL_DIR}")
include(CheckIncludeFileCXX)
check_include_file_cxx("execinfo.h" HAVE_EXECINFO)
if (HAVE_EXECINFO)
add_definitions(-DHAVE_EXECINFO)
endif()
if (build_static_lib)
if (lib_utc_datetime)
add_definitions(-DELPP_UTC_DATETIME)
endif()
require_cpp14()
add_library(easyloggingpp STATIC src/easylogging++.cc)
set_property(TARGET easyloggingpp PROPERTY POSITION_INDEPENDENT_CODE ON)
install(TARGETS
easyloggingpp
ARCHIVE DESTINATION lib)
endif()
export(PACKAGE ${PROJECT_NAME})
########################################## Unit Testing ###################################
if (test)
# We need C++14 (Google Test requirement)
require_cpp14()
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
find_package (GTest REQUIRED)
include_directories (${GTEST_INCLUDE_DIRS})
enable_testing()
if (EMSCRIPTEN)
set(CMAKE_EXE_LINKER_FLAGS "-O2 -s TOTAL_MEMORY=134217728")
endif()
add_executable(easyloggingpp-unit-tests
src/easylogging++.cc
test/main.cc
)
target_compile_definitions(easyloggingpp-unit-tests PUBLIC
ELPP_FEATURE_ALL
ELPP_LOGGING_FLAGS_FROM_ARG
ELPP_NO_DEFAULT_LOG_FILE
ELPP_FRESH_LOG_FILE
)
# Standard linking to gtest stuff.
target_link_libraries(easyloggingpp-unit-tests ${GTEST_BOTH_LIBRARIES})
add_test(NAME easyloggingppUnitTests COMMAND easyloggingpp-unit-tests -v)
endif()