include(CheckCXXCompilerFlag) add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32 comptime.c cxxutil.hpp md5.c config.h.in string.c d_main.cpp d_clisrv.c d_net.cpp d_netfil.c d_netcmd.c dehacked.c deh_soc.c deh_lua.c deh_tables.c z_zone.cpp f_finale.c f_wipe.cpp g_build_ticcmd.cpp g_demo.cpp g_game.c g_gamedata.cpp g_input.c g_party.cpp am_map.c command.c console.c cvars.cpp font.c hu_stuff.c i_time.c i_video_common.cpp y_inter.cpp st_stuff.c m_aatree.c m_anigif.c m_argv.c m_bbox.c m_cheat.c m_cond.c m_easing.c m_fixed.c m_memcpy.c m_misc.cpp m_perfstats.c m_pw.cpp m_pw_hash.c m_random.c m_queue.c info.c p_ceilng.c p_enemy.c p_floor.c p_inter.c p_lights.c p_link.cpp p_loop.c p_map.c p_mapthing.cpp p_maputl.c p_mobj.c p_polyobj.c p_saveg.cpp p_setup.cpp p_sight.c p_spec.c p_telept.c p_tick.c p_user.c p_slopes.c p_sweep.cpp p_test.cpp tables.c r_bsp.cpp r_data.c r_debug.cpp r_debug_parser.cpp r_debug_printer.cpp r_draw.cpp r_fps.cpp r_main.cpp r_plane.cpp r_segs.cpp r_skins.c r_sky.c r_splats.c r_spritefx.cpp r_things.cpp r_bbox.c r_textures.cpp r_textures_dups.cpp r_patch.cpp r_patchrotation.c r_picformats.c r_portal.c screen.c taglist.c v_draw.cpp v_video.cpp s_sound.c sounds.c w_wad.cpp filesrch.c mserv.c http-mserv.c i_tcp.c lzf.c vid_copy.s lua_script.c lua_baselib.c lua_mathlib.c lua_hooklib.c lua_consolelib.c lua_infolib.c lua_mobjlib.c lua_playerlib.c lua_skinlib.c lua_thinkerlib.c lua_maplib.c lua_taglib.c lua_terrainlib.c lua_polyobjlib.c lua_blockmaplib.c lua_botvarslib.c lua_hudlib.c lua_hudlib_drawlist.c lua_followerlib.c lua_itemroulettelib.c lua_respawnvarslib.c lua_waypointslib.c lua_grandprixlib.c lua_profile.cpp k_kart.c k_respawn.c k_collide.cpp k_color.c k_race.c k_battle.c k_pwrlv.c k_waypoint.cpp k_pathfind.c k_bheap.c k_bot.cpp k_botitem.cpp k_botsearch.cpp k_grandprix.cpp k_boss.c k_hud.cpp k_hud_track.cpp k_menufunc.c k_menudraw.c k_terrain.c k_brightmap.c k_terrain.c k_director.cpp k_follower.c k_profiles.cpp k_specialstage.c k_roulette.c k_podium.cpp k_rank.cpp k_vote.c k_serverstats.c k_zvote.c k_mapuser.c k_powerup.cpp k_hitlag.c k_dialogue.cpp k_tally.cpp k_bans.cpp k_endcam.cpp k_credits.cpp k_modinfo.cpp music.cpp music_manager.cpp sanitize.cpp p_deepcopy.cpp ) # Always compile some files with optimizations in Debug config. # This is to make the debugging experience less slow for the majority of cases. set(always_optimize_options "") if(MSVC) set(always_optimize_options "$<$:/O2;/Ob2>") else() set(always_optimize_options "$<$:-O3>") endif() set_source_files_properties( r_bsp.cpp r_data.c r_debug.cpp r_debug_parser.cpp r_debug_printer.cpp r_draw.cpp r_fps.cpp r_main.cpp r_plane.cpp r_segs.cpp r_skins.c r_sky.c r_splats.c r_spritefx.cpp r_things.cpp r_bbox.c r_textures.cpp r_textures_dups.cpp r_patch.cpp r_patchrotation.c r_picformats.c r_portal.c PROPERTIES COMPILE_OPTIONS "${always_optimize_options}" ) set_target_properties(SRB2SDL2 PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/sdl/macosx/MacOSXBundleInfo.plist.in") if(SRB2_CONFIG_ENABLE_WEBM_MOVIES) target_sources(SRB2SDL2 PRIVATE m_avrecorder.cpp) endif() if(NOT SRB2_CONFIG_SKIP_COMPTIME) # This updates the modification time for comptime.c at the # end of building so when the build system is ran next time, # that file gets flagged. comptime.c will always be rebuilt. # # This begs the question, why always rebuild comptime.c? # Some things like the git commit must be checked each time # the program is built. But the build system determines which # files should be rebuilt before anything else. So # comptime.c, which only needs to be rebuilt based on # information known at build time, must be told to rebuild # before that information can be ascertained. add_custom_command( TARGET SRB2SDL2 POST_BUILD COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${CMAKE_CURRENT_SOURCE_DIR}/comptime.c ) endif() # config.h is generated by this command. It should be done at # build time for accurate git information and before anything # that needs it, obviously. add_custom_target(_SRB2_reconf ALL COMMAND ${CMAKE_COMMAND} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DBINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/.. -P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Comptime.cmake WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.." ) add_dependencies(SRB2SDL2 _SRB2_reconf) if(("${CMAKE_COMPILER_IS_GNUCC}") AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows") target_link_options(SRB2SDL2 PRIVATE "-Wl,--disable-dynamicbase") if("${SRB2_CONFIG_STATIC_STDLIB}") # On MinGW with internal libraries, link the standard library statically target_link_options(SRB2SDL2 PRIVATE -Wl,--add-stdcall-alias -static-libgcc -static-libstdc++ -static -lpthread) set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads REQUIRED) target_link_libraries(SRB2SDL2 PRIVATE Threads::Threads) endif() if(CMAKE_SIZEOF_VOID_P EQUAL 4) target_link_options(SRB2SDL2 PRIVATE "-Wl,--large-address-aware") endif() endif() if(MSVC OR CMAKE_CXX_LINK_EXECUTABLE MATCHES "lld-link\\.exe") target_link_options(SRB2SDL2 PRIVATE /MANIFEST:NO) target_link_libraries(SRB2SDL2 PRIVATE "dbghelp") endif() if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND MSVC) # Stuff to make paths not include the builder's file system paths on clang-cl string(REPLACE "/" "\\" backslashes_cmake_source_dir "${CMAKE_SOURCE_DIR}") target_compile_options(SRB2SDL2 PRIVATE "$<$:/clang:-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=X:/ringracers>") target_compile_options(SRB2SDL2 PRIVATE "$<$:/clang:-fdebug-prefix-map=${backslashes_cmake_source_dir}=X:/ringracers>") target_compile_options(SRB2SDL2 PRIVATE "$<$:/clang:-fdebug-compilation-dir=${CMAKE_SOURCE_DIR}>") target_link_options(SRB2SDL2 PRIVATE "$<$:/pdbaltpath:%_PDB%>") endif() target_compile_features(SRB2SDL2 PRIVATE c_std_11 cxx_std_17) set_target_properties(SRB2SDL2 PROPERTIES C_STANDARD 11 C_STANDARD_REQUIRED ON C_STANDARD_EXTENSIONS OFF CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF ) set(SRB2_ASM_SOURCES vid_copy.s) set(SRB2_NASM_SOURCES tmap_mmx.nas tmap.nas) ### Configuration set(SRB2_CONFIG_USEASM OFF CACHE BOOL "Enable NASM tmap implementation for software mode speedup.") set(SRB2_CONFIG_YASM OFF CACHE BOOL "Use YASM in place of NASM.") add_subdirectory(blua) # OS macros if (UNIX) target_compile_definitions(SRB2SDL2 PRIVATE -DUNIXCOMMON) endif() if (BSD MATCHES "FreeBSD") target_compile_definitions(SRB2SDL2 PRIVATE -DFREEBSD) endif() if(CMAKE_COMPILER_IS_GNUCC) find_program(OBJCOPY objcopy) endif() if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") target_compile_definitions(SRB2SDL2 PRIVATE -DLINUX) if(${SRB2_SYSTEM_BITS} EQUAL 64) target_compile_definitions(SRB2SDL2 PRIVATE -DLINUX64) endif() endif() if("${CMAKE_SYSTEM_NAME}" MATCHES "Haiku") target_compile_definitions(SRB2SDL2 PRIVATE -DNOEXECINFO) target_link_libraries(SRB2SDL2 PRIVATE network) endif() if("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") target_compile_definitions(SRB2SDL2 PRIVATE -DMACOSX) endif() # Enable SSE2 for IA-32. if(SRB2_SYSTEM_BITS EQUAL 32) if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang|AppleClang)") check_cxx_compiler_flag("-msse2" has_sse2) if(has_sse2) message(STATUS "Using SSE2 on IA-32") target_compile_options(SRB2SDL2 PRIVATE "-msse2") else() message(FATAL_ERROR "Needs -msse2 compiler support") endif() elseif(MSVC) check_cxx_compiler_flag("/arch:sse2" has_sse2) if(has_sse2) message(STATUS "Using SSE2 on IA-32") target_compile_options(SRB2SDL2 PRIVATE "/arch:SSE2") else() message(FATAL_ERROR "Needs /arch:SSE2 compiler support") endif() endif() endif() target_link_libraries(SRB2SDL2 PRIVATE ZLIB::ZLIB) target_link_libraries(SRB2SDL2 PRIVATE PNG::PNG) target_link_libraries(SRB2SDL2 PRIVATE CURL::libcurl) target_link_libraries(SRB2SDL2 PRIVATE Opus::opus) if(WIN32 AND NOT MINGW) target_link_libraries(SRB2SDL2 PRIVATE cpptrace::cpptrace) target_compile_definitions(SRB2SDL2 PRIVATE HAVE_CPPTRACE) endif() target_link_libraries(SRB2SDL2 PRIVATE ReNameNoise::renamenoise) if("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD") target_link_libraries(SRB2SDL2 PRIVATE -lexecinfo) target_link_libraries(SRB2SDL2 PRIVATE -lpthread) endif() target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_ZLIB -DHAVE_PNG -DHAVE_CURL -D_LARGEFILE64_SOURCE) target_sources(SRB2SDL2 PRIVATE apng.c) target_compile_definitions(SRB2SDL2 PRIVATE -DUSE_STUN) target_sources(SRB2SDL2 PRIVATE stun.cpp) if(SRB2_CONFIG_ENABLE_DISCORDRPC) target_link_libraries(SRB2SDL2 PRIVATE DiscordRPC::DiscordRPC) target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_DISCORDRPC) target_sources(SRB2SDL2 PRIVATE discord.c) endif() target_link_libraries(SRB2SDL2 PRIVATE tcbrindle::span) target_link_libraries(SRB2SDL2 PRIVATE glm::glm) target_link_libraries(SRB2SDL2 PRIVATE Stb) target_link_libraries(SRB2SDL2 PRIVATE xmp-lite::xmp-lite) target_link_libraries(SRB2SDL2 PRIVATE glad::glad) target_link_libraries(SRB2SDL2 PRIVATE fmt::fmt-header-only) target_link_libraries(SRB2SDL2 PRIVATE imgui::imgui) target_link_libraries(SRB2SDL2 PRIVATE Tracy::TracyClient) if(SRB2_CONFIG_ENABLE_WEBM_MOVIES) target_link_libraries(SRB2SDL2 PRIVATE webm::libwebm_mkvmuxer) target_link_libraries(SRB2SDL2 PRIVATE libyuv::libyuv) target_link_libraries(SRB2SDL2 PRIVATE Vorbis::vorbis Vorbis::vorbisenc) target_link_libraries(SRB2SDL2 PRIVATE Ogg::ogg) if(unofficial-libvpx_FOUND) target_link_libraries(SRB2SDL2 PRIVATE unofficial::libvpx::libvpx) else() target_link_libraries(SRB2SDL2 PRIVATE libvpx::libvpx) endif() target_compile_definitions(SRB2SDL2 PRIVATE -DSRB2_CONFIG_ENABLE_WEBM_MOVIES) endif() target_link_libraries(SRB2SDL2 PRIVATE nlohmann_json::nlohmann_json) set(SRB2_HAVE_THREADS ON) target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_THREADS) if(${SRB2_CONFIG_HAVE_ZLIB}) if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) set(ZLIB_FOUND ON) set(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/zlib) if(${SRB2_SYSTEM_BITS} EQUAL 64) set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz64") else() # 32-bit set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz32") endif() else() find_package(ZLIB) endif() if(${ZLIB_FOUND}) set(SRB2_HAVE_ZLIB ON) target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_ZLIB) else() message(WARNING "You have specified that ZLIB is available but it was not found. Dr Robotnik's Ring Racers may not compile correctly.") endif() endif() if(${SRB2_CONFIG_HAVE_PNG} AND ${SRB2_CONFIG_HAVE_ZLIB}) if (${ZLIB_FOUND}) if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) set(PNG_FOUND ON) set(PNG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libpng-src) if(${SRB2_SYSTEM_BITS} EQUAL 64) set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng64") else() # 32-bit set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng32") endif() else() find_package(PNG) endif() if(${PNG_FOUND}) set(SRB2_HAVE_PNG ON) target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_PNG) target_compile_definitions(SRB2SDL2 PRIVATE -D_LARGEFILE64_SOURCE) target_sources(SRB2SDL2 PRIVATE apng.c) else() message(WARNING "You have specified that PNG is available but it was not found. Dr Robotnik's Ring Racers may not compile correctly.") endif() endif() endif() if("${SRB2_CONFIG_HWRENDER}") target_compile_definitions(SRB2SDL2 PRIVATE -DHWRENDER) add_subdirectory(hardware) if("${SRB2_CONFIG_STATIC_OPENGL}") find_package(OpenGL) if(${OPENGL_FOUND}) target_compile_definitions(SRB2SDL2 PRIVATE -DSTATIC_OPENGL) else() message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.") endif() endif() endif() if(${SRB2_CONFIG_USEASM}) #SRB2_ASM_FLAGS can be used to pass flags to either nasm or yasm. if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") set(SRB2_ASM_FLAGS "-DLINUX ${SRB2_ASM_FLAGS}") endif() if(${SRB2_CONFIG_YASM}) set(CMAKE_ASM_YASM_SOURCE_FILE_EXTENSIONS ${CMAKE_ASM_YASM_SOURCE_FILE_EXTENSIONS} nas) set(CMAKE_ASM_YASM_FLAGS "${SRB2_ASM_FLAGS}" CACHE STRING "Flags used by the assembler during all build types.") enable_language(ASM_YASM) else() set(CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS ${CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS} nas) set(CMAKE_ASM_NASM_FLAGS "${SRB2_ASM_FLAGS}" CACHE STRING "Flags used by the assembler during all build types.") enable_language(ASM_NASM) endif() set(SRB2_USEASM ON) target_compile_definitions(SRB2SDL2 PRIVATE -DUSEASM) target_compile_options(SRB2SDL2 PRIVATE -msse3 -mfpmath=sse) target_sources(SRB2SDL2 PRIVATE ${SRB2_ASM_SOURCES} ${SRB2_NASM_SOURCES}) else() set(SRB2_USEASM OFF) target_compile_definitions(SRB2SDL2 PRIVATE -DNONX86 -DNORUSEASM) endif() # Targets # If using CCACHE, then force it. # https://github.com/Cockatrice/Cockatrice/pull/3052/files if ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") get_property(RULE_LAUNCH_COMPILE GLOBAL PROPERTY RULE_LAUNCH_COMPILE) if(RULE_LAUNCH_COMPILE) MESSAGE(STATUS "Force enabling CCache usage under macOS") # Set up wrapper scripts configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/launch-c.in ${CMAKE_BINARY_DIR}/launch-c) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/launch-cxx.in ${CMAKE_BINARY_DIR}/launch-cxx) execute_process(COMMAND chmod a+rx "${CMAKE_BINARY_DIR}/launch-c" "${CMAKE_BINARY_DIR}/launch-cxx") # Set Xcode project attributes to route compilation through our scripts set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/launch-c") set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/launch-cxx") set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/launch-c") set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/launch-cxx") endif() endif() # Compatibility flag with later versions of GCC # We should really fix our code to not need this if (NOT SRB2_CONFIG_FORCE_NO_MS_BITFIELDS) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") check_cxx_compiler_flag("-mno-ms-bitfields" HAS_NO_MS_BITFIELDS) if(HAS_NO_MS_BITFIELDS) target_compile_options(SRB2SDL2 PRIVATE -mno-ms-bitfields) endif() endif() endif() # Yes we know we use insecure CRT functions... if(WIN32 OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") target_compile_definitions(SRB2SDL2 PRIVATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS ) endif() # Compiler warnings configuration target_compile_options(SRB2SDL2 PRIVATE # Using generator expressions to handle per-language compile options # C, GNU # This is a direct translation from versions.mk $<$,$>: -Wall -Werror-implicit-function-declaration -Wno-trigraphs -W # Was controlled by RELAXWARNINGS -pedantic -Wpedantic -Wfloat-equal -Wundef -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align # Was controlled by NOCASTALIGNWARN -Wwrite-strings -Wsign-compare -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn -Winline -Wformat-y2k -Wformat-security $<$,2.9.5>: -Wno-div-by-zero -Wendif-labels -Wdisabled-optimization > $<$,4.0.0>: -Wold-style-definition -Wmissing-field-initializers > $<$,4.1.0>: -Wshadow > $<$,4.3.0>: -funit-at-a-time -Wlogical-op > $<$,4.5.0>: -Wlogical-op -Wno-error=array-bounds > $<$,4.6.0>: -Wno-suggest-attribute=noreturn -Wno-error=suggest-attribute=noreturn -Werror=vla > $<$,5.4.0>: -Wno-logical-op -Wno-error=logical-op > $<$,6.1.0>: -Wno-tautological-compare -Wno-error=tautological-compare > $<$,7.1.0>: -Wno-error=format-overflow=2 -Wimplicit-fallthrough=4 > $<$,8.1.0>: -Wno-error=format-overflow -Wno-error=stringop-truncation -Wno-error=stringop-overflow -Wno-format-overflow -Wno-stringop-truncation -Wno-stringop-overflow -Wno-error=multistatement-macros > $<$,9.1.0>: -Wno-error=address-of-packed-member > > # C, Clang and Apple Clang $<$,$,$>>: #-Wall -Werror=microsoft -Werror=implicit-function-declaration -Wreturn-type # Missing returns in non-void function -Wduplicate-decl-specifier -Wsometimes-uninitialized -Wno-trigraphs # Trigraphs are disabled -Wc11-extensions # Don't use C11 language extensions not part of baseline -Wno-unused-but-set-variable # Setting unread variables is fine -Wno-misleading-indentation # Some cases in code currently -Wno-deprecated-non-prototype # We have no intention of using C23 yet. -Wno-parentheses-equality -Wno-unsafe-buffer-usage # Very common in this codebase -Wno-unused-const-variable -Wno-unused-variable -Wno-unused-function > # C, MSVC $<$,$>: # All warnings at and before Visual Studio 2019 RTM # https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warnings-by-compiler-version?view=msvc-170 /Wv:19.20.27004.0 > # C++, GNU $<$,$>: -Wall -Wno-c++11-compat -Wno-c++14-compat # No C++14 compat needed > # C++, Clang and Apple Clang $<$,$,$>>: #-Wall -Werror=microsoft -Wdelete-abstract-non-virtual-dtor -Wreturn-type # Missing returns in non-void function -Wduplicate-decl-specifier -Wsometimes-uninitialized -Wno-trigraphs # Trigraphs are disabled -Wno-c++98-compat -Wno-c++11-compat -Wno-c++14-compat # No C++14 compat needed -Werror=c++20-extensions -Werror=c++23-extensions # Disallow newer language features entirely -Wno-unused-but-set-variable # Setting unread variables is fine (nontrivial C++ types issue) -Wno-misleading-indentation # Some cases in code currently -Wno-deprecated-non-prototype # We have no intention of using C23 yet. -Wno-parentheses-equality -Wno-unsafe-buffer-usage # Very common in this codebase -Wno-unused-const-variable -Wno-unused-variable -Wno-unused-function > # C++, Clang and Apple Clang # C++, MSVC $<$,$>: /Wv:19.20.27004.0 > # GNU $<$: -fmax-errors=5 > ) if(SRB2_CONFIG_ERRORMODE) target_compile_options(SRB2SDL2 PRIVATE $<$,$,$>: -Werror > $<$: /WX > ) endif() # Link warnings configuration target_link_options(SRB2SDL2 PRIVATE $<$: # -Wl,--as-needed - Was controlled by NOLDWARNING > ) if(${SRB2_CONFIG_DEV_BUILD}) target_compile_definitions(SRB2SDL2 PRIVATE -DDEVELOP) endif() target_compile_definitions(SRB2SDL2 PRIVATE -DCMAKECONFIG) # Misc. build options from Makefiles if(SRB2_CONFIG_DEBUGMODE) target_compile_definitions(SRB2SDL2 PRIVATE -DZDEBUG -DPARANOIA -DPACKETDROP) endif() if(SRB2_CONFIG_TESTERS) target_compile_definitions(SRB2SDL2 PRIVATE -DTESTERS) endif() if(SRB2_CONFIG_MOBJCONSISTANCY) target_compile_definitions(SRB2SDL2 PRIVATE -DMOBJCONSISTANCY) endif() if(SRB2_CONFIG_PACKETDROP) target_compile_definitions(SRB2SDL2 PRIVATE -DPACKETDROP) endif() if(SRB2_CONFIG_EXECINFO) else() target_compile_definitions(SRB2SDL2 PRIVATE -DNOEXECINFO) message(STATUS "You have disabled stack trace dump support") endif() if(SRB2_CONFIG_ZDEBUG) target_compile_definitions(SRB2SDL2 PRIVATE -DZDEBUG) endif() if(SRB2_CONFIG_PROFILEMODE AND "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") target_compile_options(SRB2SDL2 PRIVATE -pg) target_link_options(SRB2SDL2 PRIVATE -pg) endif() if(SRB2_CONFIG_ASAN) target_compile_options(SRB2SDL2 PRIVATE -fsanitize=address) target_link_options(SRB2SDL2 PRIVATE -fsanitize=address) endif() add_subdirectory(audio) add_subdirectory(core) add_subdirectory(hwr2) add_subdirectory(io) add_subdirectory(sdl) add_subdirectory(objects) add_subdirectory(acs) add_subdirectory(rhi) add_subdirectory(monocypher) add_subdirectory(menus) if(SRB2_CONFIG_ENABLE_WEBM_MOVIES) add_subdirectory(media) endif() add_subdirectory(hud) add_subdirectory(modp_b64) # strip debug symbols into separate file when using gcc or clang. # to be consistent with Makefile, don't generate for OS X. if((CMAKE_COMPILER_IS_GNUCC) AND NOT ("${CMAKE_SYSTEM_NAME}" MATCHES Darwin)) if(${CMAKE_BUILD_TYPE} MATCHES RelWithDebInfo OR SRB2_CONFIG_ALWAYS_MAKE_DEBUGLINK) message(STATUS "Will make separate debug symbols in *.debug") add_custom_command(TARGET SRB2SDL2 POST_BUILD COMMAND ${CMAKE_OBJCOPY} ${OBJCOPY_ONLY_KEEP_DEBUG} $ $.debug # mold linker: .gnu_debuglink is present by default, so --add-gnu-debuglink would fail COMMAND ${CMAKE_OBJCOPY} --strip-debug --remove-section=.gnu_debuglink $ COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=$.debug $ ) endif() endif() # copy DLLs to bin/ directory if building internal shared on windows if("${CMAKE_SYSTEM_NAME}" STREQUAL Windows AND NOT "${SRB2_CONFIG_INTERNAL_LIBRARIES}" AND NOT MSVC) # also copy implicitly linked system libraries set(ADDITIONAL_DLLS "") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL GNU) string(CONCAT gcc_search_dirs_path "${CMAKE_BINARY_DIR}" /gcc_search_dirs.txt) #message(STATUS gcc_search_dirs_path=${gcc_search_dirs_path}) execute_process( COMMAND ${CMAKE_CXX_COMPILER} -print-search-dirs OUTPUT_FILE "${gcc_search_dirs_path}" #OUTPUT_VARIABLE gcc_search_dirs ) file(READ "${gcc_search_dirs_path}" gcc_search_dirs) #message(STATUS gcc_search_dirs=${gcc_search_dirs}) #set(gcc_install_dir "${gcc_search_dirs}") #string(REGEX MATCH "install: =[ \t]*([^\r\n]*)" gcc_install_dir "${gcc_install_dir}" ) #set(gcc_install_dir "${CMAKE_MATCH_1}") #message(STATUS gcc_install_dir="${gcc_install_dir}") string(CONCAT gcc_search_dirs_install_path_1 "${CMAKE_BINARY_DIR}" /gcc_search_dirs_install_1.txt) #message(STATUS gcc_search_dirs_install_path_1=${gcc_search_dirs_install_path_1}) execute_process( COMMAND grep "^install:" INPUT_FILE "${gcc_search_dirs_path}" OUTPUT_FILE "${gcc_search_dirs_install_path_1}" ) string(CONCAT gcc_search_dirs_install_path_2 "${CMAKE_BINARY_DIR}" /gcc_search_dirs_install_2.txt) #message(STATUS gcc_search_dirs_install_path_2=${gcc_search_dirs_install_path_2}) execute_process( COMMAND sed -e "s/^install: //" -e "s,=/,/,g" INPUT_FILE "${gcc_search_dirs_install_path_1}" OUTPUT_FILE "${gcc_search_dirs_install_path_2}" ) if(NOT ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")) string(REPLACE ":" ";" gcc_install_dir "${gcc_install_dir}") endif() file(READ ${gcc_search_dirs_install_path_2} gcc_install_dir) #set(gcc_programs_dir "${gcc_search_dirs}") #string(REGEX MATCH "programs: =[ \t]*([^\r\n]*)" gcc_programs_dir "${gcc_programs_dir}" ) #set(gcc_programs_dir "${CMAKE_MATCH_1}") #message(STATUS gcc_programs_dir="${gcc_programs_dir}") string(CONCAT gcc_search_dirs_programs_path_1 "${CMAKE_BINARY_DIR}" /gcc_search_dirs_programs_1.txt) #message(STATUS gcc_search_dirs_programs_path_1=${gcc_search_dirs_programs_path_1}) execute_process( COMMAND grep "^programs:" INPUT_FILE "${gcc_search_dirs_path}" OUTPUT_FILE "${gcc_search_dirs_programs_path_1}" ) string(CONCAT gcc_search_dirs_programs_path_2 "${CMAKE_BINARY_DIR}" /gcc_search_dirs_programs_2.txt) #message(STATUS gcc_search_dirs_programs_path_2=${gcc_search_dirs_programs_path_2}) execute_process( COMMAND sed -e "s/^programs: =//" -e "s,=/,/,g" INPUT_FILE "${gcc_search_dirs_programs_path_1}" OUTPUT_FILE "${gcc_search_dirs_programs_path_2}" ) file(READ ${gcc_search_dirs_programs_path_2} gcc_programs_dir) if(NOT ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")) string(REPLACE ":" ";" gcc_programs_dir "${gcc_programs_dir}") endif() #set(gcc_libraries_dir "${gcc_search_dirs}") #string(REGEX MATCH "libraries: =[ \t]*([^\r\n]*)" gcc_libraries_dir "${gcc_libraries_dir}" ) #set(gcc_libraries_dir "${CMAKE_MATCH_1}") #message(STATUS gcc_libraries_dir="${gcc_libraries_dir}") string(CONCAT gcc_search_dirs_libraries_path_1 "${CMAKE_BINARY_DIR}" /gcc_search_dirs_libraries_1.txt) #message(STATUS gcc_search_dirs_libraries_path_1=${gcc_search_dirs_libraries_path_1}) execute_process( COMMAND grep "^libraries:" INPUT_FILE "${gcc_search_dirs_path}" OUTPUT_FILE "${gcc_search_dirs_libraries_path_1}" ) string(CONCAT gcc_search_dirs_libraries_path_2 "${CMAKE_BINARY_DIR}" /gcc_search_dirs_libraries_2.txt) #message(STATUS gcc_search_dirs_libraries_path_2=${gcc_search_dirs_libraries_path_2}) execute_process( COMMAND sed -e "s/^libraries: =//" -e "s,=/,/,g" INPUT_FILE "${gcc_search_dirs_libraries_path_1}" OUTPUT_FILE "${gcc_search_dirs_libraries_path_2}" ) file(READ ${gcc_search_dirs_libraries_path_2} gcc_libraries_dir) if(NOT ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")) string(REPLACE ":" ";" gcc_libraries_dir "${gcc_libraries_dir}") endif() #list(LENGTH gcc_install_dir gcc_install_dir_len) #list(LENGTH gcc_programs_dir gcc_programs_dir_len) #list(LENGTH gcc_libraries_dir gcc_libraries_dir_len) #message(STATUS gcc_install_dir_len="${gcc_install_dir_len}") #message(STATUS gcc_install_dir="${gcc_install_dir}") #message(STATUS gcc_programs_dir_len="${gcc_programs_dir_len}") #message(STATUS gcc_programs_dir="${gcc_programs_dir}") #message(STATUS gcc_libraries_dir_len="${gcc_libraries_dir_len}") #message(STATUS gcc_libraries_dir="${gcc_libraries_dir}") get_filename_component(CMAKE_CXX_COMPILER_DIR ${CMAKE_CXX_COMPILER} DIRECTORY) #message(STATUS CMAKE_CXX_COMPILER_DIR="${CMAKE_CXX_COMPILER_DIR}") set(OLD_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) set(CMAKE_FIND_LIBRARY_SUFFIXES "" ${CMAKE_FIND_LIBRARY_SUFFIXES}) set(OLD_CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES}) set(CMAKE_FIND_LIBRARY_PREFIXES "" ${CMAKE_FIND_LIBRARY_PREFIXES}) find_library(LIBUNWIND NAMES "libunwind.dll" PATHS ${gcc_programs_dir} ${CMAKE_CXX_COMPILER_DIR} ) if (LIBUNWIND) #message(STATUS LIBUNWIND="${LIBUNWIND}") list(APPEND ADDITIONAL_DLLS ${LIBUNWIND}) endif() unset(LIBUNWIND) find_library(LIBGCC NAMES "libgcc_s_dw2-1.dll" "libgcc_s_sjlj-1.dll" "libgcc_s_seh-1.dll" PATHS ${gcc_programs_dir} ${CMAKE_CXX_COMPILER_DIR} ) if (LIBGCC) #message(STATUS LIBGCC="${LIBGCC}") list(APPEND ADDITIONAL_DLLS ${LIBGCC}) endif() unset(LIBGCC) find_library(LIBSTDCPP NAMES "libstdc++-6.dll" "libc++.dll" PATHS ${gcc_programs_dir} ${CMAKE_CXX_COMPILER_DIR} ) if (LIBSTDCPP) #message(STATUS LIBSTDCPP="${LIBSTDCPP}") list(APPEND ADDITIONAL_DLLS ${LIBSTDCPP}) endif() unset(LIBSTDCPP) find_library(LIBPTHREAD NAMES "winpthread-1.dll" "libwinpthread-1.dll" "pthreadGC2.dll" PATHS ${gcc_libraries_dir} ${CMAKE_CXX_COMPILER_DIR} ) if(LIBPTHREAD) #message(STATUS LIBPTHREAD="${LIBPTHREAD}") list(APPEND ADDITIONAL_DLLS ${LIBPTHREAD}) endif() set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_CMAKE_FIND_LIBRARY_SUFFIXES}) set(CMAKE_FIND_LIBRARY_PREFIXES ${OLD_CMAKE_FIND_LIBRARY_PREFIXES}) unset(LIBPTHREAD) unset(gcc_install_dir) unset(gcc_programs_dir) unset(gcc_libraries_dir) unset(OLD_CMAKE_FIND_LIBRARY_SUFFIXES) unset(OLD_CMAKE_FIND_LIBRARY_PREFIXES) #message(STATUS ADDITIONAL_DLLS="${ADDITIONAL_DLLS}") endif() add_custom_command(TARGET SRB2SDL2 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ ${ADDITIONAL_DLLS} $ COMMAND_EXPAND_LISTS COMMENT "Copying runtime DLLs" ) endif() # Setup clang-tidy if(SRB2_CONFIG_ENABLE_CLANG_TIDY_C) target_set_default_clang_tidy(SRB2SDL2 C "-*,clang-analyzer-*,-clang-analyzer-cplusplus-*") endif() if(SRB2_CONFIG_ENABLE_CLANG_TIDY_CXX) target_set_default_clang_tidy(SRB2SDL2 CXX "-*,clang-analyzer-*,modernize-*") endif()