1 ========================================
2 How to Build the LLVM* OpenMP* Libraries
3 ========================================
4 This repository requires `CMake <http://www.cmake.org/>`_ v2.8.0 or later. LLVM
5 and Clang need a more recent version which also applies for in-tree builds. For
6 more information than available in this document please see
7 `LLVM's CMake documentation <https://llvm.org/docs/CMake.html>`_ and the
8 `official documentation <https://cmake.org/cmake/help/v2.8.0/cmake.html>`_.
13 How to Call CMake Initially, then Repeatedly
14 ============================================
15 - When calling CMake for the first time, all needed compiler options must be
16 specified on the command line. After this initial call to CMake, the compiler
17 definitions must not be included for further calls to CMake. Other options
18 can be specified on the command line multiple times including all definitions
19 in the build options section below.
20 - Example of configuring, building, reconfiguring, rebuilding:
22 .. code-block:: console
26 $ cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ .. # Initial configuration
30 $ cmake -DCMAKE_BUILD_TYPE=Debug .. # Second configuration
34 $ cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ .. # Third configuration
37 - Notice in the example how the compiler definitions are only specified for an
38 empty build directory, but other build options are used at any time.
39 - The file ``CMakeCache.txt`` which is created after the first call to CMake is
40 a configuration file which holds all values for the build options. These
41 values can be changed using a text editor to modify ``CMakeCache.txt`` as
42 opposed to using definitions on the command line.
43 - To have CMake create a particular type of build generator file simply include
44 the ``-G <Generator name>`` option:
46 .. code-block:: console
48 $ cmake -G "Unix Makefiles" ...
50 You can see a list of generators CMake supports by executing the cmake command
55 .. code-block:: console
57 $ cd openmp_top_level/ [ this directory with libomptarget/, runtime/, etc. ]
62 $ cmake -DCMAKE_C_COMPILER=<C Compiler> -DCMAKE_CXX_COMPILER=<C++ Compiler> ..
64 [ Windows* Libraries ]
65 $ cmake -G <Generator Type> -DCMAKE_C_COMPILER=<C Compiler> -DCMAKE_CXX_COMPILER=<C++ Compiler> -DCMAKE_ASM_MASM_COMPILER=[ml | ml64] -DCMAKE_BUILD_TYPE=Release ..
72 Builds with CMake can be customized by means of options as already seen above.
73 One possibility is to pass them via the command line:
75 .. code-block:: console
77 $ cmake -DOPTION=<value> path/to/source
79 .. note:: The first value listed is the respective default for that option.
83 For full documentation consult the CMake manual or execute
84 ``cmake --help-variable VARIABLE_NAME`` to get information about a specific
87 **CMAKE_BUILD_TYPE** = ``Release|Debug|RelWithDebInfo``
88 Build type can be ``Release``, ``Debug``, or ``RelWithDebInfo`` which chooses
89 the optimization level and presence of debugging symbols.
91 **CMAKE_C_COMPILER** = <C compiler name>
92 Specify the C compiler.
94 **CMAKE_CXX_COMPILER** = <C++ compiler name>
95 Specify the C++ compiler.
97 **CMAKE_Fortran_COMPILER** = <Fortran compiler name>
98 Specify the Fortran compiler. This option is only needed when
99 **LIBOMP_FORTRAN_MODULES** is ``ON`` (see below). So typically, a Fortran
100 compiler is not needed during the build.
102 **CMAKE_ASM_MASM_COMPILER** = ``ml|ml64``
103 This option is only relevant for Windows*.
105 Options for all Libraries
106 -------------------------
108 **OPENMP_ENABLE_WERROR** = ``OFF|ON``
109 Treat warnings as errors and fail, if a compiler warning is triggered.
111 **OPENMP_LIBDIR_SUFFIX** = ``""``
112 Extra suffix to append to the directory where libraries are to be installed.
114 **OPENMP_TEST_C_COMPILER** = ``${CMAKE_C_COMPILER}``
115 Compiler to use for testing. Defaults to the compiler that was also used for
118 **OPENMP_TEST_CXX_COMPILER** = ``${CMAKE_CXX_COMPILER}``
119 Compiler to use for testing. Defaults to the compiler that was also used for
122 **OPENMP_LLVM_TOOLS_DIR** = ``/path/to/built/llvm/tools``
123 Additional path to search for LLVM tools needed by tests.
125 **OPENMP_LLVM_LIT_EXECUTABLE** = ``/path/to/llvm-lit``
126 Specify full path to ``llvm-lit`` executable for running tests. The default
127 is to search the ``PATH`` and the directory in **OPENMP_LLVM_TOOLS_DIR**.
129 **OPENMP_FILECHECK_EXECUTABLE** = ``/path/to/FileCheck``
130 Specify full path to ``FileCheck`` executable for running tests. The default
131 is to search the ``PATH`` and the directory in **OPENMP_LLVM_TOOLS_DIR**.
133 **OPENMP_NOT_EXECUTABLE** = ``/path/to/not``
134 Specify full path to ``not`` executable for running tests. The default
135 is to search the ``PATH`` and the directory in **OPENMP_LLVM_TOOLS_DIR**.
137 Options for ``libomp``
138 ----------------------
140 **LIBOMP_ARCH** = ``aarch64|arm|i386|loongarch64|mic|mips|mips64|ppc64|ppc64le|x86_64|riscv64``
141 The default value for this option is chosen based on probing the compiler for
142 architecture macros (e.g., is ``__x86_64__`` predefined by compiler?).
144 **LIBOMP_MIC_ARCH** = ``knc|knf``
145 Intel(R) Many Integrated Core Architecture (Intel(R) MIC Architecture) to
146 build for. This value is ignored if **LIBOMP_ARCH** does not equal ``mic``.
148 **LIBOMP_LIB_TYPE** = ``normal|profile|stubs``
149 Library type can be ``normal``, ``profile``, or ``stubs``.
151 **LIBOMP_USE_VERSION_SYMBOLS** = ``ON|OFF``
152 Use versioned symbols for building the library. This option only makes sense
153 for ELF based libraries where version symbols are supported (Linux*, some BSD*
154 variants). It is ``OFF`` by default for Windows* and macOS*, but ``ON`` for
155 other Unix based operating systems.
157 **LIBOMP_ENABLE_SHARED** = ``ON|OFF``
158 Build a shared library. If this option is ``OFF``, static OpenMP libraries
159 will be built instead of dynamic ones.
163 Static libraries are not supported on Windows*.
165 **LIBOMP_FORTRAN_MODULES** = ``OFF|ON``
166 Create the Fortran modules (requires Fortran compiler).
170 If libomptarget is built in-tree with both flang and openmp in
171 `LLVM_ENABLE_PROJECTS`, flang will be used for Fortran offloading
176 On macOS* machines, it is possible to build universal (or fat) libraries which
177 include both i386 and x86_64 architecture objects in a single archive.
179 .. code-block:: console
181 $ cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_OSX_ARCHITECTURES='i386;x86_64' ..
184 There is also an option **LIBOMP_OSX_ARCHITECTURES** which can be set in case
185 this is an LLVM source tree build. It will only apply for the ``libomp`` library
186 avoids having the entire LLVM/Clang build produce universal binaries.
191 **LIBOMP_USE_ADAPTIVE_LOCKS** = ``ON|OFF``
192 Include adaptive locks, based on Intel(R) Transactional Synchronization
193 Extensions (Intel(R) TSX). This feature is x86 specific and turned ``ON``
194 by default for IA-32 architecture and Intel(R) 64 architecture.
196 **LIBOMP_USE_INTERNODE_ALIGNMENT** = ``OFF|ON``
197 Align certain data structures on 4096-byte. This option is useful on
198 multi-node systems where a small ``CACHE_LINE`` setting leads to false sharing.
200 **LIBOMP_OMPT_SUPPORT** = ``ON|OFF``
201 Include support for the OpenMP Tools Interface (OMPT).
202 This option is supported and ``ON`` by default for x86, x86_64, AArch64,
203 PPC64, RISCV64 and LoongArch64 on Linux* and macOS*.
204 This option is ``OFF`` if this feature is not supported for the platform.
206 **LIBOMP_OMPT_OPTIONAL** = ``ON|OFF``
207 Include support for optional OMPT functionality. This option is ignored if
208 **LIBOMP_OMPT_SUPPORT** is ``OFF``.
210 **LIBOMP_STATS** = ``OFF|ON``
211 Include stats-gathering code.
213 **LIBOMP_USE_DEBUGGER** = ``OFF|ON``
214 Include the friendly debugger interface.
216 **LIBOMP_USE_HWLOC** = ``OFF|ON``
217 Use `OpenMPI's hwloc library <https://www.open-mpi.org/projects/hwloc/>`_ for
218 topology detection and affinity.
220 **LIBOMP_HWLOC_INSTALL_DIR** = ``/path/to/hwloc/install/dir``
221 Specify install location of hwloc. The configuration system will look for
222 ``hwloc.h`` in ``${LIBOMP_HWLOC_INSTALL_DIR}/include`` and the library in
223 ``${LIBOMP_HWLOC_INSTALL_DIR}/lib``. The default is ``/usr/local``.
224 This option is only used if **LIBOMP_USE_HWLOC** is ``ON``.
226 Additional Compiler Flags
227 """""""""""""""""""""""""
229 These flags are **appended**, they do not overwrite any of the preset flags.
231 **LIBOMP_CPPFLAGS** = <space-separated flags>
232 Additional C preprocessor flags.
234 **LIBOMP_CXXFLAGS** = <space-separated flags>
235 Additional C++ compiler flags.
237 **LIBOMP_ASMFLAGS** = <space-separated flags>
238 Additional assembler flags.
240 **LIBOMP_LDFLAGS** = <space-separated flags>
241 Additional linker flags.
243 **LIBOMP_LIBFLAGS** = <space-separated flags>
244 Additional libraries to link.
246 **LIBOMP_FFLAGS** = <space-separated flags>
247 Additional Fortran compiler flags.
249 Options for ``libomptarget``
250 ----------------------------
252 An installed LLVM package is a prerequisite for building ``libomptarget``
253 library. So ``libomptarget`` may only be built in two cases:
255 - As a project of a regular LLVM build via **LLVM_ENABLE_PROJECTS**,
256 **LLVM_EXTERNAL_PROJECTS**, or **LLVM_ENABLE_RUNTIMES** or
257 - as a standalone project build that uses a pre-installed LLVM package.
258 In this mode one has to make sure that the default CMake
259 ``find_package(LLVM)`` call `succeeds <https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure>`_.
261 **LIBOMPTARGET_OPENMP_HEADER_FOLDER** = ``""``
262 Path of the folder that contains ``omp.h``. This is required for testing
265 **LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER** = ``""``
266 Path of the folder that contains ``libomp.so``, and ``libLLVMSupport.so``
267 when profiling is enabled. This is required for testing.
269 Options for ``NVPTX device RTL``
270 --------------------------------
272 **LIBOMPTARGET_NVPTX_ENABLE_BCLIB** = ``ON|OFF``
273 Enable CUDA LLVM bitcode offloading device RTL. This is used for link time
274 optimization of the OMP runtime and application code. This option is enabled
275 by default if the build system determines that `CMAKE_C_COMPILER` is able to
276 compile and link the library.
278 **LIBOMPTARGET_NVPTX_CUDA_COMPILER** = ``""``
279 Location of a CUDA compiler capable of emitting LLVM bitcode. Currently only
280 the Clang compiler is supported. This is only used when building the CUDA LLVM
281 bitcode offloading device RTL. If unspecified, either the Clang from the build
282 itself is used (i.e. an in-tree build with LLVM_ENABLE_PROJECTS including
283 clang), or the Clang compiler that the build uses as C compiler
284 (CMAKE_C_COMPILER; only if it is Clang). The latter is common for a
285 stage2-build or when using -DLLVM_ENABLE_RUNTIMES=openmp.
287 **LIBOMPTARGET_NVPTX_BC_LINKER** = ``""``
288 Location of a linker capable of linking LLVM bitcode objects. This is only
289 used when building the CUDA LLVM bitcode offloading device RTL. If
290 unspecified, either the llvm-link in that same directory as
291 LIBOMPTARGET_NVPTX_CUDA_COMPILER is used, or the llvm-link from the
292 same build (available in an in-tree build).
294 **LIBOMPTARGET_NVPTX_ALTERNATE_HOST_COMPILER** = ``""``
295 Host compiler to use with NVCC. This compiler is not going to be used to
296 produce any binary. Instead, this is used to overcome the input compiler
297 checks done by NVCC. E.g. if using a default host compiler that is not
298 compatible with NVCC, this option can be use to pass to NVCC a valid compiler
301 **LIBOMPTARGET_NVPTX_COMPUTE_CAPABILITIES** = ``35``
302 List of CUDA compute capabilities that should be supported by the NVPTX
303 device RTL. E.g. for compute capabilities 6.0 and 7.0, the option "60;70"
304 should be used. Compute capability 3.5 is the minimum required.
306 **LIBOMPTARGET_NVPTX_DEBUG** = ``OFF|ON``
307 Enable printing of debug messages from the NVPTX device RTL.
309 **LIBOMPTARGET_LIT_ARGS** = ``""``
310 Arguments given to lit. ``make check-libomptarget`` and
311 ``make check-libomptarget-*`` are affected. For example, use
312 ``LIBOMPTARGET_LIT_ARGS="-j4"`` to force ``lit`` to start only four parallel
313 jobs instead of by default the number of threads in the system.
315 Example Usages of CMake
316 =======================
321 .. code-block:: console
323 $ cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ..
324 $ cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ ..
325 $ cmake -DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icpc ..
327 Advanced Builds with Various Options
328 ------------------------------------
330 - Build the i386 Linux* library using GCC*
332 .. code-block:: console
334 $ cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DLIBOMP_ARCH=i386 ..
336 - Build the x86_64 debug Mac library using Clang*
338 .. code-block:: console
340 $ cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLIBOMP_ARCH=x86_64 -DCMAKE_BUILD_TYPE=Debug ..
342 - Build the library (architecture determined by probing compiler) using the
343 Intel(R) C Compiler and the Intel(R) C++ Compiler. Also, create Fortran
344 modules with the Intel(R) Fortran Compiler.
346 .. code-block:: console
348 $ cmake -DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icpc -DCMAKE_Fortran_COMPILER=ifort -DLIBOMP_FORTRAN_MODULES=on ..
350 - Have CMake find the C/C++ compiler and specify additional flags for the
351 preprocessor and C++ compiler.
353 .. code-blocks:: console
355 $ cmake -DLIBOMP_CPPFLAGS='-DNEW_FEATURE=1 -DOLD_FEATURE=0' -DLIBOMP_CXXFLAGS='--one-specific-flag --two-specific-flag' ..
357 - Build the stubs library
359 .. code-blocks:: console
361 $ cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DLIBOMP_LIB_TYPE=stubs ..
365 .. [*] Other names and brands may be claimed as the property of others.
370 There are following check-* make targets for tests.
372 - ``check-ompt`` (ompt tests under runtime/test/ompt)
373 - ``check-ompt-multiplex`` (ompt multiplex tests under tools/multiplex/tests)
374 - ``check-libarcher`` (libarcher tests under tools/archer/tests)
375 - ``check-libomp`` (libomp tests under runtime/test. This includes check-ompt tests too)
376 - ``check-libomptarget-*`` (libomptarget tests for specific target under libomptarget/test)
377 - ``check-libomptarget`` (all check-libomptarget-* tests)
378 - ``check-openmp`` (combination of all above tests excluding duplicates)
380 For example, to run all available tests, use ``make check-openmp``.
384 Tests use lit framework.
385 See `lit documentation <https://llvm.org/docs/CommandGuide/lit.html>`_ for lit options.
387 **CHECK_OPENMP_ENV** = ``""``
388 Default environment variables which test process uses for ``check-openmp``
389 separated by space. This can be used for individual targets (``check-ompt``,
390 ``check-ompt-multiplex``, ``check-libarcher``, ``check-libomp`` and
391 ``check-libomptarget-*``) too. Note that each test still overrides
392 environment variables if needed. For example, to change barrier pattern to be
393 used from default hyper barrier to hierarchical barrier, run:
395 .. code-block:: console
397 $ CHECK_OPENMP_ENV="KMP_PLAIN_BARRIER_PATTERN=hier,hier KMP_FORKJOIN_BARRIER_PATTERN=hier,hier KMP_REDUCTION_BARRIER_PATTERN=hier,hier" make check-openmp