1cmake_minimum_required(VERSION 3.13.4)
2
3# Add cmake directory to search for custom cmake functions.
4set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
5
6# llvm/runtimes/ will set OPENMP_STANDALONE_BUILD.
7if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
8  set(OPENMP_STANDALONE_BUILD TRUE)
9  project(openmp C CXX)
10
11  # CMAKE_BUILD_TYPE was not set, default to Release.
12  if (NOT CMAKE_BUILD_TYPE)
13    set(CMAKE_BUILD_TYPE Release)
14  endif()
15
16  # Group common settings.
17  set(OPENMP_ENABLE_WERROR FALSE CACHE BOOL
18    "Enable -Werror flags to turn warnings into errors for supporting compilers.")
19  set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING
20    "Suffix of lib installation directory, e.g. 64 => lib64")
21  # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR.
22  set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}")
23
24  # Group test settings.
25  set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
26    "C compiler to use for testing OpenMP runtime libraries.")
27  set(OPENMP_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING
28    "C++ compiler to use for testing OpenMP runtime libraries.")
29  set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing.")
30else()
31  set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
32  # If building in tree, we honor the same install suffix LLVM uses.
33  set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}")
34
35  if (NOT MSVC)
36    set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
37    set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
38  else()
39    set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe)
40    set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
41  endif()
42endif()
43
44# Check and set up common compiler flags.
45include(config-ix)
46include(HandleOpenMPOptions)
47
48# Set up testing infrastructure.
49include(OpenMPTesting)
50
51set(OPENMP_TEST_FLAGS "" CACHE STRING
52  "Extra compiler flags to send to the test compiler.")
53set(OPENMP_TEST_OPENMP_FLAGS ${OPENMP_TEST_COMPILER_OPENMP_FLAGS} CACHE STRING
54  "OpenMP compiler flag to use for testing OpenMP runtime libraries.")
55
56
57# Build host runtime library.
58add_subdirectory(runtime)
59
60
61set(ENABLE_LIBOMPTARGET ON)
62# Currently libomptarget cannot be compiled on Windows or MacOS X.
63# Since the device plugins are only supported on Linux anyway,
64# there is no point in trying to compile libomptarget on other OSes.
65if (APPLE OR WIN32 OR NOT OPENMP_HAVE_STD_CPP14_FLAG)
66  set(ENABLE_LIBOMPTARGET OFF)
67endif()
68
69# Attempt to locate LLVM source, required by libomptarget
70if (NOT LIBOMPTARGET_LLVM_MAIN_INCLUDE_DIR)
71  if (LLVM_MAIN_INCLUDE_DIR)
72    set(LIBOMPTARGET_LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_INCLUDE_DIR})
73  elseif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../llvm/include)
74    set(LIBOMPTARGET_LLVM_MAIN_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../llvm/include)
75  endif()
76endif()
77
78if (NOT LIBOMPTARGET_LLVM_MAIN_INCLUDE_DIR)
79  message(STATUS "Missing definition for LIBOMPTARGET_LLVM_MAIN_INCLUDE_DIR, disabling libomptarget")
80  set(ENABLE_LIBOMPTARGET OFF)
81endif()
82
83option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading."
84       ${ENABLE_LIBOMPTARGET})
85if (OPENMP_ENABLE_LIBOMPTARGET)
86  # Check that the library can actually be built.
87  if (APPLE OR WIN32)
88    message(FATAL_ERROR "libomptarget cannot be built on Windows and MacOS X!")
89  elseif (NOT OPENMP_HAVE_STD_CPP14_FLAG)
90    message(FATAL_ERROR "Host compiler must support C++14 to build libomptarget!")
91  endif()
92
93  add_subdirectory(libomptarget)
94endif()
95
96set(ENABLE_OMPT_TOOLS ON)
97# Currently tools are not tested well on Windows or MacOS X.
98if (APPLE OR WIN32)
99  set(ENABLE_OMPT_TOOLS OFF)
100endif()
101
102option(OPENMP_ENABLE_OMPT_TOOLS "Enable building ompt based tools for OpenMP."
103       ${ENABLE_OMPT_TOOLS})
104if (OPENMP_ENABLE_OMPT_TOOLS)
105  add_subdirectory(tools)
106endif()
107
108
109# Build documentation
110add_subdirectory(docs)
111
112# Now that we have seen all testsuites, create the check-openmp target.
113construct_check_openmp_target()
114