232 lines
7.9 KiB
CMake
232 lines
7.9 KiB
CMake
cmake_minimum_required(VERSION 3.24)
|
|
|
|
project(IsoEngine LANGUAGES CXX)
|
|
|
|
# Options for shared/static libraries, testbeds, and sandbox
|
|
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs) instead of static libraries" OFF)
|
|
option(BUILD_CLIENT "Build the client testbed executable" ON)
|
|
option(BUILD_SANDBOX "Build sandbox client and server" ON)
|
|
|
|
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()
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
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, provide include directory
|
|
set(ENET_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/thirdparty/enet")
|
|
|
|
# Fetch Raylib and other dependencies
|
|
FetchContent_Declare(
|
|
raylib
|
|
URL https://github.com/raysan5/raylib/archive/refs/tags/5.0.zip
|
|
)
|
|
FetchContent_MakeAvailable(raylib)
|
|
|
|
FetchContent_Declare(
|
|
imgui
|
|
GIT_REPOSITORY https://github.com/ocornut/imgui.git
|
|
GIT_TAG v1.91.1
|
|
GIT_SHALLOW TRUE
|
|
)
|
|
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
|
|
)
|
|
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
|
|
)
|
|
FetchContent_MakeAvailable(rlimgui)
|
|
|
|
FetchContent_Declare(
|
|
box2d
|
|
GIT_REPOSITORY https://github.com/erincatto/box2d.git
|
|
GIT_TAG v3.0.0
|
|
)
|
|
FetchContent_MakeAvailable(box2d)
|
|
|
|
FetchContent_Declare(
|
|
entt
|
|
GIT_REPOSITORY https://github.com/skypjack/entt.git
|
|
GIT_TAG v3.13.2
|
|
)
|
|
FetchContent_MakeAvailable(entt)
|
|
|
|
FetchContent_Declare(
|
|
physfs
|
|
GIT_REPOSITORY https://github.com/icculus/physfs.git
|
|
GIT_TAG release-3.2.0
|
|
)
|
|
FetchContent_MakeAvailable(physfs)
|
|
|
|
# PhysFS settings
|
|
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)
|
|
else()
|
|
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)
|
|
endif()
|
|
set(PHYSFS_BUILD_TEST OFF CACHE BOOL "Disable PhysFS test program" FORCE)
|
|
|
|
# Main Engine Library
|
|
set(ENGINE_SOURCES
|
|
src/IsoEngine.cpp
|
|
src/enet_client.cpp
|
|
src/enet_server.cpp
|
|
|
|
src/components/sprite_component.cpp
|
|
src/Logger.cpp
|
|
src/Logger.h
|
|
src/components/transform_component.h
|
|
src/components/physics_component.cpp
|
|
src/components/physics_component.h
|
|
src/components/input_component.cpp
|
|
src/components/input_component.h
|
|
src/components/health_component.h
|
|
)
|
|
|
|
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}
|
|
)
|
|
|
|
target_link_libraries(IsoEngine PRIVATE raylib box2d EnTT::EnTT)
|
|
|
|
# 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)
|
|
|
|
# Testbed and Sandbox executables (client/server)
|
|
if(BUILD_CLIENT OR BUILD_SANDBOX)
|
|
# 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.")
|
|
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."
|
|
)
|
|
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."
|
|
)
|
|
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."
|
|
)
|
|
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."
|
|
)
|
|
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."
|
|
)
|
|
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."
|
|
)
|
|
endif()
|
|
endif()
|
|
endif()
|