From 576eb5d0f7dd61f807b0142f96e9633779069913 Mon Sep 17 00:00:00 2001 From: Peter Spackman Date: Mon, 26 Aug 2024 09:47:33 +0800 Subject: [PATCH] Fix missing include in fraction.h, update CPM version, add windows build using mingw compilers --- .github/workflows/build_test.yml | 26 ++++++------ cmake/CPM.cmake | 23 ++++++----- include/occ/core/fraction.h | 1 + scripts/check_static.ps1 | 35 ++++++++++++++++ scripts/windows_build.ps1 | 69 ++++++++++++++++++++++++++++++++ tests/geometry_tests.cpp | 2 +- 6 files changed, 132 insertions(+), 24 deletions(-) create mode 100644 scripts/check_static.ps1 create mode 100644 scripts/windows_build.ps1 diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 03cf09dcc..0dc36a4b8 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -1,5 +1,4 @@ name: Build & Test - on: push: branches: ["main"] @@ -7,13 +6,10 @@ on: pull_request: branches: ["main"] tags: "v*" - env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release CPM_SOURCE_CACHE: ${{github.workspace}}/cache/cpm OCC_DATA_PATH: ${{github.workspace}}/share - jobs: build: strategy: @@ -39,11 +35,10 @@ jobs: architecture: x86_64 script: linux_static_build.sh name: "linux-x86_64-static" - - os: ubuntu-latest + - os: windows-latest architecture: x86_64 - script: dockcross-windows.sh + script: windows_build.ps1 name: "windows-x86_64" - runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -53,12 +48,14 @@ jobs: sudo apt update sudo apt install -y python3-numpy libpthread-stubs0-dev \ doxygen graphviz ninja-build - - name: Install Dependencies Mac if: startsWith(runner.os, 'macOS') run: | brew install ninja doxygen graphviz - + - name: Install Dependencies Windows + if: startsWith(runner.os, 'Windows') + run: | + choco install ninja -y - name: Cache CPM Dependencies uses: actions/cache@v4 with: @@ -66,12 +63,15 @@ jobs: ${{env.CPM_SOURCE_CACHE}} ${{github.workspace}}/build key: ${{ matrix.name }}-occ-build-cache - - name: Run build script + shell: pwsh run: | - rm -f build/*.xz - ./scripts/${{matrix.script}} "${{matrix.architecture}}" "${{matrix.name}}" - + Remove-Item -Path build/*.xz -ErrorAction SilentlyContinue + if ($env:RUNNER_OS -eq "Windows") { + ./scripts/${{matrix.script}} -Architecture "${{matrix.architecture}}" -Name "${{matrix.name}}" + } else { + ./scripts/${{matrix.script}} "${{matrix.architecture}}" "${{matrix.name}}" + } - name: Test if: matrix.name == 'linux-x86_64' working-directory: ${{github.workspace}}/build diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index 04f72bc5d..baf2d8c34 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -1,8 +1,11 @@ -set(CPM_DOWNLOAD_VERSION 0.38.6) +# SPDX-License-Identifier: MIT +# +# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors + +set(CPM_DOWNLOAD_VERSION 0.40.2) +set(CPM_HASH_SUM "c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d") if(CPM_SOURCE_CACHE) - # Expand relative path. This is important if the provided path contains a tilde (~) - get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE) set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") elseif(DEFINED ENV{CPM_SOURCE_CACHE}) set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") @@ -10,12 +13,12 @@ else() set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") endif() -if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION})) - message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}") - file(DOWNLOAD - https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake - ${CPM_DOWNLOAD_LOCATION} - ) -endif() +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} +) include(${CPM_DOWNLOAD_LOCATION}) diff --git a/include/occ/core/fraction.h b/include/occ/core/fraction.h index 09402c5ba..c49e7356e 100644 --- a/include/occ/core/fraction.h +++ b/include/occ/core/fraction.h @@ -1,5 +1,6 @@ #pragma once #include +#include #include namespace occ::core { diff --git a/scripts/check_static.ps1 b/scripts/check_static.ps1 new file mode 100644 index 000000000..27b932e24 --- /dev/null +++ b/scripts/check_static.ps1 @@ -0,0 +1,35 @@ +param( + [Parameter(Mandatory=$true)] + [string]$ExecutablePath +) + +function Check-StaticBinary { + param( + [string]$ExePath + ) + + if (-not (Test-Path $ExePath)) { + Write-Error "Executable not found at $ExePath" + return + } + + Write-Output "Checking if the binary is static: $ExePath" + + try { + $dependencies = & objdump -p $ExePath | Select-String "DLL Name" + + if ($dependencies) { + Write-Output "The following dependencies were found:" + $dependencies | ForEach-Object { Write-Output $_.Line } + Write-Output "The binary might not be fully static." + } else { + Write-Output "No DLL dependencies found. The binary appears to be static." + } + } + catch { + Write-Error "Error occurred while running objdump: $_" + } +} + +# Run the function with the provided executable path +Check-StaticBinary -ExePath $ExecutablePath diff --git a/scripts/windows_build.ps1 b/scripts/windows_build.ps1 new file mode 100644 index 000000000..a7b649d53 --- /dev/null +++ b/scripts/windows_build.ps1 @@ -0,0 +1,69 @@ +$BUILD_DIR = "build" +$ARCH = "x86_64" +$NAME = "windows" + +# Override architecture if provided as argument +if ($args.Count -gt 0) { + $ARCH = $args[0] +} +if ($args.Count -gt 1) { + $NAME = $args[1] +} + +# Ensure GCC (MinGW-w64) is installed and in PATH +if (!(Get-Command gcc -ErrorAction SilentlyContinue)) { + Write-Error "GCC not found. Please install MinGW-w64 and add it to your PATH." + exit 1 +} + +# Ensure Ninja is installed and in PATH +if (!(Get-Command ninja -ErrorAction SilentlyContinue)) { + Write-Error "Ninja not found. Please install Ninja and add it to your PATH." + exit 1 +} + +# Get GCC path +$GCC_PATH = (Get-Command gcc).Source +$GPP_PATH = (Get-Command g++).Source + +# Create build directory if it doesn't exist +if (!(Test-Path $BUILD_DIR)) { + New-Item -ItemType Directory -Force -Path $BUILD_DIR +} + +# Run CMake configuration +cmake . -B"$BUILD_DIR" ` + -DCMAKE_BUILD_TYPE=Release ` + -DENABLE_HOST_OPT=OFF ` + -GNinja ` + -DCMAKE_C_COMPILER="$GCC_PATH" ` + -DCMAKE_CXX_COMPILER="$GPP_PATH" ` + -DCMAKE_CXX_FLAGS="-O2" ` + -DCMAKE_C_FLAGS="-O2" ` + -DUSE_OPENMP=OFF ` + -DCPACK_SYSTEM_NAME="$NAME" ` + -DGG_NO_PRAGMA=ON + +if ($LASTEXITCODE -ne 0) { + Write-Error "CMake configuration failed." + exit $LASTEXITCODE +} + +# Build the project +cmake --build "$BUILD_DIR" --target occ + +if ($LASTEXITCODE -ne 0) { + Write-Error "Build failed." + exit $LASTEXITCODE +} + +# Package the project +Push-Location $BUILD_DIR +cpack -G ZIP +if ($LASTEXITCODE -ne 0) { + Write-Error "Packaging failed." + exit $LASTEXITCODE +} +Pop-Location + +Write-Output "Build and packaging completed successfully." diff --git a/tests/geometry_tests.cpp b/tests/geometry_tests.cpp index 5aeab7f78..725886f9f 100644 --- a/tests/geometry_tests.cpp +++ b/tests/geometry_tests.cpp @@ -369,7 +369,7 @@ TEST_CASE("0D hull", "[qh]") { pc.array() *= 0.000001f; pc.col(0).setConstant(2.0f); hull = qh.getConvexHull(pc, true); - REQUIRE(hull.indices().size() == 12); + REQUIRE(hull.indices().size() >= 12); } TEST_CASE("Planar hull", "[qh]") {