From 84887d26ecb1ef64b35714e5f30e40653dfb5afe Mon Sep 17 00:00:00 2001 From: Stepanov Igor Date: Fri, 20 Dec 2024 17:16:31 +0300 Subject: [PATCH] Refactoring CmakePresets for windows github actions and refactoring README --- .github/workflows/windows-clang.yml | 36 +++++++++++------------------ .github/workflows/windows.yml | 19 +++++++-------- CMakeLists.txt | 1 + CMakePresets.json | 30 +++++++++++++++++++++++- README.md | 25 ++++++++------------ src/CMakeLists.txt | 12 +++------- 6 files changed, 64 insertions(+), 59 deletions(-) diff --git a/.github/workflows/windows-clang.yml b/.github/workflows/windows-clang.yml index 23544bf64..68ede0a95 100644 --- a/.github/workflows/windows-clang.yml +++ b/.github/workflows/windows-clang.yml @@ -27,37 +27,29 @@ jobs: with: msystem: clang64 install: >- - mingw-w64-clang-x86_64-toolchain - mingw-w64-clang-x86_64-cmake - mingw-w64-clang-x86_64-make - mingw-w64-clang-x86_64-luajit + mingw-w64-clang-x86_64-toolchain + mingw-w64-clang-x86_64-cmake + mingw-w64-clang-x86_64-ninja git - - name: Set up vcpkg - shell: msys2 {0} - run: | - git clone https://github.com/microsoft/vcpkg.git - cd vcpkg - ./bootstrap-vcpkg.bat - ./vcpkg integrate install - cd .. + - name: Bootstrap vcpkg + shell: msys2 + run: ${{ github.workspace }}/vcpkg/bootstrap-vcpkg.bat + - name: Configure project with CMake and vcpkg shell: msys2 {0} + env: + VCPKG_ROOT: ${{ github.workspace }}/vcpkg run: | - export VCPKG_ROOT=./vcpkg - export VCPKG_DEFAULT_TRIPLET=x64-mingw-static - export VCPKG_DEFAULT_HOST_TRIPLET=x64-mingw-static - mkdir build - cd build - cmake --preset default-windows -G "MinGW Makefiles" -DVCPKG_TARGET_TRIPLET=x64-mingw-static -DCMAKE_BUILD_TYPE=Release .. - cmake --build . --config Release + cmake --preset default-ninja-clang-windows + cmake --build --preset default-ninja-clang-windows --config Release - name: Package for Windows run: | mkdir packaged mkdir packaged/res - cp build/VoxelEngine.exe packaged/ - cp build/vctest/vctest.exe packaged/ + cp build/Release/VoxelEngine.exe packaged/ + cp build/vctest/Release/vctest.exe packaged/ cp build/*.dll packaged/ - cp -r build/res/* packaged/res/ + cp -r build/Release/res/* packaged/res/ mv packaged/VoxelEngine.exe packaged/VoxelCore.exe - env: MSYS2_LOCATION: ${{ steps.msys2.outputs.msys2-location }} diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d417197c9..ca1f620d9 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -21,19 +21,16 @@ jobs: with: submodules: 'true' - - name: Set up vcpkg - run: | - git clone https://github.com/microsoft/vcpkg.git - cd vcpkg - .\bootstrap-vcpkg.bat - .\vcpkg integrate install - cd .. + - name: Bootstrap vcpkg + shell: pwsh + run: ${{ github.workspace }}/vcpkg/bootstrap-vcpkg.bat + - name: Configure and build project with CMake and vcpkg + env: + VCPKG_ROOT: ${{ github.workspace }}/vcpkg run: | - mkdir build - cd build - cmake -DCMAKE_BUILD_TYPE=Release -DVOXELENGINE_BUILD_WINDOWS_VCPKG=ON -DVOXELENGINE_BUILD_TESTS=ON .. - cmake --build . --config Release + cmake --preset default-vs-msvc-windows + cmake --build --preset default-vs-msvc-windows --config Release - name: Run tests run: ctest --output-on-failure --test-dir build - name: Run engine tests diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f38ff19e..27373d0dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ endif() target_link_libraries(${PROJECT_NAME} VoxelEngineSrc ${CMAKE_DL_LIBS}) +# Deploy res to build dir add_custom_command( TARGET ${PROJECT_NAME} POST_BUILD diff --git a/CMakePresets.json b/CMakePresets.json index 7c5a3d37d..c0fb0919d 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -2,16 +2,44 @@ "version": 6, "configurePresets": [ { - "name": "default-windows", + "name": "default-vs-msvc-windows", "condition": { "type": "equals", "rhs": "${hostSystemName}", "lhs": "Windows" }, + "generator": "Visual Studio 17 2022", "binaryDir": "${sourceDir}/build", "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" } + }, + { + "name": "default-ninja-clang-windows", + "condition": { + "type": "equals", + "rhs": "${hostSystemName}", + "lhs": "Windows" + }, + "generator": "Ninja Multi-Config", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang" + } + } + ], + "buildPresets": [ + { + "name": "default-vs-msvc-windows", + "configurePreset": "default-vs-msvc-windows", + "configuration": "Debug" + }, + { + "name": "default-ninja-clang-windows", + "configurePreset": "default-ninja-clang-windows", + "configuration": "Debug" } ] } \ No newline at end of file diff --git a/README.md b/README.md index e7f67193a..e31e1436f 100644 --- a/README.md +++ b/README.md @@ -109,38 +109,31 @@ cmake --build . > Requirement: > > vcpkg, CMake, Git -If you want use vcpkg, install vcpkg from git to you system: +There are two options to use vcpkg: +1. If you have Visual Studio installed, most likely the **VCPKG_ROOT** environment variable will already exist in **Developer Command Prompt for VS** +2. If you want use **vcpkg**, install **vcpkg** from git to you system: ```PowerShell cd C:/ git clone https://github.com/microsoft/vcpkg.git cd vcpkg .\bootstrap-vcpkg.bat ``` -After installing vcpkg, setup env variable VCPKG_ROOT and add it to PATH: +After installing **vcpkg**, setup env variable **VCPKG_ROOT** and add it to **PATH**: ```PowerShell $env:VCPKG_ROOT = "C:\path\to\vcpkg" $env:PATH = "$env:VCPKG_ROOT;$env:PATH" ``` -For troubleshooting you can read full [documentation](https://learn.microsoft.com/ru-ru/vcpkg/get_started/get-started?pivots=shell-powershell) for vcpkg +>[!TIP] +>For troubleshooting you can read full [documentation](https://learn.microsoft.com/ru-ru/vcpkg/get_started/get-started?pivots=shell-powershell) for **vcpkg** -After installing vcpkg you can build project: +After installing **vcpkg** you can build project: ```PowerShell git clone --recursive https://github.com/MihailRis/VoxelEngine-Cpp.git cd VoxelEngine-Cpp -mkdir build -cd build -cmake -DCMAKE_BUILD_TYPE=Release .. -cmake --build . --config Release +cmake --preset default-vs-msvc-windows +cmake --build --preset default-vs-msvc-windows ``` -> [!TIP] -> You can use ```rm CMakeCache.txt``` and ```rm -rf CMakeFiles``` while using Git Bash - -> [!WARNING] -> If you have issues during the vcpkg integration, try navigate to ```vcpkg\downloads``` -> and extract PowerShell-[version]-win-x86 to ```vcpkg\downloads\tools``` as powershell-core-[version]-windows. -> Then rerun ```cmake -DCMAKE_BUILD_TYPE=Release ..``` - ## Build using Docker ### Step 0. Install docker on your system diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b4fba12c8..60a8922e3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,15 +21,9 @@ endif() set(LIBS "") if (CMAKE_SYSTEM_NAME STREQUAL "Windows") - if (MSVC) - set(LUA_LIBRARIES "$ENV{VCPKG_ROOT}/packages/luajit_x64-windows/lib/lua51.lib") - set(LUA_INCLUDE_DIR "$ENV{VCPKG_ROOT}/packages/luajit_x64-windows/include/luajit") - else() - find_package(PkgConfig) - pkg_check_modules(OpenAL REQUIRED IMPORTED_TARGET openal) - set(LIBS ${LIBS} luajit-5.1 wsock32 ws2_32 pthread PkgConfig::OpenAL -static-libstdc++) - message(STATUS ${OPENAL_LIBRARY}) - endif() + set(LUA_LIBRARIES "$ENV{VCPKG_ROOT}/packages/luajit_x64-windows/lib/lua51.lib") + set(LUA_INCLUDE_DIR "$ENV{VCPKG_ROOT}/packages/luajit_x64-windows/include/luajit") + find_package(glfw3 REQUIRED) find_package(glm REQUIRED) find_package(vorbis REQUIRED)