forked from lighttransport/tubular-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
90 lines (75 loc) · 3.15 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
cmake_minimum_required(VERSION 3.10) # We could lower CMake version
project(tubular LANGUAGES CXX C)
set(BUILD_TARGET tubular)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
option(BUILD_WITH_MARCH_NATIVE "Enable architecture-aware optimization (-march=native)" OFF)
option(USE_SANITIZER "Enable Address/Memory sanitizer to check memory leak etc..." OFF)
option(USE_CCACHE "Use ccache to accelerate a build(if available)" ON)
# build type
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Release")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
# CCACHE
find_program(CCACHE_EXE ccache)
if(USE_CCACHE AND CCACHE_EXE)
message(STATUS "ccache: Enabled")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_EXE}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_EXE}")
else()
message(STATUS "ccache: Disabled")
set(USE_CCACHE OFF)
endif()
# Sanitizer
if(USE_SANITIZER)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
message(STATUS "Address/Memory sanitizer: ENABLED")
else()
message(STATUS "Address/Memory sanitizer: DISABLED")
endif()
# Overall compile options
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_GLIBCXX_DEBUG -D_LIBCPP_DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG -D_LIBCPP_DEBUG")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
if(BUILD_WITH_MARCH_NATIVE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=native -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=native -march=native")
message(STATUS "Architecture-aware optimization (-march=native): ENABLED")
else()
if (MSVC)
else(MSVC)
# TODO(LTE): Use compiler generator expression
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=native")
message(STATUS "Architecture-aware optimization (-march=native): DISABLED")
endif(MSVC)
endif()
set(CMAKE_CXX_STANDARD 11)
# find package and check third party
# - google glog (optional)
# - pthread
# Stack Trace logger (Glog)
option(USE_STACK_TRACE_LOGGER "Enable automatic stack trace logger of google-glog" OFF)
if(USE_STACK_TRACE_LOGGER)
message(STATUS "Stack trace logger: ENABLED")
# Glog
find_package(Glog REQUIRED)
else()
message(STATUS "Stack trace logger: DISABLED")
endif()
# Threads
find_package(Threads REQUIRED)
if(NOT Threads_FOUND)
message(FATAL_ERROR "Threads not found")
endif()
set(TUBULAR_CLANG_COMPILE_OPTIONS
-Wall -Wextra -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded)
# build selection
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/StaticJSON/)
add_subdirectory(src)
add_subdirectory(pc)