Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions .github/ci/cmake-consumer-smoke-vcpkg.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
$ErrorActionPreference = "Stop"

function Assert-NativeCommandSucceeded {
param(
[int] $ExitCode,
[string] $Description
)
if ($ExitCode -ne 0) {
throw "$Description failed with exit code $ExitCode."
}
}

$prefix = $args[0]
if (-not $prefix) {
throw "usage: cmake-consumer-smoke-vcpkg.ps1 <install-prefix>"
Expand Down Expand Up @@ -111,10 +121,9 @@ cmake -S (Join-Path $work "a") -B (Join-Path $work "a\build") -G "Visual Studio
"-DVCPKG_INSTALLED_DIR=$consumerVcpkgInstalled" `
"-DVCPKG_TARGET_TRIPLET=x64-windows" `
"-DCMAKE_PREFIX_PATH=$prefix" 2>&1 | Tee-Object -FilePath (Join-Path $work "a\configure.log")
if ($LASTEXITCODE -ne 0) {
throw "consumer_a configure failed."
}
Assert-NativeCommandSucceeded $LASTEXITCODE "consumer_a configure"
cmake --build (Join-Path $work "a\build") --config $env:BUILD_TYPE
Assert-NativeCommandSucceeded $LASTEXITCODE "consumer_a build"

cmake -S (Join-Path $work "b") -B (Join-Path $work "b\build") -G "Visual Studio 17 2022" -A x64 `
"-DCMAKE_TOOLCHAIN_FILE=$toolchain" `
Expand All @@ -123,7 +132,9 @@ cmake -S (Join-Path $work "b") -B (Join-Path $work "b\build") -G "Visual Studio
"-DVCPKG_INSTALLED_DIR=$consumerVcpkgInstalled" `
"-DVCPKG_TARGET_TRIPLET=x64-windows" `
"-DCMAKE_PREFIX_PATH=$prefix"
Assert-NativeCommandSucceeded $LASTEXITCODE "consumer_b configure"
cmake --build (Join-Path $work "b\build") --config $env:BUILD_TYPE
Assert-NativeCommandSucceeded $LASTEXITCODE "consumer_b build"

cmake -S (Join-Path $work "c") -B (Join-Path $work "c\build") -G "Visual Studio 17 2022" -A x64 `
"-DCMAKE_TOOLCHAIN_FILE=$toolchain" `
Expand All @@ -132,7 +143,9 @@ cmake -S (Join-Path $work "c") -B (Join-Path $work "c\build") -G "Visual Studio
"-DVCPKG_INSTALLED_DIR=$consumerVcpkgInstalled" `
"-DVCPKG_TARGET_TRIPLET=x64-windows" `
"-DCMAKE_PREFIX_PATH=$prefix"
Assert-NativeCommandSucceeded $LASTEXITCODE "consumer_c configure"
cmake --build (Join-Path $work "c\build") --config $env:BUILD_TYPE
Assert-NativeCommandSucceeded $LASTEXITCODE "consumer_c build"

cmake -S (Join-Path $work "d") -B (Join-Path $work "d\build") -G "Visual Studio 17 2022" -A x64 `
"-DCMAKE_TOOLCHAIN_FILE=$toolchain" `
Expand All @@ -141,7 +154,9 @@ cmake -S (Join-Path $work "d") -B (Join-Path $work "d\build") -G "Visual Studio
"-DVCPKG_INSTALLED_DIR=$consumerVcpkgInstalled" `
"-DVCPKG_TARGET_TRIPLET=x64-windows" `
"-DCMAKE_PREFIX_PATH=$prefix"
Assert-NativeCommandSucceeded $LASTEXITCODE "consumer_d configure"
cmake --build (Join-Path $work "d\build") --config $env:BUILD_TYPE
Assert-NativeCommandSucceeded $LASTEXITCODE "consumer_d build"

if (-not (Select-String -Path (Join-Path $work "a\configure.log") -Pattern "Gecode_VERSION=" -Quiet)) {
throw "Gecode_VERSION was not reported during consumer configure."
Expand Down
58 changes: 57 additions & 1 deletion .github/ci/cmake-consumer-smoke.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
$ErrorActionPreference = "Stop"

function Assert-NativeCommandSucceeded {
param(
[int] $ExitCode,
[string] $Description
)
if ($ExitCode -ne 0) {
throw "$Description failed with exit code $ExitCode."
}
}

$prefix = $args[0]
if (-not $prefix) {
throw "usage: cmake-consumer-smoke.ps1 <install-prefix>"
}

$work = Join-Path $env:RUNNER_TEMP "gecode-consumers-win"
if (Test-Path $work) { Remove-Item -Recurse -Force $work }
New-Item -ItemType Directory -Force -Path (Join-Path $work "a"), (Join-Path $work "b"), (Join-Path $work "c") | Out-Null
New-Item -ItemType Directory -Force -Path `
(Join-Path $work "a"), `
(Join-Path $work "b"), `
(Join-Path $work "c"), `
(Join-Path $work "manual") | Out-Null

@'
cmake_minimum_required(VERSION 3.21)
Expand Down Expand Up @@ -52,14 +66,56 @@ int main(void) {
}
'@ | Set-Content -Encoding utf8 (Join-Path $work "c\main.cpp")

@'
cmake_minimum_required(VERSION 3.21)
project(manual_consumer LANGUAGES CXX)
set(GECODE_PREFIX "" CACHE PATH "Installed Gecode prefix")
find_path(GECODE_INCLUDE_DIR
NAMES gecode/support/config.hpp
PATHS "${GECODE_PREFIX}/include"
NO_DEFAULT_PATH
REQUIRED)
find_library(GECODE_SUPPORT_LIBRARY
NAMES gecodesupport
PATHS "${GECODE_PREFIX}/lib"
NO_DEFAULT_PATH
REQUIRED)
add_executable(manual_consumer main.cpp)
target_include_directories(manual_consumer PRIVATE "${GECODE_INCLUDE_DIR}")
target_link_libraries(manual_consumer PRIVATE "${GECODE_SUPPORT_LIBRARY}")
'@ | Set-Content -Encoding utf8 (Join-Path $work "manual\CMakeLists.txt")
@'
#include <gecode/support.hh>
#ifndef GECODE_NO_AUTOLINK
#error "CMake-installed headers must disable legacy MSVC auto-linking"
#endif
int main(void) {
(void) Gecode::Support::hwrnd();
return 0;
}
'@ | Set-Content -Encoding utf8 (Join-Path $work "manual\main.cpp")

cmake -S (Join-Path $work "a") -B (Join-Path $work "a\build") -G "Visual Studio 17 2022" -A x64 "-DCMAKE_PREFIX_PATH=$prefix" 2>&1 | Tee-Object -FilePath (Join-Path $work "a\configure.log")
Assert-NativeCommandSucceeded $LASTEXITCODE "consumer_a configure"
cmake --build (Join-Path $work "a\build") --config $env:BUILD_TYPE
Assert-NativeCommandSucceeded $LASTEXITCODE "consumer_a build"

cmake -S (Join-Path $work "b") -B (Join-Path $work "b\build") -G "Visual Studio 17 2022" -A x64 "-DCMAKE_PREFIX_PATH=$prefix"
Assert-NativeCommandSucceeded $LASTEXITCODE "consumer_b configure"
cmake --build (Join-Path $work "b\build") --config $env:BUILD_TYPE
Assert-NativeCommandSucceeded $LASTEXITCODE "consumer_b build"

cmake -S (Join-Path $work "c") -B (Join-Path $work "c\build") -G "Visual Studio 17 2022" -A x64 "-DCMAKE_PREFIX_PATH=$prefix"
Assert-NativeCommandSucceeded $LASTEXITCODE "consumer_c configure"
cmake --build (Join-Path $work "c\build") --config $env:BUILD_TYPE
Assert-NativeCommandSucceeded $LASTEXITCODE "consumer_c build"

# Exercise the installed headers and library without loading the CMake package
# or inheriting compile definitions from an exported target.
cmake -S (Join-Path $work "manual") -B (Join-Path $work "manual\build") -G "Visual Studio 17 2022" -A x64 "-DGECODE_PREFIX=$prefix"
Assert-NativeCommandSucceeded $LASTEXITCODE "manual_consumer configure"
cmake --build (Join-Path $work "manual\build") --config $env:BUILD_TYPE
Assert-NativeCommandSucceeded $LASTEXITCODE "manual_consumer build"

if (-not (Select-String -Path (Join-Path $work "a\configure.log") -Pattern "Gecode_VERSION=" -Quiet)) {
throw "Gecode_VERSION was not reported during consumer configure."
Expand Down
141 changes: 140 additions & 1 deletion .github/ci/cmake-consumer-smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ esac
work="$RUNNER_TEMP/gecode-consumers"
rm -rf "$work"
mkdir -p "$work/a" "$work/b" "$work/c" "$work/d/cmake" "$work/e/cmake" "$work/e/stale" \
"$work/f" "$work/g" "$work/h" "$work/i" "$work/j" "$work/k" \
"$work/mpfr-prefix/lib/cmake/MPFR"

cat > "$work/a/CMakeLists.txt" <<'EOF'
cmake_minimum_required(VERSION 3.21)
project(consumer_a LANGUAGES CXX)
find_package(Gecode CONFIG REQUIRED)
if(NOT Gecode_LIBRARIES STREQUAL "Gecode::gecode")
message(FATAL_ERROR "Expected aggregate Gecode_LIBRARIES, got: ${Gecode_LIBRARIES}")
endif()
message(STATUS "Gecode_VERSION=${Gecode_VERSION}")
message(STATUS "Gecode_INCLUDE_DIRS=${Gecode_INCLUDE_DIRS}")
set(EXPECTED_GECODE_INCLUDE_DIR "" CACHE PATH "Expected Gecode include directory")
Expand Down Expand Up @@ -58,6 +62,9 @@ cat > "$work/b/CMakeLists.txt" <<'EOF'
cmake_minimum_required(VERSION 3.21)
project(consumer_b LANGUAGES CXX)
find_package(Gecode CONFIG REQUIRED COMPONENTS driver)
if(NOT Gecode_LIBRARIES STREQUAL "Gecode::gecodedriver")
message(FATAL_ERROR "Expected driver-only Gecode_LIBRARIES, got: ${Gecode_LIBRARIES}")
endif()
add_executable(consumer_b main.cpp)
target_link_libraries(consumer_b PRIVATE Gecode::gecodedriver)
EOF
Expand All @@ -73,6 +80,9 @@ cat > "$work/c/CMakeLists.txt" <<'EOF'
cmake_minimum_required(VERSION 3.21)
project(consumer_c LANGUAGES CXX)
find_package(Gecode CONFIG REQUIRED COMPONENTS gecodedriver)
if(NOT Gecode_LIBRARIES STREQUAL "Gecode::gecodedriver")
message(FATAL_ERROR "Expected canonical library for legacy component, got: ${Gecode_LIBRARIES}")
endif()
add_executable(consumer_c main.cpp)
target_link_libraries(consumer_c PRIVATE Gecode::gecodedriver)
EOF
Expand All @@ -89,6 +99,9 @@ cmake_minimum_required(VERSION 3.21)
project(consumer_d LANGUAGES CXX)
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
find_package(Gecode CONFIG REQUIRED COMPONENTS float)
if(NOT Gecode_LIBRARIES STREQUAL "Gecode::gecodefloat")
message(FATAL_ERROR "Expected float-only Gecode_LIBRARIES, got: ${Gecode_LIBRARIES}")
endif()
if(NOT TARGET MPFR::MPFR)
message(FATAL_ERROR "Expected Gecode package to provide MPFR::MPFR")
endif()
Expand All @@ -103,7 +116,7 @@ if(NOT gecodefloat_links MATCHES "MPFR::MPFR")
message(FATAL_ERROR "Expected gecodefloat to link MPFR::MPFR, got: ${gecodefloat_links}")
endif()
add_executable(consumer_d main.cpp)
target_link_libraries(consumer_d PRIVATE Gecode::gecode)
target_link_libraries(consumer_d PRIVATE ${Gecode_LIBRARIES})
EOF
cat > "$work/d/main.cpp" <<'EOF'
#include <gecode/support/config.hpp>
Expand Down Expand Up @@ -155,6 +168,82 @@ set(MPFR_INCLUDE_DIRS "/bad/prior/mpfr/include")
set(MPFR_LIBRARIES "/bad/prior/mpfr/lib/libmpfr.a")
EOF

cat > "$work/f/CMakeLists.txt" <<'EOF'
cmake_minimum_required(VERSION 3.21)
project(consumer_f LANGUAGES CXX)
find_package(Gecode CONFIG REQUIRED COMPONENTS support)
if(NOT Gecode_LIBRARIES STREQUAL "Gecode::gecodesupport")
message(FATAL_ERROR "Expected support-only Gecode_LIBRARIES, got: ${Gecode_LIBRARIES}")
endif()
add_executable(consumer_f main.cpp)
target_link_libraries(consumer_f PRIVATE ${Gecode_LIBRARIES})
EOF
cat > "$work/f/main.cpp" <<'EOF'
#include <gecode/support.hh>
int main(void) { return Gecode::Support::Thread::npu() > 0 ? 0 : 1; }
EOF

cat > "$work/g/CMakeLists.txt" <<'EOF'
cmake_minimum_required(VERSION 3.21)
project(consumer_g LANGUAGES CXX)
find_package(Gecode CONFIG REQUIRED COMPONENTS gecodesupport)
if(NOT Gecode_LIBRARIES STREQUAL "Gecode::gecodesupport")
message(FATAL_ERROR "Expected canonical library for legacy component, got: ${Gecode_LIBRARIES}")
endif()
add_executable(consumer_g main.cpp)
target_link_libraries(consumer_g PRIVATE ${Gecode_LIBRARIES})
EOF
cat > "$work/g/main.cpp" <<'EOF'
#include <gecode/support.hh>
int main(void) { return 0; }
EOF

cat > "$work/h/CMakeLists.txt" <<'EOF'
cmake_minimum_required(VERSION 3.21)
project(consumer_h LANGUAGES CXX)
find_package(Gecode CONFIG REQUIRED COMPONENTS unknown_component)
EOF

cat > "$work/i/CMakeLists.txt" <<'EOF'
cmake_minimum_required(VERSION 3.21)
project(consumer_i LANGUAGES CXX)
find_package(Gecode CONFIG REQUIRED COMPONENTS float)
EOF

cat > "$work/j/CMakeLists.txt" <<'EOF'
cmake_minimum_required(VERSION 3.21)
project(consumer_j LANGUAGES CXX)
find_package(Gecode CONFIG REQUIRED COMPONENTS gist)
if(NOT Gecode_LIBRARIES STREQUAL "Gecode::gecodegist")
message(FATAL_ERROR "Expected gist-only Gecode_LIBRARIES, got: ${Gecode_LIBRARIES}")
endif()
add_executable(consumer_j main.cpp)
target_link_libraries(consumer_j PRIVATE ${Gecode_LIBRARIES})
EOF
cat > "$work/j/main.cpp" <<'EOF'
#include <gecode/gist.hh>
int main(void) { return 0; }
EOF

cat > "$work/k/CMakeLists.txt" <<'EOF'
cmake_minimum_required(VERSION 3.21)
project(consumer_k LANGUAGES CXX)
find_package(Gecode CONFIG REQUIRED COMPONENTS support)
find_package(Gecode CONFIG REQUIRED COMPONENTS float)
if(NOT TARGET MPFR::MPFR)
message(FATAL_ERROR "Expected the second component request to resolve MPFR")
endif()
if(NOT Gecode_LIBRARIES STREQUAL "Gecode::gecodefloat")
message(FATAL_ERROR "Expected the second request to replace Gecode_LIBRARIES, got: ${Gecode_LIBRARIES}")
endif()
add_executable(consumer_k main.cpp)
target_link_libraries(consumer_k PRIVATE ${Gecode_LIBRARIES})
EOF
cat > "$work/k/main.cpp" <<'EOF'
#include <gecode/float.hh>
int main(void) { Gecode::Float::Rounding rounding; return rounding.sqrt_down(4.0) == 2.0 ? 0 : 1; }
EOF

cat > "$work/mpfr-prefix/lib/cmake/MPFR/MPFRConfig.cmake" <<'EOF'
get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)
if(NOT TARGET MPFR::MPFR)
Expand Down Expand Up @@ -182,16 +271,66 @@ cmake --build "$work/b/build" -j4
cmake -S "$work/c" -B "$work/c/build" -DCMAKE_PREFIX_PATH="$prefix"
cmake --build "$work/c/build" -j4

# A support-only consumer must not discover dependencies belonging exclusively
# to Float, FlatZinc, or Gist, even when those targets exist in the package.
cmake -S "$work/f" -B "$work/f/build" \
-DCMAKE_PREFIX_PATH="$prefix" \
-DCMAKE_DISABLE_FIND_PACKAGE_MPFR=TRUE \
-DCMAKE_DISABLE_FIND_PACKAGE_Qt5=TRUE \
-DCMAKE_DISABLE_FIND_PACKAGE_Qt6=TRUE
cmake --build "$work/f/build" -j4

cmake -S "$work/g" -B "$work/g/build" \
-DCMAKE_PREFIX_PATH="$prefix" \
-DCMAKE_DISABLE_FIND_PACKAGE_MPFR=TRUE \
-DCMAKE_DISABLE_FIND_PACKAGE_Qt5=TRUE \
-DCMAKE_DISABLE_FIND_PACKAGE_Qt6=TRUE
cmake --build "$work/g/build" -j4

if cmake -S "$work/h" -B "$work/h/build" -DCMAKE_PREFIX_PATH="$prefix"; then
echo "Unknown required Gecode component unexpectedly succeeded" >&2
exit 1
fi

if [ "$mode" = "mpfr" ]; then
cmake -S "$work/d" -B "$work/d/build" -DCMAKE_PREFIX_PATH="$prefix"
cmake --build "$work/d/build" -j4

cmake -S "$work/e" -B "$work/e/build" -DCMAKE_PREFIX_PATH="$prefix"
cmake --build "$work/e/build" -j4

cmake -S "$work/k" -B "$work/k/build" -DCMAKE_PREFIX_PATH="$prefix"
cmake --build "$work/k/build" -j4

if cmake -S "$work/i" -B "$work/i/build" \
-DCMAKE_PREFIX_PATH="$prefix" \
-DCMAKE_DISABLE_FIND_PACKAGE_MPFR=TRUE; then
echo "Float component unexpectedly succeeded without MPFR" >&2
exit 1
fi
fi

targets_file="$(find "$prefix" -name GecodeTargets.cmake -print -quit)"
if grep -q 'add_library(Gecode::gecodegist ' "$targets_file"; then
if cmake -S "$work/j" -B "$work/j/no-qt-build" \
-DCMAKE_PREFIX_PATH="$prefix" \
-DCMAKE_DISABLE_FIND_PACKAGE_Qt5=TRUE \
-DCMAKE_DISABLE_FIND_PACKAGE_Qt6=TRUE; then
echo "Gist component unexpectedly succeeded without Qt" >&2
exit 1
fi
cmake -S "$work/j" -B "$work/j/build" -DCMAKE_PREFIX_PATH="$prefix"
cmake --build "$work/j/build" -j4
else
if cmake -S "$work/j" -B "$work/j/missing-build" -DCMAKE_PREFIX_PATH="$prefix"; then
echo "Missing required Gist component unexpectedly succeeded" >&2
exit 1
fi
fi

grep -q "Gecode_VERSION=" "$work/a/configure.log"
grep -q "Gecode_INCLUDE_DIRS=$expected_include" "$work/a/configure.log"
grep -q '^#define GECODE_NO_AUTOLINK 1$' "$expected_include/gecode/support/config.hpp"
if [ "$mode" = "mpfr" ]; then
grep -q '^#define GECODE_HAS_MPFR /\*\*/' "$expected_include/gecode/support/config.hpp"
fi
Expand Down
Loading
Loading