engine/CMakeLists.txt

221 lines
6.4 KiB
CMake
Raw Normal View History

2022-11-08 15:34:59 +00:00
cmake_minimum_required(VERSION 3.24)
2022-09-02 11:06:59 +00:00
2024-01-31 16:30:48 +00:00
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
2022-09-02 11:06:59 +00:00
# options
2022-11-07 20:15:26 +00:00
option(ENGINE_BUILD_TEST "Compile the test program" ON)
2024-07-29 17:58:33 +00:00
if (MSVC)
option(ENGINE_HOT_RELOAD "Enable VS hot reload" OFF)
endif()
2022-09-02 11:06:59 +00:00
2024-06-04 18:01:49 +00:00
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo")
2023-03-12 20:39:11 +00:00
2024-04-27 22:56:59 +00:00
# enable link time code generation for all targets in the solution
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
2023-12-12 09:56:37 +00:00
project(engine LANGUAGES CXX C
2024-03-19 11:58:40 +00:00
VERSION "0.2.0"
2022-09-02 11:06:59 +00:00
)
2023-05-09 08:47:52 +00:00
# from command: find . -regex "^\.\/.*" | sort
2022-10-23 19:26:42 +00:00
set(SRC_FILES
2023-05-09 08:47:52 +00:00
"src/application.cpp"
"src/application_component.cpp"
2023-09-19 07:40:45 +00:00
"src/ecs.cpp"
2024-06-04 18:01:49 +00:00
"src/file_dialog.cpp"
"src/files.cpp"
"src/gen_tangents.cpp"
2024-06-04 22:31:22 +00:00
"src/gfx_device.cpp"
2024-06-04 18:01:49 +00:00
"src/gltf_loader.cpp"
2023-05-09 08:47:52 +00:00
"src/input_manager.cpp"
"src/renderer.cpp"
2024-06-01 22:03:39 +00:00
"src/resource_font.cpp"
"src/resource_material.cpp"
"src/resource_mesh.cpp"
"src/resource_shader.cpp"
"src/resource_texture.cpp"
2023-05-09 08:47:52 +00:00
"src/scene.cpp"
"src/scene_manager.cpp"
2024-06-01 22:03:39 +00:00
"src/system_collisions.cpp"
"src/system_custom_behaviour.cpp"
"src/system_mesh_render.cpp"
"src/system_transform.cpp"
"src/vulkan_allocator.cpp"
2024-06-04 18:01:49 +00:00
"src/vulkan_device.cpp"
2024-06-01 22:03:39 +00:00
"src/vulkan_instance.cpp"
"src/vulkan_swapchain.cpp"
2023-05-09 08:47:52 +00:00
"src/window.cpp"
2024-06-01 22:03:39 +00:00
)
2022-09-13 18:25:18 +00:00
2022-10-23 19:26:42 +00:00
set(INCLUDE_FILES
2023-05-09 08:47:52 +00:00
"include/application.h"
"include/application_component.h"
2024-06-01 22:03:39 +00:00
"include/component_collider.h"
"include/component_custom.h"
"include/component_mesh.h"
"include/component_transform.h"
2024-06-04 18:01:49 +00:00
"include/debug_line.h"
2023-09-19 07:40:45 +00:00
"include/ecs.h"
2024-06-04 18:01:49 +00:00
"include/entity.h"
2023-05-09 08:47:52 +00:00
"include/event_system.h"
2024-06-04 18:01:49 +00:00
"include/file_dialog.h"
"include/files.h"
"include/gen_tangents.h"
2023-05-09 08:47:52 +00:00
"include/gfx.h"
"include/gfx_device.h"
2024-06-04 18:01:49 +00:00
"include/gltf_loader.h"
2024-06-01 22:03:39 +00:00
"include/input_keys.h"
2024-06-04 18:01:49 +00:00
"include/input_manager.h"
2024-06-01 22:03:39 +00:00
"include/input_mouse.h"
2023-05-09 08:47:52 +00:00
"include/log.h"
"include/logger.h"
"include/renderer.h"
2024-06-01 22:03:39 +00:00
"include/resource_font.h"
2024-06-04 18:01:49 +00:00
"include/resource_manager.h"
2024-06-01 22:03:39 +00:00
"include/resource_material.h"
"include/resource_mesh.h"
"include/resource_shader.h"
"include/resource_texture.h"
2023-05-09 08:47:52 +00:00
"include/scene.h"
"include/scene_manager.h"
2024-06-01 22:03:39 +00:00
"include/system_collisions.h"
"include/system_custom_behaviour.h"
"include/system_mesh_render.h"
"include/system_transform.h"
2023-05-09 08:47:52 +00:00
"include/util.h"
2024-06-04 18:01:49 +00:00
"include/vulkan_allocator.h"
"include/vulkan_device.h"
"include/vulkan_instance.h"
"include/vulkan_swapchain.h"
2023-05-09 08:47:52 +00:00
"include/window.h"
2024-06-01 22:03:39 +00:00
)
2022-10-23 19:26:42 +00:00
add_library(${PROJECT_NAME} STATIC
${SRC_FILES}
${INCLUDE_FILES}
2024-01-31 16:30:48 +00:00
${RES_FILES}
2022-10-23 19:26:42 +00:00
)
2024-06-04 18:01:49 +00:00
# show game engine resources in VS generated solution explorer
file(GLOB_RECURSE RES_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/res/engine/*")
# Organise files in VS generated solution explorer
2022-10-23 19:26:42 +00:00
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "Source" FILES ${SRC_FILES})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/include" PREFIX "Include" FILES ${INCLUDE_FILES})
2024-01-31 16:30:48 +00:00
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/res/engine" PREFIX "Resources" FILES ${RES_FILES})
2022-10-23 19:26:42 +00:00
2022-09-02 11:06:59 +00:00
# compiling options:
if (WIN32)
target_compile_definitions(${PROJECT_NAME} PRIVATE DEFINITIONS "NOMINMAX") # stop windows.h conflicting with 'std::max'
endif()
2024-06-04 18:01:49 +00:00
# This project uses C++20 and C11
2022-09-02 11:06:59 +00:00
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
2023-02-18 17:11:35 +00:00
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_EXTENSIONS OFF)
2023-12-12 09:56:37 +00:00
set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 11)
2023-02-18 17:11:35 +00:00
set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD_REQUIRED ON)
set_property(TARGET ${PROJECT_NAME} PROPERTY C_EXTENSIONS OFF)
2022-09-02 11:06:59 +00:00
2024-07-29 17:58:33 +00:00
# compiler warnings
2022-09-02 11:06:59 +00:00
if (MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W3)
2022-09-02 23:02:09 +00:00
target_compile_options(${PROJECT_NAME} PRIVATE /MP)
target_compile_definitions(${PROJECT_NAME} PRIVATE _CRT_SECURE_NO_WARNINGS)
2023-01-05 13:21:33 +00:00
else()
2023-12-12 09:56:37 +00:00
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic)
2022-09-02 11:06:59 +00:00
endif()
2024-07-29 17:58:33 +00:00
if (MSVC AND ENGINE_HOT_RELOAD)
target_compile_options(${PROJECT_NAME} PRIVATE /ZI)
target_link_options(${PROJECT_NAME} PRIVATE /INCREMENTAL)
endif()
2022-09-02 11:06:59 +00:00
target_include_directories(${PROJECT_NAME} PUBLIC include)
target_include_directories(${PROJECT_NAME} PRIVATE src)
# Pass some project information into the source code
configure_file(config.h.in config.h)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
2022-09-02 11:06:59 +00:00
2022-11-07 20:15:26 +00:00
# Build the test
if (ENGINE_BUILD_TEST)
add_subdirectory(test)
2024-06-04 18:01:49 +00:00
# Copy DLLs to the enginetest.exe folder (I think that's what this does?)
2022-11-07 20:15:26 +00:00
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:enginetest>)
2024-06-04 18:01:49 +00:00
# Set enginetest.exe as the default startup project in VS
2023-10-02 11:54:37 +00:00
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT enginetest)
2022-11-07 20:15:26 +00:00
endif()
2022-09-07 09:02:01 +00:00
2023-05-09 08:47:52 +00:00
# private libraries:
2022-09-02 11:06:59 +00:00
# Volk
set(VOLK_STATIC_DEFINES "")
set(VOLK_PULL_IN_VULKAN ON)
set(VOLK_INSTALL OFF)
set(VOLK_HEADERS_ONLY OFF)
if (WIN32)
set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_WIN32_KHR)
endif()
2024-06-02 10:49:09 +00:00
add_subdirectory(vendor/volk)
target_link_libraries(${PROJECT_NAME} PUBLIC volk::volk)
# Vulkan Memory Allocator
2024-06-04 18:01:49 +00:00
add_subdirectory(vendor/VulkanMemoryAllocator)
target_link_libraries(${PROJECT_NAME} PUBLIC VulkanMemoryAllocator)
2024-06-02 10:49:09 +00:00
# shaderc
if (MSVC)
include(FindVulkan)
find_package(Vulkan COMPONENTS shaderc_combined)
2024-06-02 10:49:09 +00:00
target_link_libraries(${PROJECT_NAME} PUBLIC Vulkan::shaderc_combined)
else()
2024-06-02 10:49:09 +00:00
target_link_libraries(${PROJECT_NAME} PUBLIC shaderc_shared)
2022-11-08 13:42:07 +00:00
endif()
2022-10-09 13:57:41 +00:00
2023-05-09 08:47:52 +00:00
# SDL2:
set(SDL2_DISABLE_INSTALL ON CACHE INTERNAL "" FORCE)
set(SDL_SHARED ON CACHE INTERNAL "" FORCE)
set(SDL_STATIC OFF CACHE INTERNAL "" FORCE)
set(SDL_TEST OFF CACHE INTERNAL "" FORCE)
set(BUILD_SHARED_LIBS ON)
2024-06-02 10:49:09 +00:00
add_subdirectory(vendor/SDL)
2023-05-09 08:47:52 +00:00
target_link_libraries(${PROJECT_NAME} PUBLIC SDL2::SDL2)
target_link_libraries(${PROJECT_NAME} PUBLIC SDL2::SDL2main)
# GLM:
set(BUILD_SHARED_LIBS OFF)
2024-06-02 10:49:09 +00:00
add_subdirectory(vendor/glm)
2024-06-04 18:01:49 +00:00
target_link_libraries(${PROJECT_NAME} PUBLIC glm::glm)
2023-05-09 08:47:52 +00:00
# spdlog
2024-06-04 18:01:49 +00:00
set(SPDLOG_BUILD_SHARED OFF)
set(SPDLOG_SYSTEM_INCLUDES ON)
2023-05-09 08:47:52 +00:00
set(BUILD_SHARED_LIBS OFF)
2024-06-04 18:01:49 +00:00
add_subdirectory(vendor/spdlog)
target_link_libraries(${PROJECT_NAME} PUBLIC spdlog::spdlog)
2024-06-02 10:49:09 +00:00
2024-06-02 11:55:04 +00:00
# stb
add_subdirectory(vendor/stb)
target_link_libraries(${PROJECT_NAME} PUBLIC stb)
# imgui (depends on volk, SDL2, and stb)
2024-06-02 10:49:09 +00:00
add_subdirectory(vendor/imgui)
target_link_libraries(${PROJECT_NAME} PUBLIC imgui)
# json
add_subdirectory(vendor/json)
2024-06-02 11:55:04 +00:00
target_link_libraries(${PROJECT_NAME} PUBLIC json)
# tinygltf (depends on json and stb)
add_subdirectory(vendor/tinygltf)
target_link_libraries(${PROJECT_NAME} PUBLIC tinygltf)
# mikktspace
add_subdirectory(vendor/mikktspace)
target_link_libraries(${PROJECT_NAME} PUBLIC mikktspace)
# weldmesh
add_subdirectory(vendor/weldmesh)
target_link_libraries(${PROJECT_NAME} PUBLIC weldmesh)