From 991a5991743d2ea2188263a47672f1d5d71863b7 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Wed, 15 Jan 2025 18:03:36 +0000 Subject: [PATCH] Adapt build to CMake's CMP0167 policy This is a little awkward because libloot only needs Boost's headers, but it doesn't supply a CMake config unless it's built, so we build the system stub to make that happen as quickly as possible. Also take the opportunity to run ctest in CI. --- .github/workflows/ci.yml | 47 ++++++++++++++++++++-------------------- CMakeLists.txt | 6 +++-- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20afd034..46b6d4cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,14 +41,15 @@ jobs: LIBLOOT_SAFE_DESC_REF=${LIBLOOT_DESC_REF//[\/<>\"|]/_} echo "version=$LIBLOOT_SAFE_DESC_REF" >> $GITHUB_OUTPUT + # Need to build Boost's 'system' stub to generate the CMake config file. - name: Download Boost id: get-boost run: | - BOOST_BASENAME=boost_${BOOST_VERSION//./_} - wget https://archives.boost.io/release/${BOOST_VERSION}/source/${BOOST_BASENAME}.tar.gz - tar -xf ${BOOST_BASENAME}.tar.gz + curl -sSfLO https://raw.githubusercontent.com/Ortham/ci-scripts/2.2.1/install_boost.py - echo "root=${BOOST_BASENAME}" >> $GITHUB_OUTPUT + python install_boost.py --directory ${{ github.workspace }} --boost-version ${{ env.BOOST_VERSION }} -a 64 system + + echo "root=${{ github.workspace }}/boost_${BOOST_VERSION//./_}" >> $GITHUB_OUTPUT - name: Install APT package dependencies run: | @@ -63,16 +64,14 @@ jobs: - name: Run CMake run: | - mkdir build - cd build - cmake .. -DBOOST_ROOT="${{ steps.get-boost.outputs.root }}" -DCPACK_PACKAGE_VERSION="${{ steps.get-libloot-version.outputs.version }}" - make all + cmake \ + -DCMAKE_PREFIX_PATH="${{ steps.get-boost.outputs.root }}\stage" \ + -DCPACK_PACKAGE_VERSION="${{ steps.get-libloot-version.outputs.version }}" \ + -B build + cmake --build build - name: Run tests - run: | - cd build - ./libloot_internals_tests - ./libloot_tests + run: ctest --test-dir build - uses: actions/setup-python@v5 with: @@ -140,14 +139,17 @@ jobs: - name: Install Rust i686-pc-windows-msvc target run: rustup target add i686-pc-windows-msvc + # Need to build Boost's 'system' stub to generate the CMake config file. - name: Download Boost id: get-boost run: | + curl -sSfLO https://raw.githubusercontent.com/Ortham/ci-scripts/2.2.1/install_boost.py + + python install_boost.py --directory ${{ github.workspace }} --boost-version ${{ env.BOOST_VERSION }} -a 64 system + $BOOST_BASENAME="boost_" + $env:BOOST_VERSION -replace "\.", "_" - curl -sSfLO "https://archives.boost.io/release/${env:BOOST_VERSION}/source/${BOOST_BASENAME}.7z" - 7z x "${BOOST_BASENAME}.7z" - echo "root=$BOOST_BASENAME" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append + echo "root=${{ github.workspace }}/$BOOST_BASENAME" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append - name: Get descriptive libloot version id: get-libloot-version @@ -160,16 +162,15 @@ jobs: - name: Run CMake run: | - mkdir build - cd build - cmake .. -G "Visual Studio 16 2019" -A ${{ matrix.platform }} -DBOOST_ROOT="${{ steps.get-boost.outputs.root }}" -DCPACK_PACKAGE_VERSION="${{ steps.get-libloot-version.outputs.version }}" - cmake --build . --config ${{ env.MSVC_CONFIG }} + cmake -G "Visual Studio 16 2019" \ + -A ${{ matrix.platform }} \ + -DCMAKE_PREFIX_PATH="${{ steps.get-boost.outputs.root }}\stage" \ + -DCPACK_PACKAGE_VERSION="${{ steps.get-libloot-version.outputs.version }}" \ + -B build + cmake --build build --config ${{ env.MSVC_CONFIG }} - name: Run tests - run: | - cd build/${{ env.MSVC_CONFIG }} - .\libloot_internals_tests.exe - .\libloot_tests.exe + run: ctest --test-dir build --build-config ${{ env.MSVC_CONFIG }} - uses: actions/setup-python@v5 with: diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a3c4746..9e817f07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.24) if(POLICY CMP0135) cmake_policy(SET CMP0135 NEW) endif() +if(POLICY CMP0167) + cmake_policy(SET CMP0167 NEW) +endif() project(libloot) include(ExternalProject) include(FetchContent) @@ -46,6 +49,7 @@ configure_file("${CMAKE_SOURCE_DIR}/src/api/loot_version.cpp.in" "${CMAKE_BINARY set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) +find_package(Boost REQUIRED CONFIG) if(NOT DEFINED RUST_TARGET AND WIN32) if(MSVC) @@ -72,8 +76,6 @@ else() set(RUST_CLEANUP_COMMAND ${CMAKE_COMMAND} -E rm -r "target/release/build" "target/release/deps") endif() -find_package(Boost REQUIRED) - if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") find_package(ICU REQUIRED COMPONENTS data uc) find_package(TBB REQUIRED)