blob: c206386fa6b614ffcba85c8a019d49219b28fab8 [file] [log] [blame]
Mark de Wevercbaa3592023-05-24 16:12:321cmake_minimum_required(VERSION 3.20.0)
Michael Kruse8bdc5772024-05-25 15:34:282set(LLVM_SUBPROJECT_TITLE "OpenMP")
Jonas Hahnfeld66594992016-02-05 07:00:133
John Ericson28e665f2022-01-16 05:52:224set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
5
6# Add path for custom modules
7list(INSERT CMAKE_MODULE_PATH 0
8 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
9 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
10 )
Jonas Hahnfeld5af381a2017-11-29 19:31:4811
Jonas Hahnfeld3e921d32017-11-29 19:31:4312# llvm/runtimes/ will set OPENMP_STANDALONE_BUILD.
13if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
14 set(OPENMP_STANDALONE_BUILD TRUE)
Mark de Wevercbaa3592023-05-24 16:12:3215 project(openmp C CXX ASM)
estewart0889c92b02024-06-07 20:37:4216else()
17 set(OPENMP_STANDALONE_BUILD FALSE)
John Ericson0a6b4252022-01-22 06:33:4918endif()
Jonas Hahnfeld3e921d32017-11-29 19:31:4319
John Ericson0a6b4252022-01-22 06:33:4920# Must go below project(..)
21include(GNUInstallDirs)
22
23if (OPENMP_STANDALONE_BUILD)
Jonas Hahnfeld3e921d32017-11-29 19:31:4324 # CMAKE_BUILD_TYPE was not set, default to Release.
25 if (NOT CMAKE_BUILD_TYPE)
26 set(CMAKE_BUILD_TYPE Release)
27 endif()
28
Jonas Hahnfeld5af381a2017-11-29 19:31:4829 # Group common settings.
30 set(OPENMP_ENABLE_WERROR FALSE CACHE BOOL
31 "Enable -Werror flags to turn warnings into errors for supporting compilers.")
John Ericsone941b032022-08-19 02:44:4632 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.
Martin Storsjö14435a22024-01-10 09:24:1935 set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}" CACHE STRING
36 "Path where built OpenMP libraries should be installed.")
Jonas Hahnfeld5af381a2017-11-29 19:31:4837
Jonas Hahnfeld18bec602017-11-29 19:31:5238 # 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.")
Ethan Luis McDonough9e3d59e2023-08-29 21:27:3043 set(OPENMP_TEST_Fortran_COMPILER ${CMAKE_Fortran_COMPILER} CACHE STRING
44 "FORTRAN compiler to use for testing OpenMP runtime libraries.")
Jonas Hahnfeld3e921d32017-11-29 19:31:4345 set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing.")
Martin Storsjöd187cee2023-05-03 06:57:2246
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)
Jonas Hahnfeld5af381a2017-11-29 19:31:4850else()
51 set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR})
Joseph Huber19774042024-02-28 21:39:2752
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()
Jonas Hahnfeld18bec602017-11-29 19:31:5261
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()
Martin Storsjöd187cee2023-05-03 06:57:2269
Ethan Luis McDonough2b6ba8c72023-09-01 18:57:2870 # Check for flang
71 if (NOT MSVC)
Brad Richardson06eb10d2024-10-10 08:26:0472 set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang)
Ethan Luis McDonough2b6ba8c72023-09-01 18:57:2873 else()
Brad Richardson06eb10d2024-10-10 08:26:0474 set(OPENMP_TEST_Fortran_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/flang.exe)
Ethan Luis McDonough2b6ba8c72023-09-01 18:57:2875 endif()
76
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)
Ethan Luis McDonough9e3d59e2023-08-29 21:27:3082 endif()
83
Martin Storsjöd187cee2023-05-03 06:57:2284 # 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)
Jonas Hahnfeld3e921d32017-11-29 19:31:4389endif()
Jonas Hahnfeld66594992016-02-05 07:00:1390
Jonas Hahnfeld5af381a2017-11-29 19:31:4891# Check and set up common compiler flags.
92include(config-ix)
93include(HandleOpenMPOptions)
94
Jonas Hahnfeld18bec602017-11-29 19:31:5295# Set up testing infrastructure.
96include(OpenMPTesting)
97
98set(OPENMP_TEST_FLAGS "" CACHE STRING
99 "Extra compiler flags to send to the test compiler.")
Jonas Hahnfeldfc473de2017-11-30 17:08:31100set(OPENMP_TEST_OPENMP_FLAGS ${OPENMP_TEST_COMPILER_OPENMP_FLAGS} CACHE STRING
Jonas Hahnfeld18bec602017-11-29 19:31:52101 "OpenMP compiler flag to use for testing OpenMP runtime libraries.")
102
Joseph Huber2ec85712024-05-15 16:57:48103set(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.
108if (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)
111endif()
112
113option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading."
114 ${ENABLE_LIBOMPTARGET})
Shilei Tianc571b162021-01-28 12:24:19115option(OPENMP_ENABLE_LIBOMP_PROFILING "Enable time profiling for libomp." OFF)
Giorgis Georgakoudisbb40e672021-01-25 22:10:50116
serge-sans-paille6f2ed8f2022-09-07 12:48:10117# Header install location
118if(${OPENMP_STANDALONE_BUILD})
David Tenty144091b2024-05-06 21:12:38119 set(LIBOMP_HEADERS_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}")
serge-sans-paille6f2ed8f2022-09-07 12:48:10120else()
paperchalice0beffb82023-06-03 06:29:44121 include(GetClangResourceDir)
122 get_clang_resource_dir(LIBOMP_HEADERS_INSTALL_PATH SUBDIR include)
serge-sans-paille6f2ed8f2022-09-07 12:48:10123endif()
124
Giorgis Georgakoudisbb40e672021-01-25 22:10:50125# Build host runtime library, after LIBOMPTARGET variables are set since they are needed
126# to enable time profiling support in the OpenMP runtime.
127add_subdirectory(runtime)
128
[email protected]2b8115b2019-11-18 00:23:31129set(ENABLE_OMPT_TOOLS ON)
130# Currently tools are not tested well on Windows or MacOS X.
131if (APPLE OR WIN32)
132 set(ENABLE_OMPT_TOOLS OFF)
133endif()
134
135option(OPENMP_ENABLE_OMPT_TOOLS "Enable building ompt based tools for OpenMP."
136 ${ENABLE_OMPT_TOOLS})
137if (OPENMP_ENABLE_OMPT_TOOLS)
138 add_subdirectory(tools)
139endif()
140
Johannes Doerfert330d8982024-04-22 16:51:33141# Propagate OMPT support to offload
Joachimff77f672024-06-06 14:13:50142if(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)
145endif()
Johannes Doerfert330d8982024-04-22 16:51:33146
Bran Hagger9f15cac2021-11-11 19:08:25147option(OPENMP_MSVC_NAME_SCHEME "Build dll with MSVC naming scheme." OFF)
Joseph Huber1c4c2142020-09-16 21:15:56148
Vignesh Balasubramanianae1507d2022-12-14 04:36:30149# Build libompd.so
150add_subdirectory(libompd)
151
Joseph Huber1c4c2142020-09-16 21:15:56152# Build documentation
153add_subdirectory(docs)
154
Kazuaki Ishizaki42016792020-04-04 03:06:29155# Now that we have seen all testsuites, create the check-openmp target.
Jonas Hahnfeld18bec602017-11-29 19:31:52156construct_check_openmp_target()