1 ##===----------------------------------------------------------------------===##
3 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 # See https://llvm.org/LICENSE.txt for license information.
5 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 ##===----------------------------------------------------------------------===##
9 # Build offloading library and related plugins.
11 ##===----------------------------------------------------------------------===##
13 if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
14 message(FATAL_ERROR "Direct configuration not supported, please use parent directory!")
17 # Add cmake directory to search for custom cmake functions.
18 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules ${CMAKE_MODULE_PATH})
20 # Set the path of all resulting libraries to a unified location so that it can
21 # be used for testing.
22 set(LIBOMPTARGET_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
23 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBOMPTARGET_LIBRARY_DIR})
24 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBOMPTARGET_LIBRARY_DIR})
25 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBOMPTARGET_LIBRARY_DIR})
28 include(LibomptargetUtils)
30 # Get dependencies for the different components of the project.
31 include(LibomptargetGetDependencies)
33 # LLVM source tree is required at build time for libomptarget
34 if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS)
35 message(FATAL_ERROR "Missing definition for LIBOMPTARGET_LLVM_INCLUDE_DIRS")
38 include_directories(${LIBOMPTARGET_LLVM_INCLUDE_DIRS})
40 # This is a list of all the targets that are supported/tested right now.
41 set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} aarch64-unknown-linux-gnu")
42 set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} aarch64-unknown-linux-gnu-LTO")
43 set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} amdgcn-amd-amdhsa")
44 set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} powerpc64le-ibm-linux-gnu")
45 set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} powerpc64le-ibm-linux-gnu-LTO")
46 set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} powerpc64-ibm-linux-gnu")
47 set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} powerpc64-ibm-linux-gnu-LTO")
48 set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} x86_64-pc-linux-gnu")
49 set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} x86_64-pc-linux-gnu-LTO")
50 set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} nvptx64-nvidia-cuda")
51 set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} nvptx64-nvidia-cuda-LTO")
52 set (LIBOMPTARGET_ALL_TARGETS "${LIBOMPTARGET_ALL_TARGETS} nvptx64-nvidia-cuda-JIT-LTO")
54 # Once the plugins for the different targets are validated, they will be added to
55 # the list of supported targets in the current system.
56 set (LIBOMPTARGET_SYSTEM_TARGETS "")
57 set (LIBOMPTARGET_TESTED_PLUGINS "")
59 # Check whether using debug mode. In debug mode, allow dumping progress
60 # messages at runtime by default. Otherwise, it can be enabled
61 # independently using the LIBOMPTARGET_ENABLE_DEBUG option.
62 string( TOLOWER "${CMAKE_BUILD_TYPE}" LIBOMPTARGET_CMAKE_BUILD_TYPE)
63 if(LIBOMPTARGET_CMAKE_BUILD_TYPE MATCHES debug)
64 option(LIBOMPTARGET_ENABLE_DEBUG "Allow debug output with the environment variable LIBOMPTARGET_DEBUG=1" ON)
66 option(LIBOMPTARGET_ENABLE_DEBUG "Allow debug output with the environment variable LIBOMPTARGET_DEBUG=1" OFF)
68 if(LIBOMPTARGET_ENABLE_DEBUG)
69 add_definitions(-DOMPTARGET_DEBUG)
72 # OMPT support for libomptarget
73 # Follow host OMPT support and check if host support has been requested.
74 # LIBOMP_HAVE_OMPT_SUPPORT indicates whether host OMPT support has been implemented.
75 # LIBOMP_OMPT_SUPPORT indicates whether host OMPT support has been requested (default is ON).
76 # LIBOMPTARGET_OMPT_SUPPORT indicates whether target OMPT support has been requested (default is ON).
77 set(OMPT_TARGET_DEFAULT FALSE)
78 if ((LIBOMP_HAVE_OMPT_SUPPORT) AND (LIBOMP_OMPT_SUPPORT) AND (NOT WIN32))
79 set (OMPT_TARGET_DEFAULT TRUE)
81 set(LIBOMPTARGET_OMPT_SUPPORT ${OMPT_TARGET_DEFAULT} CACHE BOOL "OMPT-target-support?")
82 if ((OMPT_TARGET_DEFAULT) AND (LIBOMPTARGET_OMPT_SUPPORT))
83 add_definitions(-DOMPT_SUPPORT=1)
84 message(STATUS "OMPT target enabled")
86 set(LIBOMPTARGET_OMPT_SUPPORT FALSE)
87 message(STATUS "OMPT target disabled")
90 pythonize_bool(LIBOMPTARGET_OMPT_SUPPORT)
92 # Check if this build supports the GPU libc.
93 set(LIBC_GPU_SUPPORT FALSE)
94 if("libc" IN_LIST LLVM_ENABLE_RUNTIMES AND (LIBC_GPU_BUILD OR
95 LIBC_GPU_ARCHITECTURES))
96 set(LIBC_GPU_SUPPORT TRUE)
99 set(LIBOMPTARGET_GPU_LIBC_SUPPORT ${LIBC_GPU_SUPPORT} CACHE BOOL
100 "Libomptarget support for the GPU libc")
101 pythonize_bool(LIBOMPTARGET_GPU_LIBC_SUPPORT)
103 set(LIBOMPTARGET_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
104 message(STATUS "OpenMP tools dir in libomptarget: ${LIBOMP_OMP_TOOLS_INCLUDE_DIR}")
105 include_directories(${LIBOMP_OMP_TOOLS_INCLUDE_DIR})
107 # Build target agnostic offloading library.
108 set(LIBOMPTARGET_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
109 add_subdirectory(${LIBOMPTARGET_SRC_DIR})
111 # Definitions for testing, for reuse when testing libomptarget-nvptx.
112 set(LIBOMPTARGET_OPENMP_HEADER_FOLDER "${LIBOMP_INCLUDE_DIR}" CACHE STRING
113 "Path to folder containing omp.h")
114 set(LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER "${LIBOMP_LIBRARY_DIR}" CACHE STRING
115 "Path to folder containing libomp.so, and libLLVMSupport.so with profiling enabled")
116 set(LIBOMPTARGET_LLVM_LIBRARY_DIR "${LLVM_LIBRARY_DIR}" CACHE STRING
117 "Path to folder containing llvm library libomptarget.so")
119 # Build offloading plugins and device RTLs if they are available.
120 add_subdirectory(plugins-nextgen)
121 add_subdirectory(DeviceRTL)
122 add_subdirectory(tools)
125 add_subdirectory(test)