Skip to content

Instantly share code, notes, and snippets.

@mikesart
Created August 7, 2019 03:24
Show Gist options
  • Save mikesart/7583dc1c350ec75e6aa0eff01bf62dbb to your computer and use it in GitHub Desktop.
Save mikesart/7583dc1c350ec75e6aa0eff01bf62dbb to your computer and use it in GitHub Desktop.
Build UE4 LIbCxx
#!/bin/bash
set -eu
SCRIPT_DIR=$(cd "$(dirname "$BASH_SOURCE")" ; pwd)
LLVM_DIR=${1:---help}
if [[ "${LLVM_DIR}" == "--help" ]] || [[ ! -f "${LLVM_DIR}/llvm/CMakeLists.txt" ]]; then
echo "Usage: ${BASH_SOURCE} llvm-git-repo"
echo " llvm-git-repo is https://github.com/llvm/llvm-project.git"
exit 2
fi
# Get num of cores
export CORES=$(getconf _NPROCESSORS_ONLN)
echo "Using ${CORES} cores for building"
echo "LLVM_DIR: ${LLVM_DIR}"
BuildLibCxx()
{
export ARCH=$1
local BUILD_DIR=${SCRIPT_DIR}/Build.${ARCH}
export INSTALL_DIR=${SCRIPT_DIR}/INSTALL.${ARCH}
echo "Building ${ARCH}"
rm -rf ${BUILD_DIR}
mkdir -p ${BUILD_DIR}
pushd ${BUILD_DIR}
set -x
cmake \
-DCMAKE_TOOLCHAIN_FILE="/tmp/__cmake_toolchain.cmake" \
-DCMAKE_MAKE_PROGRAM=$(which make) \
-DPYTHON_EXECUTABLE=$(which python) \
-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \
-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=TRUE \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" \
-DLIBCXX_ENABLE_SHARED=OFF \
-DLIBCXXABI_ENABLE_SHARED=ON \
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON \
-DLIBCXX_CXX_ABI_LIBRARY=c++abi \
-DLIBCXX_ENABLE_FILESYSTEM=OFF \
${LLVM_DIR}/llvm
set +x
make -j ${CORES} cxxabi cxx
make install-libcxx-headers
mkdir -p ${INSTALL_DIR}/lib/Linux/${ARCH}
cp lib/libc++.a ${INSTALL_DIR}/lib/Linux/${ARCH}
cp lib/libc++abi.a ${INSTALL_DIR}/lib/Linux/${ARCH}
popd
}
( cat <<_EOF_
## autogenerated by ${BASH_SOURCE} script
SET(LINUX_MULTIARCH_ROOT \$ENV{LINUX_MULTIARCH_ROOT})
SET(ARCHITECTURE_TRIPLE \$ENV{ARCH})
message (STATUS "LINUX_MULTIARCH_ROOT is '\${LINUX_MULTIARCH_ROOT}'")
message (STATUS "ARCHITECTURE_TRIPLE is '\${ARCHITECTURE_TRIPLE}'")
SET(CMAKE_CROSSCOMPILING TRUE)
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
# sysroot
SET(CMAKE_SYSROOT \${LINUX_MULTIARCH_ROOT}/\${ARCHITECTURE_TRIPLE})
SET(CMAKE_LIBRARY_ARCHITECTURE \${ARCHITECTURE_TRIPLE})
# specify the cross compiler
SET(CMAKE_C_COMPILER \${CMAKE_SYSROOT}/bin/clang)
SET(CMAKE_C_COMPILER_TARGET \${ARCHITECTURE_TRIPLE})
SET(CMAKE_C_FLAGS "-target \${ARCHITECTURE_TRIPLE}")
SET(CMAKE_CXX_COMPILER \${CMAKE_SYSROOT}/bin/clang++)
SET(CMAKE_CXX_COMPILER_TARGET \${ARCHITECTURE_TRIPLE})
SET(CMAKE_CXX_FLAGS "-target \${ARCHITECTURE_TRIPLE}")
SET(CMAKE_ASM_COMPILER \${CMAKE_SYSROOT}/bin/clang)
SET(CMAKE_FIND_ROOT_PATH \${LINUX_MULTIARCH_ROOT})
# hoping to force it to use ar
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
_EOF_
) > /tmp/__cmake_toolchain.cmake
BuildLibCxx x86_64-unknown-linux-gnu
BuildLibCxx aarch64-unknown-linux-gnueabi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment