-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
203 lines (163 loc) · 5.26 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
option(UFOEXECUTION_BUILD_DOCS "Generate documentation" OFF)
option(UFOEXECUTION_BUILD_TESTS "Unit testing" OFF)
option(UFOEXECUTION_BUILD_COVERAGE "Test Coverage" OFF)
add_library(Execution INTERFACE)
add_library(UFO::Execution ALIAS Execution)
target_link_libraries(Execution INTERFACE UFO::Utility)
# Threading library required in Linux (not in MacOS and Windows, they should just ignore it. Windows might give a warning)
find_package(Threads REQUIRED)
target_link_libraries(Execution INTERFACE Threads::Threads)
include(CheckCXXSourceCompiles)
include(CMakePushCheckState)
message(CHECK_START "Finding parallel processing libraries")
list(APPEND CMAKE_MESSAGE_INDENT " ")
unset(missingParallelLibs)
message(CHECK_START "Finding Threading Building Blocks (TBB)")
# include("${PROJECT_SOURCE_DIR}/3rdparty/tbb/tbb.cmake")
find_package(TBB QUIET)
if(TBB_FOUND)
list(APPEND CMAKE_MESSAGE_INDENT " ")
message(CHECK_START "Checking if oneTBB and not TBB")
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "-O0")
set(CMAKE_REQUIRED_LIBRARIES "TBB::tbb")
# TODO: Fix sample code
check_cxx_source_compiles("
// #include <oneapi/tbb.h>
int main() {
return 0;
}
" HAVE_ONETBB_PAR)
cmake_pop_check_state()
if(HAVE_ONETBB_PAR)
message(CHECK_PASS "has oneTBB")
list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_PASS "found and enabled")
target_link_libraries(Execution INTERFACE TBB::tbb)
target_compile_definitions(Execution INTERFACE UFO_PAR_TBB=1)
else()
message(CHECK_FAIL "only has old TBB (not oneTBB)")
list(POP_BACK CMAKE_MESSAGE_INDENT)
message(CHECK_FAIL "not found and disabled")
list(APPEND missingParallelLibs TBB)
endif()
else()
message(CHECK_FAIL "not found and disabled")
list(APPEND missingParallelLibs TBB)
endif()
message(CHECK_START "Checking Standard Template Library (STL) parallel support")
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "-O0")
check_cxx_source_compiles("
#include <algorithm>
#include <array>
#include <execution>
int main() {
std::array<int, 10> a{};
std::for_each(std::execution::par, a.begin(), a.end(), [](auto){});
(void)a;
return 0;
}
" HAVE_STL_PAR)
if(HAVE_STL_PAR)
message(CHECK_PASS "has native support")
target_compile_definitions(Execution INTERFACE UFO_PAR_STL=1)
else()
if(TBB_FOUND)
set(CMAKE_REQUIRED_LIBRARIES "TBB::tbb")
check_cxx_source_compiles("
#include <algorithm>
#include <array>
#include <execution>
int main() {
std::array<int, 10> a{};
std::for_each(std::execution::par, a.begin(), a.end(), [](auto){});
(void)a;
return 0;
}
" HAVE_STL_PAR_USING_TBB)
if(HAVE_STL_PAR_USING_TBB)
message(CHECK_PASS "has support using TBB")
target_link_libraries(Execution INTERFACE TBB::tbb)
target_compile_definitions(Execution INTERFACE UFO_PAR_STL=1)
else()
message(CHECK_FAIL "no support")
list(APPEND missingParallelLibs STL)
endif()
else()
message(CHECK_FAIL "no support")
list(APPEND missingParallelLibs STL)
endif()
endif()
cmake_pop_check_state()
message(CHECK_START "Finding Grand Central Dispatch (GCD)")
if(APPLE)
message(CHECK_PASS "found and enabled")
target_compile_definitions(Execution INTERFACE UFO_PAR_GCD=1)
else()
message(CHECK_FAIL "not found and disabled")
list(APPEND missingParallelLibs GCD)
endif()
message(CHECK_START "Finding OpenMP (OMP)")
find_package(OpenMP QUIET)
if(OpenMP_CXX_FOUND)
message(CHECK_PASS "found and enabled")
target_link_libraries(Execution INTERFACE OpenMP::OpenMP_CXX)
target_compile_definitions(Execution INTERFACE UFO_PAR_OMP=1)
else()
message(CHECK_FAIL "not found and disabled")
list(APPEND missingParallelLibs OMP)
endif()
list(POP_BACK CMAKE_MESSAGE_INDENT)
if(missingParallelLibs)
message(CHECK_FAIL "disabled parallel processing libraries: ${missingParallelLibs}")
else()
message(CHECK_PASS "all parallel processing libraries found and enabled")
endif()
include(GNUInstallDirs)
target_include_directories(Execution
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
if(UFO_BUILD_TESTS OR UFOEXECUTION_BUILD_TESTS)
add_subdirectory(tests)
endif()
if(UFO_BUILD_DOCS OR UFOEXECUTION_BUILD_DOCS)
add_subdirectory(docs)
endif()
install(TARGETS Execution EXPORT Execution-targets
COMPONENT Execution
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
install(EXPORT Execution-targets
FILE "Execution-targets.cmake"
NAMESPACE UFO::
DESTINATION lib/cmake/${PROJECT_NAME}
COMPONENT Execution
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/Execution-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Execution-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/Execution-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/Execution-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/Execution-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
COMPONENT Execution
)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include
COMPONENT Execution
DESTINATION ${CMAKE_INSTALL_PREFIX}
)