IsoEngine/CMakeLists.txt

243 lines
8.4 KiB
CMake
Raw Permalink Normal View History

2024-09-14 20:46:32 -06:00
cmake_minimum_required(VERSION 3.28)
2024-09-09 02:50:07 -06:00
project(IsoEngine LANGUAGES CXX)
# Options for shared/static libraries, and client/server examples
option(BUILD_SHARED_LIBS "Build engine library dependencies as shared (DLLs)" OFF)
option(BUILD_CLIENT "Build the client example" ON)
option(BUILD_SERVER "Build the server example" ON)
2024-09-09 02:50:07 -06:00
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "No build type specified, defaulting to Debug")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE)
endif()
2024-09-14 02:41:14 -06:00
set(CMAKE_CXX_STANDARD 20)
2024-09-09 02:50:07 -06:00
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_XCODE_GENERATE_SCHEME ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Output directory settings
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()
set(FETCHCONTENT_QUIET OFF)
include(FetchContent)
# enet is header-only
2024-09-14 20:46:32 -06:00
set(ENET_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/vendor/enet")
2024-09-09 02:50:07 -06:00
FetchContent_Declare(
raylib
URL https://github.com/raysan5/raylib/archive/refs/tags/5.0.zip
2024-09-09 02:50:07 -06:00
)
set(BUILD_EXAMPLES OF CACHE BOOL "" FORCE)
set(SUPPORT_EVENTS_WAITING ON CACHE BOOL "" FORCE)
set(SUPPORT_BUSY_WAIT_LOOP OFF CACHE BOOL "" FORCE)
if (BUILD_SHARED_LIBS)
set(RAYLIB_LIBTYPE SHARED)
endif()
2024-09-09 02:50:07 -06:00
FetchContent_MakeAvailable(raylib)
FetchContent_Declare(
imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG v1.91.1
GIT_SHALLOW TRUE
2024-09-09 02:50:07 -06:00
)
FetchContent_MakeAvailable(imgui)
add_library(ImGui ${imgui_SOURCE_DIR}/imgui.cpp
${imgui_SOURCE_DIR}/imgui_demo.cpp
${imgui_SOURCE_DIR}/imgui_draw.cpp
${imgui_SOURCE_DIR}/imgui_tables.cpp
${imgui_SOURCE_DIR}/imgui_widgets.cpp
2024-09-09 02:50:07 -06:00
)
target_include_directories(ImGui PUBLIC ${imgui_SOURCE_DIR})
FetchContent_Declare(
rlimgui
GIT_REPOSITORY https://github.com/raylib-extras/rlImGui.git
GIT_TAG main
GIT_SHALLOW TRUE
2024-09-09 02:50:07 -06:00
)
FetchContent_MakeAvailable(rlimgui)
FetchContent_Declare(
box2d
GIT_REPOSITORY https://github.com/erincatto/box2d.git
GIT_TAG v3.0.0
2024-09-09 02:50:07 -06:00
)
FetchContent_MakeAvailable(box2d)
FetchContent_Declare(
entt
GIT_REPOSITORY https://github.com/skypjack/entt.git
GIT_TAG v3.13.2
2024-09-09 02:50:07 -06:00
)
FetchContent_MakeAvailable(entt)
FetchContent_Declare(
physfs
GIT_REPOSITORY https://github.com/icculus/physfs.git
GIT_TAG release-3.2.0
2024-09-09 02:50:07 -06:00
)
# PhysFS settings (default: static)
set(PHYSFS_BUILD_STATIC ON CACHE BOOL "Build PhysFS static library" FORCE)
set(PHYSFS_BUILD_SHARED OFF CACHE BOOL "Do not build PhysFS shared library" FORCE)
2024-09-09 02:50:07 -06:00
if(BUILD_SHARED_LIBS)
set(PHYSFS_BUILD_SHARED ON CACHE BOOL "Build PhysFS shared library" FORCE)
set(PHYSFS_BUILD_STATIC OFF CACHE BOOL "Do not build PhysFS static library" FORCE)
endif()
set(PHYSFS_BUILD_TEST OFF CACHE BOOL "Disable PhysFS test program" FORCE)
FetchContent_MakeAvailable(physfs)
2024-09-09 02:50:07 -06:00
# Main Engine Library
set(ENGINE_SOURCES
src/IsoEngine.cpp
src/enet_client.cpp
src/enet_server.cpp
2024-09-09 02:50:07 -06:00
src/Logger.cpp
2024-09-13 07:43:19 -06:00
src/components/sprite_component.cpp
2024-09-09 02:50:07 -06:00
src/components/physics_component.cpp
src/components/input_component.cpp
src/components/ui_component.cpp
2024-09-13 07:43:19 -06:00
src/scene_manager.cpp
2024-09-13 07:43:19 -06:00
src/filepacker.cpp
2024-09-09 02:50:07 -06:00
)
2024-09-14 02:41:14 -06:00
if (WIN32)
list(APPEND ENGINE_SOURCES src/platform/windows/FatalHandlerWindows.cpp)
elseif(UNIX)
list(APPEND ENGINE_SOURCES src/platform/posix/FatalHandlerPosix.cpp)
endif()
2024-09-09 02:50:07 -06:00
add_library(IsoEngine ${ENGINE_SOURCES})
target_include_directories(IsoEngine PUBLIC
${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/src/components
${raylib_SOURCE_DIR}
${imgui_SOURCE_DIR}
${rlimgui_SOURCE_DIR}
${box2d_SOURCE_DIR}/include
${physfs_SOURCE_DIR}/src
${entt_SOURCE_DIR}/src
${ENET_INCLUDE_DIR}
2024-09-09 02:50:07 -06:00
)
target_link_libraries(IsoEngine PRIVATE raylib box2d EnTT::EnTT)
2024-09-12 21:25:28 -06:00
target_precompile_headers(IsoEngine PRIVATE src/IsoEnginePCH.h)
2024-09-09 02:50:07 -06:00
# PhysFS linkage
if(BUILD_SHARED_LIBS)
target_link_libraries(IsoEngine PRIVATE PhysFS::PhysFS)
else()
target_link_libraries(IsoEngine PRIVATE PhysFS::PhysFS-static)
target_compile_definitions(IsoEngine PRIVATE PHYSFS_STATIC)
endif()
# rlImGui library linking
add_library(rlImGui ${rlimgui_SOURCE_DIR}/rlImGui.cpp)
target_include_directories(rlImGui PUBLIC ${rlimgui_SOURCE_DIR} ${imgui_SOURCE_DIR})
target_link_libraries(rlImGui PRIVATE raylib ImGui)
target_link_libraries(IsoEngine PRIVATE ImGui rlImGui)
# Example executables (client/server)
2024-09-14 02:41:14 -06:00
if(BUILD_CLIENT)
2024-09-09 02:50:07 -06:00
# Client executable
set(CLIENT_SOURCE "${CMAKE_CURRENT_LIST_DIR}/sandbox/client.cpp")
add_executable(client ${CLIENT_SOURCE})
target_include_directories(client PRIVATE ${ENET_INCLUDE_DIR})
target_link_libraries(client PRIVATE IsoEngine raylib)
# Platform-specific linking for client (Windows)
if(WIN32)
target_link_libraries(client PRIVATE winmm ws2_32)
endif()
# Server executable
set(SERVER_SOURCE "${CMAKE_CURRENT_LIST_DIR}/sandbox/server.cpp")
add_executable(server ${SERVER_SOURCE})
target_include_directories(server PRIVATE ${ENET_INCLUDE_DIR})
target_link_libraries(server PRIVATE IsoEngine)
# Platform-specific linking for server (Windows)
if(WIN32)
target_link_libraries(server PRIVATE winmm ws2_32)
endif()
endif()
# Platform-specific linking for IsoEngine (Raylib and Winsock for ENet on Windows)
if(WIN32)
target_link_libraries(IsoEngine PRIVATE winmm ws2_32)
add_definitions(-DWIN32_LEAN_AND_MEAN)
add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
add_definitions(-D_HAS_EXCEPTIONS=0)
elseif(APPLE)
target_link_libraries(IsoEngine PRIVATE "-framework CoreVideo" "-framework IOKit" "-framework Cocoa" "-framework GLUT" "-framework OpenGL")
else()
target_link_libraries(IsoEngine PRIVATE m pthread GL dl X11)
endif()
# Build Configuration Optimizations
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Configuring Debug build: No optimizations applied.")
2024-09-14 02:41:14 -06:00
target_compile_definitions(IsoEngine PRIVATE ENABLE_LOGGING)
2024-09-09 02:50:07 -06:00
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
message(STATUS "Configuring Release build: Applying moderate optimizations.")
target_compile_options(IsoEngine PRIVATE -O2)
if(BUILD_CLIENT OR BUILD_SANDBOX)
target_compile_options(client PRIVATE -O2)
target_compile_options(server PRIVATE -O2)
endif()
# Strip symbols after building
if(NOT MSVC)
add_custom_command(TARGET IsoEngine POST_BUILD
COMMAND ${CMAKE_STRIP} --strip-unneeded $<TARGET_FILE:IsoEngine>
COMMENT "Stripping unneeded symbols from the IsoEngine binary in Release build."
2024-09-09 02:50:07 -06:00
)
if(BUILD_CLIENT OR BUILD_SANDBOX)
add_custom_command(TARGET client POST_BUILD
COMMAND ${CMAKE_STRIP} --strip-unneeded $<TARGET_FILE:client>
COMMENT "Stripping unneeded symbols from the client binary in Release build."
2024-09-09 02:50:07 -06:00
)
add_custom_command(TARGET server POST_BUILD
COMMAND ${CMAKE_STRIP} --strip-unneeded $<TARGET_FILE:server>
COMMENT "Stripping unneeded symbols from the server binary in Release build."
2024-09-09 02:50:07 -06:00
)
endif()
endif()
elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
message(STATUS "Configuring MinSizeRel build: Applying aggressive size optimizations.")
target_compile_options(IsoEngine PRIVATE -Os -ffunction-sections -fdata-sections)
target_link_options(IsoEngine PRIVATE -Wl,--gc-sections -Wl,--as-needed)
# Strip symbols aggressively after building
if(NOT MSVC)
add_custom_command(TARGET IsoEngine POST_BUILD
COMMAND ${CMAKE_STRIP} --strip-all $<TARGET_FILE:IsoEngine>
COMMENT "Stripping all symbols from the IsoEngine binary in MinSizeRel build."
2024-09-09 02:50:07 -06:00
)
if(BUILD_CLIENT OR BUILD_SANDBOX)
add_custom_command(TARGET client POST_BUILD
COMMAND ${CMAKE_STRIP} --strip-all $<TARGET_FILE:client>
COMMENT "Stripping all symbols from the client binary in MinSizeRel build."
2024-09-09 02:50:07 -06:00
)
add_custom_command(TARGET server POST_BUILD
COMMAND ${CMAKE_STRIP} --strip-all $<TARGET_FILE:server>
COMMENT "Stripping all symbols from the server binary in MinSizeRel build."
2024-09-09 02:50:07 -06:00
)
endif()
endif()
endif()