cmake_minimum_required(VERSION 4.2) project(netcode_demo LANGUAGES CXX) set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) # ENet enable shared set(ENET_SHARED ON CACHE BOOL "Build enet as a shared library" FORCE) set(ENET_STATIC OFF CACHE BOOL "Build enet as a static library" FORCE) # Build flags option(BUILD_ALL "Build everything" ON) option(BUILD_COMMON "Build common" ON) option(BUILD_CLIENT "Build client" ON) option(BUILD_SERVER "Build server" ON) option(BUILD_APP "Build app" ON) option(BUILD_SAPP "Build sapp" ON) find_package(SFML 3.0 COMPONENTS System Window Graphics Network REQUIRED) #add_compile_definitions(ENET_IPV6=1) add_subdirectory(extern/enet) #target_compile_definitions(enet_shared PUBLIC ENET_IPV6=1) # --------------------------- # Common library # --------------------------- if(BUILD_COMMON OR BUILD_ALL) add_library(common SHARED common/src/common.cpp ) set_target_properties(common PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) target_include_directories(common PUBLIC common/include) target_link_libraries(common PUBLIC enet::enet_shared) if(WIN32) target_link_libraries(common PUBLIC ws2_32 winmm) endif() endif() # --------------------------- # App library # --------------------------- if(BUILD_APP OR BUILD_ALL) add_library(app SHARED app/src/app_entry.cpp app/include/app/network_simulation.hpp ) set_target_properties(app PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) target_include_directories(app PUBLIC app/include) if(BUILD_COMMON OR BUILD_ALL) target_link_libraries(app PUBLIC common) endif() endif() # --------------------------- # Sapp library # --------------------------- if(BUILD_SAPP OR BUILD_ALL) add_library(sapp SHARED sapp/src/sapp_entry.cpp ) set_target_properties(sapp PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) target_include_directories(sapp PUBLIC sapp/include) if(BUILD_COMMON OR BUILD_ALL) target_link_libraries(sapp PUBLIC common) endif() endif() # --------------------------- # Client executable # --------------------------- if(BUILD_CLIENT OR BUILD_ALL) add_executable(client client/cl_main.cpp ) target_include_directories(client PRIVATE client) target_link_libraries(client PUBLIC $<$:common> $<$:app> SFML::System SFML::Window SFML::Graphics SFML::Network enet::enet_shared ) if(WIN32) target_link_libraries(client PRIVATE ws2_32 winmm) endif() set_target_properties(client PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/client/$ ) if(WIN32) add_custom_command(TARGET client POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ COMMAND_EXPAND_LISTS ) endif() endif() # --------------------------- # Server executable # --------------------------- if(BUILD_SERVER OR BUILD_ALL) add_executable(server server/sv_main.cpp) target_include_directories(server PRIVATE server) target_link_libraries(server PUBLIC $<$:common> $<$:sapp> enet::enet_shared ) if(WIN32) target_link_libraries(server PRIVATE ws2_32 winmm) endif() set_target_properties(server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/server/$ ) if(WIN32) add_custom_command(TARGET server POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ COMMAND_EXPAND_LISTS ) endif() endif() # --------------------------- # Main target # --------------------------- add_custom_target(netcode_demo ALL COMMENT "Build all enabled subprojects according to BUILD_* flags" ) if(BUILD_COMMON OR BUILD_ALL) add_dependencies(netcode_demo common) endif() if(BUILD_APP OR BUILD_ALL) add_dependencies(netcode_demo app) endif() if(BUILD_SAPP OR BUILD_ALL) add_dependencies(netcode_demo sapp) endif() if(BUILD_CLIENT OR BUILD_ALL) add_dependencies(netcode_demo client) endif() if(BUILD_SERVER OR BUILD_ALL) add_dependencies(netcode_demo server) endif()