Skip to content

Commit

Permalink
Add CI build for Windows (#46)
Browse files Browse the repository at this point in the history
* Update README.md

* update CI pipelines

* add install-ccache.ps1

* d

* d

* directly find suitesparse (before assume Ceres achieve this)

* try removing the direct linking of CHOLMOD library

* add vcpkg.json

* remove unnecessary features

* d

* remove requirement for cuda

* d

* d

* d

* d

* D

* d

* d

* d

* d

* d

* d

* d

* d

* d

* d

* d

* d

* d

* d

* d

* d

* d

* d

---------

Co-authored-by: Linfei Pan <[email protected]>
Co-authored-by: lpanaf <[email protected]>
  • Loading branch information
3 people authored Aug 8, 2024
1 parent 1dc20d7 commit c0579ef
Show file tree
Hide file tree
Showing 11 changed files with 1,045 additions and 31 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/install-ccache.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string] $Destination
)

$version = "4.8"
$folder = "ccache-$version-windows-x86_64"
$url = "https://github.com/ccache/ccache/releases/download/v$version/$folder.zip"
$expectedSha256 = "A2B3BAB4BB8318FFC5B3E4074DC25636258BC7E4B51261F7D9BEF8127FDA8309"

$ErrorActionPreference = "Stop"

try {
New-Item -Path "$Destination" -ItemType Container -ErrorAction SilentlyContinue

Write-Host "Download CCache"
$zipFilePath = Join-Path "$env:TEMP" "$folder.zip"
Invoke-WebRequest -Uri $url -UseBasicParsing -OutFile "$zipFilePath" -MaximumRetryCount 3

$hash = Get-FileHash $zipFilePath -Algorithm "sha256"
if ($hash.Hash -ne $expectedSha256) {
throw "File $Path hash $hash.Hash did not match expected hash $expectedHash"
}

Write-Host "Unzip CCache"
Expand-Archive -Path "$zipFilePath" -DestinationPath "$env:TEMP"

Write-Host "Move CCache"
Move-Item -Force "$env:TEMP/$folder/ccache.exe" "$Destination"
Remove-Item "$zipFilePath"
Remove-Item -Recurse "$env:TEMP/$folder"
}
catch {
Write-Host "Installation failed with an error"
$_.Exception | Format-List
exit -1
}
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml → .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ jobs:
-DCMAKE_BUILD_TYPE=${{ matrix.config.cmakeBuildType }} \
-DCMAKE_INSTALL_PREFIX=./install \
-DCMAKE_CUDA_ARCHITECTURES=50 \
-DSuiteSparse_CHOLMOD_LIBRARY="/usr/lib/x86_64-linux-gnu/libcholmod.so" \
-DSuiteSparse_CHOLMOD_INCLUDE_DIR="/usr/include/suitesparse" \
-DTESTS_ENABLED=ON \
-DASAN_ENABLED=${{ matrix.config.asanEnabled }}
ninja -k 10000
Expand Down
142 changes: 142 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: Windows

on:
push:
branches:
- main
pull_request:
types: [ assigned, opened, synchronize, reopened ]
release:
types: [ published, edited ]

jobs:
build:
name: ${{ matrix.config.os }} ${{ matrix.config.cmakeBuildType }} ${{ matrix.config.cudaEnabled && 'CUDA' || '' }}
runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config: [
{
os: windows-2019,
cmakeBuildType: Release,
cudaEnabled: false,
testsEnabled: true,
exportPackage: false,
},
{
os: windows-2022,
cmakeBuildType: Release,
cudaEnabled: false,
testsEnabled: true,
exportPackage: true,
},
]

env:
COMPILER_CACHE_VERSION: 1
COMPILER_CACHE_DIR: ${{ github.workspace }}/compiler-cache
CCACHE_DIR: ${{ github.workspace }}/compiler-cache/ccache
CCACHE_BASEDIR: ${{ github.workspace }}
VCPKG_COMMIT_ID: e01906b2ba7e645a76ee021a19de616edc98d29f
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"

steps:
- uses: actions/checkout@v4

