[memprof] Use a new constructor of IndexedAllocationInfo (NFC) (#116920)
[llvm-project.git] / openmp / CMakeLists.txt
blobc206386fa6b614ffcba85c8a019d49219b28fab8
1 cmake_minimum_required(VERSION 3.20.0)
2 set(LLVM_SUBPROJECT_TITLE "OpenMP")
4 set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
6 # Add path for custom modules
7 list(INSERT CMAKE_MODULE_PATH 0
8   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
9   "${LLVM_COMMON_CMAKE_UTILS}/Modules"
10   )
12 # llvm/runtimes/ will set OPENMP_STANDALONE_BUILD.
13 if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
14   set(OPENMP_STANDALONE_BUILD TRUE)
15   project(openmp C CXX ASM)
16 else()
17   set(OPENMP_STANDALONE_BUILD FALSE)
18 endif()
20 # Must go below project(..)
21 include(GNUInstallDirs)
23 if (OPENMP_STANDALONE_BUILD)
24   # CMAKE_BUILD_TYPE was not set, default to Release.
25   if (NOT CMAKE_BUILD_TYPE)
26     set(CMAKE_BUILD_TYPE Release)
27   endif()
29   # Group common settings.
30   set(OPENMP_ENABLE_WERROR FALSE CACHE BOOL
31     "Enable -Werror flags to turn warnings into errors for supporting compilers.")
32   set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING
33     "Suffix of lib installation directory, e.g. 64 => lib64")
34   # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR.
35   set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}" CACHE STRING
36       "Path where built OpenMP libraries should be installed.")
38   # Group test settings.
39   set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING
40     "C compiler to use for testing OpenMP runtime libraries.")
41   set(OPENMP_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING
42     "C++ compiler to use for testing OpenMP runtime libraries.")
43   set(OPENMP_TEST_Fortran_COMPILER ${CMAKE_Fortran_COMPILER} CACHE STRING
44     "FORTRAN compiler to use for testing OpenMP runtime libraries.")
45   set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing.")
47   set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
48   set(CMAKE_CXX_STANDARD_REQUIRED NO)
49   set(CMAKE_CXX_EXTENSIONS NO)
50 else()
51   set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
53   # When building in tree we install the runtime according to the LLVM settings.
54   if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
55     set(OPENMP_INSTALL_LIBDIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE STRING
56         "Path where built openmp libraries should be installed.")
57   else()
58     set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}" CACHE STRING
59         "Path where built OpenMP libraries should be installed.")
60   endif()
62   if (NOT MSVC)
63     set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
64     set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
65   else()
66     set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe)
67     set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe)
68   endif()
70   # Check for flang
71   if (NOT MSVC)
72     set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang)
73   else()
74     set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang.exe)
75   endif()
77   # Set fortran test compiler if flang is found
78   if (EXISTS "${OPENMP_TEST_Fortran_COMPILER}")
79     message("Using local flang build at ${OPENMP_TEST_Fortran_COMPILER}")
80   else()
81     unset(OPENMP_TEST_Fortran_COMPILER)
82   endif()
84   # If not standalone, set CMAKE_CXX_STANDARD but don't set the global cache value,
85   # only set it locally for OpenMP.
86   set(CMAKE_CXX_STANDARD 17)
87   set(CMAKE_CXX_STANDARD_REQUIRED NO)
88   set(CMAKE_CXX_EXTENSIONS NO)
89 endif()
91 # Check and set up common compiler flags.
92 include(config-ix)
93 include(HandleOpenMPOptions)
95 # Set up testing infrastructure.
96 include(OpenMPTesting)
98 set(OPENMP_TEST_FLAGS "" CACHE STRING
99   "Extra compiler flags to send to the test compiler.")
100 set(OPENMP_TEST_OPENMP_FLAGS ${OPENMP_TEST_COMPILER_OPENMP_FLAGS} CACHE STRING
101   "OpenMP compiler flag to use for testing OpenMP runtime libraries.")
103 set(ENABLE_LIBOMPTARGET ON)
104 # Currently libomptarget cannot be compiled on Windows or MacOS X.
105 # Since the device plugins are only supported on Linux anyway,
106 # there is no point in trying to compile libomptarget on other OSes.
107 # 32-bit systems are not supported either.
108 if (APPLE OR WIN32 OR WASM OR NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES
109     OR NOT CMAKE_SIZEOF_VOID_P EQUAL 8 OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
110   set(ENABLE_LIBOMPTARGET OFF)
111 endif()
113 option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading."
114        ${ENABLE_LIBOMPTARGET})
115 option(OPENMP_ENABLE_LIBOMP_PROFILING "Enable time profiling for libomp." OFF)
117 # Header install location
118 if(${OPENMP_STANDALONE_BUILD})
119   set(LIBOMP_HEADERS_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}")
120 else()
121   include(GetClangResourceDir)
122   get_clang_resource_dir(LIBOMP_HEADERS_INSTALL_PATH SUBDIR include)
123 endif()
125 # Build host runtime library, after LIBOMPTARGET variables are set since they are needed
126 # to enable time profiling support in the OpenMP runtime.
127 add_subdirectory(runtime)
129 set(ENABLE_OMPT_TOOLS ON)
130 # Currently tools are not tested well on Windows or MacOS X.
131 if (APPLE OR WIN32)
132   set(ENABLE_OMPT_TOOLS OFF)
133 endif()
135 option(OPENMP_ENABLE_OMPT_TOOLS "Enable building ompt based tools for OpenMP."
136        ${ENABLE_OMPT_TOOLS})
137 if (OPENMP_ENABLE_OMPT_TOOLS)
138   add_subdirectory(tools)
139 endif()
141 # Propagate OMPT support to offload
142 if(NOT ${OPENMP_STANDALONE_BUILD})
143   set(LIBOMP_HAVE_OMPT_SUPPORT ${LIBOMP_HAVE_OMPT_SUPPORT} PARENT_SCOPE)
144   set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${LIBOMP_OMP_TOOLS_INCLUDE_DIR} PARENT_SCOPE)
145 endif()
147 option(OPENMP_MSVC_NAME_SCHEME "Build dll with MSVC naming scheme." OFF)
149 # Build libompd.so
150 add_subdirectory(libompd)
152 # Build documentation
153 add_subdirectory(docs)
155 # Now that we have seen all testsuites, create the check-openmp target.
156 construct_check_openmp_target()