From a28f6520d0d71cbf00d7304cbe7cd1940e9d0cee Mon Sep 17 00:00:00 2001 From: illyum Date: Wed, 11 Sep 2024 23:21:07 -0600 Subject: [PATCH] build: rework cmake static and shared library building --- CMakeLists.txt | 124 ++++++++++++++++++++++++------------------------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eddf5d1..fb89bc1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,10 +2,10 @@ 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) +# 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) if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "No build type specified, defaulting to Debug") @@ -29,78 +29,78 @@ endif() set(FETCHCONTENT_QUIET OFF) include(FetchContent) -# ENet is header-only, provide include directory +# enet is header-only 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 + raylib + URL https://github.com/raysan5/raylib/archive/refs/tags/5.0.zip ) +if (BUILD_SHARED_LIBS) + set(RAYLIB_LIBTYPE SHARED) +endif() FetchContent_MakeAvailable(raylib) FetchContent_Declare( - imgui - GIT_REPOSITORY https://github.com/ocornut/imgui.git - GIT_TAG v1.91.1 - GIT_SHALLOW TRUE + 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 + ${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 + 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 + 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 + 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 + physfs + GIT_REPOSITORY https://github.com/icculus/physfs.git + GIT_TAG release-3.2.0 ) -FetchContent_MakeAvailable(physfs) - -# PhysFS settings +# 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) 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) +FetchContent_MakeAvailable(physfs) # Main Engine Library set(ENGINE_SOURCES - src/IsoEngine.cpp - src/enet_client.cpp - src/enet_server.cpp - - src/components/sprite_component.cpp + 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 @@ -114,15 +114,15 @@ set(ENGINE_SOURCES 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} + ${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) @@ -141,7 +141,7 @@ target_include_directories(rlImGui PUBLIC ${rlimgui_SOURCE_DIR} ${imgui_SOURCE_D target_link_libraries(rlImGui PRIVATE raylib ImGui) target_link_libraries(IsoEngine PRIVATE ImGui rlImGui) -# Testbed and Sandbox executables (client/server) +# Example executables (client/server) if(BUILD_CLIENT OR BUILD_SANDBOX) # Client executable set(CLIENT_SOURCE "${CMAKE_CURRENT_LIST_DIR}/sandbox/client.cpp") @@ -192,17 +192,17 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release") # Strip symbols after building if(NOT MSVC) add_custom_command(TARGET IsoEngine POST_BUILD - COMMAND ${CMAKE_STRIP} --strip-unneeded $ - COMMENT "Stripping unneeded symbols from the IsoEngine binary in Release build." + COMMAND ${CMAKE_STRIP} --strip-unneeded $ + 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 $ - COMMENT "Stripping unneeded symbols from the client binary in Release build." + COMMAND ${CMAKE_STRIP} --strip-unneeded $ + COMMENT "Stripping unneeded symbols from the client binary in Release build." ) add_custom_command(TARGET server POST_BUILD - COMMAND ${CMAKE_STRIP} --strip-unneeded $ - COMMENT "Stripping unneeded symbols from the server binary in Release build." + COMMAND ${CMAKE_STRIP} --strip-unneeded $ + COMMENT "Stripping unneeded symbols from the server binary in Release build." ) endif() endif() @@ -214,17 +214,17 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel") # Strip symbols aggressively after building if(NOT MSVC) add_custom_command(TARGET IsoEngine POST_BUILD - COMMAND ${CMAKE_STRIP} --strip-all $ - COMMENT "Stripping all symbols from the IsoEngine binary in MinSizeRel build." + COMMAND ${CMAKE_STRIP} --strip-all $ + 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 $ - COMMENT "Stripping all symbols from the client binary in MinSizeRel build." + COMMAND ${CMAKE_STRIP} --strip-all $ + COMMENT "Stripping all symbols from the client binary in MinSizeRel build." ) add_custom_command(TARGET server POST_BUILD - COMMAND ${CMAKE_STRIP} --strip-all $ - COMMENT "Stripping all symbols from the server binary in MinSizeRel build." + COMMAND ${CMAKE_STRIP} --strip-all $ + COMMENT "Stripping all symbols from the server binary in MinSizeRel build." ) endif() endif() -- 2.40.0.windows.1