1 cmake_minimum_required(VERSION 3.13.4)
3 set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
5 # Add path for custom modules
6 list(INSERT CMAKE_MODULE_PATH 0
7 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
8 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
11 # llvm/runtimes/ will set OPENMP_STANDALONE_BUILD.
12 if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
13 set(OPENMP_STANDALONE_BUILD TRUE)
15 if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
17 "Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
18 "minimum version of CMake required to build LLVM will become 3.20.0, and "
19 "using an older CMake will become an error. Please upgrade your CMake to "
20 "at least 3.20.0 now to avoid issues in the future!")
24 # Must go below project(..)
25 include(GNUInstallDirs)
27 if (OPENMP_STANDALONE_BUILD)
28 # CMAKE_BUILD_TYPE was not set, default to Release.
29 if (NOT CMAKE_BUILD_TYPE)
30 set(CMAKE_BUILD_TYPE Release)
33 # Group common settings.
34 set(OPENMP_ENABLE_WERROR FALSE CACHE BOOL
35 "Enable -Werror flags to turn warnings into errors for supporting compilers.")
36 set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING
37 "Suffix of lib installation directory, e.g. 64 => lib64")
38 # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR.
39 set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}")
41 # Group test settings.
42 set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
43 "C compiler to use for testing OpenMP runtime libraries.")
44 set(OPENMP_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING
45 "C++ compiler to use for testing OpenMP runtime libraries.")
46 set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing.")
48 set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
49 # If building in tree, we honor the same install suffix LLVM uses.
50 set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}")
53 set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
54 set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
56 set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe)
57 set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
61 # Check and set up common compiler flags.
63 include(HandleOpenMPOptions)
65 # Set up testing infrastructure.
66 include(OpenMPTesting)
68 set(OPENMP_TEST_FLAGS "" CACHE STRING
69 "Extra compiler flags to send to the test compiler.")
70 set(OPENMP_TEST_OPENMP_FLAGS ${OPENMP_TEST_COMPILER_OPENMP_FLAGS} CACHE STRING
71 "OpenMP compiler flag to use for testing OpenMP runtime libraries.")
73 set(ENABLE_LIBOMPTARGET ON)
74 # Currently libomptarget cannot be compiled on Windows or MacOS X.
75 # Since the device plugins are only supported on Linux anyway,
76 # there is no point in trying to compile libomptarget on other OSes.
77 # 32-bit systems are not supported either.
78 if (APPLE OR WIN32 OR NOT OPENMP_HAVE_STD_CPP17_FLAG OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
79 set(ENABLE_LIBOMPTARGET OFF)
82 option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading."
83 ${ENABLE_LIBOMPTARGET})
84 option(OPENMP_ENABLE_LIBOMP_PROFILING "Enable time profiling for libomp." OFF)
86 # Header install location
87 if(${OPENMP_STANDALONE_BUILD})
88 set(LIBOMP_HEADERS_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}")
90 string(REGEX MATCH "[0-9]+" CLANG_VERSION ${PACKAGE_VERSION})
91 set(LIBOMP_HEADERS_INSTALL_PATH "${OPENMP_INSTALL_LIBDIR}/clang/${CLANG_VERSION}/include")
94 # Build host runtime library, after LIBOMPTARGET variables are set since they are needed
95 # to enable time profiling support in the OpenMP runtime.
96 add_subdirectory(runtime)
98 if (OPENMP_ENABLE_LIBOMPTARGET)
99 # Check that the library can actually be built.
101 message(FATAL_ERROR "libomptarget cannot be built on Windows and MacOS X!")
102 elseif (NOT OPENMP_HAVE_STD_CPP17_FLAG)
103 message(FATAL_ERROR "Host compiler must support C++17 to build libomptarget!")
104 elseif (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
105 message(FATAL_ERROR "libomptarget on 32-bit systems are not supported!")
108 add_subdirectory(libomptarget)
111 set(ENABLE_OMPT_TOOLS ON)
112 # Currently tools are not tested well on Windows or MacOS X.
114 set(ENABLE_OMPT_TOOLS OFF)
117 option(OPENMP_ENABLE_OMPT_TOOLS "Enable building ompt based tools for OpenMP."
118 ${ENABLE_OMPT_TOOLS})
119 if (OPENMP_ENABLE_OMPT_TOOLS)
120 add_subdirectory(tools)
123 option(OPENMP_MSVC_NAME_SCHEME "Build dll with MSVC naming scheme." OFF)
126 add_subdirectory(libompd)
128 # Build documentation
129 add_subdirectory(docs)
131 # Now that we have seen all testsuites, create the check-openmp target.
132 construct_check_openmp_target()