- name: Export GitHub Actions cache env
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Compiler cache
uses: actions/cache@v4
id: cache-builds
with:
key: v${{ env.COMPILER_CACHE_VERSION }}-${{ matrix.config.os }}-${{ matrix.config.cmakeBuildType }}-${{ matrix.config.asanEnabled }}--${{ matrix.config.cudaEnabled }}-${{ github.run_id }}-${{ github.run_number }}
restore-keys: v${{ env.COMPILER_CACHE_VERSION }}-${{ matrix.config.os }}-${{ matrix.config.cmakeBuildType }}-${{ matrix.config.asanEnabled }}--${{ matrix.config.cudaEnabled }}
path: ${{ env.COMPILER_CACHE_DIR }}

- name: Install ccache
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path "${{ env.CCACHE_DIR }}"
echo "${{ env.COMPILER_CACHE_DIR }}/bin" | Out-File -Encoding utf8 -Append -FilePath $env:GITHUB_PATH
if (Test-Path -PathType Leaf "${{ env.COMPILER_CACHE_DIR }}/bin/ccache.exe") {
exit
}
.github/workflows/install-ccache.ps1 -Destination "${{ env.COMPILER_CACHE_DIR }}/bin"
- name: Install CMake and Ninja
uses: lukka/get-cmake@latest

