diff --git a/.github/workflows/windows-clang.yml b/.github/workflows/windows-clang.yml index 183f2d6dc..67c24d1c5 100644 --- a/.github/workflows/windows-clang.yml +++ b/.github/workflows/windows-clang.yml @@ -21,55 +21,37 @@ jobs: - uses: actions/checkout@v2 with: submodules: 'true' - - uses: msys2/setup-msys2@v2 - id: msys2 - name: Setup MSYS2 - 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 - git - - name: Set up vcpkg - shell: msys2 {0} + + - name: Install latest cmake and ninja + uses: lukka/get-cmake@latest + + - name: Bootstrap vcpkg + shell: pwsh + run: | + git clone https://github.com/microsoft/vcpkg.git + ${{ github.workspace }}/vcpkg/bootstrap-vcpkg.bat + + - name: Configure and build project with CMake and vcpkg + env: + VCPKG_ROOT: ${{ github.workspace }}/vcpkg run: | - git clone https://github.com/microsoft/vcpkg.git - cd vcpkg - ./bootstrap-vcpkg.bat - ./vcpkg integrate install - cd .. - - name: Configure project with CMake and vcpkg - shell: msys2 {0} + cmake --preset default-ninja-clang-windows + cmake --build --preset default-ninja-clang-windows --config Release + - name: Run tests + run: ctest --preset default-vs-msvc-windows + - name: Run engine tests run: | - export VCPKG_DEFAULT_TRIPLET=x64-mingw-static - export VCPKG_DEFAULT_HOST_TRIPLET=x64-mingw-static - mkdir build - cd build - cmake -G "MinGW Makefiles" -DVCPKG_TARGET_TRIPLET=x64-mingw-static -DCMAKE_BUILD_TYPE=Release -DVOXELENGINE_BUILD_WINDOWS_VCPKG=ON .. - cmake --build . --config Release + build/vctest/Release/vctest.exe -e build/Release/VoxelEngine.exe -d dev/tests -u build --output-always + timeout-minutes: 1 - name: Package for Windows run: | mkdir packaged - mkdir packaged/res - cp build/VoxelEngine.exe packaged/ - cp build/vctest/vctest.exe packaged/ - cp build/*.dll packaged/ - cp -r build/res/* packaged/res/ + cp -r build/Release/* packaged/ + cp build/vctest/Release/vctest.exe packaged/ + cp C:/Windows/System32/msvcp140.dll packaged/msvcp140.dll mv packaged/VoxelEngine.exe packaged/VoxelCore.exe - - env: - MSYS2_LOCATION: ${{ steps.msys2.outputs.msys2-location }} - name: Add lua51.dll to the package - run: | - cp $env:MSYS2_LOCATION/clang64/bin/lua51.dll ${{ github.workspace }}/packaged/ working-directory: ${{ github.workspace }} - uses: actions/upload-artifact@v4 with: name: Windows-Build path: 'packaged/*' - - name: Run engine tests - shell: msys2 {0} - working-directory: ${{ github.workspace }} - run: | - packaged/vctest.exe -e packaged/VoxelCore.exe -d dev/tests -u build --output-always diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d417197c9..cc95fe82e 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -21,21 +21,20 @@ jobs: with: submodules: 'true' - - name: Set up vcpkg + - name: Bootstrap vcpkg + shell: pwsh run: | git clone https://github.com/microsoft/vcpkg.git - cd vcpkg - .\bootstrap-vcpkg.bat - .\vcpkg integrate install - cd .. + ${{ 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 + run: ctest --preset default-vs-msvc-windows - name: Run engine tests run: | build/vctest/Release/vctest.exe -e build/Release/VoxelEngine.exe -d dev/tests -u build --output-always @@ -43,11 +42,12 @@ jobs: - name: Package for Windows run: | mkdir packaged - cp -r build/* packaged/ - cp C:/Windows/System32/msvcp140.dll packaged/Release/msvcp140.dll - mv packaged/Release/VoxelEngine.exe packaged/Release/VoxelCore.exe + cp -r build/Release/* packaged/ + cp build/vctest/Release/vctest.exe packaged/ + cp C:/Windows/System32/msvcp140.dll packaged/msvcp140.dll + mv packaged/VoxelEngine.exe packaged/VoxelCore.exe working-directory: ${{ github.workspace }} - uses: actions/upload-artifact@v4 with: name: Windows-Build - path: 'build/Release/*' + path: 'packaged/*' diff --git a/.gitignore b/.gitignore index a1ce6e33c..9056cce5b 100644 --- a/.gitignore +++ b/.gitignore @@ -36,10 +36,6 @@ Debug/voxel_engine AppDir appimage-build/ -# for vcpkg -/vcpkg/ -.gitmodules - # macOS folder attributes *.DS_Store diff --git a/CMakeLists.txt b/CMakeLists.txt index a2415ad97..e3d7c6f82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,11 @@ -option(VOXELENGINE_BUILD_WINDOWS_VCPKG ON) -if(VOXELENGINE_BUILD_WINDOWS_VCPKG AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake") - set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "") -endif() - cmake_minimum_required(VERSION 3.15) project(VoxelEngine) -option(VOXELENGINE_BUILD_APPDIR OFF) -option(VOXELENGINE_BUILD_TESTS OFF) +option(VOXELENGINE_BUILD_APPDIR "" OFF) +option(VOXELENGINE_BUILD_TESTS "" OFF) set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) add_subdirectory(src) add_executable(${PROJECT_NAME} src/main.cpp) @@ -44,31 +40,6 @@ else() endif() endif() -if(VOXELENGINE_BUILD_WINDOWS_VCPKG AND WIN32) - if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/.git") - find_package(Git QUIET) - if(GIT_FOUND) - message(STATUS "Adding vcpkg as a git submodule...") - execute_process(COMMAND ${GIT_EXECUTABLE} submodule add https://github.com/microsoft/vcpkg.git vcpkg WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - else() - message(FATAL_ERROR "Git not found, cannot add vcpkg submodule.") - endif() - endif() - - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/.git") - message(STATUS "Initializing and updating vcpkg submodule...") - execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - execute_process(COMMAND ${CMAKE_COMMAND} -E chdir vcpkg ./bootstrap-vcpkg.bat WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - endif() - - foreach(CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES}) - string(TOUPPER ${CONFIG_TYPE} CONFIG_TYPE_UPPER) - add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${CMAKE_SOURCE_DIR}/res ${CMAKE_BINARY_DIR}/${CONFIG_TYPE_UPPER}/res) - endforeach() -endif() - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie -lstdc++fs") endif() @@ -79,7 +50,14 @@ endif() target_link_libraries(${PROJECT_NAME} VoxelEngineSrc ${CMAKE_DL_LIBS}) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/res DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +# Deploy res to build dir +add_custom_command( + TARGET ${PROJECT_NAME} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different + ${CMAKE_CURRENT_SOURCE_DIR}/res + $/res + ) if (VOXELENGINE_BUILD_TESTS) enable_testing() diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 000000000..e572a4c8e --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,68 @@ +{ + "version": 6, + "configurePresets": [ + { + "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", + "VOXELENGINE_BUILD_TESTS": "ON" + } + }, + { + "name": "default-ninja-clang-windows", + "condition": { + "type": "equals", + "rhs": "${hostSystemName}", + "lhs": "Windows" + }, + "generator": "Ninja Multi-Config", + "binaryDir": "${sourceDir}/build", + "environment": { + "VCPKG_DEFAULT_TRIPLET": "x64-mingw-static", + "VCPKG_DEFAULT_HOST_TRIPLET": "x64-mingw-static" + }, + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "VCPKG_TARGET_TRIPLET": "x64-mingw-static", + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang", + "VOXELENGINE_BUILD_TESTS": "ON" + } + } + ], + "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" + } + ], + "testPresets": [ + { + "name": "default-vs-msvc-windows", + "configurePreset": "default-vs-msvc-windows", + "output": { + "outputOnFailure": true + } + }, + { + "name": "default-ninja-clang-windows", + "configurePreset": "default-ninja-clang-windows", + "output": { + "outputOnFailure": true + } + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 418d372cb..e31e1436f 100644 --- a/README.md +++ b/README.md @@ -108,28 +108,32 @@ cmake --build . >[!NOTE] > Requirement: > -> vcpkg, CMake +> vcpkg, CMake, Git +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**: +```PowerShell +$env:VCPKG_ROOT = "C:\path\to\vcpkg" +$env:PATH = "$env:VCPKG_ROOT;$env:PATH" +``` +>[!TIP] +>For troubleshooting you can read full [documentation](https://learn.microsoft.com/ru-ru/vcpkg/get_started/get-started?pivots=shell-powershell) for **vcpkg** -```sh +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 -DVOXELENGINE_BUILD_WINDOWS_VCPKG=ON .. -del CMakeCache.txt -rmdir /s /q CMakeFiles -cmake -DCMAKE_BUILD_TYPE=Release -DVOXELENGINE_BUILD_WINDOWS_VCPKG=ON .. -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 -DVOXELENGINE_BUILD_WINDOWS_VCPKG=ON ..``` - ## Build using Docker ### Step 0. Install docker on your system diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4e8ae3489..34f708061 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,8 +8,6 @@ list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) -option(VOXELENGINE_BUILD_WINDOWS_VCPKG ON) - find_package(OpenGL REQUIRED) find_package(GLEW REQUIRED) find_package(OpenAL REQUIRED) @@ -22,26 +20,19 @@ endif() set(LIBS "") -if (WIN32) - if(VOXELENGINE_BUILD_WINDOWS_VCPKG) - if (MSVC) - set(LUA_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/packages/luajit_x64-windows/lib/lua51.lib") - set(LUA_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg/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(${OPENAL_LIBRARY}) - endif() - find_package(glfw3 REQUIRED) - find_package(glm REQUIRED) - find_package(vorbis REQUIRED) - set(VORBISLIB Vorbis::vorbis Vorbis::vorbisfile) - else() - find_package(Lua REQUIRED) - set(VORBISLIB vorbis vorbisfile) # not tested - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/glfw) - endif() +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + # Use directly linking to lib instead PkgConfig (because pkg-config dont install on windows as default) + # TODO: Do it with findLua. + set(LUA_INCLUDE_DIR "$ENV{VCPKG_ROOT}/packages/luajit_${VCPKG_TARGET_TRIPLET}/include/luajit") + find_package(Lua REQUIRED) + + message(STATUS "LUA Libraries: ${LUA_LIBRARIES}") + message(STATUS "LUA Include Dir: ${LUA_INCLUDE_DIR}") + find_package(glfw3 REQUIRED) + find_package(glm REQUIRED) + find_package(vorbis REQUIRED) + set(VORBISLIB Vorbis::vorbis Vorbis::vorbisfile) + elseif(APPLE) find_package(PkgConfig) pkg_check_modules(LUAJIT REQUIRED luajit) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cbe038a6e..0597d6e47 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,5 +15,16 @@ target_link_libraries( GTest::gtest_main ) +# HACK: copy res to test/ folder for fixing problem compatibility MultiConfig and non +# MultiConfig builds. Delete in future and use only root res folder +# Also this resolve problem with ctests, because it set cwd to CMAKE_CURRENT_BINARY_DIR +add_custom_command( + TARGET ${PROJECT_NAME} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different + ${CMAKE_SOURCE_DIR}/res + ${CMAKE_CURRENT_BINARY_DIR}/res + ) + include(GoogleTest) gtest_discover_tests(${PROJECT_NAME}) diff --git a/test/coders/vec3.cpp b/test/coders/vec3.cpp index cb699bc33..d404e92bd 100644 --- a/test/coders/vec3.cpp +++ b/test/coders/vec3.cpp @@ -5,7 +5,7 @@ TEST(VEC3, Decode) { auto file = std::filesystem::u8path( - "../res/models/block.vec3" + "res/models/block.vec3" ); auto bytes = files::read_bytes_buffer(file); auto model = vec3::load(file.u8string(), bytes);