diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 2942ee9a..3af2ee8b 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -17,12 +17,7 @@ jobs: - name: Install dependencies from brew run: | - brew install glfw3 glew libpng openal-soft luajit libvorbis skypjack/entt/entt googletest - - - name: Install specific version of GLM - run: | - curl -O https://raw.githubusercontent.com/Homebrew/homebrew-core/5c7655a866646aa4b857c002b8ae5465b9d26f65/Formula/g/glm.rb - brew install --formula glm.rb + brew install glfw3 glew libpng openal-soft luajit libvorbis skypjack/entt/entt googletest glm - name: Configure run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DVOXELENGINE_BUILD_TESTS=ON -DVOXELENGINE_BUILD_APPDIR=1 diff --git a/.github/workflows/windows-clang.yml b/.github/workflows/windows-clang.yml index 7722ce4e..1356149f 100644 --- a/.github/workflows/windows-clang.yml +++ b/.github/workflows/windows-clang.yml @@ -28,9 +28,7 @@ jobs: 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-cmake git - name: Set up vcpkg shell: msys2 {0} @@ -41,11 +39,12 @@ jobs: ./vcpkg integrate install cd .. - name: Configure project with CMake and vcpkg + env: + VCPKG_DEFAULT_TRIPLET: x64-mingw-static + VCPKG_DEFAULT_HOST_TRIPLET: x64-mingw-static shell: msys2 {0} run: | - export VCPKG_DEFAULT_TRIPLET=x64-mingw-static - export VCPKG_DEFAULT_HOST_TRIPLET=x64-mingw-static - export VCPKG_ROOT=./vcpkg + export VCPKG_ROOT=$(pwd)/vcpkg mkdir build cd build cmake -G "MinGW Makefiles" -DVCPKG_TARGET_TRIPLET=x64-mingw-static -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake .. diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f773002..f64a574e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,84 +1,47 @@ cmake_minimum_required(VERSION 3.26) project(VoxelEngine) -option(VOXELENGINE_BUILD_APPDIR "" OFF) -option(VOXELENGINE_BUILD_TESTS "" OFF) - set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +execute_process(COMMAND ${CMAKE_COMMAND} --version) + +option(VOXELENGINE_BUILD_APPDIR "Pack linux build" OFF) +option(VOXELENGINE_BUILD_TESTS "Build tests" OFF) + +# Need for static compilation on Windows with MSVC clang TODO: Make single build +# on Windows to avoid dependence on combinations of platforms and compilers and +# make it independent if(CMAKE_SYSTEM_NAME STREQUAL "Windows") # We use two types linking: for clang build is static (vcpkg triplet # x64-windows-static) and for msvc build is dynamic linking (vcpkg triplet # x64-windows) By default CMAKE_MSVC_RUNTIME_LIBRARY set by # MultiThreaded$<$:Debug>DLL if(VCPKG_TARGET_TRIPLET MATCHES "static") + # Need for MSVC clang set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") endif() endif() add_subdirectory(src) -add_executable(${PROJECT_NAME} src/main.cpp) -target_include_directories(${PROJECT_NAME} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) +add_executable(VoxelEngine src/main.cpp) if(VOXELENGINE_BUILD_APPDIR) include(${CMAKE_CURRENT_SOURCE_DIR}/dev/cmake/BuildAppdir.cmake) endif() -if(MSVC) - if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE - Release - CACHE STRING "Build type" FORCE) - endif() - if((CMAKE_BUILD_TYPE EQUAL "Release") OR (CMAKE_BUILD_TYPE EQUAL - "RelWithDebInfo")) - target_compile_options(${PROJECT_NAME} PRIVATE /W4 /MT /O2) - else() - target_compile_options(${PROJECT_NAME} PRIVATE /W4) - endif() - set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} /source-charset:UTF-8 /D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR" - ) -else() - target_compile_options( - ${PROJECT_NAME} - PRIVATE -Wall - -Wextra - # additional warnings - -Wformat-nonliteral - -Wcast-align - -Wpointer-arith - -Wundef - -Wwrite-strings - -Wno-unused-parameter) - if(CMAKE_BUILD_TYPE MATCHES "Debug") - target_compile_options(${PROJECT_NAME} PRIVATE -Og) - endif() - if(WIN32) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") - endif() -endif() +target_link_libraries(VoxelEngine PRIVATE VoxelEngineSrc + $<$:winmm>) -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie") -endif() - -if(WIN32) - target_link_libraries(${PROJECT_NAME} VoxelEngineSrc winmm) -endif() - -target_link_libraries(${PROJECT_NAME} VoxelEngineSrc ${CMAKE_DL_LIBS}) +target_link_options(VoxelEngine PRIVATE $<$:-no-pie>) # Deploy res to build dir add_custom_command( - TARGET ${PROJECT_NAME} + TARGET VoxelEngine POST_BUILD - COMMAND - ${CMAKE_COMMAND} -E copy_directory_if_different - ${CMAKE_CURRENT_SOURCE_DIR}/res $/res) + 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 index d4c6aa47..bc81fc91 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -14,6 +14,34 @@ "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", "VOXELENGINE_BUILD_TESTS": "ON" } + }, + { + "name": "default-ninja-gnu-linux", + "condition": { + "type": "equals", + "rhs": "${hostSystemName}", + "lhs": "Linux" + }, + "generator": "Ninja Multi-Config", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "VOXELENGINE_BUILD_TESTS": "ON", + "VOXELENGINE_BUILD_APPDIR": "ON" + } + }, + { + "name": "default-ninja-clang-macos", + "condition": { + "type": "equals", + "rhs": "${hostSystemName}", + "lhs": "Darwin" + }, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "VOXELENGINE_BUILD_TESTS": "ON", + "VOXELENGINE_BUILD_APPDIR": "ON" + } } ], "buildPresets": [ @@ -21,6 +49,16 @@ "name": "default-vs-msvc-windows", "configurePreset": "default-vs-msvc-windows", "configuration": "Debug" + }, + { + "name": "default-ninja-gnu-linux", + "configurePreset": "default-ninja-gnu-linux", + "configuration": "Debug" + }, + { + "name": "default-ninja-clang-macos", + "configurePreset": "default-ninja-clang-macos", + "configuration": "Debug" } ], "testPresets": [ @@ -30,6 +68,20 @@ "output": { "outputOnFailure": true } + }, + { + "name": "default-ninja-gnu-linux", + "configurePreset": "default-ninja-gnu-linux", + "output": { + "outputOnFailure": true + } + }, + { + "name": "default-ninja-clang-macos", + "configurePreset": "default-ninja-clang-macos", + "output": { + "outputOnFailure": true + } } ] } \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 09d3d0c8..8a97d2fc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,87 +1,122 @@ project(VoxelEngineSrc) -set(CMAKE_CXX_STANDARD 17) +file(GLOB_RECURSE headers ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp) +file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +list(REMOVE_ITEM sources ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) -file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp) -file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) -list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) - -add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS}) +add_library(VoxelEngineSrc STATIC ${sources} ${headers}) find_package(OpenGL REQUIRED) find_package(GLEW REQUIRED) +find_package(glm REQUIRED) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") # specific for vcpkg find_package(OpenAL CONFIG REQUIRED) - set(OPENAL_LIBRARY OpenAL::OpenAL) else() find_package(OpenAL REQUIRED) endif() find_package(ZLIB REQUIRED) find_package(PNG REQUIRED) find_package(CURL REQUIRED) +find_package(glfw3 REQUIRED) if(NOT APPLE) find_package(EnTT REQUIRED) endif() -set(LIBS "") - 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. - if(MSVC) - set(LUA_INCLUDE_DIR - "$ENV{VCPKG_ROOT}/packages/luajit_${VCPKG_TARGET_TRIPLET}/include/luajit" - ) - find_package(Lua REQUIRED) - else() - # Used for mingw-clang cross compiling from msys2 - set(LIBS ${LIBS} luajit-5.1) - endif() - find_package(glfw3 REQUIRED) - find_package(glm REQUIRED) find_package(vorbis REQUIRED) - set(VORBISLIB Vorbis::vorbis Vorbis::vorbisfile) + if(VCPKG_TARGET_TRIPLET MATCHES "static") + add_library(luajit STATIC IMPORTED) + set_target_properties( + luajit + PROPERTIES + IMPORTED_LOCATION + "$ENV{VCPKG_ROOT}/packages/luajit_${VCPKG_TARGET_TRIPLET}/lib/libluajit-5.1.a" + INTERFACE_INCLUDE_DIRECTORIES + "$ENV{VCPKG_ROOT}/packages/luajit_${VCPKG_TARGET_TRIPLET}/include/" + ) + else() + add_library(luajit SHARED IMPORTED) + set_target_properties( + luajit + PROPERTIES + IMPORTED_LOCATION + "$ENV{VCPKG_ROOT}/packages/luajit_${VCPKG_TARGET_TRIPLET}/bin/lua51.dll" + IMPORTED_IMPLIB + "$ENV{VCPKG_ROOT}/packages/luajit_${VCPKG_TARGET_TRIPLET}/lib/lua51.lib" + INTERFACE_INCLUDE_DIRECTORIES + "$ENV{VCPKG_ROOT}/packages/luajit_${VCPKG_TARGET_TRIPLET}/include/luajit" + ) + endif() -elseif(APPLE) - find_package(PkgConfig) - pkg_check_modules(LUAJIT REQUIRED luajit) - pkg_check_modules(VORBIS REQUIRED vorbis vorbisfile) - set(LUA_INCLUDE_DIR "/opt/homebrew/include/luajit-2.1") - set(LUA_LIBRARIES "/opt/homebrew/lib/libluajit-5.1.a") - message(STATUS "LUA Libraries: ${LUA_LIBRARIES}") - message(STATUS "LUA Include Dir: ${LUA_INCLUDE_DIR}") - - set(VORBISLIB ${VORBIS_LDFLAGS}) - message(STATUS "Vorbis Lib: ${VORBIS_LDFLAGS}") + add_library(luajit::luajit ALIAS luajit) else() find_package(PkgConfig) - pkg_check_modules(LUAJIT REQUIRED luajit) - pkg_check_modules(VORBIS REQUIRED vorbis vorbisfile) - set(LUA_LIBRARIES ${LUAJIT_LIBRARIES}) - set(LUA_INCLUDE_DIR ${LUAJIT_INCLUDE_DIRS}) - set(VORBISLIB ${VORBIS_LDFLAGS}) + + pkg_check_modules(luajit REQUIRED IMPORTED_TARGET luajit) + pkg_check_modules(vorbis REQUIRED IMPORTED_TARGET vorbis) + pkg_check_modules(vorbisfile REQUIRED IMPORTED_TARGET vorbisfile) + add_library(Vorbis::vorbis ALIAS PkgConfig::vorbis) + add_library(Vorbis::vorbisfile ALIAS PkgConfig::vorbisfile) + add_library(luajit::luajit ALIAS PkgConfig::luajit) endif() -if(UNIX) - find_package(glfw3 3.3 REQUIRED) - find_package(Threads REQUIRED) - set(LIBS ${LIBS} Threads::Threads) -endif() +target_include_directories(VoxelEngineSrc PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${LUA_INCLUDE_DIR}) -include_directories(${CURL_INCLUDE_DIR}) -target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries( - ${PROJECT_NAME} - ${LIBS} - glfw - OpenGL::GL - ${OPENAL_LIBRARY} - GLEW::GLEW - ZLIB::ZLIB - PNG::PNG - CURL::libcurl - ${VORBISLIB} - ${LUA_LIBRARIES} - ${CMAKE_DL_LIBS}) + VoxelEngineSrc + PRIVATE glfw + OpenGL::GL + GLEW::GLEW + ZLIB::ZLIB + PNG::PNG + CURL::libcurl + OpenAL::OpenAL + Vorbis::vorbis + Vorbis::vorbisfile + luajit::luajit + PUBLIC glm::glm # Need public for src/delegates.hpp, which including to + # main.cpp +) + +target_compile_options( + VoxelEngineSrc + PUBLIC $<$: + /utf-8 + /MP + /D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR + /W4 + /wd4244 # conversion from 'a' to 'T', possible loss of data + /wd4267 # conversion from 'size_t' to 'int', possible loss of data + /wd4245 # conversion from 'int' to 'const size_t', signed/unsigned + # mismatch + /wd4100 # unreferenced formal parameter + /wd4458 # declaration of 'var' hides class member + /wd4101 # 'var': unreferenced local variable + /wd4388 # 'token' : signed/unsigned mismatch + /wd4018 # '>': signed/unsigned mismatch + > + $<$>: + -Wall + -Wextra + # additional warnings + -Wformat-nonliteral + -Wcast-align + -Wpointer-arith + -Wundef + -Wwrite-strings + -Wno-unused-parameter + -Wno-sign-compare + $<$:-Og> + >) + +target_link_options( + VoxelEngineSrc + PUBLIC + $<$: + -no-pie + > + # Need for static compilation on Windows with clang TODO: Make single build + # on Windows to avoid dependence on combinations of platforms and compilers + # and make it independent + $<$:$<$:-static>>) diff --git a/src/content/loading/GeneratorLoader.cpp b/src/content/loading/GeneratorLoader.cpp index 99ffde50..a845bc21 100644 --- a/src/content/loading/GeneratorLoader.cpp +++ b/src/content/loading/GeneratorLoader.cpp @@ -7,6 +7,7 @@ #include "io/io.hpp" #include "io/engine_paths.hpp" #include "logic/scripting/scripting.hpp" +#include "util/stringutil.hpp" #include "world/generator/GeneratorDef.hpp" #include "world/generator/VoxelFragment.hpp" #include "debug/Logger.hpp" diff --git a/src/graphics/ui/elements/Label.cpp b/src/graphics/ui/elements/Label.cpp index 9a174c74..ace5e507 100644 --- a/src/graphics/ui/elements/Label.cpp +++ b/src/graphics/ui/elements/Label.cpp @@ -1,12 +1,13 @@ #include "Label.hpp" #include + +#include "assets/Assets.hpp" #include "graphics/core/DrawContext.hpp" #include "graphics/core/Batch2D.hpp" #include "graphics/core/Font.hpp" -#include "assets/Assets.hpp" +#include "graphics/ui/markdown.hpp" #include "util/stringutil.hpp" -#include "../markdown.hpp" using namespace gui; diff --git a/src/graphics/ui/elements/TextBox.cpp b/src/graphics/ui/elements/TextBox.cpp index 96d9ea01..220073dc 100644 --- a/src/graphics/ui/elements/TextBox.cpp +++ b/src/graphics/ui/elements/TextBox.cpp @@ -1,15 +1,16 @@ #include "TextBox.hpp" +#include #include #include -#include #include "Label.hpp" -#include "devtools/syntax_highlighting.hpp" -#include "graphics/core/DrawContext.hpp" -#include "graphics/core/Batch2D.hpp" -#include "graphics/core/Font.hpp" #include "assets/Assets.hpp" +#include "devtools/syntax_highlighting.hpp" +#include "graphics/core/Batch2D.hpp" +#include "graphics/core/DrawContext.hpp" +#include "graphics/core/Font.hpp" +#include "graphics/ui/markdown.hpp" #include "util/stringutil.hpp" #include "window/Events.hpp" #include "window/Window.hpp" diff --git a/src/util/HandlersList.hpp b/src/util/HandlersList.hpp index 45882512..9cda6572 100644 --- a/src/util/HandlersList.hpp +++ b/src/util/HandlersList.hpp @@ -1,15 +1,15 @@ #pragma once -#include -#include #include +#include #include +#include -#include "typedefs.hpp" #include "delegates.hpp" +#include "typedefs.hpp" namespace util { - template + template class HandlersList { int nextid = 1; std::unordered_map> handlers; @@ -35,7 +35,7 @@ namespace util { int id = nextid++; handlers[id] = std::move(handler); order.push_back(id); - return observer_handler(new int(id), [this](int* id) { //-V508 + return observer_handler(new int(id), [this](int* id) { //-V508 std::lock_guard lock(mutex); handlers.erase(*id); order.erase( @@ -45,7 +45,7 @@ namespace util { }); } - void notify(Types...args) { + void notify(Types... args) { std::vector orderCopy; decltype(handlers) handlersCopy; { diff --git a/src/voxels/blocks_agent.hpp b/src/voxels/blocks_agent.hpp index 3bee3685..34fde035 100644 --- a/src/voxels/blocks_agent.hpp +++ b/src/voxels/blocks_agent.hpp @@ -13,6 +13,7 @@ #include "content/Content.hpp" #include "maths/voxmaths.hpp" +#include #include #include #include diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index df2d1e17..e2aae2a7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,26 +1,22 @@ project(VoxelEngineTest) -set(CMAKE_CXX_STANDARD 17) - -file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) find_package(GTest) -add_executable(${PROJECT_NAME} ${SOURCES}) +add_executable(VoxelEngineTest ${sources}) -target_include_directories(${PROJECT_NAME} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src) -target_link_libraries(${PROJECT_NAME} VoxelEngineSrc GTest::gtest_main) +target_link_libraries(VoxelEngineTest PRIVATE VoxelEngineSrc 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 +# ${CMAKE_CURRENT_BINARY_DIR} add_custom_command( - TARGET ${PROJECT_NAME} + TARGET VoxelEngineTest 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}) +gtest_discover_tests(VoxelEngineTest) diff --git a/test/coders/lua_parsing.cpp b/test/coders/lua_parsing.cpp index 86f3f415..dcfaeffc 100644 --- a/test/coders/lua_parsing.cpp +++ b/test/coders/lua_parsing.cpp @@ -1,7 +1,8 @@ +#include "coders/lua_parsing.hpp" + #include #include "coders/commons.hpp" -#include "coders/lua_parsing.hpp" #include "io/io.hpp" #include "io/devices/StdfsDevice.hpp" #include "util/stringutil.hpp" diff --git a/vctest/CMakeLists.txt b/vctest/CMakeLists.txt index 6f195fe9..70a65ef2 100644 --- a/vctest/CMakeLists.txt +++ b/vctest/CMakeLists.txt @@ -1,42 +1,22 @@ project(vctest) -set(CMAKE_CXX_STANDARD 17) +add_executable(vctest ${CMAKE_CURRENT_LIST_DIR}/main.cpp) -file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) +# Needed for header-only source util/ArgsReader.hpp +target_include_directories(vctest PRIVATE ${CMAKE_SOURCE_DIR}/src) -add_executable(${PROJECT_NAME} ${SOURCES}) +target_compile_options( + vctest + PRIVATE $<$:/W4> + $<$>: + -Wall + -Wextra + -Wformat-nonliteral + -Wcast-align + -Wpointer-arith + -Wundef + -Wwrite-strings + -Wno-unused-parameter + >) -if(MSVC) - if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE - Release - CACHE STRING "Build type" FORCE) - endif() - if((CMAKE_BUILD_TYPE EQUAL "Release") OR (CMAKE_BUILD_TYPE EQUAL - "RelWithDebInfo")) - set(CMAKE_MSVC_RUNTIME_LIBRARY - "MultiThreaded$<$:Release>") - target_compile_options(${PROJECT_NAME} PRIVATE /W4 /MT /O2) - else() - target_compile_options(${PROJECT_NAME} PRIVATE /W4) - endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -else() - target_compile_options( - ${PROJECT_NAME} - PRIVATE -Wall - -Wextra - -Wformat-nonliteral - -Wcast-align - -Wpointer-arith - -Wundef - -Wwrite-strings - -Wno-unused-parameter) -endif() - -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie") -endif() - -target_include_directories( - ${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_DL_LIBS}) +target_link_options(vctest PRIVATE $<$:-no-pie>)