forked from lpereira/lwan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
101 lines (83 loc) · 3.23 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
project(lwan C)
cmake_minimum_required(VERSION 2.8)
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, defaulting to Debug")
set(CMAKE_BUILD_TYPE "Debug")
endif ()
find_package(ZLIB REQUIRED)
find_package(Threads REQUIRED)
set(ADDITIONAL_LIBRARIES ${ZLIB_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
include(CheckCSourceCompiles)
check_c_source_compiles("int main(void) { __builtin_cpu_init(); }" HAVE_BUILTIN_CPU_INIT)
if (HAVE_BUILTIN_CPU_INIT)
add_definitions("-DHAVE_BUILTIN_CPU_INIT")
endif ()
check_c_source_compiles("int main(void) { unsigned long long p; (void)__builtin_umull_overflow(0, 0, &p); }" HAVE_BUILTIN_UMULL_OVERFLOW)
if (HAVE_BUILTIN_UMULL_OVERFLOW)
add_definitions("-DHAVE_BUILTIN_UMULL_OVERFLOW")
endif ()
check_c_source_compiles("int main(void) { _Static_assert(1, \"\"); }" HAVE_STATIC_ASSERT)
if (HAVE_STATIC_ASSERT)
add_definitions("-DHAVE_STATIC_ASSERT")
endif ()
include(CheckFunctionExists)
set(CMAKE_EXTRA_INCLUDE_FILES time.h)
check_function_exists(clock_gettime HAS_CLOCK_GETTIME)
if (HAS_CLOCK_GETTIME)
message(STATUS "libc has clock_gettime(). Good.")
else ()
list(APPEND ADDITIONAL_LIBRARIES rt)
message(STATUS "No clock_gettime() in libc. Linking with -lrt.")
endif ()
find_library(TCMALLOC_LIBRARY NAMES tcmalloc_minimal tcmalloc)
if (TCMALLOC_LIBRARY)
message(STATUS "tcmalloc found: ${TCMALLOC_LIBRARY}")
list(APPEND ADDITIONAL_LIBRARIES ${TCMALLOC_LIBRARY})
else ()
find_library(JEMALLOC_LIBRARY NAMES jemalloc)
if (JEMALLOC_LIBRARY)
message(STATUS "jemalloc found: ${JEMALLOC_LIBRARY}")
list(APPEND ADDITIONAL_LIBRARIES ${JEMALLOC_LIBRARY})
else ()
message(STATUS "jemalloc and tcmalloc were not found, using system malloc")
endif()
endif()
set(C_FLAGS_REL "-mtune=native -fno-asynchronous-unwind-tables")
include(CheckCCompilerFlag)
if (${CMAKE_BUILD_TYPE} MATCHES "Rel")
check_c_compiler_flag(-flto HAS_LTO)
if (HAS_LTO)
set(C_FLAGS_REL "${C_FLAGS_REL} -flto")
check_c_compiler_flag(-ffat-lto-objects HAS_FAT_LTO_OBJECTS)
if (HAS_FAT_LTO_OBJECTS)
set(C_FLAGS_REL "${C_FLAGS_REL} -ffat-lto-objects")
endif ()
endif ()
check_c_compiler_flag(-mcrc32 HAVE_BUILTIN_IA32_CRC32)
if (HAVE_BUILTIN_IA32_CRC32)
add_definitions("-DHAVE_BUILTIN_IA32_CRC32=1")
set(C_FLAGS_REL "${C_FLAGS_REL} -mcrc32")
endif ()
else ()
check_c_compiler_flag(-fsanitize=undefined HAS_UNDEFINED_SANITIZER)
if (HAS_UNDEFINED_SANITIZER)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=undefined")
endif ()
endif ()
find_path(VALGRIND_INCLUDE_DIR valgrind.h /usr/include /usr/include/valgrind /usr/local/include /usr/local/include/valgrind)
if (VALGRIND_INCLUDE_DIR)
message(STATUS "Building with Valgrind support")
add_definitions("-DUSE_VALGRIND=1")
else ()
message(STATUS "Valgrind headers not found -- disabling valgrind support")
endif()
set(CMAKE_C_FLAGS "-Wall -Wextra -Wshadow -Wconversion -std=gnu11")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${C_FLAGS_REL}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${C_FLAGS_REL}")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${C_FLAGS_REL}")
add_definitions("-D_FILE_OFFSET_BITS=64")
add_subdirectory(common)
include_directories(common)
add_subdirectory(lwan)
add_subdirectory(freegeoip)
add_subdirectory(techempower)