- name: Setup vcpkg
shell: pwsh
run: |
./scripts/shell/enter_vs_dev_shell.ps1
cd ${{ github.workspace }}
git clone https://github.com/microsoft/vcpkg
cd vcpkg
git reset --hard ${{ env.VCPKG_COMMIT_ID }}
./bootstrap-vcpkg.bat
- name: Configure and build
shell: pwsh
run: |
./scripts/shell/enter_vs_dev_shell.ps1
cd ${{ github.workspace }}
./vcpkg/vcpkg.exe integrate install
mkdir build
cd build
cmake .. `
-GNinja `
-DCMAKE_MAKE_PROGRAM=ninja `
-DCMAKE_BUILD_TYPE=Release `
-DTESTS_ENABLED=ON `
-DCUDA_ENABLED=OFF `
-DGUI_ENABLED=OFF `
-DCGAL_ENABLED=OFF `
-DCMAKE_CUDA_ARCHITECTURES=all-major `
-DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" `
-DVCPKG_TARGET_TRIPLET=x64-windows-release `
-DCMAKE_INSTALL_PREFIX=install
ninja
- name: Run tests
shell: pwsh
run: |
./vcpkg/vcpkg.exe integrate install
cd build
ctest -E .+colmap_.* --output-on-failure
- name: Export package
if: matrix.config.exportPackage
shell: pwsh
run: |
./vcpkg/vcpkg.exe integrate install
cd build
ninja install
../vcpkg/vcpkg.exe install `
--triplet=x64-windows-release
../vcpkg/vcpkg.exe export --raw --output-dir vcpkg_export --output glomap
cp vcpkg_export/glomap/installed/x64-windows/bin/*.dll install/bin
cp vcpkg_export/glomap/installed/x64-windows-release/bin/*.dll install/bin
- name: Upload package
uses: actions/upload-artifact@v4
if: ${{ matrix.config.exportPackage }}
with:
name: glomap-x64-windows
path: build/install

- name: Cleanup compiler cache
shell: pwsh
run: |
ccache --show-stats --verbose
ccache --evict-older-than 1d
ccache --show-stats --verbose
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ option(FETCH_POSELIB "Whether to use PoseLib with FetchContent or with self-inst

include(cmake/FindDependencies.cmake)

# Propagate options to vcpkg manifest.
if (TESTS_ENABLED)
enable_testing()
endif()
Expand Down
48 changes: 26 additions & 22 deletions cmake/FindDependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

find_package(Eigen3 3.4 REQUIRED)
find_package(SuiteSparse COMPONENTS CHOLMOD REQUIRED)
find_package(Ceres REQUIRED COMPONENTS SuiteSparse)
find_package(Boost REQUIRED)

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
find_package(Glog REQUIRED)
if(DEFINED glog_VERSION_MAJOR)
# Older versions of glog don't export version variables.
add_definitions("-DGLOG_VERSION_MAJOR=${glog_VERSION_MAJOR}")
add_definitions("-DGLOG_VERSION_MINOR=${glog_VERSION_MINOR}")
endif()
endif()

if(TESTS_ENABLED)
message(STATUS "Enabling tests")
find_package(GTest REQUIRED)
endif()

if (OPENMP_ENABLED)
message(STATUS "Enabling OpenMP")
find_package(OpenMP REQUIRED)
endif()

include(FetchContent)
FetchContent_Declare(PoseLib
GIT_REPOSITORY https://github.com/PoseLib/PoseLib.git
Expand Down Expand Up @@ -25,25 +51,3 @@ else()
find_package(COLMAP REQUIRED)
endif()
message(STATUS "Configuring COLMAP... done")

find_package(Eigen3 3.4 REQUIRED)
find_package(Ceres REQUIRED COMPONENTS SuiteSparse)
find_package(Boost REQUIRED)

if(TESTS_ENABLED)
message(STATUS "Enabling tests")
find_package(GTest REQUIRED)
endif()

if (OPENMP_ENABLED)
message(STATUS "Enabling OpenMP")
find_package(OpenMP REQUIRED)
endif()

find_package(SuiteSparse QUIET)
if(SuiteSparse_FOUND)
set(SuiteSparse_CHOLMOD_INCLUDE_DIR "${SUITESPARSE_INCLUDE_DIRS}/suitesparse")
set(SuiteSparse_CHOLMOD_LIBRARY SuiteSparse::cholmod)
else()
message(STATUS "SuiteSparse not found, assuming Ceres provides SuiteSparse")
endif()
118 changes: 118 additions & 0 deletions cmake/FindGlog.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Copyright (c) 2023, ETH Zurich and UNC Chapel Hill.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of ETH Zurich and UNC Chapel Hill nor the names of
# its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.


# Find package module for Glog library.
#
# The following variables are set by this module:
#
# GLOG_FOUND: TRUE if Glog is found.
# glog::glog: Imported target to link against.
#
# The following variables control the behavior of this module:
#
# GLOG_INCLUDE_DIR_HINTS: List of additional directories in which to
# search for Glog includes.
# GLOG_LIBRARY_DIR_HINTS: List of additional directories in which to
# search for Glog libraries.

set(GLOG_INCLUDE_DIR_HINTS "" CACHE PATH "Glog include directory")
set(GLOG_LIBRARY_DIR_HINTS "" CACHE PATH "Glog library directory")

unset(GLOG_FOUND)

find_package(glog CONFIG QUIET)
if(TARGET glog::glog)
set(GLOG_FOUND TRUE)
message(STATUS "Found Glog")
message(STATUS " Target : glog::glog")
else()
# Older versions of glog don't come with a find_package config.
# Fall back to custom logic to find the library and remap to imported target.

include(FindPackageHandleStandardArgs)

list(APPEND GLOG_CHECK_INCLUDE_DIRS
/usr/local/include
/usr/local/homebrew/include
/opt/local/var/macports/software
/opt/local/include
/usr/include)
list(APPEND GLOG_CHECK_PATH_SUFFIXES
glog/include
glog/Include
Glog/include
Glog/Include
src/windows)

list(APPEND GLOG_CHECK_LIBRARY_DIRS
/usr/local/lib
/usr/local/homebrew/lib
/opt/local/lib
/usr/lib)
list(APPEND GLOG_CHECK_LIBRARY_SUFFIXES
glog/lib
glog/Lib
Glog/lib
Glog/Lib
x64/Release)

find_path(GLOG_INCLUDE_DIRS
NAMES
glog/logging.h
PATHS
${GLOG_INCLUDE_DIR_HINTS}
${GLOG_CHECK_INCLUDE_DIRS}
PATH_SUFFIXES
${GLOG_CHECK_PATH_SUFFIXES})
find_library(GLOG_LIBRARIES
NAMES
glog
libglog
PATHS
${GLOG_LIBRARY_DIR_HINTS}
${GLOG_CHECK_LIBRARY_DIRS}
PATH_SUFFIXES
${GLOG_CHECK_LIBRARY_SUFFIXES})

if(GLOG_INCLUDE_DIRS AND GLOG_LIBRARIES)
set(GLOG_FOUND TRUE)
message(STATUS "Found Glog")
message(STATUS " Includes : ${GLOG_INCLUDE_DIRS}")
message(STATUS " Libraries : ${GLOG_LIBRARIES}")
endif()

add_library(glog::glog INTERFACE IMPORTED)
target_include_directories(glog::glog INTERFACE ${GLOG_INCLUDE_DIRS})
target_link_libraries(glog::glog INTERFACE ${GLOG_LIBRARIES})
endif()

if(NOT GLOG_FOUND AND GLOG_FIND_REQUIRED)
message(FATAL_ERROR "Could not find Glog")
endif()
Loading

0 comments on commit c0579ef

Please sign in to comment.