Skip to content

Commit

Permalink
ci: add Github Actions config
Browse files Browse the repository at this point in the history
  • Loading branch information
ntamas committed Sep 7, 2023
1 parent 211c99b commit a79c637
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 22 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright (c) 2021-2022-2023 Luca Cappa
# Released under the term specified in file LICENSE.txt
# SPDX short identifier: MIT
#
# The peculiarity of this workflow is that assumes vcpkg stored as a submodule of this repository.
# The workflow runs on x64 and ARM platforms.
# Workflow steps:
# - Setup vcpkg and cache it on the GitHub Action cloud based cache.
# - Runs CMake with CMakePreset.json using a presest configuration
# that leverages the vcpkg's toolchain file. This will automatically run vcpkg
# to install dependencies described by the vcpkg.json manifest file.
# This stage also runs vcpkg with Binary Caching leveraging GitHub Action cache to
# store the built packages artifacts, hence it will be a no-op if those are restored
# from cache (e.g., already previously built).
# - Finally builds the sources with Ninja, and tests as well.
name: hosted-ninja-vcpkg_submod-autocache
on:
push:
pull_request:
branches:
- v11
- main
workflow_dispatch:
schedule:
- cron: "0 1 * * *"

jobs:
job:
name: ${{ matrix.os }}-${{ github.workflow }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
[
ubuntu-latest,
macos-latest,
windows-latest,
buildjet-2vcpu-ubuntu-2204-arm,
]
#env:
#
# [OPTIONAL] Define the vcpkg's triplet
# you want to enforce, otherwise the default one
# for the hosting system will be automatically
# choosen (x64 is the default on all platforms,
# e.g. x64-osx).
# VCPKG_DEFAULT_TRIPLET: ${{ matrix.triplet }}

steps:
- uses: actions/checkout@v3
with:
submodules: true

- uses: lukka/get-cmake@latest

- name: Setup and run vcpkg
uses: lukka/run-vcpkg@v11
with:
vcpkgJsonGlob: "vcpkg.json"

# Note: if the preset misses the "configuration", it is possible to explicitly select the
# configuration with the additional `--config` flag, e.g.:
# buildPreset: 'ninja-vcpkg'
# buildPresetAdditionalArgs: "[`--config`, `Release`]"
# testPreset: 'ninja-vcpkg'
# testPresetAdditionalArgs: "[`--config`, `Release`]"
- name: Run CMake + vcpkg + Ninja
uses: lukka/run-cmake@v10
with:
configurePreset: "ninja-multi-vcpkg"
buildPreset: "ninja-vcpkg-release"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
.vscode/
builds/
src/config.h
src/Makefile
stitch
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/microsoft/vcpkg.git
33 changes: 20 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.21)

project(stitch)

Expand All @@ -7,23 +7,26 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/etc/cmake)

# Optionally let CMake know that we prefer static libraries
option(PREFER_STATIC_LIBRARIES "Prefer static libraries over shared ones when linking" OFF)

if(PREFER_STATIC_LIBRARIES)
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
else(WIN32)
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif(WIN32)
endif()

