10
10
#
11
11
##===----------------------------------------------------------------------===##
12
12
13
- if ("${CMAKE_SOURCE_DIR} " STREQUAL "${CMAKE_CURRENT_SOURCE_DIR} " )
14
- message (FATAL_ERROR "Direct configuration not supported, please use parent directory!" )
13
+ cmake_minimum_required (VERSION 3.20.0)
14
+
15
+ if ("${CMAKE_SOURCE_DIR} " STREQUAL "${CMAKE_CURRENT_SOURCE_DIR} " )
16
+ set (OPENMP_STANDALONE_BUILD TRUE )
17
+ project (offload C CXX ASM)
18
+ endif ()
19
+
20
+ set (ENABLE_LIBOMPTARGET ON )
21
+ # Currently libomptarget cannot be compiled on Windows or MacOS X.
22
+ # Since the device plugins are only supported on Linux anyway,
23
+ # there is no point in trying to compile libomptarget on other OSes.
24
+ # 32-bit systems are not supported either.
25
+ if (APPLE OR WIN32 OR NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
26
+ set (ENABLE_LIBOMPTARGET OFF )
15
27
endif ()
16
28
17
- # Add cmake directory to search for custom cmake functions.
18
- set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} /cmake/Modules ${CMAKE_MODULE_PATH} )
29
+ option (OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading."
30
+ ${ENABLE_LIBOMPTARGET} )
31
+ if (OPENMP_ENABLE_LIBOMPTARGET)
32
+ # Check that the library can actually be built.
33
+ if (APPLE OR WIN32 )
34
+ message (FATAL_ERROR "libomptarget cannot be built on Windows and MacOS X!" )
35
+ elseif (NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
36
+ message (FATAL_ERROR "Host compiler must support C++17 to build libomptarget!" )
37
+ elseif (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
38
+ message (FATAL_ERROR "libomptarget on 32-bit systems are not supported!" )
39
+ endif ()
40
+ endif ()
41
+
42
+ # TODO: Leftover from the move, could probably be just LLVM_LIBDIR_SUFFIX everywhere.
43
+ set (OFFLOAD_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX} " )
44
+
45
+ set (LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR} /../cmake)
46
+
47
+ # Add path for custom modules
48
+ list (INSERT CMAKE_MODULE_PATH 0
49
+ "${CMAKE_CURRENT_SOURCE_DIR} /cmake"
50
+ "${CMAKE_CURRENT_SOURCE_DIR} /cmake/Modules"
51
+ "${LLVM_COMMON_CMAKE_UTILS} /Modules"
52
+ )
53
+
54
+ if (OPENMP_STANDALONE_BUILD)
55
+ # CMAKE_BUILD_TYPE was not set, default to Release.
56
+ if (NOT CMAKE_BUILD_TYPE )
57
+ set (CMAKE_BUILD_TYPE Release)
58
+ endif ()
59
+
60
+ # Group common settings.
61
+ set (OPENMP_ENABLE_WERROR FALSE CACHE BOOL
62
+ "Enable -Werror flags to turn warnings into errors for supporting compilers." )
63
+ set (OPENMP_LIBDIR_SUFFIX "" CACHE STRING
64
+ "Suffix of lib installation directory, e.g. 64 => lib64" )
65
+ # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR.
66
+ set (OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX} " )
67
+
68
+ # Group test settings.
69
+ set (OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
70
+ "C compiler to use for testing OpenMP runtime libraries." )
71
+ set (OPENMP_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING
72
+ "C++ compiler to use for testing OpenMP runtime libraries." )
73
+ set (OPENMP_TEST_Fortran_COMPILER ${CMAKE_Fortran_COMPILER} CACHE STRING
74
+ "FORTRAN compiler to use for testing OpenMP runtime libraries." )
75
+ set (OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing." )
76
+
77
+ set (CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to" )
78
+ set (CMAKE_CXX_STANDARD_REQUIRED NO )
79
+ set (CMAKE_CXX_EXTENSIONS NO )
80
+ else ()
81
+ set (OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR} )
82
+ # If building in tree, we honor the same install suffix LLVM uses.
83
+ set (OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX} " )
84
+
85
+ if (NOT MSVC )
86
+ set (OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR} /clang)
87
+ set (OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR} /clang++)
88
+ else ()
89
+ set (OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR} /clang.exe)
90
+ set (OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR} /clang++.exe)
91
+ endif ()
92
+
93
+ # Check for flang
94
+ if (NOT MSVC )
95
+ set (OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR} /flang-new)
96
+ else ()
97
+ set (OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR} /flang-new.exe)
98
+ endif ()
99
+
100
+ # Set fortran test compiler if flang is found
101
+ if (EXISTS "${OPENMP_TEST_Fortran_COMPILER} " )
102
+ message ("Using local flang build at ${OPENMP_TEST_Fortran_COMPILER} " )
103
+ else ()
104
+ unset (OPENMP_TEST_Fortran_COMPILER)
105
+ endif ()
106
+
107
+ # If not standalone, set CMAKE_CXX_STANDARD but don't set the global cache value,
108
+ # only set it locally for OpenMP.
109
+ set (CMAKE_CXX_STANDARD 17)
110
+ set (CMAKE_CXX_STANDARD_REQUIRED NO )
111
+ set (CMAKE_CXX_EXTENSIONS NO )
112
+ endif ()
19
113
20
114
# Set the path of all resulting libraries to a unified location so that it can
21
115
# be used for testing.
@@ -36,6 +130,9 @@ include(LibomptargetUtils)
36
130
# Get dependencies for the different components of the project.
37
131
include (LibomptargetGetDependencies)
38
132
133
+ # Set up testing infrastructure.
134
+ include (OpenMPTesting)
135
+
39
136
# LLVM source tree is required at build time for libomptarget
40
137
if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS)
41
138
message (FATAL_ERROR "Missing definition for LIBOMPTARGET_LLVM_INCLUDE_DIRS" )
@@ -101,6 +198,58 @@ if (LIBOMPTARGET_USE_LTO)
101
198
list (APPEND offload_link_flags ${CMAKE_CXX_COMPILE_OPTIONS_IPO} )
102
199
endif ()
103
200
201
+ if (OPENMP_STANDALONE_BUILD)
202
+ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
203
+ execute_process (
204
+ OUTPUT_STRIP_TRAILING_WHITESPACE
205
+ COMMAND ${CMAKE_CXX_COMPILER} --print-resource -dir
206
+ RESULT_VARIABLE COMMAND_RETURN_CODE
207
+ OUTPUT_VARIABLE COMPILER_RESOURCE_DIR
208
+ )
209
+ endif ()
210
+
211
+ set (LIBOMP_HAVE_OMPT_SUPPORT FALSE )
212
+ set (LIBOMP_OMPT_SUPPORT FALSE )
213
+
214
+ find_path (
215
+ LIBOMP_OMP_TOOLS_INCLUDE_DIR
216
+ NAMES
217
+ omp-tools.h
218
+ HINTS
219
+ ${COMPILER_RESOURCE_DIR} /include
220
+ ${CMAKE_INSTALL_PREFIX} /include
221
+ )
222
+
223
+ if (LIBOMP_OMP_TOOLS_INCLUDE_DIR)
224
+ set (LIBOMP_HAVE_OMPT_SUPPORT TRUE )
225
+ set (LIBOMP_OMPT_SUPPORT TRUE )
226
+ endif ()
227
+
228
+ # LLVM_LIBRARY_DIRS set by find_package(LLVM) in LibomptargetGetDependencies
229
+ find_library (
230
+ LIBOMP_STANDALONE
231
+ NAMES
232
+ omp
233
+ HINTS
234
+ ${CMAKE_INSTALL_PREFIX} /lib
235
+ ${LLVM_LIBRARY_DIRS}
236
+ REQUIRED
237
+ )
238
+ # Check LIBOMP_HAVE_VERSION_SCRIPT_FLAG
239
+ include (LLVMCheckCompilerLinkerFlag)
240
+ if (NOT APPLE )
241
+ llvm_check_compiler_linker_flag(C "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR} /../openmp/runtime/src/exports_test_so.txt" LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
242
+ endif ()
243
+
244
+ macro (pythonize_bool var)
245
+ if (${var} )
246
+ set (${var} True )
247
+ else ()
248
+ set (${var} False )
249
+ endif ()
250
+ endmacro ()
251
+ endif ()
252
+
104
253
# OMPT support for libomptarget
105
254
# Follow host OMPT support and check if host support has been requested.
106
255
# LIBOMP_HAVE_OMPT_SUPPORT indicates whether host OMPT support has been implemented.
@@ -127,13 +276,10 @@ pythonize_bool(LIBOMPTARGET_GPU_LIBC_SUPPORT)
127
276
128
277
set (LIBOMPTARGET_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} /include )
129
278
message (STATUS "OpenMP tools dir in libomptarget: ${LIBOMP_OMP_TOOLS_INCLUDE_DIR} " )
130
- include_directories (${LIBOMP_OMP_TOOLS_INCLUDE_DIR} )
279
+ if (LIBOMP_OMP_TOOLS_INCLUDE_DIR)
280
+ include_directories (${LIBOMP_OMP_TOOLS_INCLUDE_DIR} )
281
+ endif ()
131
282
132
- # Definitions for testing, for reuse when testing libomptarget-nvptx.
133
- set (LIBOMPTARGET_OPENMP_HEADER_FOLDER "${LIBOMP_INCLUDE_DIR} " CACHE STRING
134
- "Path to folder containing omp.h" )
135
- set (LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER "${LIBOMP_LIBRARY_DIR} " CACHE STRING
136
- "Path to folder containing libomp.so, and libLLVMSupport.so with profiling enabled" )
137
283
set (LIBOMPTARGET_LLVM_LIBRARY_DIR "${LLVM_LIBRARY_DIR} " CACHE STRING
138
284
"Path to folder containing llvm library libomptarget.so" )
139
285
set (LIBOMPTARGET_LLVM_LIBRARY_INTDIR "${LIBOMPTARGET_INTDIR} " CACHE STRING
0 commit comments