2 #//===----------------------------------------------------------------------===//
4 #// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 #// See https://llvm.org/LICENSE.txt for license information.
6 #// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 #//===----------------------------------------------------------------------===//
11 if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
12 message(FATAL_ERROR "Direct configuration not supported, please use parent directory!")
15 # Add cmake directory to search for custom cmake functions
16 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
19 set(LIBOMP_VERSION_MAJOR 5)
20 set(LIBOMP_VERSION_MINOR 0)
22 # These include files are in the cmake/ subdirectory
24 include(LibompGetArchitecture)
25 include(LibompHandleFlags)
26 include(LibompDefinitions)
28 # Determine the target architecture
29 if(${OPENMP_STANDALONE_BUILD})
30 # If adding a new architecture, take a look at cmake/LibompGetArchitecture.cmake
31 libomp_get_architecture(LIBOMP_DETECTED_ARCH)
32 set(LIBOMP_ARCH ${LIBOMP_DETECTED_ARCH} CACHE STRING
33 "The architecture to build for (x86_64/i386/arm/ppc64/ppc64le/aarch64/mic/mips/mips64/riscv64/loongarch64/ve/s390x).")
34 # Should assertions be enabled? They are on by default.
35 set(LIBOMP_ENABLE_ASSERTIONS TRUE CACHE BOOL
37 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
38 else() # Part of LLVM build
39 # Determine the native architecture from LLVM.
40 string(TOLOWER "${LLVM_TARGET_ARCH}" LIBOMP_NATIVE_ARCH)
41 if( LIBOMP_NATIVE_ARCH STREQUAL "host" )
42 string(REGEX MATCH "^[^-]*" LIBOMP_NATIVE_ARCH ${LLVM_HOST_TRIPLE})
44 if(LIBOMP_NATIVE_ARCH MATCHES "i[2-6]86")
46 elseif(LIBOMP_NATIVE_ARCH STREQUAL "x86")
48 elseif(LIBOMP_NATIVE_ARCH STREQUAL "amd64")
49 set(LIBOMP_ARCH x86_64)
50 elseif(LIBOMP_NATIVE_ARCH STREQUAL "x86_64")
51 set(LIBOMP_ARCH x86_64)
52 elseif(LIBOMP_NATIVE_ARCH MATCHES "powerpc64le")
53 set(LIBOMP_ARCH ppc64le)
54 elseif(LIBOMP_NATIVE_ARCH MATCHES "powerpc")
55 set(LIBOMP_ARCH ppc64)
56 elseif(LIBOMP_NATIVE_ARCH MATCHES "aarch64")
57 set(LIBOMP_ARCH aarch64)
58 elseif(LIBOMP_NATIVE_ARCH MATCHES "arm64")
59 set(LIBOMP_ARCH aarch64)
60 elseif(LIBOMP_NATIVE_ARCH MATCHES "arm")
62 elseif(LIBOMP_NATIVE_ARCH MATCHES "riscv64")
63 set(LIBOMP_ARCH riscv64)
64 elseif(LIBOMP_NATIVE_ARCH MATCHES "loongarch64")
65 set(LIBOMP_ARCH loongarch64)
66 elseif(LIBOMP_NATIVE_ARCH MATCHES "ve")
68 elseif(LIBOMP_NATIVE_ARCH MATCHES "s390x")
69 set(LIBOMP_ARCH s390x)
72 libomp_get_architecture(LIBOMP_ARCH)
74 set(LIBOMP_ENABLE_ASSERTIONS ${LLVM_ENABLE_ASSERTIONS})
77 # Time profiling support
78 set(LIBOMP_PROFILING_SUPPORT ${OPENMP_ENABLE_LIBOMP_PROFILING})
80 # FUJITSU A64FX is a special processor because its cache line size is 256.
81 # We need to pass this information into kmp_config.h.
82 if(LIBOMP_ARCH STREQUAL "aarch64")
83 libomp_is_aarch64_a64fx(LIBOMP_DETECT_AARCH64_A64FX)
84 if (LIBOMP_DETECT_AARCH64_A64FX)
85 set(LIBOMP_ARCH "aarch64_a64fx")
86 set(LIBOMP_ARCH_AARCH64_A64FX TRUE)
90 libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc64 ppc64le aarch64 aarch64_a64fx mic mips mips64 riscv64 loongarch64 ve s390x)
92 set(LIBOMP_LIB_TYPE normal CACHE STRING
93 "Performance,Profiling,Stubs library (normal/profile/stubs)")
94 libomp_check_variable(LIBOMP_LIB_TYPE normal profile stubs)
95 # Set the OpenMP Year and Month associated with version
96 set(LIBOMP_OMP_YEAR_MONTH 201611)
97 set(LIBOMP_MIC_ARCH knc CACHE STRING
98 "Intel(R) Many Integrated Core Architecture (Intel(R) MIC Architecture) (knf/knc). Ignored if not Intel(R) MIC Architecture build.")
99 if("${LIBOMP_ARCH}" STREQUAL "mic")
100 libomp_check_variable(LIBOMP_MIC_ARCH knf knc)
102 set(LIBOMP_FORTRAN_MODULES FALSE CACHE BOOL
103 "Create Fortran module files? (requires fortran compiler)")
105 # - Support for universal fat binary builds on Mac
106 # - Having this extra variable allows people to build this library as a universal library
107 # without forcing a universal build of the llvm/clang compiler.
108 set(LIBOMP_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}" CACHE STRING
109 "For Mac builds, semicolon separated list of architectures to build for universal fat binary.")
110 set(CMAKE_OSX_ARCHITECTURES ${LIBOMP_OSX_ARCHITECTURES})
112 # Should @rpath be used for dynamic libraries on Mac?
113 # The if(NOT DEFINED) is there to guard a cached value of the variable if one
114 # exists so there is no interference with what the user wants. Also, no cache entry
115 # is created so there are no inadvertant effects on other parts of LLVM.
116 if(NOT DEFINED CMAKE_MACOSX_RPATH)
117 set(CMAKE_MACOSX_RPATH TRUE)
120 # User specified flags. These are appended to the configured flags.
121 set(LIBOMP_CXXFLAGS "" CACHE STRING
122 "Appended user specified C++ compiler flags.")
123 set(LIBOMP_CPPFLAGS "" CACHE STRING
124 "Appended user specified C preprocessor flags.")
125 set(LIBOMP_ASMFLAGS "" CACHE STRING
126 "Appended user specified assembler flags.")
127 set(LIBOMP_LDFLAGS "" CACHE STRING
128 "Appended user specified linker flags.")
129 set(LIBOMP_LIBFLAGS "" CACHE STRING
130 "Appended user specified linked libs flags. (e.g., -lm)")
131 set(LIBOMP_FFLAGS "" CACHE STRING
132 "Appended user specified Fortran compiler flags. These are only used if LIBOMP_FORTRAN_MODULES==TRUE.")
134 # Should the libomp library and generated headers be copied into the original source exports/ directory
135 # Turning this to FALSE aids parallel builds to not interfere with each other.
136 # Currently, the testsuite module expects the just built OpenMP library to be located inside the exports/
137 # directory. TODO: have testsuite run under llvm-lit directly. We can then get rid of copying to exports/
138 set(LIBOMP_COPY_EXPORTS FALSE CACHE STRING
139 "Should exports be copied into source exports/ directory?")
142 set(LIBOMP_USE_HWLOC FALSE CACHE BOOL
143 "Use Hwloc (http://www.open-mpi.org/projects/hwloc/) library for affinity?")
144 set(LIBOMP_HWLOC_INSTALL_DIR /usr/local CACHE PATH
145 "Install path for hwloc library")
147 # Get the build number from kmp_version.cpp
148 libomp_get_build_number("${CMAKE_CURRENT_SOURCE_DIR}" LIBOMP_VERSION_BUILD)
149 math(EXPR LIBOMP_VERSION_BUILD_YEAR "${LIBOMP_VERSION_BUILD}/10000")
150 math(EXPR LIBOMP_VERSION_BUILD_MONTH_DAY "${LIBOMP_VERSION_BUILD}%10000")
152 # Currently don't record any timestamps
153 set(LIBOMP_BUILD_DATE "No_Timestamp")
160 set(AARCH64_A64FX FALSE)
168 set(LOONGARCH64 FALSE)
171 if("${LIBOMP_ARCH}" STREQUAL "i386" OR "${LIBOMP_ARCH}" STREQUAL "32") # IA-32 architecture
173 elseif("${LIBOMP_ARCH}" STREQUAL "x86_64" OR "${LIBOMP_ARCH}" STREQUAL "32e") # Intel(R) 64 architecture
175 elseif("${LIBOMP_ARCH}" STREQUAL "arm") # ARM architecture
177 elseif("${LIBOMP_ARCH}" STREQUAL "ppc64") # PPC64BE architecture
180 elseif("${LIBOMP_ARCH}" STREQUAL "ppc64le") # PPC64LE architecture
183 elseif("${LIBOMP_ARCH}" STREQUAL "aarch64") # AARCH64 architecture
185 elseif("${LIBOMP_ARCH}" STREQUAL "aarch64_a64fx") # AARCH64_A64FX architecture
186 set(AARCH64_A64FX TRUE)
187 elseif("${LIBOMP_ARCH}" STREQUAL "mic") # Intel(R) Many Integrated Core Architecture
189 elseif("${LIBOMP_ARCH}" STREQUAL "mips") # MIPS architecture
191 elseif("${LIBOMP_ARCH}" STREQUAL "mips64") # MIPS64 architecture
193 elseif("${LIBOMP_ARCH}" STREQUAL "riscv64") # RISCV64 architecture
195 elseif("${LIBOMP_ARCH}" STREQUAL "loongarch64") # LoongArch64 architecture
196 set(LOONGARCH64 TRUE)
197 elseif("${LIBOMP_ARCH}" STREQUAL "ve") # VE architecture
199 elseif("${LIBOMP_ARCH}" STREQUAL "s390x") # S390x (Z) architecture
203 # Set some flags based on build_type
204 set(RELEASE_BUILD FALSE)
205 set(DEBUG_BUILD FALSE)
206 set(RELWITHDEBINFO_BUILD FALSE)
207 set(MINSIZEREL_BUILD FALSE)
208 if("${uppercase_CMAKE_BUILD_TYPE}" STREQUAL "RELEASE")
209 set(RELEASE_BUILD TRUE)
210 elseif("${uppercase_CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
211 set(DEBUG_BUILD TRUE)
212 elseif("${uppercase_CMAKE_BUILD_TYPE}" STREQUAL "RELWITHDEBINFO")
213 set(RELWITHDEBINFO_BUILD TRUE)
214 elseif("${uppercase_CMAKE_BUILD_TYPE}" STREQUAL "MINSIZEREL")
215 set(MINSIZEREL_BUILD TRUE)
218 # Include itt notify interface?
219 set(LIBOMP_USE_ITT_NOTIFY TRUE CACHE BOOL
220 "Enable ITT notify?")
222 # normal, profile, stubs library.
223 set(NORMAL_LIBRARY FALSE)
224 set(STUBS_LIBRARY FALSE)
225 set(PROFILE_LIBRARY FALSE)
226 if("${LIBOMP_LIB_TYPE}" STREQUAL "normal")
227 set(NORMAL_LIBRARY TRUE)
228 elseif("${LIBOMP_LIB_TYPE}" STREQUAL "profile")
229 set(PROFILE_LIBRARY TRUE)
230 elseif("${LIBOMP_LIB_TYPE}" STREQUAL "stubs")
231 set(STUBS_LIBRARY TRUE)
234 # Setting directory names
235 set(LIBOMP_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
236 set(LIBOMP_SRC_DIR ${LIBOMP_BASE_DIR}/src)
237 set(LIBOMP_TOOLS_DIR ${LIBOMP_BASE_DIR}/tools)
238 set(LIBOMP_INC_DIR ${LIBOMP_SRC_DIR}/include)
239 set(LIBOMP_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
241 # Enabling Fortran if it is needed
242 if(${LIBOMP_FORTRAN_MODULES})
243 enable_language(Fortran)
245 # Enable MASM Compiler if it is needed (Windows only)
247 enable_language(ASM_MASM)
250 # Getting legal type/arch
251 libomp_get_legal_type(LIBOMP_LEGAL_TYPE)
252 libomp_get_legal_arch(LIBOMP_LEGAL_ARCH)
254 # Compiler flag checks, library checks, threading check, etc.
257 # Is there a quad precision data type available?
258 # TODO: Make this a real feature check
259 set(LIBOMP_USE_QUAD_PRECISION "${LIBOMP_HAVE_QUAD_PRECISION}" CACHE BOOL
260 "Should 128-bit precision entry points be built?")
261 if(LIBOMP_USE_QUAD_PRECISION AND (NOT LIBOMP_HAVE_QUAD_PRECISION))
262 libomp_error_say("128-bit quad precision functionality requested but not available")
265 # libgomp drop-in compatibility requires versioned symbols
266 set(LIBOMP_USE_VERSION_SYMBOLS "${LIBOMP_HAVE_VERSION_SYMBOLS}" CACHE BOOL
267 "Should version symbols be used? These provide binary compatibility with libgomp.")
268 if(LIBOMP_USE_VERSION_SYMBOLS AND (NOT LIBOMP_HAVE_VERSION_SYMBOLS))
269 libomp_error_say("Version symbols functionality requested but not available")
272 # On multinode systems, larger alignment is desired to avoid false sharing
273 set(LIBOMP_USE_INTERNODE_ALIGNMENT FALSE CACHE BOOL
274 "Should larger alignment (4096 bytes) be used for some locks and data structures?")
276 # Build code that allows the OpenMP library to conveniently interface with debuggers
277 set(LIBOMP_USE_DEBUGGER FALSE CACHE BOOL
278 "Enable debugger interface code?")
280 # Should we link to C++ library?
281 set(LIBOMP_USE_STDCPPLIB FALSE CACHE BOOL
282 "Should we link to C++ library?")
284 # Intel(R) Transactional Synchronization Extensions (Intel(R) TSX) based locks have
285 # __asm code which can be troublesome for some compilers. This feature is also x86 specific.
286 # TODO: Make this a real feature check
287 set(LIBOMP_USE_ADAPTIVE_LOCKS "${LIBOMP_HAVE_ADAPTIVE_LOCKS}" CACHE BOOL
288 "Should Intel(R) TSX lock be compiled (adaptive lock in kmp_lock.cpp). These are x86 specific.")
289 if(LIBOMP_USE_ADAPTIVE_LOCKS AND (NOT LIBOMP_HAVE_ADAPTIVE_LOCKS))
290 libomp_error_say("Adaptive locks (Intel(R) TSX) functionality is only supported on x86 Architecture")
293 # - stats-gathering enables OpenMP stats where things like the number of
294 # parallel regions, clock ticks spent in particular openmp regions are recorded.
295 set(LIBOMP_STATS FALSE CACHE BOOL
296 "Stats-Gathering functionality?")
297 if(LIBOMP_STATS AND (NOT LIBOMP_HAVE_STATS))
298 libomp_error_say("Stats-gathering functionality requested but not available")
300 # The stats functionality requires the std c++ library
302 set(LIBOMP_USE_STDCPPLIB TRUE)
305 # Shared library can be switched to a static library
306 set(LIBOMP_ENABLE_SHARED TRUE CACHE BOOL
307 "Shared library instead of static library?")
309 if(WIN32 AND NOT LIBOMP_ENABLE_SHARED)
310 libomp_error_say("Static libraries requested but not available on Windows")
313 if(LIBOMP_USE_ITT_NOTIFY AND NOT LIBOMP_ENABLE_SHARED)
314 message(STATUS "ITT Notify not supported for static libraries - forcing ITT Notify off")
315 set(LIBOMP_USE_ITT_NOTIFY FALSE)
318 if(LIBOMP_USE_VERSION_SYMBOLS AND (NOT LIBOMP_ENABLE_SHARED) )
319 message(STATUS "Version symbols not supported for static libraries - forcing Version symbols functionality off")
320 set (LIBOMP_USE_VERSION_SYMBOLS FALSE)
323 # OMPT-support defaults to ON for OpenMP 5.0+ and if the requirements in
324 # cmake/config-ix.cmake are fulfilled.
325 set(OMPT_DEFAULT FALSE)
326 if ((LIBOMP_HAVE_OMPT_SUPPORT) AND (NOT WIN32))
327 set(OMPT_DEFAULT TRUE)
329 set(LIBOMP_OMPT_SUPPORT ${OMPT_DEFAULT} CACHE BOOL
332 set(LIBOMP_OMPT_DEBUG FALSE CACHE BOOL
333 "Trace OMPT initialization?")
334 set(LIBOMP_OMPT_OPTIONAL TRUE CACHE BOOL
336 if(LIBOMP_OMPT_SUPPORT AND (NOT LIBOMP_HAVE_OMPT_SUPPORT))
337 libomp_error_say("OpenMP Tools Interface requested but not available in this implementation")
341 # Enable if OMPT SUPPORT is ON
342 set(OMPD_DEFAULT FALSE)
343 if (LIBOMP_HAVE_OMPT_SUPPORT AND ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux"))
344 set(OMPD_DEFAULT TRUE)
347 set(LIBOMP_OMPD_SUPPORT ${OMPD_DEFAULT} CACHE BOOL
350 if(LIBOMP_OMPD_SUPPORT AND ((NOT LIBOMP_OMPT_SUPPORT) OR (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")))
351 libomp_warning_say("OpenMP Debug Interface(OMPD) requested but not available in this implementation")
352 set(LIBOMP_OMPD_SUPPORT FALSE)
355 # OMPX Taskgraph support
356 # Whether to build with OMPX Taskgraph (e.g. task record & replay)
357 set(LIBOMP_OMPX_TASKGRAPH FALSE CACHE BOOL "OMPX-taskgraph (task record & replay)?")
359 # Error check hwloc support after config-ix has run
360 if(LIBOMP_USE_HWLOC AND (NOT LIBOMP_HAVE_HWLOC))
361 libomp_error_say("Hwloc requested but not available")
364 # Hierarchical scheduling support
365 set(LIBOMP_USE_HIER_SCHED FALSE CACHE BOOL
366 "Hierarchical scheduling support?")
368 # Setting final library name
369 set(LIBOMP_DEFAULT_LIB_NAME libomp)
370 if(${PROFILE_LIBRARY})
371 set(LIBOMP_DEFAULT_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME}prof)
374 set(LIBOMP_DEFAULT_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME}stubs)
376 set(LIBOMP_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME} CACHE STRING "Base OMP library name")
377 if (OPENMP_MSVC_NAME_SCHEME)
378 # MSVC_TOOLS_VERSION corresponds to the version of the VC++ toolset.
379 set(MSVC_TOOLS_VERSION 140)
380 set(LIBOMP_LIB_NAME ${LIBOMP_LIB_NAME}${MSVC_TOOLS_VERSION}.${LIBOMP_ARCH})
383 if(${LIBOMP_ENABLE_SHARED})
384 set(LIBOMP_LIBRARY_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
385 set(LIBOMP_LIBRARY_KIND SHARED)
386 set(LIBOMP_INSTALL_KIND LIBRARY)
388 set(LIBOMP_LIBRARY_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
389 set(LIBOMP_LIBRARY_KIND STATIC)
390 set(LIBOMP_INSTALL_KIND ARCHIVE)
393 set(LIBOMP_LIB_FILE ${LIBOMP_LIB_NAME}${LIBOMP_LIBRARY_SUFFIX})
395 # Optional backwards compatibility aliases.
396 set(LIBOMP_INSTALL_ALIASES TRUE CACHE BOOL
397 "Install libgomp and libiomp5 library aliases for backwards compatibility")
399 # Print configuration after all variables are set.
400 if(${OPENMP_STANDALONE_BUILD})
401 libomp_say("Operating System -- ${CMAKE_SYSTEM_NAME}")
402 libomp_say("Target Architecture -- ${LIBOMP_ARCH}")
404 libomp_say("Intel(R) MIC Architecture -- ${LIBOMP_MIC_ARCH}")
406 libomp_say("Build Type -- ${CMAKE_BUILD_TYPE}")
407 libomp_say("Library Kind -- ${LIBOMP_LIBRARY_KIND}")
408 libomp_say("Library Type -- ${LIBOMP_LIB_TYPE}")
409 libomp_say("Fortran Modules -- ${LIBOMP_FORTRAN_MODULES}")
410 # will say development if all zeros
411 if(${LIBOMP_VERSION_BUILD} STREQUAL 00000000)
412 set(LIBOMP_BUILD Development)
414 set(LIBOMP_BUILD ${LIBOMP_VERSION_BUILD})
416 libomp_say("Build -- ${LIBOMP_BUILD}")
417 libomp_say("Use Stats-gathering -- ${LIBOMP_STATS}")
418 libomp_say("Use Debugger-support -- ${LIBOMP_USE_DEBUGGER}")
419 libomp_say("Use ITT notify -- ${LIBOMP_USE_ITT_NOTIFY}")
420 libomp_say("Use OMPT-support -- ${LIBOMP_OMPT_SUPPORT}")
421 if(${LIBOMP_OMPT_SUPPORT})
422 libomp_say("Use OMPT-optional -- ${LIBOMP_OMPT_OPTIONAL}")
424 libomp_say("Use OMPD-support -- ${LIBOMP_OMPD_SUPPORT}")
425 libomp_say("Use Adaptive locks -- ${LIBOMP_USE_ADAPTIVE_LOCKS}")
426 libomp_say("Use quad precision -- ${LIBOMP_USE_QUAD_PRECISION}")
427 libomp_say("Use Hwloc library -- ${LIBOMP_USE_HWLOC}")
428 libomp_say("Use OMPX-taskgraph -- ${LIBOMP_OMPX_TASKGRAPH}")
431 add_subdirectory(src)
432 add_subdirectory(test)
434 # make these variables available for tools:
435 set(LIBOMP_LIBRARY_DIR ${LIBOMP_LIBRARY_DIR} PARENT_SCOPE)
436 set(LIBOMP_INCLUDE_DIR ${LIBOMP_INCLUDE_DIR} PARENT_SCOPE)
437 set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${LIBOMP_OMP_TOOLS_INCLUDE_DIR} PARENT_SCOPE)
438 # make these variables available for tools/libompd:
439 set(LIBOMP_SRC_DIR ${LIBOMP_SRC_DIR} PARENT_SCOPE)
440 set(LIBOMP_OMPD_SUPPORT ${LIBOMP_OMPD_SUPPORT} PARENT_SCOPE)