if(NOT APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static")
endif(NOT APPLE)
endif(PREFER_STATIC_LIBRARIES)
endif()
endif()

# Find all the required dependencies
find_package(CURL REQUIRED)
find_package(JPEG)
find_package(PNG)
find_package(TIFF)
find_package(GEOTIFF)
find_package(PROJ CONFIG)
find_library(MATH_LIBRARY m)

# Turn on all compiler warnings
Expand All @@ -39,13 +42,17 @@ configure_file(
add_executable(stitch src/stitch.c)
target_include_directories(stitch PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src ${CURL_INCLUDE_DIRS})
target_link_libraries(stitch ${MATH_LIBRARY} CURL::libcurl)

if(JPEG_FOUND)
target_link_libraries(stitch JPEG::JPEG)
endif(JPEG_FOUND)
target_link_libraries(stitch JPEG::JPEG)
endif()

if(PNG_FOUND)
target_link_libraries(stitch PNG::PNG)
endif(PNG_FOUND)
if(GEOTIFF_FOUND)
target_include_directories(stitch PRIVATE ${GEOTIFF_INCLUDE_DIRS} ${TIFF_INCLUDE_DIRS})
target_link_libraries(stitch ${GEOTIFF_LIBRARIES} ${TIFF_LIBRARIES})
endif(GEOTIFF_FOUND)
target_link_libraries(stitch PNG::PNG)
endif()

if(GEOTIFF_FOUND AND PROJ_FOUND)
target_include_directories(stitch PRIVATE ${GEOTIFF_INCLUDE_DIR} ${TIFF_INCLUDE_DIRS})
target_link_libraries(stitch ${GEOTIFF_LIBRARY} ${TIFF_LIBRARIES})
target_link_libraries(stitch PROJ::proj)
endif()
46 changes: 46 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"name": "ninja-multi-vcpkg",
"displayName": "Ninja Multi-Config",
"description": "Configure with vcpkg toolchain and generate Ninja project files for all configurations",
"binaryDir": "${sourceDir}/builds/${presetName}",
"generator": "Ninja Multi-Config",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": {
"type": "FILEPATH",
"value": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake"
}
}
}
],
"buildPresets": [
{
"name": "ninja-vcpkg-debug",
"configurePreset": "ninja-multi-vcpkg",
"displayName": "Build (Debug)",
"description": "Build with Ninja/vcpkg (Debug)",
"configuration": "Debug"
},
{
"name": "ninja-vcpkg-release",
"configurePreset": "ninja-multi-vcpkg",
"displayName": "Build (Release)",
"description": "Build with Ninja/vcpkg (Release)",
"configuration": "Release"
},
{
"name": "ninja-vcpkg",
"configurePreset": "ninja-multi-vcpkg",
"displayName": "Build",
"description": "Build with Ninja/vcpkg"
}
],
"testPresets": []
}
79 changes: 71 additions & 8 deletions etc/cmake/FindGEOTIFF.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,71 @@
find_path(GEOTIFF_INCLUDE_DIR geotiffio.h PATH_SUFFIXES include)
find_library(GEOTIFF_LIBRARY NAMES geotiff)
set(GEOTIFF_INCLUDE_DIRS ${GEOTIFF_INCLUDE_DIR})
set(GEOTIFF_LIBRARIES ${GEOTIFF_LIBRARY})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GEOTIFF DEFAULT_MSG GEOTIFF_LIBRARY GEOTIFF_INCLUDE_DIR)
mark_as_advanced(GEOTIFF_INCLUDE_DIR GEOTIFF_LIBRARY)
###############################################################################
#
# CMake module to search for GeoTIFF library
#
# On success, the macro sets the following variables:
# GEOTIFF_FOUND = if the library found
# GEOTIFF_LIBRARIES = full path to the library
# GEOTIFF_INCLUDE_DIR = where to find the library headers
# also defined, but not for general use are
# GEOTIFF_LIBRARY, where to find the PROJ.4 library.
#
# Copyright (c) 2009 Mateusz Loskot <[email protected]>
#
# Module source: http://github.com/mloskot/workshop/tree/master/cmake/
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
###############################################################################

SET(GEOTIFF_NAMES geotiff)

IF(WIN32)

IF(MINGW)
FIND_PATH(GEOTIFF_INCLUDE_DIR
geotiff.h
PATH_PREFIXES geotiff
PATHS
/usr/local/include
/usr/include
c:/msys/local/include)

FIND_LIBRARY(GEOTIFF_LIBRARY
NAMES ${GEOTIFF_NAMES}
PATHS
/usr/local/lib
/usr/lib
c:/msys/local/lib)
ENDIF(MINGW)

IF(MSVC)
SET(GEOTIFF_INCLUDE_DIR "$ENV{LIB_DIR}/include" CACHE STRING INTERNAL)

SET(GEOTIFF_NAMES ${GEOTIFF_NAMES} geotiff_i)
FIND_LIBRARY(GEOTIFF_LIBRARY NAMES
NAMES ${GEOTIFF_NAMES}
PATHS
"$ENV{LIB_DIR}/lib"
/usr/lib
c:/msys/local/lib)
ENDIF(MSVC)

ELSEIF(UNIX)

FIND_PATH(GEOTIFF_INCLUDE_DIR geotiff.h PATH_PREFIXES geotiff)

FIND_LIBRARY(GEOTIFF_LIBRARY NAMES ${GEOTIFF_NAMES})

ELSE()
MESSAGE("FindGeoTIFF.cmake: unrecognized or unsupported operating system")
ENDIF()

IF(GEOTIFF_FOUND)
SET(GEOTIFF_LIBRARIES ${GEOTIFF_LIBRARY})
ENDIF()

# Handle the QUIETLY and REQUIRED arguments and set SPATIALINDEX_FOUND to TRUE
# if all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GEOTIFF DEFAULT_MSG GEOTIFF_LIBRARY GEOTIFF_INCLUDE_DIR)
1 change: 1 addition & 0 deletions vcpkg
Submodule vcpkg added at 095ee8
4 changes: 4 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"dependencies": ["libpng", "libjpeg-turbo", "curl", "tiff", "libgeotiff"]
}

0 comments on commit a79c637

Please sign in to comment.