• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2#//===----------------------------------------------------------------------===//
3#//
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
7#//
8#//===----------------------------------------------------------------------===//
9#
10
11if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
12  message(FATAL_ERROR "Direct configuration not supported, please use parent directory!")
13endif()
14
15# Add cmake directory to search for custom cmake functions
16set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
17
18# Set libomp version
19set(LIBOMP_VERSION_MAJOR 5)
20set(LIBOMP_VERSION_MINOR 0)
21
22# These include files are in the cmake/ subdirectory
23include(LibompUtils)
24include(LibompGetArchitecture)
25include(LibompHandleFlags)
26include(LibompDefinitions)
27
28# Determine the target architecture
29if(${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
36    "enable assertions?")
37else() # 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})
42  endif ()
43  if(LIBOMP_NATIVE_ARCH MATCHES "i[2-6]86")
44    set(LIBOMP_ARCH i386)
45  elseif(LIBOMP_NATIVE_ARCH STREQUAL "x86")
46    set(LIBOMP_ARCH i386)
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")
60    set(LIBOMP_ARCH arm)
61  elseif(LIBOMP_NATIVE_ARCH MATCHES "riscv64")
62    set(LIBOMP_ARCH riscv64)
63  else()
64    # last ditch effort
65    libomp_get_architecture(LIBOMP_ARCH)
66  endif ()
67  set(LIBOMP_ENABLE_ASSERTIONS ${LLVM_ENABLE_ASSERTIONS})
68endif()
69libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc64 ppc64le aarch64 mic mips mips64 riscv64)
70
71set(LIBOMP_LIB_TYPE normal CACHE STRING
72  "Performance,Profiling,Stubs library (normal/profile/stubs)")
73libomp_check_variable(LIBOMP_LIB_TYPE normal profile stubs)
74# Set the OpenMP Year and Month associated with version
75set(LIBOMP_OMP_YEAR_MONTH 201611)
76set(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.")
78if("${LIBOMP_ARCH}" STREQUAL "mic")
79  libomp_check_variable(LIBOMP_MIC_ARCH knf knc)
80endif()
81set(LIBOMP_FORTRAN_MODULES FALSE CACHE BOOL
82  "Create Fortran module files? (requires fortran compiler)")
83
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.
87set(LIBOMP_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}" CACHE STRING
88  "For Mac builds, semicolon separated list of architectures to build for universal fat binary.")
89set(CMAKE_OSX_ARCHITECTURES ${LIBOMP_OSX_ARCHITECTURES})
90
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.
95if(NOT DEFINED CMAKE_MACOSX_RPATH)
96  set(CMAKE_MACOSX_RPATH TRUE)
97endif()
98
99# User specified flags.  These are appended to the configured flags.
100set(LIBOMP_CXXFLAGS "" CACHE STRING
101  "Appended user specified C++ compiler flags.")
102set(LIBOMP_CPPFLAGS "" CACHE STRING
103  "Appended user specified C preprocessor flags.")
104set(LIBOMP_ASMFLAGS "" CACHE STRING
105  "Appended user specified assembler flags.")
106set(LIBOMP_LDFLAGS "" CACHE STRING
107  "Appended user specified linker flags.")
108set(LIBOMP_LIBFLAGS "" CACHE STRING
109  "Appended user specified linked libs flags. (e.g., -lm)")
110set(LIBOMP_FFLAGS "" CACHE STRING
111  "Appended user specified Fortran compiler flags.  These are only used if LIBOMP_FORTRAN_MODULES==TRUE.")
112
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/
117set(LIBOMP_COPY_EXPORTS FALSE CACHE STRING
118  "Should exports be copied into source exports/ directory?")
119
120# HWLOC-support
121set(LIBOMP_USE_HWLOC FALSE CACHE BOOL
122  "Use Hwloc (http://www.open-mpi.org/projects/hwloc/) library for affinity?")
123set(LIBOMP_HWLOC_INSTALL_DIR /usr/local CACHE PATH
124  "Install path for hwloc library")
125
126# Get the build number from kmp_version.cpp
127libomp_get_build_number("${CMAKE_CURRENT_SOURCE_DIR}" LIBOMP_VERSION_BUILD)
128math(EXPR LIBOMP_VERSION_BUILD_YEAR "${LIBOMP_VERSION_BUILD}/10000")
129math(EXPR LIBOMP_VERSION_BUILD_MONTH_DAY "${LIBOMP_VERSION_BUILD}%10000")
130
131# Currently don't record any timestamps
132set(LIBOMP_BUILD_DATE "No_Timestamp")
133
134# Architecture
135set(IA32 FALSE)
136set(INTEL64 FALSE)
137set(ARM FALSE)
138set(AARCH64 FALSE)
139set(PPC64BE FALSE)
140set(PPC64LE FALSE)
141set(PPC64 FALSE)
142set(MIC FALSE)
143set(MIPS64 FALSE)
144set(MIPS FALSE)
145set(RISCV64 FALSE)
146if("${LIBOMP_ARCH}" STREQUAL "i386" OR "${LIBOMP_ARCH}" STREQUAL "32")    # IA-32 architecture
147  set(IA32 TRUE)
148elseif("${LIBOMP_ARCH}" STREQUAL "x86_64" OR "${LIBOMP_ARCH}" STREQUAL "32e") # Intel(R) 64 architecture
149  set(INTEL64 TRUE)
150elseif("${LIBOMP_ARCH}" STREQUAL "arm") # ARM architecture
151  set(ARM TRUE)
152elseif("${LIBOMP_ARCH}" STREQUAL "ppc64") # PPC64BE architecture
153  set(PPC64BE TRUE)
154  set(PPC64 TRUE)
155elseif("${LIBOMP_ARCH}" STREQUAL "ppc64le") # PPC64LE architecture
156  set(PPC64LE TRUE)
157  set(PPC64 TRUE)
158elseif("${LIBOMP_ARCH}" STREQUAL "aarch64") # AARCH64 architecture
159  set(AARCH64 TRUE)
160elseif("${LIBOMP_ARCH}" STREQUAL "mic") # Intel(R) Many Integrated Core Architecture
161  set(MIC TRUE)
162elseif("${LIBOMP_ARCH}" STREQUAL "mips") # MIPS architecture
163    set(MIPS TRUE)
164elseif("${LIBOMP_ARCH}" STREQUAL "mips64") # MIPS64 architecture
165    set(MIPS64 TRUE)
166  elseif("${LIBOMP_ARCH}" STREQUAL "riscv64") # RISCV64 architecture
167    set(RISCV64 TRUE)
168endif()
169
170# Set some flags based on build_type
171set(RELEASE_BUILD FALSE)
172set(DEBUG_BUILD FALSE)
173set(RELWITHDEBINFO_BUILD FALSE)
174set(MINSIZEREL_BUILD FALSE)
175string(TOLOWER "${CMAKE_BUILD_TYPE}" libomp_build_type_lowercase)
176if("${libomp_build_type_lowercase}" STREQUAL "release")
177  set(RELEASE_BUILD TRUE)
178elseif("${libomp_build_type_lowercase}" STREQUAL "debug")
179  set(DEBUG_BUILD TRUE)
180elseif("${libomp_build_type_lowercase}" STREQUAL "relwithdebinfo")
181  set(RELWITHDEBINFO_BUILD TRUE)
182elseif("${libomp_build_type_lowercase}" STREQUAL "minsizerel")
183  set(MINSIZEREL_BUILD TRUE)
184endif()
185
186# Include itt notify interface?
187set(LIBOMP_USE_ITT_NOTIFY TRUE CACHE BOOL
188  "Enable ITT notify?")
189
190# normal, profile, stubs library.
191set(NORMAL_LIBRARY FALSE)
192set(STUBS_LIBRARY FALSE)
193set(PROFILE_LIBRARY FALSE)
194if("${LIBOMP_LIB_TYPE}" STREQUAL "normal")
195  set(NORMAL_LIBRARY TRUE)
196elseif("${LIBOMP_LIB_TYPE}" STREQUAL "profile")
197  set(PROFILE_LIBRARY TRUE)
198elseif("${LIBOMP_LIB_TYPE}" STREQUAL "stubs")
199  set(STUBS_LIBRARY TRUE)
200endif()
201
202# Setting directory names
203set(LIBOMP_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
204set(LIBOMP_SRC_DIR ${LIBOMP_BASE_DIR}/src)
205set(LIBOMP_TOOLS_DIR ${LIBOMP_BASE_DIR}/tools)
206set(LIBOMP_INC_DIR ${LIBOMP_SRC_DIR}/include)
207set(LIBOMP_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
208
209# Enabling Fortran if it is needed
210if(${LIBOMP_FORTRAN_MODULES})
211  enable_language(Fortran)
212endif()
213# Enable MASM Compiler if it is needed (Windows only)
214if(WIN32)
215  enable_language(ASM_MASM)
216endif()
217
218# Getting legal type/arch
219libomp_get_legal_type(LIBOMP_LEGAL_TYPE)
220libomp_get_legal_arch(LIBOMP_LEGAL_ARCH)
221
222# Compiler flag checks, library checks, threading check, etc.
223include(config-ix)
224
225# Is there a quad precision data type available?
226# TODO: Make this a real feature check
227set(LIBOMP_USE_QUAD_PRECISION "${LIBOMP_HAVE_QUAD_PRECISION}" CACHE BOOL
228  "Should 128-bit precision entry points be built?")
229if(LIBOMP_USE_QUAD_PRECISION AND (NOT LIBOMP_HAVE_QUAD_PRECISION))
230  libomp_error_say("128-bit quad precision functionality requested but not available")
231endif()
232
233# libgomp drop-in compatibility requires versioned symbols
234set(LIBOMP_USE_VERSION_SYMBOLS "${LIBOMP_HAVE_VERSION_SYMBOLS}" CACHE BOOL
235  "Should version symbols be used? These provide binary compatibility with libgomp.")
236if(LIBOMP_USE_VERSION_SYMBOLS AND (NOT LIBOMP_HAVE_VERSION_SYMBOLS))
237  libomp_error_say("Version symbols functionality requested but not available")
238endif()
239
240# On multinode systems, larger alignment is desired to avoid false sharing
241set(LIBOMP_USE_INTERNODE_ALIGNMENT FALSE CACHE BOOL
242  "Should larger alignment (4096 bytes) be used for some locks and data structures?")
243
244# Build code that allows the OpenMP library to conveniently interface with debuggers
245set(LIBOMP_USE_DEBUGGER FALSE CACHE BOOL
246  "Enable debugger interface code?")
247
248# Should we link to C++ library?
249set(LIBOMP_USE_STDCPPLIB FALSE CACHE BOOL
250  "Should we link to C++ library?")
251
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
255set(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.")
257if(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")
259endif()
260
261# - stats-gathering enables OpenMP stats where things like the number of
262# parallel regions, clock ticks spent in particular openmp regions are recorded.
263set(LIBOMP_STATS FALSE CACHE BOOL
264  "Stats-Gathering functionality?")
265if(LIBOMP_STATS AND (NOT LIBOMP_HAVE_STATS))
266  libomp_error_say("Stats-gathering functionality requested but not available")
267endif()
268# The stats functionality requires the std c++ library
269if(LIBOMP_STATS)
270  set(LIBOMP_USE_STDCPPLIB TRUE)
271endif()
272
273# Shared library can be switched to a static library
274set(LIBOMP_ENABLE_SHARED TRUE CACHE BOOL
275  "Shared library instead of static library?")
276
277if(WIN32 AND NOT LIBOMP_ENABLE_SHARED)
278  libomp_error_say("Static libraries requested but not available on Windows")
279endif()
280
281if(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)
284endif()
285
286if(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)
289endif()
290
291# OMPT-support defaults to ON for OpenMP 5.0+ and if the requirements in
292# cmake/config-ix.cmake are fulfilled.
293set(OMPT_DEFAULT FALSE)
294if ((LIBOMP_HAVE_OMPT_SUPPORT) AND (NOT WIN32))
295  set(OMPT_DEFAULT TRUE)
296endif()
297set(LIBOMP_OMPT_SUPPORT ${OMPT_DEFAULT} CACHE BOOL
298  "OMPT-support?")
299
300set(LIBOMP_OMPT_DEBUG FALSE CACHE BOOL
301  "Trace OMPT initialization?")
302set(LIBOMP_OMPT_OPTIONAL TRUE CACHE BOOL
303  "OMPT-optional?")
304if(LIBOMP_OMPT_SUPPORT AND (NOT LIBOMP_HAVE_OMPT_SUPPORT))
305  libomp_error_say("OpenMP Tools Interface requested but not available in this implementation")
306endif()
307
308# TSAN-support
309set(LIBOMP_TSAN_SUPPORT FALSE CACHE BOOL
310  "TSAN-support?")
311if(LIBOMP_TSAN_SUPPORT AND (NOT LIBOMP_HAVE_TSAN_SUPPORT))
312  libomp_error_say("TSAN functionality requested but not available")
313endif()
314
315# Error check hwloc support after config-ix has run
316if(LIBOMP_USE_HWLOC AND (NOT LIBOMP_HAVE_HWLOC))
317  libomp_error_say("Hwloc requested but not available")
318endif()
319
320# Hierarchical scheduling support
321set(LIBOMP_USE_HIER_SCHED FALSE CACHE BOOL
322  "Hierarchical scheduling support?")
323
324# Setting final library name
325set(LIBOMP_DEFAULT_LIB_NAME libomp)
326if(${PROFILE_LIBRARY})
327  set(LIBOMP_DEFAULT_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME}prof)
328endif()
329if(${STUBS_LIBRARY})
330  set(LIBOMP_DEFAULT_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME}stubs)
331endif()
332set(LIBOMP_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME} CACHE STRING "Base OMP library name")
333
334if(${LIBOMP_ENABLE_SHARED})
335  set(LIBOMP_LIBRARY_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
336  set(LIBOMP_LIBRARY_KIND SHARED)
337  set(LIBOMP_INSTALL_KIND LIBRARY)
338else()
339  set(LIBOMP_LIBRARY_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
340  set(LIBOMP_LIBRARY_KIND STATIC)
341  set(LIBOMP_INSTALL_KIND ARCHIVE)
342endif()
343
344set(LIBOMP_LIB_FILE ${LIBOMP_LIB_NAME}${LIBOMP_LIBRARY_SUFFIX})
345
346# Optional backwards compatibility aliases.
347set(LIBOMP_INSTALL_ALIASES TRUE CACHE BOOL
348  "Install libgomp and libiomp5 library aliases for backwards compatibility")
349
350# Print configuration after all variables are set.
351if(${OPENMP_STANDALONE_BUILD})
352  libomp_say("Operating System     -- ${CMAKE_SYSTEM_NAME}")
353  libomp_say("Target Architecture  -- ${LIBOMP_ARCH}")
354  if(${MIC})
355    libomp_say("Intel(R) MIC Architecture    -- ${LIBOMP_MIC_ARCH}")
356  endif()
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)
364  else()
365    set(LIBOMP_BUILD ${LIBOMP_VERSION_BUILD})
366  endif()
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}")
374  endif()
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}")
379endif()
380
381add_subdirectory(src)
382add_subdirectory(test)
383
384# make these variables available for tools:
385set(LIBOMP_LIBRARY_DIR ${LIBOMP_LIBRARY_DIR} PARENT_SCOPE)
386set(LIBOMP_INCLUDE_DIR ${LIBOMP_INCLUDE_DIR} PARENT_SCOPE)
387