Skip to content

Commit c6a443d

Browse files
saiislamjdoerfert
authored andcommitted
[Offload] Support standalone build for OpenMP and Offload
The standalone offload build will just search for the ompt header and if found then OMPT support will be enabled. This caused the LIBOMP_HAVE_VERSION_SCRIPT_FLAG detection and pythonize_bool to move into offload/CMakeLists.txt. If the cmake compiler is clang, get the resource directory for installation of openmp headers. find_package(LLVM) is already called in LibomptargetGetDependencies. Depends on #75125
1 parent e24a5d1 commit c6a443d

File tree

4 files changed

+83
-5
lines changed

4 files changed

+83
-5
lines changed

offload/CMakeLists.txt

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
#
1111
##===----------------------------------------------------------------------===##
1212

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+
1320
set(ENABLE_LIBOMPTARGET ON)
1421
# Currently libomptarget cannot be compiled on Windows or MacOS X.
1522
# Since the device plugins are only supported on Linux anyway,
@@ -35,11 +42,12 @@ endif()
3542
# TODO: Leftover from the move, could probably be just LLVM_LIBDIR_SUFFIX everywhere.
3643
set(OFFLOAD_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}")
3744

38-
set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
45+
set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
3946

4047
# Add path for custom modules
4148
list(INSERT CMAKE_MODULE_PATH 0
4249
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
50+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
4351
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
4452
)
4553

@@ -190,6 +198,58 @@ if (LIBOMPTARGET_USE_LTO)
190198
list(APPEND offload_link_flags ${CMAKE_CXX_COMPILE_OPTIONS_IPO})
191199
endif()
192200

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+
193253
# OMPT support for libomptarget
194254
# Follow host OMPT support and check if host support has been requested.
195255
# LIBOMP_HAVE_OMPT_SUPPORT indicates whether host OMPT support has been implemented.
@@ -216,7 +276,9 @@ pythonize_bool(LIBOMPTARGET_GPU_LIBC_SUPPORT)
216276

217277
set(LIBOMPTARGET_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
218278
message(STATUS "OpenMP tools dir in libomptarget: ${LIBOMP_OMP_TOOLS_INCLUDE_DIR}")
219-
include_directories(${LIBOMP_OMP_TOOLS_INCLUDE_DIR})
279+
if(LIBOMP_OMP_TOOLS_INCLUDE_DIR)
280+
include_directories(${LIBOMP_OMP_TOOLS_INCLUDE_DIR})
281+
endif()
220282

221283
set(LIBOMPTARGET_LLVM_LIBRARY_DIR "${LLVM_LIBRARY_DIR}" CACHE STRING
222284
"Path to folder containing llvm library libomptarget.so")

offload/plugins-nextgen/host/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ endif()
3333

3434
# Install plugin under the lib destination folder.
3535
install(TARGETS omptarget.rtl.${machine}
36-
LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
36+
LIBRARY DESTINATION "${OFFLOAD_INSTALL_LIBDIR}")
3737
set_target_properties(omptarget.rtl.${machine} PROPERTIES
3838
INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/.."
3939
POSITION_INDEPENDENT_CODE ON

offload/src/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313
libomptarget_say("Building offloading runtime library libomptarget.")
1414

15+
if(LIBOMP_STANDALONE)
16+
set(LIBOMP ${LIBOMP_STANDALONE})
17+
else()
18+
set(LIBOMP omp)
19+
endif()
20+
1521
add_llvm_library(omptarget
1622
SHARED
1723

@@ -38,7 +44,7 @@ add_llvm_library(omptarget
3844

3945
LINK_LIBS
4046
PUBLIC
41-
omp
47+
${LIBOMP}
4248

4349
NO_INSTALL_RPATH
4450
BUILDTREE_ONLY

openmp/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,17 @@ option(OPENMP_ENABLE_LIBOMP_PROFILING "Enable time profiling for libomp." OFF)
113113

114114
# Header install location
115115
if(${OPENMP_STANDALONE_BUILD})
116-
set(LIBOMP_HEADERS_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}")
116+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
117+
execute_process(
118+
OUTPUT_STRIP_TRAILING_WHITESPACE
119+
COMMAND ${CMAKE_CXX_COMPILER} --print-resource-dir
120+
RESULT_VARIABLE COMMAND_RETURN_CODE
121+
OUTPUT_VARIABLE COMPILER_RESOURCE_DIR
122+
)
123+
set(LIBOMP_HEADERS_INSTALL_PATH "${COMPILER_RESOURCE_DIR}/include")
124+
else()
125+
set(LIBOMP_HEADERS_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}")
126+
endif()
117127
else()
118128
include(GetClangResourceDir)
119129
get_clang_resource_dir(LIBOMP_HEADERS_INSTALL_PATH SUBDIR include)

0 commit comments

Comments
 (0)