Onyx-Engine/CMakeLists.txt
2025-05-18 13:29:55 -05:00

133 lines
3.4 KiB
CMake

cmake_minimum_required(VERSION 3.16)
project(CreatePBR VERSION 0.1.0 LANGUAGES C CXX)
# Build type (for single-config generators like Make/Ninja)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the build type (Debug or Release)" FORCE)
endif()
# Language standards
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
# --- Output directories for multi-config builds ---
foreach(OUTPUTCONFIG IN ITEMS Debug Release)
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG_UPPER)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${CMAKE_BINARY_DIR}/bin/${OUTPUTCONFIG})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${CMAKE_BINARY_DIR}/lib/${OUTPUTCONFIG})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${CMAKE_BINARY_DIR}/lib/${OUTPUTCONFIG})
endforeach()
# --- External Libraries ---
include(FetchContent)
# GLFW
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw.git
GIT_TAG latest
)
FetchContent_MakeAvailable(glfw)
# Assimp
FetchContent_Declare(
assimp
GIT_REPOSITORY https://github.com/assimp/assimp.git
GIT_TAG master
)
set(ASSIMP_NO_EXPORT ON CACHE BOOL "" FORCE)
set(ASSIMP_BUILD_ASSIMP_TOOLS OFF CACHE BOOL "" FORCE)
set(ASSIMP_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(ASSIMP_BUILD_SAMPLES OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(assimp)
# ImGui (Docking)
FetchContent_Declare(
imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG docking
)
FetchContent_MakeAvailable(imgui)
# Required packages
find_package(yaml-cpp REQUIRED)
find_package(GLEW REQUIRED)
# --- ImGui Static Library ---
add_library(ImGui STATIC
${imgui_SOURCE_DIR}/imgui.cpp
${imgui_SOURCE_DIR}/imgui_draw.cpp
${imgui_SOURCE_DIR}/imgui_demo.cpp
${imgui_SOURCE_DIR}/imgui_tables.cpp
${imgui_SOURCE_DIR}/imgui_widgets.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp
)
target_include_directories(ImGui PUBLIC
${imgui_SOURCE_DIR}
${imgui_SOURCE_DIR}/backends
)
target_compile_definitions(ImGui PUBLIC
IMGUI_IMPL_OPENGL_LOADER_GLEW
)
# --- Core Engine Library ---
file(GLOB_RECURSE CORE_SOURCES CONFIGURE_DEPENDS
src/core/*.cpp
src/core/*.h
)
add_library(Core STATIC
${CORE_SOURCES}
src/core/systems/MACROS.h
)
target_include_directories(Core PUBLIC src/core)
# Add _DEBUG define only for debug builds
target_compile_definitions(Core PRIVATE
$<$<CONFIG:Debug>:_DEBUG>
)
# --- Editor Executable ---
file(GLOB_RECURSE APP_SOURCES CONFIGURE_DEPENDS
src/editor/*.cpp
src/editor/*.h
)
add_executable(Editor ${APP_SOURCES}
main.cpp
src/editor/Editor.cpp
src/editor/Editor.h
src/editor/Windows/LoggerWindow.cpp
src/editor/Windows/LoggerWindow.h
)
target_include_directories(Editor PRIVATE
src/editor
src/core
)
target_link_libraries(Editor PRIVATE
Core
ImGui
glfw
assimp::assimp
GLEW::GLEW
${CMAKE_DL_LIBS}
)
target_compile_definitions(Editor PRIVATE
$<$<CONFIG:Debug>:_DEBUG>
)
# --- Install ---
install(TARGETS Editor RUNTIME DESTINATION bin)