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

Fix usage vcpkg for windows and add cmake preset for vscode #414

Open
wants to merge 30 commits into
base: headless-mode
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ea23ed2
add cmake presets
Dec 14, 2024
dccda99
Fix usage vcpkg for windows and fix readme, remove vcpkg usage flag f…
Dec 14, 2024
7547152
Fix resources linking
Dec 14, 2024
326630e
Check config working
Dec 14, 2024
9c53cd3
undo
Dec 14, 2024
dd09e3f
Cleanup
Dec 14, 2024
75f5a47
Merge branch 'MihailRis:main' into Fix-usage-vcpkg-for-windows-and-ad…
Ygrik2003 Dec 20, 2024
3b96c13
Merge branch 'headless-mode' into Fix-usage-vcpkg-for-windows-and-add…
Dec 20, 2024
cd4948c
Merge branch 'Fix-usage-vcpkg-for-windows-and-add-cmake-preset-for-vs…
Dec 20, 2024
84887d2
Refactoring CmakePresets for windows github actions and refactoring R…
Dec 20, 2024
c8c5b45
Try fix builds on agents
Dec 20, 2024
6863282
Fix ctests
Dec 20, 2024
9fe3f9a
HACK: use dot for get path to vcpkg on MSYS2
Dec 20, 2024
6155d6f
fix triplet for windows
Ygrik2003 Dec 21, 2024
8c4d0dc
Fix ctests
Ygrik2003 Dec 21, 2024
b16c77c
Fix vcpkg for msys2 again
Ygrik2003 Dec 21, 2024
b81dab3
Fix luajit linking for clang
Ygrik2003 Dec 21, 2024
fdcc5b6
Remove relative path
Ygrik2003 Dec 21, 2024
8854389
Fix resources
Ygrik2003 Dec 21, 2024
2229cd5
Fix ctest
Dec 21, 2024
d0e8f43
Fix lua linking
Dec 21, 2024
e34a7bb
Fik lib ext for clang
Dec 21, 2024
b458df4
Fik lib luajit
Dec 22, 2024
d699764
Refactoring and try move to pwsh for clang
Dec 22, 2024
5eab58f
Fix comment
Dec 22, 2024
d889b79
Try remove maybe unused code
Dec 22, 2024
a14e7c1
Refactoring
Dec 22, 2024
fa1d450
Return latest ninja and cmake installing
Dec 22, 2024
0e02451
Review fixes: Fix path loading to artifactory
Dec 22, 2024
a0a32ce
Fix res folder deploy
Dec 22, 2024
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
64 changes: 23 additions & 41 deletions .github/workflows/windows-clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 14 additions & 14 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,33 @@ 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
timeout-minutes: 1
- 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/*'
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ Debug/voxel_engine
AppDir
appimage-build/

# for vcpkg
/vcpkg/
.gitmodules

# macOS folder attributes
*.DS_Store

Expand Down
44 changes: 11 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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
$<TARGET_FILE_DIR:${PROJECT_NAME}>/res
)

if (VOXELENGINE_BUILD_TESTS)
enable_testing()
Expand Down
63 changes: 63 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"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",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"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
}
}
]
}
38 changes: 21 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 13 additions & 22 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
2 changes: 1 addition & 1 deletion test/coders/vec3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down