From f93e23a6ddb0609b1d5ff51007e994c7d6d18141 Mon Sep 17 00:00:00 2001 From: Sergii Kryvonos Date: Sat, 21 Sep 2024 18:56:38 +0200 Subject: [PATCH 1/2] vcpkg GitHub action --- .github/workflows/vcpkg.yml | 186 ++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 .github/workflows/vcpkg.yml diff --git a/.github/workflows/vcpkg.yml b/.github/workflows/vcpkg.yml new file mode 100644 index 000000000..8af769d5b --- /dev/null +++ b/.github/workflows/vcpkg.yml @@ -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 }} From 2dffeacd56ef542f86c6d2617b7a477fe3e29915 Mon Sep 17 00:00:00 2001 From: Sergii Kryvonos Date: Thu, 26 Sep 2024 15:25:43 +0200 Subject: [PATCH 2/2] Vcpkg: MinGW buildfix --- CMakeLists.txt | 76 ++++++++++++++++++++++++++++++------------ cmake/vcpkg.cmake | 61 +++++++++++++++++++-------------- omnn/rt/CMakeLists.txt | 32 +++++++++++++----- 3 files changed, 113 insertions(+), 56 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc2794f45..c1a18a825 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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") @@ -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() @@ -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") diff --git a/cmake/vcpkg.cmake b/cmake/vcpkg.cmake index d150bf7da..b012de2af 100644 --- a/cmake/vcpkg.cmake +++ b/cmake/vcpkg.cmake @@ -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}) @@ -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) @@ -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() diff --git a/omnn/rt/CMakeLists.txt b/omnn/rt/CMakeLists.txt index e0f49cf6b..b20660128 100644 --- a/omnn/rt/CMakeLists.txt +++ b/omnn/rt/CMakeLists.txt @@ -1,19 +1,33 @@ -set(DEPENDENCIES boost) -if(Boost_FOUND) - if(NOT MSVC OR OPENMIND_USE_CONAN) - set(DEPENDENCIES ${DEPENDENCIES} Boost::filesystem) - if(OPENMIND_BUILD_TESTS) - set(DEPENDENCIES ${DEPENDENCIES} - Boost::test_exec_monitor - Boost::unit_test_framework +if (OPENMIND_USE_VCPKG) + set(DEPENDENCIES + Boost::filesystem + Boost::multiprecision + Boost::system + ) + if(OPENMIND_BUILD_TESTS) + list(APPEND DEPENDENCIES Boost::unit_test_framework) + endif() +else () + set(DEPENDENCIES boost) + if(Boost_FOUND) + if(NOT MSVC OR OPENMIND_USE_CONAN) + list(APPEND DEPENDENCIES Boost::filesystem) + if(OPENMIND_BUILD_TESTS) + list(APPEND DEPENDENCIES + Boost::test_exec_monitor + Boost::unit_test_framework ) + endif() endif() endif() endif() if(OPENMIND_USE_OPENCL) - set(DEPENDENCIES ${DEPENDENCIES} OpenCL) + list(APPEND DEPENDENCIES OpenCL) + if (OPENMIND_USE_VCPKG) + list(APPEND DEPENDENCIES Boost::compute) + endif() endif() lib(${DEPENDENCIES})