forked from fluent/fluent-bit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
98 lines (82 loc) · 2.57 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
cmake_minimum_required(VERSION 2.8)
project(chunk-io)
# CFLAGS
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 ")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall ")
endif()
# Set __FILENAME__
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FILENAME__=__FILE__")
endif()
# ChunkIO options
option(CIO_DEV "Enable dev/test mode" Off)
option(CIO_LIB_STATIC "Enable static library build" On)
option(CIO_LIB_SHARED "Enable shared library build" Off)
option(CIO_SANITIZE_ADDRESS "Enable address sanitizer" Off)
option(CIO_TESTS "Enable tests" Off)
option(CIO_BACKEND_FILESYSTEM "Enable filesystem backend" On)
# Windows does not have file system backend support yet.
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(CIO_BACKEND_FILESYSTEM Off)
endif()
# Force Option value
macro(CIO_OPTION option value)
set(${option} ${value} CACHE "" INTERNAL FORCE)
endmacro()
# Development/Test mode
if(CIO_DEV)
CIO_OPTION(CMAKE_BUILD_TYPE "Debug")
CIO_OPTION(CIO_TESTS On)
CIO_OPTION(CIO_LIB_STATIC On)
endif()
# Macro to set definitions
macro(CIO_DEFINITION var)
add_definitions(-D${var})
set(CIO_BUILD_FLAGS "${CIO_BUILD_FLAGS}#ifndef ${var}\n#define ${var}\n#endif\n")
set(CIO_INFO_FLAGS "${CIO_INFO_FLAGS} ${var}")
endmacro()
# Check if Address Sanitizer is enabled
if(CIO_SANITIZE_ADDRESS OR SANITIZE_ADDRESS)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/sanitizers-cmake/cmake" ${CMAKE_MODULE_PATH})
if(NOT SANITIZE_ADDRESS)
add_definitions(-DSANITIZE_ADDRESS=On)
endif()
find_package(Sanitizers)
# Note that this package don't define Sanitizers_FOUND:
# https://github.com/arsenm/sanitizers-cmake/issues/16
if (NOT DEFINED SANITIZE_LINK_STATIC)
message(FATAL_ERROR "CMake Sanitizer not found")
else()
message(STATUS "Enabling address sanitizer")
endif()
endif()
if(CIO_BACKEND_FILESYSTEM)
CIO_DEFINITION(CIO_HAVE_BACKEND_FILESYSTEM)
endif()
include(CheckCSourceCompiles)
# fallocate support
check_c_source_compiles("
#include <fcntl.h>
int main() {
fallocate(0,0,0);
return 0;
}" CIO_HAVE_FALLOCATE)
if(CIO_HAVE_FALLOCATE)
CIO_DEFINITION(CIO_HAVE_FALLOCATE)
endif()
include_directories(
include
deps/
deps/monkey/include
)
add_subdirectory(deps/crc32)
add_subdirectory(src)
add_subdirectory(tools)
if(CIO_TESTS)
add_subdirectory(tests)
endif()