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).")
34 # Should assertions be enabled? They are on by default.
35 set(LIBOMP_ENABLE_ASSERTIONS TRUE CACHE BOOL
37 else() # Part of LLVM build
38 # Determine the native architecture from LLVM.
39 string(TOLOWER "${LLVM_TARGET_ARCH}" LIBOMP_NATIVE_ARCH)
40 if( LIBOMP_NATIVE_ARCH STREQUAL "host" )
41 string(REGEX MATCH "^[^-]*" LIBOMP_NATIVE_ARCH ${LLVM_HOST_TRIPLE})
43 if(LIBOMP_NATIVE_ARCH MATCHES "i[2-6]86")
45 elseif(LIBOMP_NATIVE_ARCH STREQUAL "x86")
47 elseif(LIBOMP_NATIVE_ARCH STREQUAL "amd64")
48 set(LIBOMP_ARCH x86_64)
49 elseif(LIBOMP_NATIVE_ARCH STREQUAL "x86_64")
50 set(LIBOMP_ARCH x86_64)
51 elseif(LIBOMP_NATIVE_ARCH MATCHES "powerpc64le")
52 set(LIBOMP_ARCH ppc64le)
53 elseif(LIBOMP_NATIVE_ARCH MATCHES "powerpc")
54 set(LIBOMP_ARCH ppc64)
55 elseif(LIBOMP_NATIVE_ARCH MATCHES "aarch64")
56 set(LIBOMP_ARCH aarch64)
57 elseif(LIBOMP_NATIVE_ARCH MATCHES "arm64")
58 set(LIBOMP_ARCH aarch64)
59 elseif(LIBOMP_NATIVE_ARCH MATCHES "arm")
61 elseif(LIBOMP_NATIVE_ARCH MATCHES "riscv64")
62 set(LIBOMP_ARCH riscv64)
65 libomp_get_architecture(LIBOMP_ARCH)
67 set(LIBOMP_ENABLE_ASSERTIONS ${LLVM_ENABLE_ASSERTIONS})
69 libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc64 ppc64le aarch64 mic mips mips64 riscv64)
71 set(LIBOMP_LIB_TYPE normal CACHE STRING
72 "Performance,Profiling,Stubs library (normal/profile/stubs)")
73 libomp_check_variable(LIBOMP_LIB_TYPE normal profile stubs)
74 # Set the OpenMP Year and Month associated with version
75 set(LIBOMP_OMP_YEAR_MONTH 201611)
76 set(LIBOMP_MIC_ARCH knc CACHE STRING
77 "Intel(R) Many Integrated Core Architecture (Intel(R) MIC Architecture) (knf/knc). Ignored if not Intel(R) MIC Architecture build.")
78 if("${LIBOMP_ARCH}" STREQUAL "mic")
79 libomp_check_variable(LIBOMP_MIC_ARCH knf knc)
81 set(LIBOMP_FORTRAN_MODULES FALSE CACHE BOOL
82 "Create Fortran module files? (requires fortran compiler)")
84 # - Support for universal fat binary builds on Mac
85 # - Having this extra variable allows people to build this library as a universal library
86 # without forcing a universal build of the llvm/clang compiler.
87 set(LIBOMP_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}" CACHE STRING
88 "For Mac builds, semicolon separated list of architectures to build for universal fat binary.")
89 set(CMAKE_OSX_ARCHITECTURES ${LIBOMP_OSX_ARCHITECTURES})
91 # Should @rpath be used for dynamic libraries on Mac?
92 # The if(NOT DEFINED) is there to guard a cached value of the variable if one
93 # exists so there is no interference with what the user wants. Also, no cache entry
94 # is created so there are no inadvertant effects on other parts of LLVM.
95 if(NOT DEFINED CMAKE_MACOSX_RPATH)
96 set(CMAKE_MACOSX_RPATH TRUE)
99 # User specified flags. These are appended to the configured flags.
100 set(LIBOMP_CXXFLAGS "" CACHE STRING
101 "Appended user specified C++ compiler flags.")
102 set(LIBOMP_CPPFLAGS "" CACHE STRING
103 "Appended user specified C preprocessor flags.")
104 set(LIBOMP_ASMFLAGS "" CACHE STRING
105 "Appended user specified assembler flags.")
106 set(LIBOMP_LDFLAGS "" CACHE STRING
107 "Appended user specified linker flags.")
108 set(LIBOMP_LIBFLAGS "" CACHE STRING
109 "Appended user specified linked libs flags. (e.g., -lm)")
110 set(LIBOMP_FFLAGS "" CACHE STRING
111 "Appended user specified Fortran compiler flags. These are only used if LIBOMP_FORTRAN_MODULES==TRUE.")
113 # Should the libomp library and generated headers be copied into the original source exports/ directory
114 # Turning this to FALSE aids parallel builds to not interfere with each other.
115 # Currently, the testsuite module expects the just built OpenMP library to be located inside the exports/
116 # directory. TODO: have testsuite run under llvm-lit directly. We can then get rid of copying to exports/
117 set(LIBOMP_COPY_EXPORTS FALSE CACHE STRING
118 "Should exports be copied into source exports/ directory?")
121 set(LIBOMP_USE_HWLOC FALSE CACHE BOOL
122 "Use Hwloc (http://www.open-mpi.org/projects/hwloc/) library for affinity?")
123 set(LIBOMP_HWLOC_INSTALL_DIR /usr/local CACHE PATH
124 "Install path for hwloc library")
126 # Get the build number from kmp_version.cpp
127 libomp_get_build_number("${CMAKE_CURRENT_SOURCE_DIR}" LIBOMP_VERSION_BUILD)
128 math(EXPR LIBOMP_VERSION_BUILD_YEAR "${LIBOMP_VERSION_BUILD}/10000")
129 math(EXPR LIBOMP_VERSION_BUILD_MONTH_DAY "${LIBOMP_VERSION_BUILD}%10000")
131 # Currently don't record any timestamps
132 set(LIBOMP_BUILD_DATE "No_Timestamp")
146 if("${LIBOMP_ARCH}" STREQUAL "i386" OR "${LIBOMP_ARCH}" STREQUAL "32") # IA-32 architecture
148 elseif("${LIBOMP_ARCH}" STREQUAL "x86_64" OR "${LIBOMP_ARCH}" STREQUAL "32e") # Intel(R) 64 architecture
150 elseif("${LIBOMP_ARCH}" STREQUAL "arm") # ARM architecture
152 elseif("${LIBOMP_ARCH}" STREQUAL "ppc64") # PPC64BE architecture
155 elseif("${LIBOMP_ARCH}" STREQUAL "ppc64le") # PPC64LE architecture
158 elseif("${LIBOMP_ARCH}" STREQUAL "aarch64") # AARCH64 architecture
160 elseif("${LIBOMP_ARCH}" STREQUAL "mic") # Intel(R) Many Integrated Core Architecture
162 elseif("${LIBOMP_ARCH}" STREQUAL "mips") # MIPS architecture
164 elseif("${LIBOMP_ARCH}" STREQUAL "mips64") # MIPS64 architecture
166 elseif("${LIBOMP_ARCH}" STREQUAL "riscv64") # RISCV64 architecture
170 # Set some flags based on build_type
171 set(RELEASE_BUILD FALSE)
172 set(DEBUG_BUILD FALSE)
173 set(RELWITHDEBINFO_BUILD FALSE)
174 set(MINSIZEREL_BUILD FALSE)
175 string(TOLOWER "${CMAKE_BUILD_TYPE}" libomp_build_type_lowercase)
176 if("${libomp_build_type_lowercase}" STREQUAL "release")
177 set(RELEASE_BUILD TRUE)
178 elseif("${libomp_build_type_lowercase}" STREQUAL "debug")
179 set(DEBUG_BUILD TRUE)
180 elseif("${libomp_build_type_lowercase}" STREQUAL "relwithdebinfo")
181 set(RELWITHDEBINFO_BUILD TRUE)
182 elseif("${libomp_build_type_lowercase}" STREQUAL "minsizerel")
183 set(MINSIZEREL_BUILD TRUE)
186 # Include itt notify interface?
187 set(LIBOMP_USE_ITT_NOTIFY TRUE CACHE BOOL
188 "Enable ITT notify?")
190 # normal, profile, stubs library.
191 set(NORMAL_LIBRARY FALSE)
192 set(STUBS_LIBRARY FALSE)
193 set(PROFILE_LIBRARY FALSE)
194 if("${LIBOMP_LIB_TYPE}" STREQUAL "normal")
195 set(NORMAL_LIBRARY TRUE)
196 elseif("${LIBOMP_LIB_TYPE}" STREQUAL "profile")
197 set(PROFILE_LIBRARY TRUE)
198 elseif("${LIBOMP_LIB_TYPE}" STREQUAL "stubs")
199 set(STUBS_LIBRARY TRUE)
202 # Setting directory names
203 set(LIBOMP_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
204 set(LIBOMP_SRC_DIR ${LIBOMP_BASE_DIR}/src)
205 set(LIBOMP_TOOLS_DIR ${LIBOMP_BASE_DIR}/tools)
206 set(LIBOMP_INC_DIR ${LIBOMP_SRC_DIR}/include)
207 set(LIBOMP_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
209 # Enabling Fortran if it is needed
210 if(${LIBOMP_FORTRAN_MODULES})
211 enable_language(Fortran)
213 # Enable MASM Compiler if it is needed (Windows only)
215 enable_language(ASM_MASM)
218 # Getting legal type/arch
219 libomp_get_legal_type(LIBOMP_LEGAL_TYPE)
220 libomp_get_legal_arch(LIBOMP_LEGAL_ARCH)
222 # Compiler flag checks, library checks, threading check, etc.
225 # Is there a quad precision data type available?
226 # TODO: Make this a real feature check
227 set(LIBOMP_USE_QUAD_PRECISION "${LIBOMP_HAVE_QUAD_PRECISION}" CACHE BOOL
228 "Should 128-bit precision entry points be built?")
229 if(LIBOMP_USE_QUAD_PRECISION AND (NOT LIBOMP_HAVE_QUAD_PRECISION))
230 libomp_error_say("128-bit quad precision functionality requested but not available")
233 # libgomp drop-in compatibility requires versioned symbols
234 set(LIBOMP_USE_VERSION_SYMBOLS "${LIBOMP_HAVE_VERSION_SYMBOLS}" CACHE BOOL
235 "Should version symbols be used? These provide binary compatibility with libgomp.")
236 if(LIBOMP_USE_VERSION_SYMBOLS AND (NOT LIBOMP_HAVE_VERSION_SYMBOLS))
237 libomp_error_say("Version symbols functionality requested but not available")
240 # On multinode systems, larger alignment is desired to avoid false sharing
241 set(LIBOMP_USE_INTERNODE_ALIGNMENT FALSE CACHE BOOL
242 "Should larger alignment (4096 bytes) be used for some locks and data structures?")
244 # Build code that allows the OpenMP library to conveniently interface with debuggers
245 set(LIBOMP_USE_DEBUGGER FALSE CACHE BOOL
246 "Enable debugger interface code?")
248 # Should we link to C++ library?
249 set(LIBOMP_USE_STDCPPLIB FALSE CACHE BOOL
250 "Should we link to C++ library?")
252 # Intel(R) Transactional Synchronization Extensions (Intel(R) TSX) based locks have
253 # __asm code which can be troublesome for some compilers. This feature is also x86 specific.
254 # TODO: Make this a real feature check
255 set(LIBOMP_USE_ADAPTIVE_LOCKS "${LIBOMP_HAVE_ADAPTIVE_LOCKS}" CACHE BOOL
256 "Should Intel(R) TSX lock be compiled (adaptive lock in kmp_lock.cpp). These are x86 specific.")
257 if(LIBOMP_USE_ADAPTIVE_LOCKS AND (NOT LIBOMP_HAVE_ADAPTIVE_LOCKS))
258 libomp_error_say("Adaptive locks (Intel(R) TSX) functionality is only supported on x86 Architecture")
261 # - stats-gathering enables OpenMP stats where things like the number of
262 # parallel regions, clock ticks spent in particular openmp regions are recorded.
263 set(LIBOMP_STATS FALSE CACHE BOOL
264 "Stats-Gathering functionality?")
265 if(LIBOMP_STATS AND (NOT LIBOMP_HAVE_STATS))
266 libomp_error_say("Stats-gathering functionality requested but not available")
268 # The stats functionality requires the std c++ library
270 set(LIBOMP_USE_STDCPPLIB TRUE)
273 # Shared library can be switched to a static library
274 set(LIBOMP_ENABLE_SHARED TRUE CACHE BOOL
275 "Shared library instead of static library?")
277 if(WIN32 AND NOT LIBOMP_ENABLE_SHARED)
278 libomp_error_say("Static libraries requested but not available on Windows")
281 if(LIBOMP_USE_ITT_NOTIFY AND NOT LIBOMP_ENABLE_SHARED)
282 message(STATUS "ITT Notify not supported for static libraries - forcing ITT Notify off")
283 set(LIBOMP_USE_ITT_NOTIFY FALSE)
286 if(LIBOMP_USE_VERSION_SYMBOLS AND (NOT LIBOMP_ENABLE_SHARED) )
287 message(STATUS "Version symbols not supported for static libraries - forcing Version symbols functionality off")
288 set (LIBOMP_USE_VERSION_SYMBOLS FALSE)
291 # OMPT-support defaults to ON for OpenMP 5.0+ and if the requirements in
292 # cmake/config-ix.cmake are fulfilled.
293 set(OMPT_DEFAULT FALSE)
294 if ((LIBOMP_HAVE_OMPT_SUPPORT) AND (NOT WIN32))
295 set(OMPT_DEFAULT TRUE)
297 set(LIBOMP_OMPT_SUPPORT ${OMPT_DEFAULT} CACHE BOOL
300 set(LIBOMP_OMPT_DEBUG FALSE CACHE BOOL
301 "Trace OMPT initialization?")
302 set(LIBOMP_OMPT_OPTIONAL TRUE CACHE BOOL
304 if(LIBOMP_OMPT_SUPPORT AND (NOT LIBOMP_HAVE_OMPT_SUPPORT))
305 libomp_error_say("OpenMP Tools Interface requested but not available in this implementation")
309 set(LIBOMP_TSAN_SUPPORT FALSE CACHE BOOL
311 if(LIBOMP_TSAN_SUPPORT AND (NOT LIBOMP_HAVE_TSAN_SUPPORT))
312 libomp_error_say("TSAN functionality requested but not available")
315 # Error check hwloc support after config-ix has run
316 if(LIBOMP_USE_HWLOC AND (NOT LIBOMP_HAVE_HWLOC))
317 libomp_error_say("Hwloc requested but not available")
320 # Hierarchical scheduling support
321 set(LIBOMP_USE_HIER_SCHED FALSE CACHE BOOL
322 "Hierarchical scheduling support?")
324 # Setting final library name
325 set(LIBOMP_DEFAULT_LIB_NAME libomp)
326 if(${PROFILE_LIBRARY})
327 set(LIBOMP_DEFAULT_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME}prof)
330 set(LIBOMP_DEFAULT_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME}stubs)
332 set(LIBOMP_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME} CACHE STRING "Base OMP library name")
334 if(${LIBOMP_ENABLE_SHARED})
335 set(LIBOMP_LIBRARY_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
336 set(LIBOMP_LIBRARY_KIND SHARED)
337 set(LIBOMP_INSTALL_KIND LIBRARY)
339 set(LIBOMP_LIBRARY_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
340 set(LIBOMP_LIBRARY_KIND STATIC)
341 set(LIBOMP_INSTALL_KIND ARCHIVE)
344 set(LIBOMP_LIB_FILE ${LIBOMP_LIB_NAME}${LIBOMP_LIBRARY_SUFFIX})
346 # Optional backwards compatibility aliases.
347 set(LIBOMP_INSTALL_ALIASES TRUE CACHE BOOL
348 "Install libgomp and libiomp5 library aliases for backwards compatibility")
350 # Print configuration after all variables are set.
351 if(${OPENMP_STANDALONE_BUILD})
352 libomp_say("Operating System -- ${CMAKE_SYSTEM_NAME}")
353 libomp_say("Target Architecture -- ${LIBOMP_ARCH}")
355 libomp_say("Intel(R) MIC Architecture -- ${LIBOMP_MIC_ARCH}")
357 libomp_say("Build Type -- ${CMAKE_BUILD_TYPE}")
358 libomp_say("Library Kind -- ${LIBOMP_LIBRARY_KIND}")
359 libomp_say("Library Type -- ${LIBOMP_LIB_TYPE}")
360 libomp_say("Fortran Modules -- ${LIBOMP_FORTRAN_MODULES}")
361 # will say development if all zeros
362 if(${LIBOMP_VERSION_BUILD} STREQUAL 00000000)
363 set(LIBOMP_BUILD Development)
365 set(LIBOMP_BUILD ${LIBOMP_VERSION_BUILD})
367 libomp_say("Build -- ${LIBOMP_BUILD}")
368 libomp_say("Use Stats-gathering -- ${LIBOMP_STATS}")
369 libomp_say("Use Debugger-support -- ${LIBOMP_USE_DEBUGGER}")
370 libomp_say("Use ITT notify -- ${LIBOMP_USE_ITT_NOTIFY}")
371 libomp_say("Use OMPT-support -- ${LIBOMP_OMPT_SUPPORT}")
372 if(${LIBOMP_OMPT_SUPPORT})
373 libomp_say("Use OMPT-optional -- ${LIBOMP_OMPT_OPTIONAL}")
375 libomp_say("Use Adaptive locks -- ${LIBOMP_USE_ADAPTIVE_LOCKS}")
376 libomp_say("Use quad precision -- ${LIBOMP_USE_QUAD_PRECISION}")
377 libomp_say("Use TSAN-support -- ${LIBOMP_TSAN_SUPPORT}")
378 libomp_say("Use Hwloc library -- ${LIBOMP_USE_HWLOC}")
381 add_subdirectory(src)
382 add_subdirectory(test)
384 # make these variables available for tools:
385 set(LIBOMP_LIBRARY_DIR ${LIBOMP_LIBRARY_DIR} PARENT_SCOPE)
386 set(LIBOMP_INCLUDE_DIR ${LIBOMP_INCLUDE_DIR} PARENT_SCOPE)