90 lines
2.8 KiB
CMake
90 lines
2.8 KiB
CMake
add_library(${ENGINE_TARGET} STATIC
|
|
src/IO/parser.cpp
|
|
src/IO/file_manager.cpp
|
|
|
|
src/window/window.cpp
|
|
|
|
src/components/batch.cpp
|
|
|
|
src/renderer/debug.cpp
|
|
src/renderer/mesh.cpp
|
|
src/renderer/shader.cpp
|
|
src/renderer/texture.cpp
|
|
src/renderer/wavefront.cpp
|
|
src/renderer/core.cpp
|
|
src/renderer/renderer.cpp
|
|
|
|
# src/main.cpp
|
|
)
|
|
|
|
set_target_properties(${ENGINE_TARGET} PROPERTIES
|
|
CXX_STANDARD 17
|
|
CXX_STANDARD_REQUIRED ON
|
|
CXX_VISIBILITY_PRESET hidden
|
|
VISIBILITY_INLINES_HIDDEN YES
|
|
)
|
|
|
|
target_include_directories(${ENGINE_TARGET} PUBLIC
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
${CMAKE_CURRENT_SOURCE_DIR}/contrib
|
|
)
|
|
target_link_libraries(${ENGINE_TARGET} PUBLIC
|
|
SDL3::SDL3
|
|
OpenGL::GL
|
|
GLEW::GLEW
|
|
glm::glm
|
|
EnTT::EnTT
|
|
)
|
|
|
|
if (MSVC)
|
|
target_compile_options(${ENGINE_TARGET} PRIVATE $<$<CONFIG:Debug>:/Zi>)
|
|
target_link_options(${ENGINE_TARGET} PRIVATE $<$<CONFIG:Debug>:/DEBUG:FULL>)
|
|
else()
|
|
target_compile_options(${ENGINE_TARGET} PRIVATE $<$<CONFIG:Debug>:-ggdb>)
|
|
endif()
|
|
|
|
# Release flags
|
|
if (MSVC)
|
|
# /O2: optimize speed, /GL: whole program opt (LTCG), /DNDEBUG: disable asserts
|
|
target_compile_options(${ENGINE_TARGET} PRIVATE
|
|
$<$<CONFIG:Release>:/O2>
|
|
$<$<CONFIG:Release>:/DNDEBUG>
|
|
$<$<CONFIG:RelWithDebInfo>:/O2>
|
|
)
|
|
# Link-time codegen & extra linker opts for smaller/faster binaries
|
|
target_link_options(${ENGINE_TARGET} PRIVATE
|
|
$<$<CONFIG:Release>:/LTCG /OPT:ICF /OPT:REF>
|
|
$<$<CONFIG:RelWithDebInfo>:/LTCG /OPT:ICF /OPT:REF>
|
|
)
|
|
else()
|
|
# GCC/Clang
|
|
# -O3 for max opts, -ffast-math optional but can be risky; we keep it OFF by default.
|
|
option(CODINGGAME_USE_MARCH_NATIVE "Enable -march=native on Release for this machine" ON)
|
|
target_compile_options(${ENGINE_TARGET} PRIVATE
|
|
$<$<CONFIG:Release>:-O3>
|
|
$<$<AND:$<CONFIG:Release>,$<BOOL:${CODINGGAME_USE_MARCH_NATIVE}>>:-march=native>
|
|
$<$<CONFIG:Release>:-DNDEBUG>
|
|
$<$<CONFIG:RelWithDebInfo>:-O3 -g>
|
|
)
|
|
# Linker: enable LTO when available; optionally strip symbols on non-Apple
|
|
include(CheckIPOSupported) # IPO == LTO in CMake terms
|
|
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_msg)
|
|
if(ipo_supported)
|
|
set_property(TARGET ${ENGINE_TARGET} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
|
|
set_property(TARGET ${ENGINE_TARGET} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
|
endif()
|
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT APPLE)
|
|
# -s strips symbols at link stage (use only for pure Release)
|
|
target_link_options(${ENGINE_TARGET} PRIVATE $<$<CONFIG:Release>:-s>)
|
|
endif()
|
|
endif()
|
|
|
|
# ---------- Windows: copy runtime DLLs ----------
|
|
if (WIN32)
|
|
add_custom_command(TARGET ${ENGINE_TARGET} POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
$<TARGET_RUNTIME_DLLS:${ENGINE_TARGET}> $<TARGET_FILE_DIR:${ENGINE_TARGET}>
|
|
COMMAND_EXPAND_LISTS)
|
|
endif()
|