-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeListsHelpers.txt
148 lines (134 loc) · 4.4 KB
/
CMakeListsHelpers.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
# Contains common functions used by all cmake files, such as finding various libraries
# or checking for the presence of specific system features
function (findOpenMP)
# unset OpenMP_CXX_FLAGS. If OpenMP loading fails once, it will be set to NOT_FOUND
# and happily cached, thus messing up the compilation flags forever
unset(OpenMP_CXX_FLAGS CACHE)
find_package(OpenMP REQUIRED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" PARENT_SCOPE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" PARENT_SCOPE)
set(OpenMP_CXX_LIBRARIES "${OpenMP_CXX_LIBRARIES}" PARENT_SCOPE)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(OpenMP_CXX_LIBRARIES ${OpenMP_CXX_LIBRARIES} -latomic PARENT_SCOPE)
endif()
endfunction()
# check for std::filesystem::temp_directory_path
function (checkFileSystem)
include(CheckCXXSourceRuns)
set(CMAKE_REQUIRED_FLAGS " -std=c++17")
check_cxx_source_runs("
#include <iostream>
#include <filesystem>
int main() {
std::cout << std::filesystem::temp_directory_path();
return 0;
}
" CPPNOFS)
if(NOT CPPNOFS)
set(CMAKE_REQUIRED_FLAGS " -std=c++17")
set(CMAKE_REQUIRED_LIBRARIES "c++fs")
check_cxx_source_runs("
#include <iostream>
#include <filesystem>
int main() {
std::cout << std::filesystem::temp_directory_path();
return 0;
}
" CPPFS)
unset(CMAKE_REQUIRED_FLAGS)
unset(CMAKE_REQUIRED_LIBRARIES)
if(CPPFS)
set(FILESYSTEM_LIBRARY -lc++fs PARENT_SCOPE)
else()
set(CMAKE_REQUIRED_FLAGS " -std=c++17")
set(CMAKE_REQUIRED_LIBRARIES "stdc++fs")
check_cxx_source_runs("
#include <iostream>
#include <filesystem>
int main() {
std::cout << std::filesystem::temp_directory_path();
return 0;
}
" STDCPPFS)
unset(CMAKE_REQUIRED_FLAGS)
unset(CMAKE_REQUIRED_LIBRARIES)
if(STDCPPFS)
set(FILESYSTEM_LIBRARY -lstdc++fs PARENT_SCOPE)
else()
message(FATAL_ERROR "std::filesystem not found")
endif()
endif()
endif()
endfunction()
function (findFolly)
unset(FOLLY_FOUND PARENT_SCOPE)
unset(Boost_INCLUDE_DIR CACHE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR})
find_package(Boost)
find_package(Jemalloc)
if(Jemalloc_FOUND)
if(${JEMALLOC_VERSION} VERSION_LESS 4.0)
message(WARNING "jemalloc version less than 4.0")
unset(Jemalloc_FOUND)
endif()
endif()
if(Jemalloc_FOUND AND Boost_FOUND)
message(STATUS "Configuring Folly")
include(external-libraries/folly/CMake/FollyConfigChecks.cmake)
configure_file(
external-libraries/folly/CMake/folly-config.h.cmake
${CMAKE_BINARY_DIR}/external-libraries/folly/include/folly/folly-config.h
)
add_library(fbvector STATIC
external-libraries/folly/folly/ScopeGuard.cpp
external-libraries/folly/folly/memory/detail/MallocImpl.cpp
)
target_include_directories(fbvector SYSTEM PRIVATE
${JEMALLOC_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
external-libraries/folly
${CMAKE_BINARY_DIR}/external-libraries/folly/include
${PROJECT_SOURCE_DIR}/src/common
)
target_link_libraries(fbvector PRIVATE ${JEMALLOC_LIBRARIES})
set(FOLLY_FOUND TRUE PARENT_SCOPE)
endif()
endfunction()
function (buildProgressBar EXTERNAL_LIB_DIR libName)
set(${libName} progress_bar PARENT_SCOPE)
if(TARGET progress_bar)
return()
endif()
add_library(progress_bar STATIC
${EXTERNAL_LIB_DIR}/cpp_progress_bar/progress_bar.cpp
)
endfunction()
function (buildMersenneTwister EXTERNAL_LIB_DIR libName)
set(${libName} mersenne_twister PARENT_SCOPE)
if(TARGET mersenne_twister)
return()
endif()
add_library(mersenne_twister STATIC
${EXTERNAL_LIB_DIR}/rollinghashcpp/mersennetwister.cpp
)
endfunction()
function (findGTest)
if(TARGET gtest)
return()
endif()
execute_process(COMMAND rm -rf ${EXTERNAL_LIB_DIR}/sdsl-lite/include/gtest)
add_subdirectory(${EXTERNAL_LIB_DIR}/googletest googletest EXCLUDE_FROM_ALL)
target_compile_options(gtest_main PRIVATE -w)
target_compile_options(gtest PRIVATE -w)
set(GTEST_BOTH_LIBRARIES gtest gtest_main PARENT_SCOPE)
endfunction()
# Enables using ccache in order to speed up compilation. Make sure you
# brew install ccache to benefit from it
function (enableCCache)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
else()
message(STATUS "ccache not found. Run 'brew install ccache' to speed up re-compilation")
endif(CCACHE_FOUND)
endfunction()