1 cmake_minimum_required(VERSION 3.20.0)
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)
14 project(openmp C CXX ASM)
17 # Must go below project(..)
18 include(GNUInstallDirs)
20 if (OPENMP_STANDALONE_BUILD)
21 # CMAKE_BUILD_TYPE was not set, default to Release.
22 if (NOT CMAKE_BUILD_TYPE)
23 set(CMAKE_BUILD_TYPE Release)
26 # Group common settings.
27 set(OPENMP_ENABLE_WERROR FALSE CACHE BOOL
28 "Enable -Werror flags to turn warnings into errors for supporting compilers.")
29 set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING
30 "Suffix of lib installation directory, e.g. 64 => lib64")
31 # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR.
32 set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}")
34 # Group test settings.
35 set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
36 "C compiler to use for testing OpenMP runtime libraries.")
37 set(OPENMP_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING
38 "C++ compiler to use for testing OpenMP runtime libraries.")
39 set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing.")
41 set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
42 set(CMAKE_CXX_STANDARD_REQUIRED NO)
43 set(CMAKE_CXX_EXTENSIONS NO)
45 set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
46 # If building in tree, we honor the same install suffix LLVM uses.
47 set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}")
50 set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
51 set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
53 set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe)
54 set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
57 # If not standalone, set CMAKE_CXX_STANDARD but don't set the global cache value,
58 # only set it locally for OpenMP.
59 set(CMAKE_CXX_STANDARD 17)
60 set(CMAKE_CXX_STANDARD_REQUIRED NO)
61 set(CMAKE_CXX_EXTENSIONS NO)
64 # Check and set up common compiler flags.
66 include(HandleOpenMPOptions)
68 # Set up testing infrastructure.
69 include(OpenMPTesting)
71 set(OPENMP_TEST_FLAGS "" CACHE STRING
72 "Extra compiler flags to send to the test compiler.")
73 set(OPENMP_TEST_OPENMP_FLAGS ${OPENMP_TEST_COMPILER_OPENMP_FLAGS} CACHE STRING
74 "OpenMP compiler flag to use for testing OpenMP runtime libraries.")
76 set(ENABLE_LIBOMPTARGET ON)
77 # Currently libomptarget cannot be compiled on Windows or MacOS X.
78 # Since the device plugins are only supported on Linux anyway,
79 # there is no point in trying to compile libomptarget on other OSes.
80 # 32-bit systems are not supported either.
81 if (APPLE OR WIN32 OR NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
82 set(ENABLE_LIBOMPTARGET OFF)
85 option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading."
86 ${ENABLE_LIBOMPTARGET})
87 option(OPENMP_ENABLE_LIBOMP_PROFILING "Enable time profiling for libomp." OFF)
89 # Header install location
90 if(${OPENMP_STANDALONE_BUILD})
91 set(LIBOMP_HEADERS_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}")
93 string(REGEX MATCH "[0-9]+" CLANG_VERSION ${PACKAGE_VERSION})
94 set(LIBOMP_HEADERS_INSTALL_PATH "${OPENMP_INSTALL_LIBDIR}/clang/${CLANG_VERSION}/include")
97 # Build host runtime library, after LIBOMPTARGET variables are set since they are needed
98 # to enable time profiling support in the OpenMP runtime.
99 add_subdirectory(runtime)
101 if (OPENMP_ENABLE_LIBOMPTARGET)
102 # Check that the library can actually be built.
104 message(FATAL_ERROR "libomptarget cannot be built on Windows and MacOS X!")
105 elseif (NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
106 message(FATAL_ERROR "Host compiler must support C++17 to build libomptarget!")
107 elseif (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
108 message(FATAL_ERROR "libomptarget on 32-bit systems are not supported!")
111 add_subdirectory(libomptarget)
114 set(ENABLE_OMPT_TOOLS ON)
115 # Currently tools are not tested well on Windows or MacOS X.
117 set(ENABLE_OMPT_TOOLS OFF)
120 option(OPENMP_ENABLE_OMPT_TOOLS "Enable building ompt based tools for OpenMP."
121 ${ENABLE_OMPT_TOOLS})
122 if (OPENMP_ENABLE_OMPT_TOOLS)
123 add_subdirectory(tools)
126 option(OPENMP_MSVC_NAME_SCHEME "Build dll with MSVC naming scheme." OFF)
129 add_subdirectory(libompd)
131 # Build documentation
132 add_subdirectory(docs)
134 # Now that we have seen all testsuites, create the check-openmp target.
135 construct_check_openmp_target()