-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
142 lines (122 loc) · 6.83 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
Cmake_minimum_required(VERSION 3.10)
project(Feller VERSION 1.0 LANGUAGES CXX DESCRIPTION "A small C++17 logging library")
if(CMAKE_BUILD_TYPE MATCHES Debug)
################################
# Clang-tidy
################################
## NB the "extra arg is meant to tell CMake not to run
## clang-tidy on system headers.
## This whole number of arguments are mostly telling clang-tidy to ignore any of the errors in
## google test.
set(CMAKE_CXX_CLANG_TIDY clang-tidy;-checks=*,-portability-*,-objc-*,-fuchsia-*,-abseil-*,-hicpp-*,-cppcoreguidelines-owning-memory,-llvm-include-order,-llvm-qualifed-auto,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-readability-magic-numbers,-cppcoreguidelines-avoid-goto,-cppcoreguidelines-pro-type-vararg,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cert-msc30-c,-cert-msc50-cpp,-hicpp-no-array-decay,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-macro-usage,-cppcoreguidelines-pro-type-static-cast-downcast,-hicpp-avoid-goto,-hicpp-vararg,-cert-err58-cpp;--extra-arg=-isystem; -fix-errors;)
################################
# GTest
################################
ADD_SUBDIRECTORY (googletest)
enable_testing()
include_directories(SYSTEM ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
add_library(FellerDebug SHARED
src/Feller_TestData.cpp
src/Feller_Data.cpp
src/Feller_Util.cpp
src/Feller_EventLog.cpp
src/Feller_MutexLock.cpp
src/Feller_NoLock.cpp
src/Feller_Logger.cpp
src/Feller_LoggingMode.cpp
src/Feller_StaticLoggingPolicy.cpp
src/Feller_LogEverything.cpp
src/Feller_LogNothing.cpp
src/Feller_Decl.cpp
src/Feller_ContiguousLogStorage.cpp)
# Clang doesn't seem to work well with GCOV at the moment.
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(FellerDebug PRIVATE -g3 -ggdb -std=c++17 -fsanitize=address,undefined -Wall -Wextra -Werror -Wpedantic -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wpedantic -Wsign-conversion -Wmisleading-indentation -Wnull-dereference -Wdouble-promotion -Wformat=2 -Wcast-qual -Wsign-promo -Wdisabled-optimization)
set(gcov_name "")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(FellerDebug PRIVATE -g3 -ggdb -std=c++17 -fsanitize=address,undefined -Wall -Wextra -Werror -Wpedantic -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wpedantic -Wsign-conversion -Wmisleading-indentation -Wnull-dereference -Wdouble-promotion -Wformat=2 -Wcast-qual -Wsign-promo -Wdisabled-optimization -fprofile-arcs -ftest-coverage)
set(gcov_name "gcov")
endif()
target_link_libraries(FellerDebug ${gcov_name} asan ubsan)
add_executable(testTestData src/Feller_TestData.t.cpp)
add_executable(testLog src/Feller_EventLog.t.cpp)
add_executable(testLock src/Feller_MutexLock.t.cpp)
add_executable(testNoLock src/Feller_NoLock.t.cpp)
add_executable(testContiguousLogStorage src/Feller_ContiguousLogStorage.t.cpp)
add_executable(testLogger src/Feller_Logger.t.cpp)
add_executable(testStaticLoggingPolicy src/Feller_StaticLoggingPolicy.t.cpp)
add_executable(testConditionalLoggingPolicy src/Feller_ConditionalLoggingPolicy.t.cpp)
### Force position independent code
set_target_properties(testTestData PROPERTIES COMPILE_FLAGS "-std=c++17")
set_target_properties(testLog PROPERTIES COMPILE_FLAGS "-std=c++17")
set_target_properties(testLock PROPERTIES COMPILE_FLAGS "-std=c++17 ")
set_target_properties(testNoLock PROPERTIES COMPILE_FLAGS "-std=c++17")
set_target_properties(testLogger PROPERTIES COMPILE_FLAGS "-std=c++17")
set_target_properties(testContiguousLogStorage PROPERTIES COMPILE_FLAGS "-std=c++17")
set_target_properties(testStaticLoggingPolicy PROPERTIES COMPILE_FLAGS "-std=c++17")
set_target_properties(testConditionalLoggingPolicy PROPERTIES COMPILE_FLAGS "-std=c++17")
### Link the target here
target_link_libraries(testTestData FellerDebug gtest gtest_main ${gcov_name} asan ubsan)
target_link_libraries(testLog FellerDebug gtest gtest_main ${gcov_name} asan ubsan)
target_link_libraries(testLock FellerDebug gtest gtest_main ${gcov_name} asan ubsan)
target_link_libraries(testNoLock FellerDebug gtest gtest_main ${gcov_name} asan ubsan)
target_link_libraries(testLogger FellerDebug gtest gtest_main ${gcov_name} asan ubsan)
target_link_libraries(testContiguousLogStorage FellerDebug gtest gtest_main ${gcov_name} asan ubsan)
target_link_libraries(testStaticLoggingPolicy FellerDebug gtest gtest_main ${gcov_name} asan ubsan)
target_link_libraries(testConditionalLoggingPolicy FellerDebug gtest gtest_main ${gcov_name} asan ubsan)
# Add here if you want ctest to pick up these tests.
# There's no reason not to have all tests here, as it makes
# running CI as simple as running Ctest
add_test(Log testLog)
add_test(TestData testTestData)
add_test(Lock testLock)
add_test(NoLock testNoLock)
add_test(Logger testLogger)
add_test(ContiguousLogStorage testContiguousLogStorage)
add_test(StaticLoggingPolicy testStaticLoggingPolicy)
add_test(ConditionalLoggingPolicy testConditionalLoggingPolicy)
endif()
##################################
# Doxygen
##################################
find_package(Doxygen)
option(BUILD_DOCUMENTATION "Create and install the HTML based API
documentation (requires Doxygen)" ${DOXYGEN_FOUND})
if(BUILD_DOCUMENTATION)
if(NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen is needed to build the documentation.")
endif()
set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set(doxyfile ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile)
configure_file(${doxyfile_in} ${doxyfile} @ONLY)
message("Doxygen build started.")
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile_in}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/doc
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
endif()
##################################
# Release mode
##################################
if (CMAKE_BUILD_TYPE MATCHES Release)
# These are compiler flags - these should not be used
# to give you a view of what the final code will look like: these are just for testing.
add_definitions("-Ofast -march=native -std=c++17 -march=native -fPIE -fPIC")
# Generate the output library
add_library(Feller SHARED
src/Feller_TestData.cpp
src/Feller_Data.cpp
src/Feller_Util.cpp
src/Feller_EventLog.cpp
src/Feller_MutexLock.cpp
src/Feller_NoLock.cpp
src/Feller_Logger.cpp
src/Feller_LoggingMode.cpp
src/Feller_StaticLoggingPolicy.cpp
src/Feller_LogEverything.cpp
src/Feller_LogNothing.cpp
src/Feller_Decl.cpp
src/Feller_ContiguousLogStorage.cpp)
add_executable(Example src/Feller_example.m.cpp)
endif()