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
+ set (ENABLE_LIBOMPTARGET ON )
14
+ # Currently libomptarget cannot be compiled on Windows or MacOS X.
15
+ # Since the device plugins are only supported on Linux anyway,
16
+ # there is no point in trying to compile libomptarget on other OSes.
17
+ # 32-bit systems are not supported either.
18
+ if (APPLE OR WIN32 OR NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8 )
19
+ set (ENABLE_LIBOMPTARGET OFF )
15
20
endif ()
16
21
17
- # Add cmake directory to search for custom cmake functions.
18
- set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} /cmake/Modules ${CMAKE_MODULE_PATH} )
22
+ option (OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading."
23
+ ${ENABLE_LIBOMPTARGET} )
24
+ if (OPENMP_ENABLE_LIBOMPTARGET )
25
+ # Check that the library can actually be built.
26
+ if (APPLE OR WIN32 )
27
+ message (FATAL_ERROR "libomptarget cannot be built on Windows and MacOS X!" )
28
+ elseif (NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES )
29
+ message (FATAL_ERROR "Host compiler must support C++17 to build libomptarget!" )
30
+ elseif (NOT CMAKE_SIZEOF_VOID_P EQUAL 8 )
31
+ message (FATAL_ERROR "libomptarget on 32-bit systems are not supported!" )
32
+ endif ()
33
+ endif ()
34
+
35
+ # TODO: Leftover from the move, could probably be just LLVM_LIBDIR_SUFFIX everywhere.
36
+ set (OFFLOAD_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX} " )
37
+
38
+ set (LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR} /cmake )
39
+
40
+ # Add path for custom modules
41
+ list (INSERT CMAKE_MODULE_PATH 0
42
+ "${CMAKE_CURRENT_SOURCE_DIR} /cmake"
43
+ "${LLVM_COMMON_CMAKE_UTILS} /Modules"
44
+ )
45
+
46
+ if (OPENMP_STANDALONE_BUILD )
47
+ # CMAKE_BUILD_TYPE was not set, default to Release.
48
+ if (NOT CMAKE_BUILD_TYPE )
49
+ set (CMAKE_BUILD_TYPE Release )
50
+ endif ()
51
+
52
+ # Group common settings.
53
+ set (OPENMP_ENABLE_WERROR FALSE CACHE BOOL
54
+ "Enable -Werror flags to turn warnings into errors for supporting compilers." )
55
+ set (OPENMP_LIBDIR_SUFFIX "" CACHE STRING
56
+ "Suffix of lib installation directory, e.g. 64 => lib64" )
57
+ # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR.
58
+ set (OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX} " )
59
+
60
+ # Group test settings.
61
+ set (OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
62
+ "C compiler to use for testing OpenMP runtime libraries." )
63
+ set (OPENMP_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING
64
+ "C++ compiler to use for testing OpenMP runtime libraries." )
65
+ set (OPENMP_TEST_Fortran_COMPILER ${CMAKE_Fortran_COMPILER} CACHE STRING
66
+ "FORTRAN compiler to use for testing OpenMP runtime libraries." )
67
+ set (OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing." )
68
+
69
+ set (CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to" )
70
+ set (CMAKE_CXX_STANDARD_REQUIRED NO )
71
+ set (CMAKE_CXX_EXTENSIONS NO )
72
+ else ()
73
+ set (OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR} )
74
+ # If building in tree, we honor the same install suffix LLVM uses.
75
+ set (OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX} " )
76
+
77
+ if (NOT MSVC )
78
+ set (OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR} /clang )
79
+ set (OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR} /clang++ )
80
+ else ()
81
+ set (OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR} /clang.exe )
82
+ set (OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR} /clang++.exe )
83
+ endif ()
84
+
85
+ # Check for flang
86
+ if (NOT MSVC )
87
+ set (OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR} /flang-new )
88
+ else ()
89
+ set (OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR} /flang-new.exe )
90
+ endif ()
91
+
92
+ # Set fortran test compiler if flang is found
93
+ if (EXISTS "${OPENMP_TEST_Fortran_COMPILER} " )
94
+ message ("Using local flang build at ${OPENMP_TEST_Fortran_COMPILER} " )
95
+ else ()
96
+ unset (OPENMP_TEST_Fortran_COMPILER )
97
+ endif ()
98
+
99
+ # If not standalone, set CMAKE_CXX_STANDARD but don't set the global cache value,
100
+ # only set it locally for OpenMP.
101
+ set (CMAKE_CXX_STANDARD 17 )
102
+ set (CMAKE_CXX_STANDARD_REQUIRED NO )
103
+ set (CMAKE_CXX_EXTENSIONS NO )
104
+ endif ()
19
105
20
106
# Set the path of all resulting libraries to a unified location so that it can
21
107
# be used for testing.
@@ -36,6 +122,9 @@ include(LibomptargetUtils)
36
122
# Get dependencies for the different components of the project.
37
123
include (LibomptargetGetDependencies )
38
124
125
+ # Set up testing infrastructure.
126
+ include (OpenMPTesting )
127
+
39
128
# LLVM source tree is required at build time for libomptarget
40
129
if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS )
41
130
message (FATAL_ERROR "Missing definition for LIBOMPTARGET_LLVM_INCLUDE_DIRS" )
@@ -129,11 +218,6 @@ set(LIBOMPTARGET_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
129
218
message (STATUS "OpenMP tools dir in libomptarget: ${LIBOMP_OMP_TOOLS_INCLUDE_DIR} " )
130
219
include_directories (${LIBOMP_OMP_TOOLS_INCLUDE_DIR} )
131
220
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
221
set (LIBOMPTARGET_LLVM_LIBRARY_DIR "${LLVM_LIBRARY_DIR} " CACHE STRING
138
222
"Path to folder containing llvm library libomptarget.so" )
139
223
set (LIBOMPTARGET_LLVM_LIBRARY_INTDIR "${LIBOMPTARGET_INTDIR} " CACHE STRING
@@ -158,3 +242,5 @@ if (EXISTS ${LLVM_THIRD_PARTY_DIR}/unittest)
158
242
endif ()
159
243
add_subdirectory (unittests )
160
244
endif ()
245
+
246
+ construct_check_offload_target ()
0 commit comments