build: rework cmake static and shared library building #1

Merged
illyum merged 1 commits from refactor/dll-support into master 2024-09-11 23:24:57 -06:00

View File

@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 3.24)
project(IsoEngine LANGUAGES CXX) project(IsoEngine LANGUAGES CXX)
# Options for shared/static libraries, testbeds, and sandbox # Options for shared/static libraries, and client/server examples
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs) instead of static libraries" OFF) option(BUILD_SHARED_LIBS "Build engine library dependencies as shared (DLLs)" OFF)
option(BUILD_CLIENT "Build the client testbed executable" ON) option(BUILD_CLIENT "Build the client example" ON)
option(BUILD_SANDBOX "Build sandbox client and server" ON) option(BUILD_SERVER "Build the server example" ON)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "No build type specified, defaulting to Debug") message(STATUS "No build type specified, defaulting to Debug")
@ -29,14 +29,16 @@ endif()
set(FETCHCONTENT_QUIET OFF) set(FETCHCONTENT_QUIET OFF)
include(FetchContent) include(FetchContent)
# ENet is header-only, provide include directory # enet is header-only
set(ENET_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/thirdparty/enet") set(ENET_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/thirdparty/enet")
# Fetch Raylib and other dependencies
FetchContent_Declare( FetchContent_Declare(
raylib raylib
URL https://github.com/raysan5/raylib/archive/refs/tags/5.0.zip 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_MakeAvailable(raylib)
FetchContent_Declare( FetchContent_Declare(
@ -82,17 +84,15 @@ FetchContent_Declare(
GIT_REPOSITORY https://github.com/icculus/physfs.git GIT_REPOSITORY https://github.com/icculus/physfs.git
GIT_TAG release-3.2.0 GIT_TAG release-3.2.0
) )
FetchContent_MakeAvailable(physfs) # PhysFS settings (default: static)
set(PHYSFS_BUILD_STATIC ON CACHE BOOL "Build PhysFS static library" FORCE)
# PhysFS settings set(PHYSFS_BUILD_SHARED OFF CACHE BOOL "Do not build PhysFS shared library" FORCE)
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
set(PHYSFS_BUILD_SHARED ON CACHE BOOL "Build PhysFS shared library" FORCE) 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) 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() endif()
set(PHYSFS_BUILD_TEST OFF CACHE BOOL "Disable PhysFS test program" FORCE) set(PHYSFS_BUILD_TEST OFF CACHE BOOL "Disable PhysFS test program" FORCE)
FetchContent_MakeAvailable(physfs)
# Main Engine Library # Main Engine Library
set(ENGINE_SOURCES set(ENGINE_SOURCES
@ -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(rlImGui PRIVATE raylib ImGui)
target_link_libraries(IsoEngine PRIVATE ImGui rlImGui) target_link_libraries(IsoEngine PRIVATE ImGui rlImGui)
# Testbed and Sandbox executables (client/server) # Example executables (client/server)
if(BUILD_CLIENT OR BUILD_SANDBOX) if(BUILD_CLIENT OR BUILD_SANDBOX)
# Client executable # Client executable
set(CLIENT_SOURCE "${CMAKE_CURRENT_LIST_DIR}/sandbox/client.cpp") set(CLIENT_SOURCE "${CMAKE_CURRENT_LIST_DIR}/sandbox/client.cpp")