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_TEST_Fortran_COMPILER ${CMAKE_Fortran_COMPILER} CACHE STRING
40 "FORTRAN compiler to use for testing OpenMP runtime libraries.")
41 set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing.")
43 set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
44 set(CMAKE_CXX_STANDARD_REQUIRED NO)
45 set(CMAKE_CXX_EXTENSIONS NO)
47 set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
48 # If building in tree, we honor the same install suffix LLVM uses.
49 set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}")
52 set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
53 set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
55 set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe)
56 set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
61 set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang-new)
63 set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang-new.exe)
66 # Set fortran test compiler if flang is found
67 if (EXISTS "${OPENMP_TEST_Fortran_COMPILER}")
68 message("Using local flang build at ${OPENMP_TEST_Fortran_COMPILER}")
70 unset(OPENMP_TEST_Fortran_COMPILER)
73 # If not standalone, set CMAKE_CXX_STANDARD but don't set the global cache value,
74 # only set it locally for OpenMP.
75 set(CMAKE_CXX_STANDARD 17)
76 set(CMAKE_CXX_STANDARD_REQUIRED NO)
77 set(CMAKE_CXX_EXTENSIONS NO)
80 # Check and set up common compiler flags.
82 include(HandleOpenMPOptions)
84 # Set up testing infrastructure.
85 include(OpenMPTesting)
87 set(OPENMP_TEST_FLAGS "" CACHE STRING
88 "Extra compiler flags to send to the test compiler.")
89 set(OPENMP_TEST_OPENMP_FLAGS ${OPENMP_TEST_COMPILER_OPENMP_FLAGS} CACHE STRING
90 "OpenMP compiler flag to use for testing OpenMP runtime libraries.")
92 set(ENABLE_LIBOMPTARGET ON)
93 # Currently libomptarget cannot be compiled on Windows or MacOS X.
94 # Since the device plugins are only supported on Linux anyway,
95 # there is no point in trying to compile libomptarget on other OSes.
96 # 32-bit systems are not supported either.
97 if (APPLE OR WIN32 OR NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
98 set(ENABLE_LIBOMPTARGET OFF)
101 option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading."
102 ${ENABLE_LIBOMPTARGET})
103 option(OPENMP_ENABLE_LIBOMP_PROFILING "Enable time profiling for libomp." OFF)
105 # Header install location
106 if(${OPENMP_STANDALONE_BUILD})
107 set(LIBOMP_HEADERS_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}")
109 include(GetClangResourceDir)
110 get_clang_resource_dir(LIBOMP_HEADERS_INSTALL_PATH SUBDIR include)
113 # Build host runtime library, after LIBOMPTARGET variables are set since they are needed
114 # to enable time profiling support in the OpenMP runtime.
115 add_subdirectory(runtime)
117 if (OPENMP_ENABLE_LIBOMPTARGET)
118 # Check that the library can actually be built.
120 message(FATAL_ERROR "libomptarget cannot be built on Windows and MacOS X!")
121 elseif (NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
122 message(FATAL_ERROR "Host compiler must support C++17 to build libomptarget!")
123 elseif (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
124 message(FATAL_ERROR "libomptarget on 32-bit systems are not supported!")
127 add_subdirectory(libomptarget)
130 set(ENABLE_OMPT_TOOLS ON)
131 # Currently tools are not tested well on Windows or MacOS X.
133 set(ENABLE_OMPT_TOOLS OFF)
136 option(OPENMP_ENABLE_OMPT_TOOLS "Enable building ompt based tools for OpenMP."
137 ${ENABLE_OMPT_TOOLS})
138 if (OPENMP_ENABLE_OMPT_TOOLS)
139 add_subdirectory(tools)
142 option(OPENMP_MSVC_NAME_SCHEME "Build dll with MSVC naming scheme." OFF)
145 add_subdirectory(libompd)
147 # Build documentation
148 add_subdirectory(docs)
150 # Now that we have seen all testsuites, create the check-openmp target.
151 construct_check_openmp_target()