-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
116 lines (95 loc) · 2.82 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
cmake_policy(SET CMP0048 NEW)
project(
ioutils
VERSION "0.1.0"
DESCRIPTION "A blazing fast small file I/O library."
LANGUAGES CXX)
cmake_minimum_required(VERSION 3.15)
# Use ccache by default
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
endif()
# Generate the version information
find_package(Git)
if(Git_NOTFOUND)
message(FATAL_ERROR "Cannot find the git command")
endif()
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --verify HEAD
OUTPUT_VARIABLE IOUTILS_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
file(WRITE "commands/version.hpp"
"constexpr char version[] = \"${IOUTILS_VERSION}\";\n")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(AddCXXCompilerFlag)
include(CXXFeatureCheck)
# Use C++ 17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(ENABLE_ALL_WARNINGS ON)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(POSITION_INDEPENDENT_CODE OFF)
# Customized options
option(IOUTILS_ENABLE_TESTING "Build unittests" ON)
option(IOUTILS_ENABLE_BENCHMARK "Build benchmark" ON)
option(USE_AVX2 "Support AVX2 by default" ON)
# Enable AVX2 by default
if(USE_AVX2)
add_cxx_compiler_flag(-mavx2)
add_cxx_compiler_flag(-DUSE_AVX2)
endif()
# Install required libraries
include(FetchContent)
# fmt
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 7.1.3)
set(BUILD_TESTING OFF)
set(FMT_DOC OFF)
set(FMT_TEST OFF)
FetchContent_Populate(fmt)
# utils
FetchContent_Declare(
utils
GIT_REPOSITORY https://github.com/hungptit/utils.git
GIT_TAG master
GIT_SHALLOW TRUE)
FetchContent_Populate(utils)
# Add cmake-scripts
FetchContent_Declare(
cmake_scripts
GIT_REPOSITORY https://github.com/StableCoder/cmake-scripts.git
GIT_TAG main
GIT_SHALLOW TRUE)
FetchContent_Populate(cmake_scripts)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/_deps/cmake_scripts-src/;")
include(c++-standards)
include(code-coverage)
include(sanitizers)
include(tools)
include(dependency-graph)
set(CMAKE_VERBOSE_MAKEFILE ON)
# Exclude test files from the code coverage report.
file(GLOB_RECURSE TEST_SRCS CONFIGURE_DEPENDS unittests/*_test.cpp)
add_code_coverage_all_targets(EXCLUDE 3p _deps/ ${TEST_SRCS})
add_subdirectory(ioutils)
add_subdirectory(commands)
if(IOUTILS_ENABLE_BENCHMARK)
add_subdirectory(benchmark)
endif()
if(IOUTILS_ENABLE_TESTING)
add_subdirectory(unittests)
endif()
# Install all header files to destination folder.
install(DIRECTORY include/ioutils DESTINATION include)
install(TARGETS ioutils DESTINATION lib)
install(TARGETS fast-find DESTINATION bin)
install(TARGETS fast-locate DESTINATION bin)
install(TARGETS fast-updatedb DESTINATION bin)
install(TARGETS fast-wc DESTINATION bin)
enable_testing()
include(cmake/format_files.cmake)