Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vcpkg GitHub action #311

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
186 changes: 186 additions & 0 deletions .github/workflows/vcpkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
name: build
on:
push:
branches:
- '*'
tags:
- '*'
pull_request:
branches:
- 'master'

jobs:
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: 'Windows x64'
os: windows-latest
triplet: x64-windows
vcpkg_dir: 'C:\vcpkg'
suffix: 'windows-win32'
generator: 'Visual Studio 17 2022'
arch: '-A x64'
- name: 'Windows x86'
os: windows-latest
triplet: x86-windows
vcpkg_dir: 'C:\vcpkg'
suffix: 'windows-win64'
generator: 'Visual Studio 17 2022'
arch: '-A Win32'
- name: 'Linux x64'
os: ubuntu-latest
triplet: x64-linux
suffix: 'linux-x86_64'
vcpkg_dir: '/usr/local/share/vcpkg'
generator: 'Unix Makefiles'
arch: ''
- name: 'Mac OSX x64'
os: macos-latest
triplet: x64-osx
suffix: 'osx-x86_64'
vcpkg_dir: '/usr/local/share/vcpkg'
generator: 'Unix Makefiles'
arch: ''

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

# # Enable this if you want specific version of vcpkg
# # For openmind tag "2020.06"
# - name: Configure Vcpkg
# shell: bash
# run: |
# cd ${{ matrix.vcpkg_dir }}
# git fetch origin --tags
# git reset --hard 2020.06
# if [ "$RUNNER_OS" == "Windows" ]; then
# ./bootstrap-vcpkg.bat
# else
# ./bootstrap-vcpkg.sh
# fi

- name: Cache vcpkg
uses: actions/cache@v2
with:
path: '${{ matrix.vcpkg_dir }}/installed'
key: vcpkg-${{ matrix.triplet }}-${{ hashFiles('vcpkg.txt') }}
restore-keys: |
vcpkg-${{ matrix.triplet }}-

- name: Install vcpkg packages
shell: bash
run: |
vcpkg install --triplet ${{ matrix.triplet }}

- name: Configure
shell: bash
run: |
mkdir build
mkdir install
if [ "$RUNNER_OS" == "Windows" ]; then
cmake \
-B ./build \
-G "${{ matrix.generator }}" ${{ matrix.arch }} \
-DCMAKE_INSTALL_PREFIX=./install \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DOPENMIND_BUILD_SAMPLES=OFF -DOPENMIND_BUILD_TESTS=ON \
-DCMAKE_TOOLCHAIN_FILE=${{ matrix.vcpkg_dir }}/scripts/buildsystems/vcpkg.cmake \
.
else
if [ "$RUNNER_OS" == "Linux" ]; then
export CC=/usr/bin/gcc-9
export CXX=/usr/bin/g++-9
fi
cmake \
-B ./build \
-G "${{ matrix.generator }}" \
-DCMAKE_INSTALL_PREFIX=./install \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DOPENMIND_BUILD_SAMPLES=OFF -DOPENMIND_BUILD_TESTS=ON \
-DCMAKE_TOOLCHAIN_FILE=${{ matrix.vcpkg_dir }}/scripts/buildsystems/vcpkg.cmake \
.
fi

- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v2
id: cpu-cores

- name: Compile
shell: bash
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
cmake --build ./build --target INSTALL --config MinSizeRel
else
cmake --build ./build --target install --config MinSizeRel
fi

- name: Tests
shell: bash
run: cd build && ctest --timeout 240 -C MinSizeRel --verbose -j ${{steps.cpu-cores.outputs.count}} -E "image_codec_test|ts|Polyfit_test"

- name: List runtime dependencies
shell: bash
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
ldd ./install/bin/openmind
elif [ "$RUNNER_OS" == "macOS" ]; then
otool -L ./install/bin/openmind
fi

