-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
177 lines (159 loc) · 6.58 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
cmake_minimum_required(VERSION 3.14)
project(orient VERSION 0.4.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(ORIE_TEST "Build Google Test for Orient Library" OFF)
option(ORIE_SYSTEM_PCRE2 "Use System PCRE2 Library" OFF)
option(ORIE_SYSTEM_ZSTD "Use System zstd Library" OFF)
option(ORIE_SYSTEM_RAPIDFUZZ "Use System rapidfuzz Library" OFF)
option(ORIE_LINK_STATIC "Statically link orient executable" OFF)
include(FetchContent)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(targs_to_install orie)
# Unfortunately PCRE2 provides no package name therefore whether to use system
# library can only be manually toggled unlike GTest.
if (NOT ORIE_SYSTEM_PCRE2)
FetchContent_Declare(pcre2
GIT_REPOSITORY https://github.com/PCRE2Project/pcre2
GIT_TAG pcre2-10.42)
set(PCRE2_BUILD_PCRE2GREP OFF CACHE INTERNAL "")
set(PCRE2_BUILD_TESTS OFF CACHE INTERNAL "")
set(PCRE2_DISABLE_PERCENT_ZT ON CACHE INTERNAL "")
if (WIN32)
set(PCRE2_NEWLINE "CRLF" CACHE INTERNAL "")
set(PCRE2_BUILD_PCRE2_8 OFF CACHE INTERNAL "")
set(PCRE2_BUILD_PCRE2_16 ON CACHE INTERNAL "")
endif(WIN32)
# By default PCRE2 build static lib only, and the bundled pcre2 is static
FetchContent_MakeAvailable(pcre2)
endif(NOT ORIE_SYSTEM_PCRE2)
set(orie_pcre2_libname pcre2-)
if (NOT ORIE_SYSTEM_ZSTD)
FetchContent_Declare(zstd
GIT_REPOSITORY https://github.com/facebook/zstd.git
GIT_TAG v1.5.1)
# zstd CMake file is in build/cmake
# cannot simply call FetchContent_MakeAvailable due to this
FetchContent_GetProperties(zstd)
if (NOT zstd_POPULATED)
FetchContent_Populate(zstd)
set(ZSTD_BUILD_SHARED OFF CACHE INTERNAL "")
set(ZSTD_LEGACY_SUPPORT OFF CACHE INTERNAL "")
set(ZSTD_BUILD_PROGRAMS OFF CACHE INTERNAL "")
set(ZSTD_BUILD_TESTS OFF CACHE INTERNAL "")
add_subdirectory(${zstd_SOURCE_DIR}/build/cmake
${zstd_BINARY_DIR})
endif (NOT zstd_POPULATED)
add_library(zstd ALIAS libzstd_static)
endif (NOT ORIE_SYSTEM_ZSTD)
if (NOT ORIE_SYSTEM_RAPIDFUZZ)
FetchContent_Declare(rapidfuzz
GIT_REPOSITORY https://github.com/maxbachmann/rapidfuzz-cpp.git
GIT_TAG main)
FetchContent_MakeAvailable(rapidfuzz)
else (NOT ORIE_SYSTEM_RAPIDFUZZ)
find_package(rapidfuzz REQUIRED)
endif (NOT ORIE_SYSTEM_RAPIDFUZZ)
# List common sources
set(s ${CMAKE_CURRENT_SOURCE_DIR}/src/fs)
set(orie_src
${s}/app.cpp ${s}/data_iter.cpp
${s}/dumper.cpp ${s}/trigram.cpp
)
set(s ${CMAKE_CURRENT_SOURCE_DIR}/src/fs_pred_tree)
set(orie_src ${orie_src}
${s}/action_node.cpp ${s}/content_node.cpp
${s}/iter_manip_node.cpp ${s}/name_node.cpp
${s}/stat_node.cpp ${s}/fs_expr_builder.cpp
)
set(s ${CMAKE_CURRENT_SOURCE_DIR}/src/util/compresslib)
set(orie_src ${orie_src}
${s}/bitpacking.cpp
${s}/integratedbitpacking.cpp
${s}/intersection.cpp
${s}/../file_mem_chunk.cpp
${s}/../arr2d.cpp
)
unset(s)
# Platform specific settings
if(WIN32)
set(orie_src ${orie_src}
${CMAKE_CURRENT_SOURCE_DIR}/src/util/dirent_win.c)
set(orie_pcre2_libname ${orie_pcre2_libname}16)
else(WIN32)
set(orie_pcre2_libname ${orie_pcre2_libname}8)
endif(WIN32)
add_library(orie ${orie_src})
add_executable(orient ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cc)
target_link_libraries(orie PUBLIC ${orie_pcre2_libname})
target_link_libraries(orie PRIVATE zstd rapidfuzz::rapidfuzz)
target_link_libraries(orient PRIVATE orie)
if(WIN32)
target_link_libraries(orie PUBLIC shlwapi)
endif(WIN32)
target_include_directories(orie PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
add_library(orie::orie ALIAS orie)
# On most systems PCRE2 libs are known as pcre2-{8,16,32}
# But on PCRE2's CMakeLists.txt, they are called pcre2-*-{static,shared}
if (NOT ORIE_SYSTEM_PCRE2)
set(orie_pcre2_libname ${orie_pcre2_libname}-static)
set_target_properties(${orie_pcre2_libname} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES
$<INSTALL_INTERFACE:include>)
set(targs_to_install ${targs_to_install} ${orie_pcre2_libname})
target_include_directories(orie PUBLIC
$<BUILD_INTERFACE:${pcre2_BINARY_DIR}>)
endif(NOT ORIE_SYSTEM_PCRE2)
if(NOT ORIE_SYSTEM_ZSTD)
target_include_directories(orie PUBLIC
$<BUILD_INTERFACE:${zstd_SOURCE_DIR}/lib>)
endif(NOT ORIE_SYSTEM_ZSTD)
if(ORIE_TEST)
add_subdirectory(test)
endif(ORIE_TEST)
unset(orie_pcre2_libname)
install(TARGETS orient DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp")
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h")
# Install liborie as CMake Module
set(ORIE_CMAKE_CONFIG_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/orie)
# Group all (only 1 in this case, which is `orient`) library targets
# into a single exported target
install(TARGETS ${targs_to_install} EXPORT orieTargs DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Generate *Config.cmake for each library target
# Only generate orie since pcre2 is static linked,
# rapidfuzz and zstd handle install by themselves
configure_package_config_file(orieConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/orieConfig.cmake
INSTALL_DESTINATION ${ORIE_CMAKE_CONFIG_DESTINATION})
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/orieConfigVersion.cmake
COMPATIBILITY SameMinorVersion)
install(EXPORT orieTargs NAMESPACE orie::
DESTINATION ${ORIE_CMAKE_CONFIG_DESTINATION})
install(TARGETS orie DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Manually install *Config.cmake for each target
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/orieConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/orieConfigVersion.cmake
DESTINATION ${ORIE_CMAKE_CONFIG_DESTINATION})
if(ORIE_LINK_STATIC)
set_target_properties(orie PROPERTIES LINK_SEARCH_START_STATIC ON)
set_target_properties(orie PROPERTIES LINK_SEARCH_END_STATIC ON)
target_link_options(orie PRIVATE -static-libgcc -static-libstdc++ -static)
set_target_properties(orient PROPERTIES LINK_SEARCH_START_STATIC ON)
set_target_properties(orient PROPERTIES LINK_SEARCH_END_STATIC ON)
target_link_options(orient PRIVATE -static-libgcc -static-libstdc++ -static)
endif(ORIE_LINK_STATIC)
target_compile_options(orie PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>
)
target_compile_options(orie PUBLIC
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-mssse3 -mpopcnt>
)