140 lines
4.8 KiB
CMake
140 lines
4.8 KiB
CMake
# Require a modern version of CMake
|
|
cmake_minimum_required(VERSION 3.15)
|
|
|
|
# Define the workspace/project
|
|
project(SakuraVNE LANGUAGES CXX)
|
|
|
|
# Enforce C++20 globally
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF) # Disables compiler-specific extensions (like gnu++20)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Output Directory Configuration (Mirrors your Premake setup)
|
|
# ------------------------------------------------------------------------------
|
|
# This mimics: build/bin/{Config}-{System}-{Architecture}
|
|
set(OUTPUT_DIR_SUFFIX "$<CONFIG>-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/${OUTPUT_DIR_SUFFIX}")
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/${OUTPUT_DIR_SUFFIX}")
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/${OUTPUT_DIR_SUFFIX}")
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Dependencies
|
|
# ------------------------------------------------------------------------------
|
|
# 1. SDL3
|
|
set(SDL_TESTS OFF CACHE BOOL "Disable SDL3 tests" FORCE)
|
|
set(SDL_EXAMPLES OFF CACHE BOOL "Disable SDL3 examples" FORCE)
|
|
add_subdirectory(libs/sdl3)
|
|
|
|
# 2. spdlog
|
|
set(SPDLOG_BUILD_COMPILED ON CACHE BOOL "Build spdlog as a compiled library" FORCE)
|
|
set(SPDLOG_BUILD_EXAMPLE OFF CACHE BOOL "Disable spdlog examples" FORCE)
|
|
set(SPDLOG_BUILD_TESTS OFF CACHE BOOL "Disable spdlog tests" FORCE)
|
|
add_subdirectory(libs/spdlog)
|
|
|
|
# 3. ImGui & ImGui Node Editor
|
|
add_subdirectory(libs/imgui)
|
|
add_subdirectory(libs/imgui-node-editor)
|
|
|
|
# 4. Catch2
|
|
add_subdirectory(libs/catch2)
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Source Gathering
|
|
# ------------------------------------------------------------------------------
|
|
# Gather all .cpp and .h files in the src folder
|
|
file(GLOB_RECURSE SAKURA_SRCS "SakuraVNE/src/*.cpp" "SakuraVNE/src/*.h")
|
|
|
|
# CRITICAL: Remove main.cpp from the list so Catch2 can provide its own main()
|
|
list(REMOVE_ITEM SAKURA_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/SakuraVNE/src/main.cpp")
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# SakuraVNE Executable Target
|
|
# ------------------------------------------------------------------------------
|
|
# Create the ConsoleApp executable (explicitly adding main.cpp back in here)
|
|
add_executable(SakuraVNE "SakuraVNE/src/main.cpp" ${SAKURA_SRCS})
|
|
|
|
# Tell the compiler where the headers are
|
|
target_include_directories(SakuraVNE PRIVATE
|
|
"SakuraVNE/src"
|
|
"libs/spdlog/include"
|
|
"libs/imgui"
|
|
"libs/imgui/misc"
|
|
"libs/imgui/backends"
|
|
"libs/imgui-node-editor"
|
|
"libs/sdl3/include"
|
|
)
|
|
|
|
# Link the libraries. CMake handles all the libdirs automatically! [cite: 5]
|
|
target_link_libraries(SakuraVNE PRIVATE
|
|
ImGui
|
|
ImGuiNodeEditor
|
|
SDL3::SDL3
|
|
spdlog::spdlog
|
|
)
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Tests Executable Target
|
|
# ------------------------------------------------------------------------------
|
|
# These tests can use the Catch2-provided main, plus ALL your engine source files
|
|
add_executable(tests "SakuraVNE/test/test.cpp" ${SAKURA_SRCS})
|
|
|
|
# The tests need the exact same include directories so your engine #includes work
|
|
target_include_directories(tests PRIVATE
|
|
"SakuraVNE/src"
|
|
"libs/spdlog/include"
|
|
"libs/imgui"
|
|
"libs/imgui/misc"
|
|
"libs/imgui/backends"
|
|
"libs/imgui-node-editor"
|
|
"libs/sdl3/include"
|
|
)
|
|
|
|
# Link Catch2 AND the exact same dependencies your game uses
|
|
target_link_libraries(tests PRIVATE
|
|
Catch2::Catch2WithMain
|
|
ImGui
|
|
ImGuiNodeEditor
|
|
SDL3::SDL3
|
|
spdlog::spdlog
|
|
)
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Platform & Configuration Filters
|
|
# ------------------------------------------------------------------------------
|
|
if(WIN32)
|
|
# Apply to Game
|
|
target_compile_definitions(SakuraVNE PRIVATE PLATFORM_WINDOWS)
|
|
target_link_options(SakuraVNE PRIVATE "/NODEFAULTLIB:MSVCRT")
|
|
|
|
# Apply to Tests
|
|
target_compile_definitions(tests PRIVATE PLATFORM_WINDOWS)
|
|
target_link_options(tests PRIVATE "/NODEFAULTLIB:MSVCRT")
|
|
|
|
elseif(UNIX AND NOT APPLE)
|
|
# Apply to Game
|
|
target_compile_definitions(SakuraVNE PRIVATE PLATFORM_LINUX)
|
|
target_link_libraries(SakuraVNE PRIVATE dl pthread)
|
|
|
|
# Apply to Tests
|
|
target_compile_definitions(tests PRIVATE PLATFORM_LINUX)
|
|
target_link_libraries(tests PRIVATE dl pthread)
|
|
endif()
|
|
|
|
# Debug vs Release definitions for Game
|
|
target_compile_definitions(SakuraVNE PRIVATE
|
|
$<$<CONFIG:Debug>:DEBUG>
|
|
$<$<CONFIG:Release>:RELEASE>
|
|
)
|
|
|
|
# Debug vs Release definitions for Tests
|
|
target_compile_definitions(tests PRIVATE
|
|
$<$<CONFIG:Debug>:DEBUG>
|
|
$<$<CONFIG:Release>:RELEASE>
|
|
)
|