diff --git a/CMakeLists.txt b/CMakeLists.txt index 0caa875cf..c356d09ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,7 +93,7 @@ include(VcPkgManifestFeatures) if(NOT VERSION_NUM) include(functions/git) get_git_tag(VERSION_NUM) - if (NOT "${VERSION_NUM}" STREQUAL "") + if(NOT "${VERSION_NUM}" STREQUAL "") string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" VERSION_NUM ${VERSION_NUM} ) endif() if(NOT VERSION_SUFFIX) @@ -196,244 +196,13 @@ endif() # Dependencies must be included after Platforms. include(Dependencies) -set(libdevilutionx_SRCS - Source/appfat.cpp - Source/automap.cpp - Source/capture.cpp - Source/codec.cpp - Source/control.cpp - Source/cursor.cpp - Source/dead.cpp - Source/debug.cpp - Source/diablo.cpp - Source/doom.cpp - Source/drlg_l1.cpp - Source/drlg_l2.cpp - Source/drlg_l3.cpp - Source/drlg_l4.cpp - Source/dthread.cpp - Source/dx.cpp - Source/encrypt.cpp - Source/engine.cpp - Source/error.cpp - Source/engine/assets.cpp - Source/gamemenu.cpp - Source/gendung.cpp - Source/gmenu.cpp - Source/help.cpp - Source/hwcursor.cpp - Source/init.cpp - Source/interfac.cpp - Source/inv.cpp - Source/itemdat.cpp - Source/items.cpp - Source/lighting.cpp - Source/loadsave.cpp - Source/menu.cpp - Source/minitext.cpp - Source/misdat.cpp - Source/missiles.cpp - Source/monstdat.cpp - Source/monster.cpp - Source/movie.cpp - Source/msg.cpp - Source/multi.cpp - Source/nthread.cpp - Source/objdat.cpp - Source/objects.cpp - Source/options.cpp - Source/pack.cpp - Source/palette.cpp - Source/path.cpp - Source/pfile.cpp - Source/player.cpp - Source/plrmsg.cpp - Source/portal.cpp - Source/quests.cpp - Source/restrict.cpp - Source/scrollrt.cpp - Source/setmaps.cpp - Source/sha.cpp - Source/spelldat.cpp - Source/spells.cpp - Source/stores.cpp - Source/sync.cpp - Source/textdat.cpp - Source/themes.cpp - Source/tmsg.cpp - Source/town.cpp - Source/towners.cpp - Source/track.cpp - Source/trigs.cpp - Source/controls/axis_direction.cpp - Source/controls/controller.cpp - Source/controls/controller_motion.cpp - Source/controls/devices/game_controller.cpp - Source/controls/devices/joystick.cpp - Source/controls/devices/kbcontroller.cpp - Source/controls/game_controls.cpp - Source/controls/menu_controls.cpp - Source/controls/modifier_hints.cpp - Source/controls/plrctrls.cpp - Source/controls/keymapper.cpp - Source/engine/animationinfo.cpp - Source/engine/demomode.cpp - Source/engine/load_cel.cpp - Source/engine/random.cpp - Source/engine/render/automap_render.cpp - Source/engine/render/cel_render.cpp - Source/engine/render/cl2_render.cpp - Source/engine/render/dun_render.cpp - Source/engine/render/text_render.cpp - Source/engine/surface.cpp - Source/mpq/mpq_reader.cpp - Source/mpq/mpq_sdl_rwops.cpp - Source/mpq/mpq_writer.cpp - Source/qol/autopickup.cpp - Source/qol/common.cpp - Source/qol/monhealthbar.cpp - Source/qol/xpbar.cpp - Source/qol/itemlabels.cpp - Source/utils/console.cpp - Source/utils/display.cpp - Source/utils/file_util.cpp - Source/utils/language.cpp - Source/utils/logged_fstream.cpp - Source/utils/paths.cpp - Source/utils/sdl_bilinear_scale.cpp - Source/utils/sdl_thread.cpp - Source/utils/utf8.cpp - Source/DiabloUI/art.cpp - Source/DiabloUI/art_draw.cpp - Source/DiabloUI/button.cpp - Source/DiabloUI/credits.cpp - Source/DiabloUI/credits_lines.cpp - Source/DiabloUI/diabloui.cpp - Source/DiabloUI/dialogs.cpp - Source/DiabloUI/errorart.cpp - Source/DiabloUI/mainmenu.cpp - Source/DiabloUI/progress.cpp - Source/DiabloUI/scrollbar.cpp - Source/DiabloUI/settingsmenu.cpp - Source/DiabloUI/selconn.cpp - Source/DiabloUI/selgame.cpp - Source/DiabloUI/selhero.cpp - Source/DiabloUI/selok.cpp - Source/DiabloUI/selstart.cpp - Source/DiabloUI/selyesno.cpp - Source/DiabloUI/support_lines.cpp - Source/DiabloUI/title.cpp - Source/panels/charpanel.cpp - Source/panels/mainpanel.cpp - Source/panels/spell_book.cpp - Source/panels/spell_icons.cpp - Source/panels/spell_list.cpp - Source/dvlnet/abstract_net.cpp - Source/dvlnet/base.cpp - Source/dvlnet/cdwrap.cpp - Source/dvlnet/frame_queue.cpp - Source/dvlnet/loopback.cpp - Source/dvlnet/packet.cpp - Source/storm/storm_net.cpp - Source/storm/storm_svid.cpp - Source/miniwin/misc_msg.cpp) - -if(IOS) - list(APPEND libdevilutionx_SRCS Source/platform/ios/ios_paths.m) -endif() - -if(USE_SDL1) - list(APPEND libdevilutionx_SRCS Source/utils/sdl2_to_1_2_backports.cpp) -endif() - -if(NOSOUND) - list(APPEND libdevilutionx_SRCS - Source/effects_stubs.cpp - Source/sound_stubs.cpp) -else() - list(APPEND libdevilutionx_SRCS - Source/effects.cpp - Source/sound.cpp - Source/utils/push_aulib_decoder.cpp - Source/utils/soundsample.cpp) -endif() - -if(NOT NONET) - if(NOT DISABLE_TCP) - list(APPEND libdevilutionx_SRCS - Source/dvlnet/tcp_client.cpp - Source/dvlnet/tcp_server.cpp) - endif() - if(NOT DISABLE_ZERO_TIER) - list(APPEND libdevilutionx_SRCS - Source/dvlnet/protocol_zt.cpp - Source/dvlnet/zerotier_native.cpp - Source/dvlnet/zerotier_lwip.cpp) - endif() -endif() - -if (VIRTUAL_GAMEPAD) - list(APPEND libdevilutionx_SRCS - Source/controls/touch/event_handlers.cpp - Source/controls/touch/gamepad.cpp - Source/controls/touch/renderers.cpp) -endif() +add_subdirectory(Source) set(BIN_TARGET devilutionx) - -if(NINTENDO_SWITCH) - list(APPEND libdevilutionx_SRCS - Source/platform/switch/network.cpp - Source/platform/switch/keyboard.cpp - Source/platform/switch/docking.cpp - Source/platform/switch/asio/pause.c - Source/platform/switch/asio/net/if.c - Source/platform/switch/asio/sys/signal.c) - - if(PACKET_ENCRYPTION) - list(APPEND libdevilutionx_SRCS - Source/platform/switch/random.cpp) - endif() -endif() - -if(VITA) - list(APPEND libdevilutionx_SRCS - Source/platform/vita/network.cpp - Source/platform/vita/keyboard.cpp - Source/platform/vita/touch.cpp) - - if(PACKET_ENCRYPTION) - list(APPEND libdevilutionx_SRCS - Source/platform/vita/random.cpp) - endif() -endif() - if(NINTENDO_3DS) - list(APPEND libdevilutionx_SRCS - Source/platform/ctr/system.cpp - Source/platform/ctr/keyboard.cpp - Source/platform/ctr/display.cpp - Source/platform/ctr/messagebox.cpp - Source/platform/ctr/sockets.cpp - Source/platform/ctr/locale.cpp - Source/platform/ctr/asio/net/if.c - Source/platform/ctr/asio/sys/socket.c - Source/platform/ctr/asio/sys/uio.c) set(BIN_TARGET ${BIN_TARGET}.elf) - - if(PACKET_ENCRYPTION) - list(APPEND libdevilutionx_SRCS - Source/platform/ctr/random.cpp) - endif() -endif() - -if(DISCORD_INTEGRATION) - list(APPEND libdevilutionx_SRCS - Source/discord/discord.cpp - ) endif() -add_library(libdevilutionx OBJECT ${libdevilutionx_SRCS}) if(ANDROID) add_library(${BIN_TARGET} SHARED Source/main.cpp) else() @@ -448,267 +217,19 @@ else() endif() target_link_libraries(${BIN_TARGET} PRIVATE libdevilutionx) -if(EMSCRIPTEN) - target_link_options(${BIN_TARGET} PRIVATE --preload-file assets) -endif() - -if(BUILD_TESTING) - if(ENABLE_CODECOVERAGE) - if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - message(WARNING "Codecoverage not supported with MSVC") - else() - target_compile_options(libdevilutionx PUBLIC --coverage) - target_link_options(libdevilutionx PUBLIC --coverage) - endif() - endif() - - target_compile_definitions(libdevilutionx PRIVATE _DVL_EXPORTING) - add_subdirectory(test) -endif() - -# Use file GENERATE instead of configure_file because configure_file -# does not support generator expressions. -get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) -if(is_multi_config) - set(CONFIG_PATH $/config.h) - target_include_directories(libdevilutionx PUBLIC ${CMAKE_BINARY_DIR}/$) -else() - set(CONFIG_PATH config.h) -endif() -file(GENERATE OUTPUT ${CONFIG_PATH} CONTENT -"#pragma once -#define PROJECT_NAME \"${PROJECT_NAME}\" -#define PROJECT_VERSION \"${PROJECT_VERSION_WITH_SUFFIX}\" -#define PROJECT_VERSION_MAJOR ${PROJECT_VERSION_MAJOR} -#define PROJECT_VERSION_MINOR ${PROJECT_VERSION_MINOR} -#define PROJECT_VERSION_PATCH ${PROJECT_VERSION_PATCH} -") - -if(DISCORD_INTEGRATION) - target_compile_definitions(libdevilutionx PRIVATE DISCORD) - target_link_libraries(libdevilutionx PRIVATE discord discord_game_sdk) -endif() - -if(GPERF) - find_package(Gperftools REQUIRED) -endif() - +# Must be included after `BIN_TARGET` and `libdevilutionx` are defined. include(Assets) -target_include_directories(libdevilutionx PUBLIC - Source - ${CMAKE_CURRENT_BINARY_DIR}) - -if(NOT NINTENDO_3DS) - target_link_libraries(libdevilutionx PUBLIC - Threads::Threads) -endif() - -target_link_libraries(libdevilutionx PUBLIC - PKWare - libmpq - libsmackerdec - simpleini - hoehrmann_utf8) - -if(WIN32) - target_link_libraries(libdevilutionx PUBLIC find_steam_game) -endif() - -if(NOT NONET) - if(NOT DISABLE_TCP) - target_link_libraries(libdevilutionx PUBLIC asio) - endif() - if(PACKET_ENCRYPTION) - target_link_libraries(libdevilutionx PUBLIC sodium) - endif() -endif() - -target_link_libraries(libdevilutionx PUBLIC fmt::fmt) - -genex_for_option(DEBUG) -target_compile_definitions(libdevilutionx PUBLIC "$<${DEBUG_GENEX}:_DEBUG>") - -if(NOT NONET AND NOT DISABLE_TCP) - target_compile_definitions(libdevilutionx PUBLIC ASIO_STANDALONE) -endif() - -# Defines without value -foreach( - def_name - NOSOUND - NONET - PREFILL_PLAYER_NAME - DISABLE_TCP - DISABLE_ZERO_TIER - DISABLE_STREAMING_MUSIC - DISABLE_STREAMING_SOUNDS - BUILD_TESTING - GPERF - GPERF_HEAP_MAIN - GPERF_HEAP_FIRST_GAME_ITERATION - STREAM_ALL_AUDIO - PACKET_ENCRYPTION - VIRTUAL_GAMEPAD -) -if(${def_name}) - list(APPEND def_list ${def_name}) -endif() -endforeach(def_name) - -# Defines with value -foreach( - def_name - DEFAULT_WIDTH - DEFAULT_HEIGHT - DEFAULT_AUDIO_SAMPLE_RATE - DEFAULT_AUDIO_CHANNELS - DEFAULT_AUDIO_BUFFER_SIZE - DEFAULT_AUDIO_RESAMPLING_QUALITY - MO_LANG_DIR - SDL1_VIDEO_MODE_BPP - SDL1_VIDEO_MODE_FLAGS - SDL1_VIDEO_MODE_SVID_FLAGS - SDL1_FORCE_SVID_VIDEO_MODE - SDL1_FORCE_DIRECT_RENDER - HAS_KBCTRL - KBCTRL_BUTTON_DPAD_LEFT - KBCTRL_BUTTON_DPAD_RIGHT - KBCTRL_BUTTON_DPAD_UP - KBCTRL_BUTTON_DPAD_DOWN - KBCTRL_BUTTON_B - KBCTRL_BUTTON_A - KBCTRL_BUTTON_Y - KBCTRL_BUTTON_X - KBCTRL_BUTTON_LEFTSTICK - KBCTRL_BUTTON_RIGHTSTICK - KBCTRL_BUTTON_RIGHTSHOULDER - KBCTRL_BUTTON_LEFTSHOULDER - KBCTRL_BUTTON_TRIGGERLEFT - KBCTRL_BUTTON_TRIGGERRIGHT - KBCTRL_BUTTON_START - KBCTRL_BUTTON_BACK - KBCTRL_IGNORE_1 - JOY_AXIS_LEFTX - JOY_AXIS_LEFTY - JOY_AXIS_RIGHTX - JOY_AXIS_RIGHTY - JOY_HAT_DPAD_UP_HAT - JOY_HAT_DPAD_UP - JOY_HAT_DPAD_DOWN_HAT - JOY_HAT_DPAD_DOWN - JOY_HAT_DPAD_LEFT_HAT - JOY_HAT_DPAD_LEFT - JOY_HAT_DPAD_RIGHT_HAT - JOY_HAT_DPAD_RIGHT - JOY_BUTTON_DPAD_LEFT - JOY_BUTTON_DPAD_RIGHT - JOY_BUTTON_DPAD_UP - JOY_BUTTON_DPAD_DOWN - JOY_BUTTON_B - JOY_BUTTON_A - JOY_BUTTON_Y - JOY_BUTTON_X - JOY_BUTTON_LEFTSTICK - JOY_BUTTON_RIGHTSTICK - JOY_BUTTON_RIGHTSHOULDER - JOY_BUTTON_LEFTSHOULDER - JOY_BUTTON_TRIGGERLEFT - JOY_BUTTON_TRIGGERRIGHT - JOY_BUTTON_START - JOY_BUTTON_BACK - REMAP_KEYBOARD_KEYS -) - if(DEFINED ${def_name}) - list(APPEND def_list ${def_name}=${${def_name}}) - endif() -endforeach(def_name) - -genex_for_option(UBSAN) -target_compile_options(libdevilutionx PUBLIC $<${UBSAN_GENEX}:-fsanitize=undefined>) -target_link_libraries(libdevilutionx PUBLIC $<${UBSAN_GENEX}:-fsanitize=undefined>) - -if(TSAN) - target_compile_options(libdevilutionx PUBLIC -fsanitize=thread) - target_link_libraries(libdevilutionx PUBLIC -fsanitize=thread) -else() - genex_for_option(ASAN) - target_compile_options(libdevilutionx PUBLIC "$<${ASAN_GENEX}:-fsanitize=address;-fsanitize-recover=address>") - target_link_libraries(libdevilutionx PUBLIC "$<${ASAN_GENEX}:-fsanitize=address;-fsanitize-recover=address>") +if(EMSCRIPTEN) + target_link_options(${BIN_TARGET} PRIVATE --preload-file assets) endif() -if(USE_SDL1) - target_link_libraries(libdevilutionx PUBLIC - ${SDL_LIBRARY} - SDL_image) - target_compile_definitions(libdevilutionx PUBLIC USE_SDL1) -else() - target_link_libraries(libdevilutionx PUBLIC - ${SDL2_MAIN} - SDL2::SDL2 - SDL2::SDL2_image) +if(NOT USE_SDL1) target_link_libraries(${BIN_TARGET} PUBLIC ${SDL2_MAIN}) endif() -if(NOT NOSOUND) - target_link_libraries(libdevilutionx PUBLIC SDL_audiolib) -endif() - -if(NOT NONET AND NOT DISABLE_ZERO_TIER) - if(NOT ANDROID) - target_link_libraries(libdevilutionx PUBLIC zt-static) - else() - target_link_libraries(libdevilutionx PUBLIC zt-shared) - endif() -endif() - -if(AMIGA) - target_link_libraries(libdevilutionx PUBLIC - ${ZLIB_LIBRARY}) - if(NOT WARPOS) - target_link_libraries(libdevilutionx PUBLIC -ldebug) - endif() -endif() - -if (VITA) - target_link_libraries(libdevilutionx PUBLIC - ScePower_stub - SceAppUtil_stub - SceNet_stub - SceNetCtl_stub - ) - target_compile_definitions(libdevilutionx PUBLIC VITA) -endif() - -if(NINTENDO_3DS) - target_link_libraries(libdevilutionx PUBLIC 3ds::citro3d 3ds::ctrulib) -endif() - -target_compile_definitions(libdevilutionx PUBLIC ${def_list}) - -if (GPERF) - target_link_libraries(libdevilutionx PUBLIC ${GPERFTOOLS_LIBRARIES}) -endif() - -if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT GPERF AND NOT HAIKU AND NOT VITA) - target_link_libraries(libdevilutionx PUBLIC "$<$>:-static-libgcc;-static-libstdc++>") -endif() - -if(WIN32) - target_link_libraries(libdevilutionx PUBLIC shlwapi wsock32 ws2_32 wininet) - - if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - target_compile_options(libdevilutionx PUBLIC $<$:-gstabs>) - endif() -endif() - -if(NOT WIN32 AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD) - # Enable POSIX extensions such as `readlink` and `ftruncate`. - add_definitions(-D_POSIX_C_SOURCE=200809L) -endif() - -if(HAIKU) - target_link_libraries(libdevilutionx PUBLIC network) +if(BUILD_TESTING) + add_subdirectory(test) endif() if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") @@ -719,23 +240,9 @@ if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") COMPILE_DEFINITIONS __FILE__="${SOURCE_FILE}" ) endforeach(SOURCE_FILE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-builtin-macro-redefined") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-builtin-macro-redefined") - - # Note: For Valgrind support. - genex_for_option(DEBUG) - target_compile_options(libdevilutionx PUBLIC $<${DEBUG_GENEX}:-fno-omit-frame-pointer>) - - # Warnings for devilutionX - target_compile_options(libdevilutionx PUBLIC -Wall -Wextra -Wno-unused-parameter) - - # For ARM and other default unsigned char platforms - target_compile_options(libdevilutionx PUBLIC -fsigned-char) -endif() - -if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - target_compile_options(libdevilutionx PUBLIC "/W3" "/Zc:__cplusplus" "/utf-8") - target_compile_definitions(libdevilutionx PUBLIC _CRT_SECURE_NO_WARNINGS) endif() if(APPLE) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt new file mode 100644 index 000000000..9b9ab5bdb --- /dev/null +++ b/Source/CMakeLists.txt @@ -0,0 +1,506 @@ +include(functions/genex) + +set(libdevilutionx_SRCS + appfat.cpp + automap.cpp + capture.cpp + codec.cpp + control.cpp + cursor.cpp + dead.cpp + debug.cpp + diablo.cpp + doom.cpp + drlg_l1.cpp + drlg_l2.cpp + drlg_l3.cpp + drlg_l4.cpp + dthread.cpp + dx.cpp + encrypt.cpp + engine.cpp + error.cpp + engine/assets.cpp + gamemenu.cpp + gendung.cpp + gmenu.cpp + help.cpp + hwcursor.cpp + init.cpp + interfac.cpp + inv.cpp + itemdat.cpp + items.cpp + lighting.cpp + loadsave.cpp + menu.cpp + minitext.cpp + misdat.cpp + missiles.cpp + monstdat.cpp + monster.cpp + movie.cpp + msg.cpp + multi.cpp + nthread.cpp + objdat.cpp + objects.cpp + options.cpp + pack.cpp + palette.cpp + path.cpp + pfile.cpp + player.cpp + plrmsg.cpp + portal.cpp + quests.cpp + restrict.cpp + scrollrt.cpp + setmaps.cpp + sha.cpp + spelldat.cpp + spells.cpp + stores.cpp + sync.cpp + textdat.cpp + themes.cpp + tmsg.cpp + town.cpp + towners.cpp + track.cpp + trigs.cpp + controls/axis_direction.cpp + controls/controller.cpp + controls/controller_motion.cpp + controls/devices/game_controller.cpp + controls/devices/joystick.cpp + controls/devices/kbcontroller.cpp + controls/game_controls.cpp + controls/menu_controls.cpp + controls/modifier_hints.cpp + controls/plrctrls.cpp + controls/keymapper.cpp + engine/animationinfo.cpp + engine/demomode.cpp + engine/load_cel.cpp + engine/random.cpp + engine/render/automap_render.cpp + engine/render/cel_render.cpp + engine/render/cl2_render.cpp + engine/render/dun_render.cpp + engine/render/text_render.cpp + engine/surface.cpp + mpq/mpq_reader.cpp + mpq/mpq_sdl_rwops.cpp + mpq/mpq_writer.cpp + qol/autopickup.cpp + qol/common.cpp + qol/monhealthbar.cpp + qol/xpbar.cpp + qol/itemlabels.cpp + utils/console.cpp + utils/display.cpp + utils/file_util.cpp + utils/language.cpp + utils/logged_fstream.cpp + utils/paths.cpp + utils/sdl_bilinear_scale.cpp + utils/sdl_thread.cpp + utils/utf8.cpp + DiabloUI/art.cpp + DiabloUI/art_draw.cpp + DiabloUI/button.cpp + DiabloUI/credits.cpp + DiabloUI/credits_lines.cpp + DiabloUI/diabloui.cpp + DiabloUI/dialogs.cpp + DiabloUI/errorart.cpp + DiabloUI/mainmenu.cpp + DiabloUI/progress.cpp + DiabloUI/scrollbar.cpp + DiabloUI/settingsmenu.cpp + DiabloUI/selconn.cpp + DiabloUI/selgame.cpp + DiabloUI/selhero.cpp + DiabloUI/selok.cpp + DiabloUI/selstart.cpp + DiabloUI/selyesno.cpp + DiabloUI/support_lines.cpp + DiabloUI/title.cpp + panels/charpanel.cpp + panels/mainpanel.cpp + panels/spell_book.cpp + panels/spell_icons.cpp + panels/spell_list.cpp + dvlnet/abstract_net.cpp + dvlnet/base.cpp + dvlnet/cdwrap.cpp + dvlnet/frame_queue.cpp + dvlnet/loopback.cpp + dvlnet/packet.cpp + storm/storm_net.cpp + storm/storm_svid.cpp + miniwin/misc_msg.cpp) + +if(IOS) + list(APPEND libdevilutionx_SRCS platform/ios/ios_paths.m) +endif() + +if(USE_SDL1) + list(APPEND libdevilutionx_SRCS utils/sdl2_to_1_2_backports.cpp) +endif() + +if(NOSOUND) + list(APPEND libdevilutionx_SRCS + effects_stubs.cpp + sound_stubs.cpp) +else() + list(APPEND libdevilutionx_SRCS + effects.cpp + sound.cpp + utils/push_aulib_decoder.cpp + utils/soundsample.cpp) +endif() + +if(NOT NONET) + if(NOT DISABLE_TCP) + list(APPEND libdevilutionx_SRCS + dvlnet/tcp_client.cpp + dvlnet/tcp_server.cpp) + endif() + if(NOT DISABLE_ZERO_TIER) + list(APPEND libdevilutionx_SRCS + dvlnet/protocol_zt.cpp + dvlnet/zerotier_native.cpp + dvlnet/zerotier_lwip.cpp) + endif() +endif() + +if(VIRTUAL_GAMEPAD) + list(APPEND libdevilutionx_SRCS + controls/touch/event_handlers.cpp + controls/touch/gamepad.cpp + controls/touch/renderers.cpp) +endif() + + +if(NINTENDO_SWITCH) + list(APPEND libdevilutionx_SRCS + platform/switch/network.cpp + platform/switch/keyboard.cpp + platform/switch/docking.cpp + platform/switch/asio/pause.c + platform/switch/asio/net/if.c + platform/switch/asio/sys/signal.c) + + if(PACKET_ENCRYPTION) + list(APPEND libdevilutionx_SRCS + platform/switch/random.cpp) + endif() +endif() + +if(VITA) + list(APPEND libdevilutionx_SRCS + platform/vita/network.cpp + platform/vita/keyboard.cpp + platform/vita/touch.cpp) + + if(PACKET_ENCRYPTION) + list(APPEND libdevilutionx_SRCS + platform/vita/random.cpp) + endif() +endif() + +if(NINTENDO_3DS) + list(APPEND libdevilutionx_SRCS + platform/ctr/system.cpp + platform/ctr/keyboard.cpp + platform/ctr/display.cpp + platform/ctr/messagebox.cpp + platform/ctr/sockets.cpp + platform/ctr/locale.cpp + platform/ctr/asio/net/if.c + platform/ctr/asio/sys/socket.c + platform/ctr/asio/sys/uio.c) + + + if(PACKET_ENCRYPTION) + list(APPEND libdevilutionx_SRCS + platform/ctr/random.cpp) + endif() +endif() + +if(DISCORD_INTEGRATION) + list(APPEND libdevilutionx_SRCS + discord/discord.cpp + ) +endif() + +add_library(libdevilutionx OBJECT ${libdevilutionx_SRCS}) +target_include_directories(libdevilutionx PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) + +# Use file GENERATE instead of configure_file because configure_file +# does not support generator expressions. +get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(is_multi_config) + set(CONFIG_PATH $/config.h) + target_include_directories(libdevilutionx PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/$) +else() + set(CONFIG_PATH config.h) +endif() +file(GENERATE OUTPUT ${CONFIG_PATH} CONTENT +"#pragma once +#define PROJECT_NAME \"${PROJECT_NAME}\" +#define PROJECT_VERSION \"${PROJECT_VERSION_WITH_SUFFIX}\" +#define PROJECT_VERSION_MAJOR ${PROJECT_VERSION_MAJOR} +#define PROJECT_VERSION_MINOR ${PROJECT_VERSION_MINOR} +#define PROJECT_VERSION_PATCH ${PROJECT_VERSION_PATCH} +") + +if(DISCORD_INTEGRATION) + target_compile_definitions(libdevilutionx PRIVATE DISCORD) + target_link_libraries(libdevilutionx PRIVATE discord discord_game_sdk) +endif() + +if(GPERF) + find_package(Gperftools REQUIRED) +endif() + +if(NOT NINTENDO_3DS) + target_link_libraries(libdevilutionx PUBLIC + Threads::Threads) +endif() + +target_link_libraries(libdevilutionx PUBLIC + PKWare + libmpq + libsmackerdec + simpleini + hoehrmann_utf8) + +if(WIN32) + target_link_libraries(libdevilutionx PUBLIC find_steam_game) +endif() + +if(NOT NONET) + if(NOT DISABLE_TCP) + target_link_libraries(libdevilutionx PUBLIC asio) + endif() + if(PACKET_ENCRYPTION) + target_link_libraries(libdevilutionx PUBLIC sodium) + endif() +endif() + +target_link_libraries(libdevilutionx PUBLIC fmt::fmt) + +genex_for_option(DEBUG) +target_compile_definitions(libdevilutionx PUBLIC "$<${DEBUG_GENEX}:_DEBUG>") + +if(NOT NONET AND NOT DISABLE_TCP) + target_compile_definitions(libdevilutionx PUBLIC ASIO_STANDALONE) +endif() + +genex_for_option(UBSAN) +target_compile_options(libdevilutionx PUBLIC $<${UBSAN_GENEX}:-fsanitize=undefined>) +target_link_libraries(libdevilutionx PUBLIC $<${UBSAN_GENEX}:-fsanitize=undefined>) + +if(TSAN) + target_compile_options(libdevilutionx PUBLIC -fsanitize=thread) + target_link_libraries(libdevilutionx PUBLIC -fsanitize=thread) +else() + genex_for_option(ASAN) + target_compile_options(libdevilutionx PUBLIC "$<${ASAN_GENEX}:-fsanitize=address;-fsanitize-recover=address>") + target_link_libraries(libdevilutionx PUBLIC "$<${ASAN_GENEX}:-fsanitize=address;-fsanitize-recover=address>") +endif() + +if(USE_SDL1) + target_link_libraries(libdevilutionx PUBLIC + ${SDL_LIBRARY} + SDL_image) + target_compile_definitions(libdevilutionx PUBLIC USE_SDL1) +else() + target_link_libraries(libdevilutionx PUBLIC + ${SDL2_MAIN} + SDL2::SDL2 + SDL2::SDL2_image) +endif() + +if(NOT NOSOUND) + target_link_libraries(libdevilutionx PUBLIC SDL_audiolib) +endif() + +if(NOT NONET AND NOT DISABLE_ZERO_TIER) + if(NOT ANDROID) + target_link_libraries(libdevilutionx PUBLIC zt-static) + else() + target_link_libraries(libdevilutionx PUBLIC zt-shared) + endif() +endif() + +if(AMIGA) + target_link_libraries(libdevilutionx PUBLIC + ${ZLIB_LIBRARY}) + if(NOT WARPOS) + target_link_libraries(libdevilutionx PUBLIC -ldebug) + endif() +endif() + +if(VITA) + target_link_libraries(libdevilutionx PUBLIC + ScePower_stub + SceAppUtil_stub + SceNet_stub + SceNetCtl_stub + ) + target_compile_definitions(libdevilutionx PUBLIC VITA) +endif() + +if(NINTENDO_3DS) + target_link_libraries(libdevilutionx PUBLIC 3ds::citro3d 3ds::ctrulib) +endif() + +if(GPERF) + target_link_libraries(libdevilutionx PUBLIC ${GPERFTOOLS_LIBRARIES}) +endif() + +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND NOT GPERF AND NOT HAIKU AND NOT VITA) + target_link_libraries(libdevilutionx PUBLIC "$<$>:-static-libgcc;-static-libstdc++>") +endif() + +if(WIN32) + target_link_libraries(libdevilutionx PUBLIC shlwapi wsock32 ws2_32 wininet) + + if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + target_compile_options(libdevilutionx PUBLIC "/W3" "/Zc:__cplusplus" "/utf-8") + target_compile_definitions(libdevilutionx PUBLIC _CRT_SECURE_NO_WARNINGS) + else() + target_compile_options(libdevilutionx PUBLIC $<$:-gstabs>) + endif() +endif() + +if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + # Note: For Valgrind support. + genex_for_option(DEBUG) + target_compile_options(libdevilutionx PUBLIC $<${DEBUG_GENEX}:-fno-omit-frame-pointer>) + + # Warnings for devilutionX + target_compile_options(libdevilutionx PUBLIC -Wall -Wextra -Wno-unused-parameter) + + # For ARM and other default unsigned char platforms + target_compile_options(libdevilutionx PUBLIC -fsigned-char) +endif() + +if(NOT WIN32 AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD) + # Enable POSIX extensions such as `readlink` and `ftruncate`. + add_definitions(-D_POSIX_C_SOURCE=200809L) +endif() + +if(HAIKU) + target_link_libraries(libdevilutionx PUBLIC network) +endif() + +if(BUILD_TESTING) + if(ENABLE_CODECOVERAGE) + if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + message(WARNING "Codecoverage not supported with MSVC") + else() + target_compile_options(libdevilutionx PUBLIC --coverage) + target_link_options(libdevilutionx PUBLIC --coverage) + endif() + endif() + + target_compile_definitions(libdevilutionx PRIVATE _DVL_EXPORTING) +endif() + +# Defines without value +foreach( + def_name + NOSOUND + NONET + PREFILL_PLAYER_NAME + DISABLE_TCP + DISABLE_ZERO_TIER + DISABLE_STREAMING_MUSIC + DISABLE_STREAMING_SOUNDS + BUILD_TESTING + GPERF + GPERF_HEAP_MAIN + GPERF_HEAP_FIRST_GAME_ITERATION + STREAM_ALL_AUDIO + PACKET_ENCRYPTION + VIRTUAL_GAMEPAD +) +if(${def_name}) + list(APPEND def_list ${def_name}) +endif() +endforeach(def_name) + +# Defines with value +foreach( + def_name + DEFAULT_WIDTH + DEFAULT_HEIGHT + DEFAULT_AUDIO_SAMPLE_RATE + DEFAULT_AUDIO_CHANNELS + DEFAULT_AUDIO_BUFFER_SIZE + DEFAULT_AUDIO_RESAMPLING_QUALITY + MO_LANG_DIR + SDL1_VIDEO_MODE_BPP + SDL1_VIDEO_MODE_FLAGS + SDL1_VIDEO_MODE_SVID_FLAGS + SDL1_FORCE_SVID_VIDEO_MODE + SDL1_FORCE_DIRECT_RENDER + HAS_KBCTRL + KBCTRL_BUTTON_DPAD_LEFT + KBCTRL_BUTTON_DPAD_RIGHT + KBCTRL_BUTTON_DPAD_UP + KBCTRL_BUTTON_DPAD_DOWN + KBCTRL_BUTTON_B + KBCTRL_BUTTON_A + KBCTRL_BUTTON_Y + KBCTRL_BUTTON_X + KBCTRL_BUTTON_LEFTSTICK + KBCTRL_BUTTON_RIGHTSTICK + KBCTRL_BUTTON_RIGHTSHOULDER + KBCTRL_BUTTON_LEFTSHOULDER + KBCTRL_BUTTON_TRIGGERLEFT + KBCTRL_BUTTON_TRIGGERRIGHT + KBCTRL_BUTTON_START + KBCTRL_BUTTON_BACK + KBCTRL_IGNORE_1 + JOY_AXIS_LEFTX + JOY_AXIS_LEFTY + JOY_AXIS_RIGHTX + JOY_AXIS_RIGHTY + JOY_HAT_DPAD_UP_HAT + JOY_HAT_DPAD_UP + JOY_HAT_DPAD_DOWN_HAT + JOY_HAT_DPAD_DOWN + JOY_HAT_DPAD_LEFT_HAT + JOY_HAT_DPAD_LEFT + JOY_HAT_DPAD_RIGHT_HAT + JOY_HAT_DPAD_RIGHT + JOY_BUTTON_DPAD_LEFT + JOY_BUTTON_DPAD_RIGHT + JOY_BUTTON_DPAD_UP + JOY_BUTTON_DPAD_DOWN + JOY_BUTTON_B + JOY_BUTTON_A + JOY_BUTTON_Y + JOY_BUTTON_X + JOY_BUTTON_LEFTSTICK + JOY_BUTTON_RIGHTSTICK + JOY_BUTTON_RIGHTSHOULDER + JOY_BUTTON_LEFTSHOULDER + JOY_BUTTON_TRIGGERLEFT + JOY_BUTTON_TRIGGERRIGHT + JOY_BUTTON_START + JOY_BUTTON_BACK + REMAP_KEYBOARD_KEYS +) + if(DEFINED ${def_name}) + list(APPEND def_list ${def_name}=${${def_name}}) + endif() +endforeach(def_name) + +target_compile_definitions(libdevilutionx PUBLIC ${def_list})