- name: Package
id: create_artifact
shell: bash
run: |
mkdir release
if [ "$RUNNER_OS" == "Windows" ]; then
ls ./install
7z a -r openmind.zip ./install/*
else
cd ./install
zip -r ./../openmind.zip *
cd ..
fi
name=openmind-${{ matrix.suffix }}-$(git describe --always).zip
mv -v ./openmind.zip release/${name}
echo "::set-output name=name::${name}"
echo "::set-output name=path::release/${name}"

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: Release
path: release

- name: Create Changelog
id: create_changelog
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
run: |
last_tag=$(git describe --tags --abbrev=0 @^ || true)
if [ -z "$last_tag" ]; then
git log --oneline --format="%C(auto) %h %s" > changelog.txt
else
git log --oneline --format="%C(auto) %h %s" ${last_tag}..@ > changelog.txt
fi
cat changelog.txt

- name: Release
uses: ncipollo/release-action@v1
if: startsWith(github.ref, 'refs/tags/v')
with:
artifacts: ${{ steps.create_artifact.outputs.path }}
allowUpdates: true
artifactContentType: application/zip
bodyFile: changelog.txt
draft: false
omitBodyDuringUpdate: true
omitNameDuringUpdate: true
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}
76 changes: 54 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,25 @@ set(_BOOST_USED_COMPONENTS
system
thread
CACHE STRING "Components" FORCE)

if(OPENMIND_USE_VCPKG)
set(_BOOST_USED_COMPONENTS ${_BOOST_USED_COMPONENTS}
boost
compute
multiprecision
CACHE STRING "Components" FORCE)
endif(OPENMIND_USE_VCPKG)
if(BUILD_TESTS OR OPENMIND_BUILD_TESTS OR _IS_DEBUG OR NOT CMAKE_BUILD_TYPE)
enable_testing()
set(_BOOST_USED_COMPONENTS ${_BOOST_USED_COMPONENTS}
unit_test_framework
test_exec_monitor
CACHE STRING "Components" FORCE)
if(OPENMIND_USE_VCPKG)
set(_BOOST_USED_COMPONENTS ${_BOOST_USED_COMPONENTS}
unit_test_framework
CACHE STRING "Components" FORCE)
else(OPENMIND_USE_VCPKG)
set(_BOOST_USED_COMPONENTS ${_BOOST_USED_COMPONENTS}
unit_test_framework
test_exec_monitor
CACHE STRING "Components" FORCE)
endif(OPENMIND_USE_VCPKG)
endif()
list(REMOVE_DUPLICATES _BOOST_USED_COMPONENTS)
set(BOOST_USED_COMPONENTS ${_BOOST_USED_COMPONENTS} CACHE STRING "Components" FORCE)
Expand Down Expand Up @@ -224,18 +236,30 @@ elseif(OPENMIND_USE_CONAN)
endif()
endif()

find_package(Boost ${OPENMIND_PREFERRED_BOOST_VERSION}
CONFIG
HINTS C:/Boost
COMPONENTS ${BOOST_USED_COMPONENTS}
)
if(NOT Boost_FOUND)
find_package(Boost ${OPENMIND_REQUIRED_BOOST_VERSION}
CONFIG
HINTS C:/Boost
COMPONENTS ${BOOST_USED_COMPONENTS}
if (NOT Boost_FOUND)
if (OPENMIND_USE_VCPKG)
include(vcpkg)
unset(Boost_DIR CACHE)
unset(Boost_INCLUDE_DIR CACHE)
find_package(Boost CONFIG REQUIRED
#COMPONENTS ${BOOST_USED_COMPONENTS}
)
endif()
endif()
if (NOT Boost_FOUND)
find_package(Boost ${OPENMIND_PREFERRED_BOOST_VERSION}
CONFIG
HINTS C:/Boost
COMPONENTS ${BOOST_USED_COMPONENTS}
)
if(NOT Boost_FOUND)
find_package(Boost ${OPENMIND_REQUIRED_BOOST_VERSION}
CONFIG
HINTS C:/Boost
COMPONENTS ${BOOST_USED_COMPONENTS}
)
endif()
endif ()
endif ()
add_custom_target(prerequisites)
set_target_properties(prerequisites PROPERTIES FOLDER "util")

Expand Down Expand Up @@ -274,7 +298,7 @@ find_package(OpenMP)
# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
#endif()

if (Boost_FOUND OR OPENMIND_USE_CONAN)
if (Boost_FOUND OR OPENMIND_USE_CONAN OR OPENMIND_USE_VCPKG)
if(NOT TARGET boost)
add_custom_target(boost)
endif()
Expand Down Expand Up @@ -369,11 +393,19 @@ if(NOT MSVC OR Boost_VERSION VERSION_LESS 1.80.0)
set(BOOST_LINK_LIBS ${BOOST_LINK_LIBS}
Boost::thread)
endif()
set(BOOST_TEST_LINK_LIBS
${BOOST_LINK_LIBS}
Boost::test_exec_monitor
Boost::unit_test_framework
)
if(OPENMIND_USE_VCPKG)
set(BOOST_LINK_LIBS ${BOOST_LINK_LIBS}
Boost::headers
)
set(BOOST_TEST_LINK_LIBS ${BOOST_LINK_LIBS}
Boost::test
)
else()
set(BOOST_TEST_LINK_LIBS ${BOOST_LINK_LIBS}
Boost::test_exec_monitor
Boost::unit_test_framework
)
endif()

IF (Boost_FOUND)
message("Boost_FOUND")
Expand Down
61 changes: 36 additions & 25 deletions cmake/vcpkg.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

function(prepend_toolchain_file)
if(EXISTS ${CMAKE_TOOLCHAIN_FILE})
list(PREPEND CMAKE_PROJECT_TOP_LEVEL_INCLUDES "${CMAKE_TOOLCHAIN_FILE}")
set(${CMAKE_PROJECT_TOP_LEVEL_INCLUDES} "${${CMAKE_PROJECT_TOP_LEVEL_INCLUDES}}" PARENT_SCOPE)
list(PREPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_PROJECT_TOP_LEVEL_INCLUDES)
set(${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES} "${${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES}}" PARENT_SCOPE)
endif()
endfunction()

macro(find_vcpkg)
if(NOT EXISTS ${CMAKE_TOOLCHAIN_FILE})
if(NOT EXISTS ${VCPKG_EXECUTABLE})
Expand All @@ -7,16 +16,20 @@ macro(find_vcpkg)
"$ENV{USERPROFILE}$ENV{HOME}/vcpkg/"
)
endif()
if (EXISTS ${VCPKG_EXECUTABLE})
get_filename_component(dir ${VCPKG_EXECUTABLE} DIRECTORY)
set(CMAKE_TOOLCHAIN_FILE "${dir}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")
endif ()
if(EXISTS ${CMAKE_TOOLCHAIN_FILE})
set(VCPKG_FOUND TRUE CACHE BOOL "VCPKG toolchain file found ${CMAKE_TOOLCHAIN_FILE}")
list(APPEND CMAKE_PROJECT_TOP_LEVEL_INCLUDES "${CMAKE_TOOLCHAIN_FILE}")
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_PROJECT_TOP_LEVEL_INCLUDES)
if (EXISTS ${VCPKG_EXECUTABLE})
message("VCPKG_EXECUTABLE=${VCPKG_EXECUTABLE}")
get_filename_component(VCPKG_ROOT ${VCPKG_EXECUTABLE} DIRECTORY)
set(VCPKG_ROOT "${VCPKG_ROOT}" CACHE PATH "Path to vcpkg installation" FORCE)
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file" FORCE)
endif()
endif()

if(EXISTS ${CMAKE_TOOLCHAIN_FILE})
set(VCPKG_FOUND TRUE CACHE BOOL "VCPKG toolchain file found ${CMAKE_TOOLCHAIN_FILE}" FORCE)
#prepend_toolchain_file()
else()
set(VCPKG_FOUND FALSE CACHE BOOL "VCPKG not found" FORCE)
endif()
endmacro()

macro(fetch_vcpkg)
Expand All @@ -42,25 +55,23 @@ endmacro()

if(NOT VCPKG_FOUND)
find_vcpkg()
else()
#prepend_toolchain_file()
endif()

option(OPENMIND_USE_VCPKG "Use vcpkg" ${VCPKG_FOUND})

if(OPENMIND_USE_VCPKG)
if(NOT ${VCPKG_FOUND})
find_vcpkg()
endif()
if(NOT ${VCPKG_FOUND})
fetch_vcpkg()
find_vcpkg()
endif()
if(NOT ${VCPKG_FOUND})
message(FATAL_ERROR "VCPKG is required but not found")
endif()
if(VCPKG_EXECUTABLE)
execute_process(
COMMAND ${VCPKG_EXECUTABLE} install
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif()
endif (OPENMIND_USE_VCPKG)
if(NOT VCPKG_FOUND)
find_vcpkg()
if(NOT VCPKG_FOUND)
fetch_vcpkg()
if(NOT VCPKG_FOUND)
find_vcpkg()
endif()
endif()
endif()
if(NOT VCPKG_FOUND)
message(WARNING "Vcpkg not found")
endif()
endif()
Loading
Loading