From 59bd63ec5e944e42cc792e6c536060d26bbce3b4 Mon Sep 17 00:00:00 2001 From: Sergii Kryvonos Date: Tue, 24 Sep 2024 22:16:16 +0200 Subject: [PATCH] CI: Windows build with vcpkg --- .github/workflows/vcpkg.yml | 17 ++++++++++++++++- .gitignore | 2 +- CMakeLists.txt | 29 +++++++++++++++-------------- cmake/bins.cmake | 2 +- cmake/vcpkg.cmake | 25 +++++++++++++------------ omnn/storage/CMakeLists.txt | 8 ++++---- 6 files changed, 50 insertions(+), 33 deletions(-) diff --git a/.github/workflows/vcpkg.yml b/.github/workflows/vcpkg.yml index 5cd050166..8217bd09a 100644 --- a/.github/workflows/vcpkg.yml +++ b/.github/workflows/vcpkg.yml @@ -6,7 +6,7 @@ jobs: build: strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: @@ -46,6 +46,21 @@ jobs: ninja --version clang --version + - name: Install dependencies (Windows) + if: runner.os == 'Windows' + uses: microsoft/setup-msbuild@v1.0.2 + + - name: Setup MSVC + if: runner.os == 'Windows' + uses: ilammy/msvc-dev-cmd@v1 + + - name: Install CMake and Ninja (Windows) + if: runner.os == 'Windows' + run: | + choco install cmake ninja + cmake --version + ninja --version + - name: Setup vcpkg uses: lukka/run-vcpkg@v11 with: diff --git a/.gitignore b/.gitignore index 7068bd9f4..79433b6d9 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ build* /.cache/ /.vs/ /.idea/ -/cmake-build-debug +/cmake-build-*/ /Testing *.user .DS_Store diff --git a/CMakeLists.txt b/CMakeLists.txt index ae205833e..744d14037 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -236,18 +236,22 @@ elseif(OPENMIND_USE_CONAN) endif() endif() -find_package(Boost ${OPENMIND_PREFERRED_BOOST_VERSION} - CONFIG - HINTS C:/Boost - COMPONENTS ${BOOST_USED_COMPONENTS} +if (OPENMIND_USE_VCPKG) + find_package(Boost CONFIG REQUIRED COMPONENTS ${BOOST_USED_COMPONENTS}) +else() + 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) + 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") @@ -385,11 +389,8 @@ if(NOT MSVC OR Boost_VERSION VERSION_LESS 1.80.0) Boost::thread) endif() if(OPENMIND_USE_VCPKG) - set(BOOST_LINK_LIBS ${BOOST_LINK_LIBS} - Boost::headers - ) set(BOOST_TEST_LINK_LIBS ${BOOST_LINK_LIBS} - Boost::test + Boost::unit_test_framework ) else() set(BOOST_TEST_LINK_LIBS ${BOOST_LINK_LIBS} diff --git a/cmake/bins.cmake b/cmake/bins.cmake index 02feefec0..a6721aa43 100644 --- a/cmake/bins.cmake +++ b/cmake/bins.cmake @@ -539,7 +539,7 @@ macro(exe) ${BOOST_LINK_LIBS} tbb ) - elseif(OPENMIND_USE_CONAN) + elseif(OPENMIND_USE_CONAN OR OPENMIND_USE_VCPKG) deps(${BOOST_LINK_LIBS}) endif() diff --git a/cmake/vcpkg.cmake b/cmake/vcpkg.cmake index 0bd75ca62..ee52711a4 100644 --- a/cmake/vcpkg.cmake +++ b/cmake/vcpkg.cmake @@ -1,3 +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}) @@ -19,8 +29,7 @@ macro(find_vcpkg) if(EXISTS ${CMAKE_TOOLCHAIN_FILE}) set(VCPKG_FOUND TRUE CACHE BOOL "VCPKG toolchain file found ${CMAKE_TOOLCHAIN_FILE}" FORCE) - list(PREPEND CMAKE_PROJECT_TOP_LEVEL_INCLUDES "${CMAKE_TOOLCHAIN_FILE}") - list(PREPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_PROJECT_TOP_LEVEL_INCLUDES) + #prepend_toolchain_file() else() set(VCPKG_FOUND FALSE CACHE BOOL "VCPKG not found" FORCE) endif() @@ -59,6 +68,8 @@ endmacro() if(NOT VCPKG_FOUND) find_vcpkg() +else() + #prepend_toolchain_file() endif() option(OPENMIND_USE_VCPKG "Use vcpkg" ${VCPKG_FOUND}) @@ -76,14 +87,4 @@ if(OPENMIND_USE_VCPKG) if(NOT VCPKG_FOUND) message(WARNING "Vcpkg not found") endif() - if(VCPKG_EXECUTABLE) - execute_process( - COMMAND ${VCPKG_EXECUTABLE} install - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - RESULT_VARIABLE VCPKG_RESULT - ) - if(NOT VCPKG_RESULT EQUAL 0) - message(FATAL_ERROR "Failed to install dependencies using vcpkg") - endif() - endif() endif() diff --git a/omnn/storage/CMakeLists.txt b/omnn/storage/CMakeLists.txt index 2eca949ef..a193825ed 100644 --- a/omnn/storage/CMakeLists.txt +++ b/omnn/storage/CMakeLists.txt @@ -1,7 +1,7 @@ option(OPENMIND_STORAGE_FOUNDATIONDB "Use Apple FoundationDB library for one of the multistorage levels" OFF) option(OPENMIND_STORAGE_LEVELDB "Use Google LevelDB library for one of the multistorage levels" ON) -set(DEPENDENCIES ${DEPENDENCIES} rt) +set(DEPENDENCIES rt) if(OPENMIND_STORAGE_LEVELDB OR OPENMIND_STORAGE_FOUNDATIONDB) option(OPENMIND_STORAGE_ALLOW_UPGRADE "Update optimized cached values during fetch if new optimizations applied" ON) option(OPENMIND_STORAGE_VOLATILE "Clean cache each start (for debugging purposes)" OFF) @@ -9,15 +9,15 @@ if(OPENMIND_STORAGE_LEVELDB OR OPENMIND_STORAGE_FOUNDATIONDB) if(OPENMIND_STORAGE_LEVELDB) find_package(Threads) # workaround leveldb config bug - set(DEPENDENCIES ${DEPENDENCIES} google/leveldb) + list(APPEND DEPENDENCIES google/leveldb) if(NOT WIN32) - set(DEPENDENCIES ${DEPENDENCIES} pthread) + list(APPEND DEPENDENCIES pthread) endif() endif() if(OPENMIND_STORAGE_FOUNDATIONDB) add_definitions(-DOPENMIND_STORAGE_FOUNDATIONDB) - set(DEPENDENCIES ${DEPENDENCIES} ohhmm/FoundationDB) + list(APPEND DEPENDENCIES ohhmm/FoundationDB) endif() if(OPENMIND_STORAGE_ALLOW_UPGRADE)