diff --git a/CMakeLists.txt b/CMakeLists.txt index a56457bd2..0431fff0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,35 @@ -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 "") +option(VOXELENGINE_BUILD_WINDOWS_VCPKG "Run vcpkg when build for windows" ON) +if(VOXELENGINE_BUILD_WINDOWS_VCPKG AND EXISTS "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake") + set(CMAKE_TOOLCHAIN_FILE "${CMAKE_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) + +# Need be at begin CMakeLists, for install vcpkg and dependencies +if(VOXELENGINE_BUILD_WINDOWS_VCPKG AND WIN32) + if(NOT EXISTS "${CMAKE_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() +endif() add_subdirectory(src) add_executable(${PROJECT_NAME} src/voxel_engine.cpp) @@ -42,21 +62,6 @@ else() 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) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 000000000..9dfcd053b --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,9 @@ +{ + "version": 9, + "configurePresets": [ + { + "name": "default", + "binaryDir": "${sourceDir}/build" + } + ] +} \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7eecaef99..e838f9cb6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,8 +8,6 @@ list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/voxel_engine.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,8 +20,8 @@ endif() if (WIN32) if(VOXELENGINE_BUILD_WINDOWS_VCPKG) - 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") + set(LUA_LIBRARIES "${CMAKE_SOURCE_DIR}/vcpkg/packages/luajit_x64-windows/lib/lua51.lib") + set(LUA_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/vcpkg/packages/luajit_x64-windows/include/luajit") find_package(glfw3 REQUIRED) find_package(glm REQUIRED) find_package(vorbis REQUIRED)