llvm-capstone/libc/examples
Mark de Wever cbaa3597aa Reland "[CMake] Bumps minimum version to 3.20.0.
This reverts commit d763c6e5e2.

Adds the patch by @hans from
https://github.com/llvm/llvm-project/issues/62719
This patch fixes the Windows build.

d763c6e5e2 reverted the reviews

D144509 [CMake] Bumps minimum version to 3.20.0.

This partly undoes D137724.

This change has been discussed on discourse
https://discourse.llvm.org/t/rfc-upgrading-llvms-minimum-required-cmake-version/66193

Note this does not remove work-arounds for older CMake versions, that
will be done in followup patches.

D150532 [OpenMP] Compile assembly files as ASM, not C

Since CMake 3.20, CMake explicitly passes "-x c" (or equivalent)
when compiling a file which has been set as having the language
C. This behaviour change only takes place if "cmake_minimum_required"
is set to 3.20 or newer, or if the policy CMP0119 is set to new.

Attempting to compile assembly files with "-x c" fails, however
this is workarounded in many cases, as OpenMP overrides this with
"-x assembler-with-cpp", however this is only added for non-Windows
targets.

Thus, after increasing cmake_minimum_required to 3.20, this breaks
compiling the GNU assembly for Windows targets; the GNU assembly is
used for ARM and AArch64 Windows targets when building with Clang.
This patch unbreaks that.

D150688 [cmake] Set CMP0091 to fix Windows builds after the cmake_minimum_required bump

The build uses other mechanism to select the runtime.

Fixes #62719

Reviewed By: #libc, Mordante

Differential Revision: https://reviews.llvm.org/D151344
2023-05-27 12:51:21 +02:00
..
hello_world Reland "[CMake] Bumps minimum version to 3.20.0. 2023-05-27 12:51:21 +02:00
examples.cmake
README.md

Examples

This directory contains a few example programs which illustrate how one can set up their own projects to use LLVM's libc, either as an overlay or as the only libc in their projects. See the the usage mode document for more information about the different modes in which one can build and use the libc.

Building the Examples

Each example has its own directory which contain the source code and the CMake build set up. To build an example, create a directory named build in the example's directory:

cd <example directory>
mkdir build
cd build

Each example can be built to use the libc in either the overlay mode or the full build mode. The CMake configure step differs slightly depending on the mode you want to use the libc in.

Building against an overlay libc

Before you can link an example against the overlay libc, you will have to install it. See the documentation of the overlay mode to learn how to install the libc's overlay static archive named libllvmlibc.a. Once installed, to build an example against it, you have specify the directory in which the static archive is installed with the option LIBC_OVERLAY_ARCHIVE_DIR:

cmake ../ -G <GEN>  \
  -DLIBC_OVERLAY_ARCHIVE_DIR=<dir in which libc is installed>

Next, if Ninja is used for <GEN>, you can build the example as follows:

ninja <example name>

Building against a full libc

Before you can link an example against the full libc, you will have to first install it. See the documentation of the full build mode to learn how to install a full libc along with the other LLVM toolchain pieces like clang, lld and compiler-rt. The CMake build for the examples will assume that you have all of these components installed in a special sysroot (see decription of the --sysroot option here.) Once you have installed them, you have to inform CMake that we are linking against the full libc as follows:

cmake ../ -G <GEN> -DLIBC_FULLBUILD=ON    \
  -DCMAKE_SYSROOT=<SYSROOT>               \
  -DCMAKE_C_COMPILER=<SYSROOT>/bin/clang  \
  -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY

<SYSROOT> is the path to the sysroot directory you have set up while installing the full libc. The option -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY tells CMake to not attempt linking full executables against shared libraries. We have to use this as LLVM's libc does not yet have support for shared libraries and dynamic linking. After the above cmake command, assuming Ninja was used for <GEN>, you can build the example as follows:

ninja <example name>