-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
150 lines (126 loc) · 3.7 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
143
144
145
146
147
148
149
150
cmake_minimum_required(VERSION 3.14)
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
set(THIS_NAME med)
project(${THIS_NAME})
enable_language(CXX)
message(STATUS "-------------------------------------------------------")
message(STATUS "MED library optional configuration:")
message(STATUS "\t(use ccmake or cmake -DWITH_XX=true)")
message(STATUS "-------------------------------------------------------")
option (WITH_BM "With Google benchmark." OFF)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
FetchContent_MakeAvailable(googletest)
find_package(Threads REQUIRED)
include_directories(
${PROJECT_SOURCE_DIR}/med
)
include(GoogleTest)
# -----------------------------------------------------------------------------
# Benchmarks
# -----------------------------------------------------------------------------
if (WITH_BM)
message(STATUS "\tWITH_BM=true (google benchmark)")
find_package(BENCHMARK REQUIRED)
if (BENCHMARK_FOUND)
include_directories( ${BENCHMARK_INCLUDE_DIRS})
message(STATUS "Google benchmark found. ${BENCHMARK_LIBS}")
else (BENCHMARK_FOUND)
message(FATAL_ERROR "Google benchmark not found. Disable WITH_BM or install it.")
endif (BENCHMARK_FOUND)
else (WITH_BM)
message(STATUS "\tWITH_BM=false (no benchmark)")
endif (WITH_BM)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++20" COMPILER_SUPPORTS_CXX20)
if (COMPILER_SUPPORTS_CXX20)
add_compile_options(-std=c++20)
else ()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++20 support. Please use a different C++ compiler.")
endif ()
# Library path
set(CMAKE_LDFLAGS "${CMAKE_LDFLAGS} -L\".\" ")
file(GLOB_RECURSE MED_SRCS med/*.hpp)
# file(GLOB_RECURSE UT_SRCS ut/*.cpp)
set(UT_SRCS
ut/bits.cpp
ut/choice.cpp
ut/copy.cpp
ut/diameter.cpp
ut/gtpc.cpp
ut/length.cpp
ut/med.cpp
ut/meta.cpp
ut/multi.cpp
ut/octets.cpp
ut/padding.cpp
ut/print.cpp
ut/protobuf.cpp
ut/sequence.cpp
ut/set.cpp
ut/unique.cpp
ut/value.cpp
ut/asn/ber.cpp
)
file(GLOB_RECURSE BM_SRCS benchmark/*.cpp)
#expose private for UTs
#add_compile_definitions(UNIT_TEST)
add_definitions(-DUNIT_TEST)
add_compile_options(
-Werror
-Wall
-Wextra
-Waddress
-Warray-bounds
-Winit-self
-Wunreachable-code
-pedantic
-pedantic-errors
#-march=native
-mtune=native
)
#set(PROJECT_CXXFLAGS "${PROJECT_CXXFLAGS} -Wno-gnu-zero-variadic-macro-arguments")
add_executable(gtest_med ${UT_SRCS} ${MED_SRCS})
if (WITH_BM)
add_executable(bm_med ${BM_SRCS})
# set_target_properties(bm_med PROPERTIES
# INTERPROCEDURAL_OPTIMIZATION ON)
target_link_libraries(bm_med
${BENCHMARK_LIBS}
${CMAKE_THREAD_LIBS_INIT}
)
add_custom_target(benchmark COMMAND echo "Benchmarking....."
DEPENDS bm_med
)
endif (WITH_BM)
# ------------------------------------------------------------------------------
# Coverage
# ------------------------------------------------------------------------------
if(COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()
#if(DEFINED ENV{BUILD_FLAGS})
# set(BUILD_FLAGS "$ENV{BUILD_FLAGS}")
#endif ()
#set_target_properties(gtest_${THIS_NAME} PROPERTIES COMPILE_FLAGS
# ${BUILD_FLAGS}
#)
target_link_libraries(gtest_med
GTest::gtest
${CMAKE_THREAD_LIBS_INIT}
)
enable_testing()
add_test(UT gtest_${THIS_NAME})
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
DEPENDS gtest_${THIS_NAME}
)