[llvm-dev] Setting clang-cpp explicitly when building LLVM/Clang

Sedat Dilek via llvm-dev llvm-dev at lists.llvm.org
Tue Aug 14 01:56:06 PDT 2018


Hi,

can you explain the meaning and setting of cpp?

I know I can explicitly set "-DCMAKE_C_COMPILER=..." and
"-DCMAKE_CXX_COMPILER=...".
I have not found a setting to do so for cpp.

$ cd build/ ; cmake ../llvm -LA | egrep -i cpp

Background is I had a typo in CMAKE_OPTS variable and CC and CXX
compilers were not set and played with Debian's way to set
alternatives for cc, c++ and cpp.

Thanks in advance.

Regards,
- Sedat -

P.S.: My current build-script.

[ build_clang-with-ninja.sh ]

#!/bin/sh

# HELP-1: <http://prereleases.llvm.org/7.0.0/#rc1>
# HELP-2: <https://stackoverflow.com/questions/7832892/how-to-change-the-default-gcc-compiler-in-ubuntu/28126262#28126262

export LANG=C
export LC_ALL=C

PKG_NAME="llvm-toolchain"
VER="7.0.0"
PKG_VER="${VER}"
##RC="rc1"
##PKG_VER="${VER}${RC}"

WORKING_DIR=$(pwd)
BUILD_DIR="$WORKING_DIR/build"

PREFIX="/opt/${PKG_NAME}-${PKG_VER}"

# CMake binary (here: v3.11.2)
CMAKE="cmake"

# CMake generator options (here: Ninja v1.8.2)
NINJA="ninja"
CMAKE_GENERATORS="Ninja"
GENERATORS_CMAKE_OPTS="-G $CMAKE_GENERATORS"

# XXX: Workaround: Use Debian's update-alternatives to set cc, c++ and cpp
# XXX: Use lower priority of 10 (default: 20 for existing alternatives)
# Check set alternatives
##for i in cc c++ cpp ; do echo [ $i ] ; $i --version ; done
# Reset to Debian's default alternatives
##for i in cc c++ cpp ; do update-alternatives --auto $i ; done
# XXX: PREREQ: Install new alternatives
# sudo update-alternatives --install /usr/bin/cc  cc  /usr/bin/clang-6.0     10
# sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-6.0   10
# sudo update-alternatives --install /usr/bin/cpp cpp /usr/bin/clang-cpp-6.0 10
##sudo update-alternatives --set cc  /usr/bin/clang-6.0
##sudo update-alternatives --set c++ /usr/bin/clang++-6.0
##sudo update-alternatives --set cpp /usr/bin/clang-cpp-6.0
##COMPILER_CC="cc"
##COMPILER_CXX="c++"

# CMake compiler options (here: Clang v6.0)
COMPILER_VER="6.0"
COMPILER_CC="clang-$COMPILER_VER"
COMPILER_CXX="clang++-$COMPILER_VER"
COMPILER_CMAKE_OPTS="-DCMAKE_C_COMPILER=$COMPILER_CC
-DCMAKE_CXX_COMPILER=$COMPILER_CXX"

# CMake parallel compile (default: 2) and link (default: 1) options
##MAX_JOBS=$(($(getconf _NPROCESSORS_ONLN)+1))
##COMPILE_JOBS="$MAX_JOBS"
COMPILE_JOBS="2"
LINK_JOBS="1"
JOBS_CMAKE_OPTS="-DLLVM_PARALLEL_COMPILE_JOBS=$COMPILE_JOBS
-DLLVM_PARALLEL_LINK_JOBS=$LINK_JOBS"

# CMake configure options
PREFIX_CMAKE_OPTS="-DCMAKE_INSTALL_PREFIX=$PREFIX"
BUILDTYPE_CMAKE_OPTS="-DCMAKE_BUILD_TYPE=RELEASE"
ASSERTIONS_CMAKE_OPTS="-DLLVM_ENABLE_ASSERTIONS=ON"
TARGETS_CMAKE_OPTS="-DLLVM_TARGETS_TO_BUILD=X86"
CONFIGURE_CMAKE_OPTS="$PREFIX_CMAKE_OPTS $BUILDTYPE_CMAKE_OPTS
$ASSERTIONS_CMAKE_OPTS $TARGETS_CMAKE_OPTS"

# CMake options
CMAKE_OPTS="$GENERATORS_CMAKE_OPTS $COMPILER_CMAKE_OPTS
$JOBS_CMAKE_OPTS $CONFIGURE_CMAKE_OPTS"
echo "CMAKE_OPTS... $CMAKE_OPTS"

[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR}
cd $BUILD_DIR

### CONFIGURE
$CMAKE ../llvm $CMAKE_OPTS

### BUILD
$CMAKE --build .

### CHECK-CLANG
$NINJA check-clang

### INSTALL
# XXX: Commented - Do this as a seperate and last step
##sudo $CMAKE --build . --target install
- EOF -


More information about the llvm-dev mailing list