Skip to content

Commit

Permalink
Move to explicitly setting CMake toolchain file (#313)
Browse files Browse the repository at this point in the history
* Move to CMake toolchain file

* Stop specifying compilers in CMake presets
  • Loading branch information
tetsuo-cpp authored Dec 2, 2022
1 parent 0167037 commit cca037e
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- name: Build with CMake Presets
shell: bash
run: |
export VCPKG_ROOT=${GITHUB_WORKSPACE}/${VCPKG_ROOT_PART}
export CMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/${VCPKG_ROOT_PART}/scripts/buildsystems/vcpkg.cmake
export INSTALL_DIR=${GITHUB_WORKSPACE}/${INSTALL_DIR_PART}
scripts/build-preset.sh debug
env:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/diff_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- { name: 'ubuntu', tag: '20.04', codename: 'focal' }
llvm: [ '14' ]
common_base: [ 'https://github.com/lifting-bits/cxx-common/releases/latest/download' ]

env:
CC: clang-${{ matrix.llvm }}
CXX: clang++-${{ matrix.llvm }}
Expand Down Expand Up @@ -62,13 +62,13 @@ jobs:
- name: Build old rellic
shell: bash
run: |
cmake -G Ninja -S old -B rellic-build-old -DVCPKG_ROOT=$GITHUB_WORKSPACE/vcpkg_${{ matrix.image.name }}-${{ matrix.image.tag }}_llvm-${{ matrix.llvm }}_amd64
cmake -G Ninja -S old -B rellic-build-old -DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/vcpkg_${{ matrix.image.name }}-${{ matrix.image.tag }}_llvm-${{ matrix.llvm }}_amd64/scripts/buildsystems/vcpkg.cmake
cmake --build rellic-build-old
- name: Build new rellic
shell: bash
run: |
cmake -G Ninja -S . -B rellic-build -DVCPKG_ROOT=$GITHUB_WORKSPACE/vcpkg_${{ matrix.image.name }}-${{ matrix.image.tag }}_llvm-${{ matrix.llvm }}_amd64
cmake -G Ninja -S . -B rellic-build -DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/vcpkg_${{ matrix.image.name }}-${{ matrix.image.tag }}_llvm-${{ matrix.llvm }}_amd64/scripts/buildsystems/vcpkg.cmake
cmake --build rellic-build
- name: Print job summary
Expand Down
11 changes: 5 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
cmake_minimum_required(VERSION 3.21)

include("cmake/options.cmake")
include("cmake/vcpkg_helper.cmake")

project(rellic)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set (VISIBILITY_INLINES_HIDDEN YES)
include("cmake/settings.cmake")
include(GNUInstallDirs)
Expand Down Expand Up @@ -62,9 +61,9 @@ find_package(Clang CONFIG REQUIRED)

if(RELLIC_ENABLE_INSTALL)
export(PACKAGE "${PROJECT_NAME}")

set(cmake_install_dir "lib/cmake/${PROJECT_NAME}")

include(CMakePackageConfigHelpers)
configure_package_config_file("${PROJECT_NAME}Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
Expand Down Expand Up @@ -112,7 +111,7 @@ if (RELLIC_ENABLE_TESTING)

get_target_property(CLANG_PATH clang LOCATION)
message(STATUS "Clang path for tests: \"${CLANG_PATH}\"")

find_package(Python3 COMPONENTS Interpreter REQUIRED)
message(STATUS "Python path for tests: \"${Python3_EXECUTABLE}\"")

Expand Down
16 changes: 7 additions & 9 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@
"generator": "Ninja",
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "$env{VCPKG_TARGET_TRIPLET}",
"VCPKG_ROOT": "$env{VCPKG_ROOT}",
"CMAKE_TOOLCHAIN_FILE": "$env{CMAKE_TOOLCHAIN_FILE}",
"CMAKE_INSTALL_PREFIX": "$env{INSTALL_DIR}/install",
"CMAKE_C_COMPILER": "$env{VCPKG_ROOT}/installed/$env{VCPKG_TARGET_TRIPLET}/tools/llvm/clang",
"CMAKE_CXX_COMPILER": "$env{VCPKG_ROOT}/installed/$env{VCPKG_TARGET_TRIPLET}/tools/llvm/clang++",
"RELLIC_ENABLE_TESTING": "ON"
}
},
Expand All @@ -86,37 +84,37 @@
"name": "vcpkg-x64-dbg",
"inherits": ["vcpkg-debug", "x86_64"],
"displayName": "Debug Build (vcpkg) (x64)",
"description": "Build a Debug version against a VCPKG installation. Define 'VCPKG_ROOT', 'INSTALL_DIR', 'VCPKG_TARGET_TRIPLET' env vars!"
"description": "Build a Debug version against a VCPKG installation. Define 'CMAKE_TOOLCHAIN_FILE', 'INSTALL_DIR', 'VCPKG_TARGET_TRIPLET' env vars!"
},
{
"name": "vcpkg-x64-rel",
"inherits": ["vcpkg-release", "x86_64"],
"displayName": "Release Build (vcpkg) (x64)",
"description": "Build a Release version against a VCPKG installation. Define 'VCPKG_ROOT', 'INSTALL_DIR', 'VCPKG_TARGET_TRIPLET' env vars!"
"description": "Build a Release version against a VCPKG installation. Define 'CMAKE_TOOLCHAIN_FILE', 'INSTALL_DIR', 'VCPKG_TARGET_TRIPLET' env vars!"
},
{
"name": "vcpkg-x64-asan",
"inherits": ["vcpkg-asan", "x86_64"],
"displayName": "Debug ASAN Build (vcpkg) (x64)",
"description": "Build a Debug ASAN version against a VCPKG installation. Define 'VCPKG_ROOT', 'INSTALL_DIR', 'VCPKG_TARGET_TRIPLET' env vars!"
"description": "Build a Debug ASAN version against a VCPKG installation. Define 'CMAKE_TOOLCHAIN_FILE', 'INSTALL_DIR', 'VCPKG_TARGET_TRIPLET' env vars!"
},
{
"name": "vcpkg-arm64-dbg",
"inherits": ["vcpkg-debug", "arm64"],
"displayName": "Debug Build (vcpkg) (arm64)",
"description": "Build a Debug version against a VCPKG installation. Define 'VCPKG_ROOT', 'INSTALL_DIR', 'VCPKG_TARGET_TRIPLET' env vars!"
"description": "Build a Debug version against a VCPKG installation. Define 'CMAKE_TOOLCHAIN_FILE', 'INSTALL_DIR', 'VCPKG_TARGET_TRIPLET' env vars!"
},
{
"name": "vcpkg-arm64-rel",
"inherits": ["vcpkg-release", "arm64"],
"displayName": "Release Build (vcpkg) (arm64)",
"description": "Build a Release version against a VCPKG installation. Define 'VCPKG_ROOT', 'INSTALL_DIR', 'VCPKG_TARGET_TRIPLET' env vars!"
"description": "Build a Release version against a VCPKG installation. Define 'CMAKE_TOOLCHAIN_FILE', 'INSTALL_DIR', 'VCPKG_TARGET_TRIPLET' env vars!"
},
{
"name": "vcpkg-arm64-asan",
"inherits": ["vcpkg-asan", "arm64"],
"displayName": "Debug ASAN Build (vcpkg) (arm64)",
"description": "Build a Debug ASAN version against a VCPKG installation. Define 'VCPKG_ROOT', 'INSTALL_DIR', 'VCPKG_TARGET_TRIPLET' env vars!"
"description": "Build a Debug ASAN version against a VCPKG installation. Define 'CMAKE_TOOLCHAIN_FILE', 'INSTALL_DIR', 'VCPKG_TARGET_TRIPLET' env vars!"
}
],
"buildPresets": [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Make sure to have the latest release of cxx-common for LLVM 14. Then, build with
```shell
cmake \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DVCPKG_ROOT=/path/to/vcpkg \
-DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake \
-DVCPKG_TARGET_TRIPLET=x64-osx-rel \
-DRELLIC_ENABLE_TESTING=OFF \
-DCMAKE_C_COMPILER=`which clang` \
Expand Down
57 changes: 0 additions & 57 deletions cmake/vcpkg_helper.cmake

This file was deleted.

22 changes: 4 additions & 18 deletions scripts/build-preset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ VCPKG_SUFFIX="-rel"
set -o pipefail

function sanity_check {
if [ -z "${VCPKG_ROOT}" ]; then
echo "Please set the VCPKG_ROOT environment variable to the VCPKG root to build against"
if [ -z "${CMAKE_TOOLCHAIN_FILE}" ]; then
echo "Please set the CMAKE_TOOLCHAIN_FILE environment variable to the CMake toolchain file to build against"
exit 1
else
echo "Building against VCPKG: [${VCPKG_ROOT}]"
echo "Building against CMake toolchain file: [${CMAKE_TOOLCHAIN_FILE}]"
fi

if [ -z "${INSTALL_DIR}" ]; then
Expand All @@ -36,22 +36,11 @@ function show_usage {
printf "\tArguments after '--' are passed to CMake during configuration (e.g. -DCMAKE_C_COMPILER=foo)\n"
printf "\n"
printf "INSTALL_DIR set to [${INSTALL_DIR}]\n"
printf "VCPKG_ROOT set to [${VCPKG_ROOT}]\n"
printf "CMAKE_TOOLCHAIN_FILE set to [${CMAKE_TOOLCHAIN_FILE}]\n"

return 0
}

function compiler_check {
printf "Checking for clang/clang++ in [${VCPKG_ROOT}] [${VCPKG_TARGET_TRIPLET}]:\n"
for c in ${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/tools/llvm/{clang,clang++}
do
ver=$(${c} --version)
printf "Found a clang [${c}]:\n"
printf "${ver}\n"
done
printf "\n"
}

function set_arch {
local arch=$(uname -m)
case ${arch} in
Expand Down Expand Up @@ -135,9 +124,6 @@ ARCH=$(set_arch)
OS=$(set_os)
export VCPKG_TARGET_TRIPLET=${ARCH}-${OS}${VCPKG_SUFFIX}

compiler_check


echo "Configuring [${BUILD_TYPE}] [${ARCH}] against vcpkg [${VCPKG_TARGET_TRIPLET}]..."
if [[ "${@}" != "" ]]
then
Expand Down
16 changes: 12 additions & 4 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CURR_DIR=$( pwd )
BUILD_DIR="${CURR_DIR}/rellic-build"
INSTALL_DIR=/usr/local
LLVM_VERSION=llvm-14
CXX_COMMON_VERSION=v0.2.10
CXX_COMMON_VERSION=v0.2.16
OS_VERSION=unknown
ARCH_VERSION=unknown
BUILD_FLAGS=
Expand Down Expand Up @@ -84,8 +84,8 @@ function GetArchVersion
ARCH_VERSION=amd64
return 0
;;
aarch64)
ARCH_VERSION=aarch64
arm64 | aarch64)
ARCH_VERSION=arm64
return 0
;;
*)
Expand Down Expand Up @@ -204,12 +204,19 @@ function DownloadLibraries
return 1
fi

VCPKG_TARGET_ARCH="${ARCH_VERSION}"
if [[ "${VCPKG_TARGET_ARCH}" == "amd64" ]]; then
VCPKG_TARGET_ARCH="x64"
fi

if [[ "${OS_VERSION}" == "macos-"* ]]; then
# TODO Figure out Xcode compatibility
LIBRARY_VERSION="vcpkg_${OS_VERSION}_${LLVM_VERSION}_xcode-${XCODE_VERSION}_${ARCH_VERSION}"
VCPKG_TARGET_TRIPLET="${VCPKG_TARGET_ARCH}-osx-rel"
else
# TODO Arch version
LIBRARY_VERSION="vcpkg_${OS_VERSION}_${LLVM_VERSION}_${ARCH_VERSION}"
VCPKG_TARGET_TRIPLET="${VCPKG_TARGET_ARCH}-linux-rel"
fi

echo "[-] Library version is ${LIBRARY_VERSION}"
Expand All @@ -235,7 +242,8 @@ function Configure
-G Ninja \
-DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
-DCMAKE_VERBOSE_MAKEFILE=True \
-DVCPKG_ROOT="${DOWNLOAD_DIR}/${LIBRARY_VERSION}" \
-DCMAKE_TOOLCHAIN_FILE="${DOWNLOAD_DIR}/${LIBRARY_VERSION}/scripts/buildsystems/vcpkg.cmake" \
-DVCPKG_TARGET_TRIPLET="${VCPKG_TARGET_TRIPLET}" \
${BUILD_FLAGS} \
"${SRC_DIR}"
) || exit $?
Expand Down

0 comments on commit cca037e

Please sign in to comment.