From 6c67cd4d9b6acf8c2961135df8e72fb6fe2a08fe Mon Sep 17 00:00:00 2001 From: Domenic Urban Date: Wed, 14 Apr 2021 18:55:01 +0200 Subject: [PATCH] added cmake support to the project --- CMakeLists.txt | 625 ++++++++++++++++++++++++++++ cmake/FindCCache.cmake | 37 ++ cmake/FindFluidSynth.cmake | 54 +++ cmake/FindMiniUPNP.cmake | 65 +++ cmake/FindSDL2.cmake | 318 ++++++++++++++ cmake/FindSDL2_mixer.cmake | 220 ++++++++++ cmake/FindZSTD.cmake | 54 +++ cmake/SimutransBackend.cmake | 26 ++ cmake/SimutransCommitInfo.cmake | 34 ++ cmake/SimutransCompileOptions.cmake | 76 ++++ cmake/SimutransDependencies.cmake | 15 + cmake/SimutransPack.cmake | 55 +++ configs/config.makeobj-linux | 16 + configs/config.makeobj-mac | 12 + configs/config.makeobj-mingw | 16 + configs/config.nettool-linux | 16 + configs/config.nettool-mac | 12 + configs/config.nettool-mingw | 18 + configs/config.sim-linux-debug-sdl2 | 17 + configs/config.sim-linux-posix | 18 + configs/config.sim-linux-sdl2mixer | 18 + configs/config.sim-mac-sdl2 | 17 + configs/config.sim-mingw-gdi | 20 + configs/config.sim-mingw-posix | 18 + configs/config.sim-mingw-sdl2 | 22 + makeobj/CMakeLists.txt | 81 ++++ nettools/CMakeLists.txt | 52 +++ simdebug.h | 7 +- simio.cc | 1 + vehicle/water_vehicle.cc | 3 + 30 files changed, 1938 insertions(+), 5 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 cmake/FindCCache.cmake create mode 100644 cmake/FindFluidSynth.cmake create mode 100644 cmake/FindMiniUPNP.cmake create mode 100644 cmake/FindSDL2.cmake create mode 100644 cmake/FindSDL2_mixer.cmake create mode 100644 cmake/FindZSTD.cmake create mode 100644 cmake/SimutransBackend.cmake create mode 100644 cmake/SimutransCommitInfo.cmake create mode 100644 cmake/SimutransCompileOptions.cmake create mode 100644 cmake/SimutransDependencies.cmake create mode 100644 cmake/SimutransPack.cmake create mode 100644 configs/config.makeobj-linux create mode 100644 configs/config.makeobj-mac create mode 100644 configs/config.makeobj-mingw create mode 100644 configs/config.nettool-linux create mode 100644 configs/config.nettool-mac create mode 100644 configs/config.nettool-mingw create mode 100644 configs/config.sim-linux-debug-sdl2 create mode 100644 configs/config.sim-linux-posix create mode 100644 configs/config.sim-linux-sdl2mixer create mode 100644 configs/config.sim-mac-sdl2 create mode 100644 configs/config.sim-mingw-gdi create mode 100644 configs/config.sim-mingw-posix create mode 100644 configs/config.sim-mingw-sdl2 create mode 100644 makeobj/CMakeLists.txt create mode 100644 nettools/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000000..5fbdc96d420 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,625 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +cmake_minimum_required(VERSION 3.8) + +# Disable in-source builds +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) + message(FATAL_ERROR "Building Simutrans in-source is not supported. " + "Please delete ${CMAKE_SOURCE_DIR}/CMakeCache.txt and configure in a different " + "(preferrably empty) directory.") +endif (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) + +set(CMAKE_WARN_DEPRECATED ON) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/") + + +find_package(CCache) +if (CCache_FOUND) + option(SIMUTRANS_USE_CCACHE "Use CCache compiler cache to improve recompilation speed" ON) + if (SIMUTRANS_USE_CCACHE) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCache_EXECUTABLE}") + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCache_EXECUTABLE}") + endif (SIMUTRANS_USE_CCACHE) +endif (CCache_FOUND) + + +project(simutrans LANGUAGES C CXX) + +include(SimutransCommitInfo) + +include(TestBigEndian) +TEST_BIG_ENDIAN(SIMUTRANS_BIG_ENDIAN) + + +# Force C++11 everywhere +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED YES) +set(CMAKE_CXX_EXTENSIONS OFF) + + +# +# Dependencies +# +include(SimutransDependencies) + +# +# Configuration options +# +include(SimutransBackend) # Select backend (SDL2 / GDI) + +if (CMAKE_USE_PTHREADS_INIT) + option(SIMUTRANS_MULTI_THREAD "Use multiple threads for drawing" ON) +else (CMAKE_USE_PTHREADS_INIT) + set(SIMUTRANS_MULTI_THREAD OFF) +endif (CMAKE_USE_PTHREADS_INIT) + +if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4) + option(SIMUTRANS_BUILD_32BIT "Build 32 or 64 bit executable" OFF) +endif () + + +option(SIMUTRANS_VALGRIND_SUPPORT "Add support for valgrind \"memcheck\" tool" OFF) + +if (Freetype_FOUND) + option(SIMUTRANS_USE_FREETYPE "Enable TrueType font support using freetype library" OFF) +endif (Freetype_FOUND) +set(SIMUTRANS_USE_FREETYPE OFF) + +if (MiniUPNP_FOUND) + option(SIMUTRANS_USE_UPNP "Use MiniUPNP for easier server setup" ON) +endif (MiniUPNP_FOUND) + +if (ZSTD_FOUND) + option(SIMUTRANS_USE_ZSTD "Enable support for zstd save file compression (larger save files than bzip2, but faster)" ON) +endif (ZSTD_FOUND) + +if (FluidSynth_FOUND) + option(SIMUTRANS_USE_FLUIDSYNTH_MIDI "Enable FluidSynth for MIDI playback" ON) +endif (FluidSynth_FOUND) + +option(SIMUTRANS_ENABLE_PROFILING "Enable profiling code" OFF) +option(SIMUTRANS_USE_SYSLOG "Enable logging to syslog" OFF) +option(SIMUTRANS_ENABLE_IPV6 "Enable connections using IPv6 in addition to IPv4" ON) +option(SIMUTRANS_ENABLE_RANDOMNESS "Disable to make get_random_seed() always return the same number" ON) +option(SIMUTRANS_DEBUG_SIMRAND "Debug the random number generator" OFF) + +set(SIMUTRANS_MSG_LEVEL 0 CACHE STRING "Message verbosity level") +set_property(CACHE SIMUTRANS_MSG_LEVEL PROPERTY STRINGS 0 1 2 3 4) + +# CMake does not fill in CMAKE_BUILD_TYPE automatically. +if (NOT MSVC) + if (CMAKE_BUILD_TYPE STREQUAL "") + set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Build type. Valid values are Debug Release MinSizeRel RelWithDebInfo" FORCE) + endif () + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel RelWithDebInfo) +endif (NOT MSVC) + + +# +# output directory +# +file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/simutrans) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/simutrans) + + +# +# sources +# +add_executable(simutrans + bauer/brueckenbauer.cc + bauer/fabrikbauer.cc + bauer/goods_manager.cc + bauer/hausbauer.cc + bauer/tunnelbauer.cc + bauer/tree_builder.cc + bauer/vehikelbauer.cc + bauer/wegbauer.cc + boden/boden.cc + boden/brueckenboden.cc + boden/fundament.cc + boden/grund.cc + boden/monorailboden.cc + boden/tunnelboden.cc + boden/wasser.cc + boden/wege/kanal.cc + boden/wege/maglev.cc + boden/wege/monorail.cc + boden/wege/narrowgauge.cc + boden/wege/runway.cc + boden/wege/schiene.cc + boden/wege/strasse.cc + boden/wege/weg.cc + dataobj/crossing_logic.cc + dataobj/environment.cc + dataobj/freelist.cc + dataobj/gameinfo.cc + dataobj/height_map_loader.cc + dataobj/koord.cc + dataobj/koord3d.cc + dataobj/loadsave.cc + dataobj/marker.cc + dataobj/objlist.cc + dataobj/powernet.cc + dataobj/records.cc + dataobj/rect.cc + dataobj/ribi.cc + dataobj/route.cc + dataobj/scenario.cc + dataobj/schedule.cc + dataobj/settings.cc + dataobj/tabfile.cc + dataobj/translator.cc + descriptor/bridge_desc.cc + descriptor/building_desc.cc + descriptor/factory_desc.cc + descriptor/goods_desc.cc + descriptor/ground_desc.cc + descriptor/image.cc + descriptor/obj_base_desc.cc + descriptor/reader/bridge_reader.cc + descriptor/reader/building_reader.cc + descriptor/reader/citycar_reader.cc + descriptor/reader/crossing_reader.cc + descriptor/reader/factory_reader.cc + descriptor/reader/good_reader.cc + descriptor/reader/ground_reader.cc + descriptor/reader/groundobj_reader.cc + descriptor/reader/image_reader.cc + descriptor/reader/imagelist2d_reader.cc + descriptor/reader/imagelist_reader.cc + descriptor/reader/obj_reader.cc + descriptor/reader/pedestrian_reader.cc + descriptor/reader/roadsign_reader.cc + descriptor/reader/root_reader.cc + descriptor/reader/sim_reader.cc + descriptor/reader/skin_reader.cc + descriptor/reader/sound_reader.cc + descriptor/reader/text_reader.cc + descriptor/reader/tree_reader.cc + descriptor/reader/tunnel_reader.cc + descriptor/reader/vehicle_reader.cc + descriptor/reader/way_obj_reader.cc + descriptor/reader/way_reader.cc + descriptor/reader/xref_reader.cc + descriptor/sound_desc.cc + descriptor/tunnel_desc.cc + descriptor/vehicle_desc.cc + descriptor/way_desc.cc + display/font.cc + display/simview.cc + display/viewport.cc + finder/placefinder.cc + freight_list_sorter.cc + gui/ai_option_t.cc + gui/ai_selector.cc + gui/banner.cc + gui/base_info.cc + gui/baum_edit.cc + gui/city_info.cc + gui/citybuilding_edit.cc + gui/citylist_frame_t.cc + gui/citylist_stats_t.cc + gui/climates.cc + gui/components/gui_aligned_container.cc + gui/components/gui_building.cc + gui/components/gui_button.cc + gui/components/gui_button_to_chart.cc + gui/components/gui_chart.cc + gui/components/gui_colorbox.cc + gui/components/gui_combobox.cc + gui/components/gui_container.cc + gui/components/gui_convoiinfo.cc + gui/components/gui_divider.cc + gui/components/gui_fixedwidth_textarea.cc + gui/components/gui_flowtext.cc + gui/components/gui_image.cc + gui/components/gui_image_list.cc + gui/components/gui_component.cc + gui/components/gui_label.cc + gui/components/gui_map_preview.cc + gui/components/gui_numberinput.cc + gui/components/gui_obj_view_t.cc + gui/components/gui_schedule.cc + gui/components/gui_scrollbar.cc + gui/components/gui_scrolled_list.cc + gui/components/gui_scrollpane.cc + gui/components/gui_speedbar.cc + gui/components/gui_tab_panel.cc + gui/components/gui_textarea.cc + gui/components/gui_textinput.cc + gui/components/gui_timeinput.cc + gui/components/gui_waytype_tab_panel.cc + gui/components/gui_world_view_t.cc + gui/convoi_detail_t.cc + gui/convoi_filter_frame.cc + gui/convoi_frame.cc + gui/convoi_info_t.cc + gui/convoy_item.cc + gui/curiosity_edit.cc + gui/curiositylist_frame_t.cc + gui/curiositylist_stats_t.cc + gui/depot_frame.cc + gui/depotlist_frame.cc + gui/display_settings.cc + gui/enlarge_map_frame_t.cc + gui/extend_edit.cc + gui/fabrik_info.cc + gui/factory_chart.cc + gui/factory_edit.cc + gui/factorylist_frame_t.cc + gui/factorylist_stats_t.cc + gui/goods_frame_t.cc + gui/goods_stats_t.cc + gui/ground_info.cc + gui/groundobj_edit.cc + gui/gui_frame.cc + gui/gui_theme.cc + gui/halt_info.cc + gui/halt_list_filter_frame.cc + gui/halt_list_frame.cc + gui/halt_list_stats.cc + gui/headquarter_info.cc + gui/help_frame.cc + gui/jump_frame.cc + gui/minimap.cc + gui/kennfarbe.cc + gui/label_info.cc + gui/labellist_frame_t.cc + gui/labellist_stats_t.cc + gui/line_item.cc + gui/line_management_gui.cc + gui/load_relief_frame.cc + gui/loadfont_frame.cc + gui/loadsave_frame.cc + gui/map_frame.cc + gui/message_frame_t.cc + gui/message_option_t.cc + gui/message_stats_t.cc + gui/messagebox.cc + gui/money_frame.cc + gui/obj_info.cc + gui/optionen.cc + gui/pakselector.cc + gui/pakinstaller.cc + gui/password_frame.cc + gui/player_frame_t.cc + gui/privatesign_info.cc + gui/savegame_frame.cc + gui/scenario_frame.cc + gui/scenario_info.cc + gui/schedule_list.cc + gui/script_tool_frame.cc + gui/server_frame.cc + gui/settings_frame.cc + gui/settings_stats.cc + gui/signal_spacing.cc + gui/simwin.cc + gui/sound_frame.cc + gui/sprachen.cc + gui/station_building_select.cc + gui/themeselector.cc + gui/tool_selector.cc + gui/trafficlight_info.cc + gui/vehiclelist_frame.cc + gui/welt.cc + io/classify_file.cc + io/raw_image.cc + io/raw_image_bmp.cc + io/raw_image_png.cc + io/raw_image_ppm.cc + io/rdwr/bzip2_file_rdwr_stream.cc + io/rdwr/raw_file_rdwr_stream.cc + io/rdwr/rdwr_stream.cc + io/rdwr/zlib_file_rdwr_stream.cc + network/checksum.cc + network/memory_rw.cc + network/network.cc + network/network_address.cc + network/network_cmd.cc + network/network_cmd_ingame.cc + network/network_cmd_scenario.cc + network/network_cmp_pakset.cc + network/network_file_transfer.cc + network/network_packet.cc + network/network_socket_list.cc + network/pakset_info.cc + obj/baum.cc + obj/bruecke.cc + obj/crossing.cc + obj/field.cc + obj/gebaeude.cc + obj/groundobj.cc + obj/label.cc + obj/leitung2.cc + obj/pillar.cc + obj/roadsign.cc + obj/signal.cc + obj/simobj.cc + obj/tunnel.cc + obj/wayobj.cc + obj/wolke.cc + obj/zeiger.cc + old_blockmanager.cc + player/ai.cc + player/ai_goods.cc + player/ai_passenger.cc + player/ai_scripted.cc + player/finance.cc + player/simplay.cc + script/api/api_city.cc + script/api/api_command.cc + script/api/api_const.cc + script/api/api_control.cc + script/api/api_convoy.cc + script/api/api_factory.cc + script/api/api_gui.cc + script/api/api_halt.cc + script/api/api_include.cc + script/api/api_line.cc + script/api/api_map_objects.cc + script/api/api_obj_desc.cc + script/api/api_obj_desc_base.cc + script/api/api_pathfinding.cc + script/api/api_player.cc + script/api/api_scenario.cc + script/api/api_schedule.cc + script/api/api_settings.cc + script/api/api_simple.cc + script/api/api_tiles.cc + script/api/api_world.cc + script/api/export_desc.cc + script/api/get_next.cc + script/api_class.cc + script/api_function.cc + script/api_param.cc + script/dynamic_string.cc + script/export_objs.cc + script/script.cc + script/script_loader.cc + script/script_tool_manager.cc + simcity.cc + simconvoi.cc + simdebug.cc + simdepot.cc + simevent.cc + simfab.cc + simhalt.cc + siminteraction.cc + simintr.cc + simio.cc + simline.cc + simlinemgmt.cc + simloadingscreen.cc + simmain.cc + simmem.cc + simmenu.cc + simmesg.cc + simplan.cc + simskin.cc + simsound.cc + simticker.cc + simtool.cc + simtool-scripted.cc + simware.cc + simworld.cc + squirrel/sq_extensions.cc + squirrel/sqstdlib/sqstdaux.cc + squirrel/sqstdlib/sqstdblob.cc + squirrel/sqstdlib/sqstdio.cc + squirrel/sqstdlib/sqstdmath.cc + squirrel/sqstdlib/sqstdrex.cc + squirrel/sqstdlib/sqstdstream.cc + squirrel/sqstdlib/sqstdstring.cc + squirrel/sqstdlib/sqstdsystem.cc + squirrel/squirrel/sqapi.cc + squirrel/squirrel/sqbaselib.cc + squirrel/squirrel/sqclass.cc + squirrel/squirrel/sqcompiler.cc + squirrel/squirrel/sqdebug.cc + squirrel/squirrel/sqfuncstate.cc + squirrel/squirrel/sqlexer.cc + squirrel/squirrel/sqmem.cc + squirrel/squirrel/sqobject.cc + squirrel/squirrel/sqstate.cc + squirrel/squirrel/sqtable.cc + squirrel/squirrel/sqvm.cc + sys/simsys.cc + unicode.cc + utils/cbuffer_t.cc + utils/checklist.cc + utils/csv.cc + utils/log.cc + utils/searchfolder.cc + utils/sha1.cc + utils/sha1_hash.cc + utils/simrandom.cc + utils/simstring.cc + utils/simthread.cc + vehicle/air_vehicle.cc + vehicle/movingobj.cc + vehicle/pedestrian.cc + vehicle/rail_vehicle.cc + vehicle/road_vehicle.cc + vehicle/simroadtraffic.cc + vehicle/vehicle.cc + vehicle/vehicle_base.cc + vehicle/water_vehicle.cc +) + +target_link_libraries(simutrans PRIVATE PNG::PNG) + + +if (WIN32) + target_sources(simutrans PRIVATE sys/clipboard_w32.cc) +else () + target_sources(simutrans PRIVATE sys/clipboard_internal.cc) +endif () + +if (SIMUTRANS_MULTI_THREAD) + target_compile_definitions(simutrans PRIVATE MULTI_THREAD=1) + target_link_libraries(simutrans PRIVATE Threads::Threads) +endif (SIMUTRANS_MULTI_THREAD) + + +# Backup sound and music routines if the selected backend does not provide any routines +if (WIN32) + set(BACKUP_SOUND sound/win32_sound.cc) + set(BACKUP_MUSIC music/w32_midi.cc) +else (WIN32) + set(BACKUP_SOUND sound/no_sound.cc) + set(BACKUP_MUSIC music/no_midi.cc) +endif (WIN32) + + +if (SIMUTRANS_BACKEND STREQUAL "sdl2") + target_sources(simutrans PRIVATE display/simgraph16.cc sys/simsys_s2.cc sound/sdl2_sound.cc) + target_link_libraries(simutrans PRIVATE SDL2::Core) + target_compile_definitions(simutrans PRIVATE COLOUR_DEPTH=16) + + if (WIN32) + target_sources(simutrans PRIVATE sys/simsys_w32_png.cc) + endif () + +elseif (SIMUTRANS_BACKEND STREQUAL "mixer_sdl2") + target_sources(simutrans PRIVATE display/simgraph16.cc sys/simsys_s2.cc sound/sdl2_mixer_sound.cc music/sdl2_mixer_midi.cc) + target_link_libraries(simutrans PRIVATE SDL2::Core SDL2::Mixer) + target_compile_definitions(simutrans PRIVATE COLOUR_DEPTH=16) + + if (WIN32) + target_sources(simutrans PRIVATE sys/simsys_w32_png.cc) + endif () + +elseif (SIMUTRANS_BACKEND STREQUAL "gdi") + target_sources(simutrans PRIVATE display/simgraph16.cc sys/simsys_w.cc sys/simsys_w32_png.cc ${BACKUP_SOUND} ) + target_link_libraries(simutrans PRIVATE imm32) + target_compile_definitions(simutrans PRIVATE COLOUR_DEPTH=16) + +else () + if (NOT SIMUTRANS_BACKEND STREQUAL "none") + message(WARNING "Unknown backend '${SIMUTRANS_BACKEND}', falling back to headless compilation") + endif () + + target_sources(simutrans PRIVATE display/simgraph0.cc sys/simsys_posix.cc sound/no_sound.cc music/no_midi.cc) + target_compile_definitions(simutrans PRIVATE COLOUR_DEPTH=0) +endif () + + +# +# Link dependencies +# +target_link_libraries(simutrans PRIVATE + ZLIB::ZLIB + BZip2::BZip2 +) + +if (WIN32) + target_link_libraries(simutrans PRIVATE ws2_32 winmm) +endif (WIN32) + +if (SIMUTRANS_USE_FREETYPE) + target_compile_definitions(simutrans PRIVATE USE_FREETYPE=1) + target_include_directories(simutrans PRIVATE ${FREETYPE_INCLUDE_DIRS}) + target_link_libraries(simutrans PRIVATE ${FREETYPE_LIBRARIES}) +endif (SIMUTRANS_USE_FREETYPE) + +if (SIMUTRANS_USE_UPNP) + target_compile_definitions(simutrans PRIVATE USE_UPNP=1) + target_link_libraries(simutrans PRIVATE MiniUPNP::MiniUPNP) +endif (SIMUTRANS_USE_UPNP) + +if (SIMUTRANS_USE_ZSTD) + target_sources(simutrans PRIVATE io/rdwr/zstd_file_rdwr_stream.cc) + target_compile_definitions(simutrans PRIVATE USE_ZSTD=1) + target_link_libraries(simutrans PRIVATE ZSTD::ZSTD) +endif (SIMUTRANS_USE_ZSTD) + +# only consider FluidSynth for SDL2 and GDI backends +if ((SIMUTRANS_BACKEND STREQUAL "sdl2") OR (SIMUTRANS_BACKEND STREQUAL "gdi")) + if (SIMUTRANS_USE_FLUIDSYNTH_MIDI) + target_sources(simutrans PRIVATE music/fluidsynth.cc gui/loadsoundfont_frame.cc) + target_compile_definitions(simutrans PRIVATE USE_FLUIDSYNTH_MIDI=1) + target_link_libraries(simutrans PRIVATE FluidSynth::FluidSynth) + else () + target_sources( simutrans PRIVATE ${BACKUP_MUSIC} ) + endif (SIMUTRANS_USE_FLUIDSYNTH_MIDI) +endif ((SIMUTRANS_BACKEND STREQUAL "sdl2") OR (SIMUTRANS_BACKEND STREQUAL "gdi")) + +# +# compile options +# +if (SIMUTRANS_BIG_ENDIAN) + target_compile_definitions(simutrans PRIVATE SIM_BIG_ENDIAN=1) +endif () + +if (SIMUTRANS_VALGRIND_SUPPORT) + add_definitions(-DUSE_VALGRIND_MEMCHECK=1) +endif () + +if (SIMUTRANS_ENABLE_PROFILING) + add_definitions(-DPROFILE=1) +endif () + +include(SimutransCompileOptions) +target_compile_options(simutrans PRIVATE ${SIMUTRANS_COMMON_COMPILE_OPTIONS}) + +target_compile_definitions(simutrans PRIVATE $,DEBUG=1,NDEBUG>) +target_compile_definitions(simutrans PRIVATE ENABLE_WATERWAY_SIGNS=0 AUTOJOIN_PUBLIC=0) +target_compile_definitions(simutrans PRIVATE MSG_LEVEL=${SIMUTRANS_MSG_LEVEL}) + +if (SIMUTRANS_WITH_REVISION) + target_compile_definitions(simutrans PRIVATE REVISION=${SIMUTRANS_SHA_SHORT}) +endif () + +if (SIMUTRANS_USE_SYSLOG) + target_compile_definitions(simutrans PRIVATE SYSLOG=1) +endif () + +if (NOT SIMUTRANS_USE_IPV6) + target_compile_definitions(simutrans PRIVATE USE_IP4_ONLY=1) +endif () + +if (NOT SIMUTRANS_ENABLE_RANDOMNESS) + target_compile_definitions(simutrans PRIVATE DISABLE_RANDOMNESS=1) +endif () + +if (SIMUTRANS_DEBUG_SIMRAND) + target_compile_definitions(simutrans PRIVATE DEBUG_SIMRAND_CALLS=1) +endif () + +if (APPLE) + target_compile_definitions(simutrans PRIVATE ALT_SDL_DIR=1) +endif (APPLE) + + +# +# Installation +# +install(TARGETS simutrans RUNTIME DESTINATION simutrans) + +install(DIRECTORY "${CMAKE_SOURCE_DIR}/simutrans/" DESTINATION "simutrans") + +install(FILES get_pak.sh DESTINATION "simutrans" + PERMISSIONS + OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE +) + + +# +# Nettool/Makeobj +# +if (PNG_FOUND) + add_subdirectory(makeobj) +endif () + +add_subdirectory(nettools) + + +# +# Packaging +# +include(SimutransPack) diff --git a/cmake/FindCCache.cmake b/cmake/FindCCache.cmake new file mode 100644 index 00000000000..d9b047fa441 --- /dev/null +++ b/cmake/FindCCache.cmake @@ -0,0 +1,37 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# +# +# - Find CCache compiler cache executable. +# +# This module defines the following variables: +# CCache_FOUND - true if CCache was found. +# CCache_EXECUTABLE - Path to CCache executable. +# CCache_VERSION - Version string of CCache executable. +# + +include(FindPackageHandleStandardArgs) + +find_program(CCache_EXECUTABLE ccache) + +if (CCache_EXECUTABLE) + execute_process(COMMAND "${CCache_EXECUTABLE}" --version + OUTPUT_VARIABLE CCache_VERSION_OUTPUT + ) + + if (CCache_VERSION_OUTPUT MATCHES "version ([0-9]+\\.[0-9]+\\.[0-9]+)") + set(CCache_VERSION "${CMAKE_MATCH_1}") + endif () +endif (CCache_EXECUTABLE) + + +find_package_handle_standard_args(CCache + FOUND_VAR CCache_FOUND + REQUIRED_VARS CCache_EXECUTABLE + VERSION_VAR CCache_VERSION +) + +if (CCache_FOUND OR NOT CCache_FIND_REQUIRED) + mark_as_advanced(CCache_EXECUTABLE) +endif () diff --git a/cmake/FindFluidSynth.cmake b/cmake/FindFluidSynth.cmake new file mode 100644 index 00000000000..a78a4f20e78 --- /dev/null +++ b/cmake/FindFluidSynth.cmake @@ -0,0 +1,54 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# +# +# - Find fluidsynth midi synthetizer library. +# +# This module defines the following variables: +# FluidSynth_FOUND - true if fluidsynth was found +# FluidSynth_INCLUDE_DIRS - Include directories needed for fluidsynth +# FluidSynth_LIBRARIES - Libraries to link to when using fluidsynth +# +# Additionally, this module defines the IMPORTED target FluidSynth::FluidSynth, +# if fluidsynth has been found. +# + +include(FindPackageHandleStandardArgs) + +if (FluidSynth_INCLUDE_DIRS AND FluidSynth_LIBRARIES) + # already in cache, be silent + set(FluidSynth_FIND_QUIETLY TRUE) +endif (FluidSynth_INCLUDE_DIRS AND FluidSynth_LIBRARIES) + +find_path(FluidSynth_INCLUDE_DIR fluidsynth.h + /usr/local/include + /usr/include + $ENV{MINGDIR}/include +) + +set(FluidSynth_NAMES fluidsynth) +find_library(FluidSynth_LIBRARY + NAMES ${FluidSynth_NAMES} + PATHS /usr/local/lib /usr/lib $ENV{MINGDIR}/lib +) + +find_package_handle_standard_args(FluidSynth + FOUND_VAR FluidSynth_FOUND + REQUIRED_VARS FluidSynth_LIBRARY FluidSynth_INCLUDE_DIR +) + +set(FluidSynth_INCLUDE_DIRS "${FluidSynth_INCLUDE_DIR}") +set(FluidSynth_LIBRARIES "${FluidSynth_LIBRARY}") + +if (FluidSynth_FOUND OR NOT FluidSynth_FIND_REQUIRED) + # Only show variables when fluidsynth is required and not found + mark_as_advanced(FluidSynth_INCLUDE_DIRS FluidSynth_LIBRARIES FluidSynth_INCLUDE_DIR FluidSynth_LIBRARY) +endif (FluidSynth_FOUND OR NOT FluidSynth_FIND_REQUIRED) + +if (FluidSynth_FOUND AND NOT TARGET FluidSynth::FluidSynth) + add_library(FluidSynth::FluidSynth UNKNOWN IMPORTED) + + set_target_properties(FluidSynth::FluidSynth PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FluidSynth_INCLUDE_DIRS}") + set_property(TARGET FluidSynth::FluidSynth APPEND PROPERTY IMPORTED_LOCATION "${FluidSynth_LIBRARIES}") +endif (FluidSynth_FOUND AND NOT TARGET FluidSynth::FluidSynth) diff --git a/cmake/FindMiniUPNP.cmake b/cmake/FindMiniUPNP.cmake new file mode 100644 index 00000000000..acbe60be82c --- /dev/null +++ b/cmake/FindMiniUPNP.cmake @@ -0,0 +1,65 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# +# +# Locate MiniUPNP library. +# This module defines +# MiniUPNP_FOUND, if miniupnp library and headers have been found +# MiniUPNP_LIBRARY, the miniupnp variant +# MiniUPNP_INCLUDE_DIR, where to find miniupnpc.h and family) +# MiniUPNP_VERSION, the API version of MiniUPNP +# + + +if (MiniUPNP_INCLUDE_DIR AND MiniUPNP_LIBRARY) + # Already in cache, be silent + set(MiniUPNP_FIND_QUIETLY TRUE) +endif () + +find_path(MiniUPNP_INCLUDE_DIR miniupnpc.h + HINTS $ENV{MINIUPNP_INCLUDE_DIR} + PATH_SUFFIXES miniupnpc +) + +find_library(MiniUPNP_LIBRARY miniupnpc + HINTS $ENV{MINIUPNP_LIBRARY} +) + +find_library(MiniUPNP_STATIC_LIBRARY libminiupnpc.a + HINTS $ENV{MINIUPNP_STATIC_LIBRARY} +) + +set(MiniUPNP_INCLUDE_DIRS ${MiniUPNP_INCLUDE_DIR}) +set(MiniUPNP_LIBRARIES ${MiniUPNP_LIBRARY}) +set(MiniUPNP_STATIC_LIBRARIES ${MiniUPNP_STATIC_LIBRARY}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + MiniUPNP DEFAULT_MSG + MiniUPNP_LIBRARY + MiniUPNP_INCLUDE_DIR +) + +if (MiniUPNP_FOUND) + file(STRINGS "${MiniUPNP_INCLUDE_DIR}/miniupnpc.h" MiniUPNP_API_VERSION_STR REGEX "^#define[\t ]+MINIUPNPC_API_VERSION[\t ]+[0-9]+") + if (MiniUPNP_API_VERSION_STR MATCHES "^#define[\t ]+MINIUPNPC_API_VERSION[\t ]+([0-9]+)") + set(MiniUPNP_API_VERSION "${CMAKE_MATCH_1}") + endif() + + if (MiniUPNP_API_VERSION GREATER_EQUAL 10 AND NOT MiniUPNP_FIND_QUIETLY) + message(STATUS "Found MiniUPNP API version ${MiniUPNP_API_VERSION}") + endif() +endif() + +mark_as_advanced(MiniUPNP_INCLUDE_DIR MiniUPNP_LIBRARY MiniUPNP_STATIC_LIBRARY) + +if (MiniUPNP_FOUND) + if (NOT TARGET MiniUPNP::MiniUPNP) + add_library(MiniUPNP::MiniUPNP UNKNOWN IMPORTED) + endif (NOT TARGET MiniUPNP::MiniUPNP) + + set_target_properties(MiniUPNP::MiniUPNP PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${MiniUPNP_INCLUDE_DIRS}") + set_target_properties(MiniUPNP::MiniUPNP PROPERTIES IMPORTED_LOCATION "${MiniUPNP_LIBRARIES}") +endif (MiniUPNP_FOUND) + diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake new file mode 100644 index 00000000000..1a0529235b8 --- /dev/null +++ b/cmake/FindSDL2.cmake @@ -0,0 +1,318 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +# Copyright 2019 Amine Ben Hassouna +# Copyright 2000-2019 Kitware, Inc. and Contributors +# All rights reserved. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: + +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. + +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. + +# * Neither the name of Kitware, Inc. nor the names of Contributors +# may be used to endorse or promote products derived from this +# software without specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#[=======================================================================[.rst: +FindSDL2 +-------- + +Locate SDL2 library + +This module defines the following 'IMPORTED' targets: + +:: + + SDL2::Core + The SDL2 library, if found. + Libraries should link to SDL2::Core + + +This module will set the following variables in your project: + +:: + + SDL2_LIBRARIES, the name of the library to link against + SDL2_INCLUDE_DIRS, where to find SDL.h + SDL2_FOUND, if false, do not try to link to SDL2 + SDL2_VERSION_STRING, human-readable string containing the version of SDL2 + + + +This module responds to the following cache variables: + +:: + + SDL2_INCLUDE_DIR + SDL2 headers path. + + SDL2_LIBRARY + SDL2 Library (.dll, .so, .a, etc) path. + + +Don't forget to include SDLmain.h and SDLmain.m in your project for the +OS X framework based version. (Other versions link to -lSDL2main which +this module will try to find on your behalf.) Also for OS X, this +module will automatically add the -framework Cocoa on your behalf. + + +Additional Note: If you see an empty SDL2_LIBRARY in your project +configuration, it means CMake did not find your SDL2 library +(SDL2.dll, libsdl2.so, SDL2.framework, etc). Set SDL2_LIBRARY to point +to your SDL2 library, and configure again. Similarly, if you see an +empty SDL2MAIN_LIBRARY, you should set this value as appropriate. These +values are used to generate the final SDL2_LIBRARIES variable and the +SDL2::Core and SDL2::Main targets, but when these values are unset, +SDL2_LIBRARIES, SDL2::Core and SDL2::Main does not get created. + + +$SDL2DIR is an environment variable that would correspond to the +./configure --prefix=$SDL2DIR used in building SDL2. l.e.galup 9-20-02 + + + +Created by Amine Ben Hassouna: + Adapt FindSDL.cmake to SDL2 (FindSDL2.cmake). + Add cache variables for more flexibility: + SDL2_PATH, SDL2_NO_DEFAULT_PATH (for details, see doc above). + Mark 'Threads' as a required dependency for non-OSX systems. + Modernize the FindSDL2.cmake module by creating specific targets: + SDL2::Core and SDL2::Main (for details, see doc above). + + +Original FindSDL.cmake module: + Modified by Eric Wing. Added code to assist with automated building + by using environmental variables and providing a more + controlled/consistent search behavior. Added new modifications to + recognize OS X frameworks and additional Unix paths (FreeBSD, etc). + Also corrected the header search path to follow "proper" SDL + guidelines. Added a search for SDLmain which is needed by some + platforms. Added a search for threads which is needed by some + platforms. Added needed compile switches for MinGW. + +On OSX, this will prefer the Framework version (if found) over others. +People will have to manually change the cache value of SDL2_LIBRARY to +override this selection or set the SDL2_PATH variable or the CMake +environment CMAKE_INCLUDE_PATH to modify the search paths. + +Note that the header path has changed from SDL/SDL.h to just SDL.h +This needed to change because "proper" SDL convention is #include +"SDL.h", not . This is done for portability reasons +because not all systems place things in SDL/ (see FreeBSD). +#]=======================================================================] + +# Define options for searching SDL2 Library in a custom path + +set(SDL2_PATH "" CACHE STRING "Custom SDL2 Library path") + +set(_SDL2_NO_DEFAULT_PATH OFF) +if(SDL2_PATH) + set(_SDL2_NO_DEFAULT_PATH ON) +endif() + +set(SDL2_NO_DEFAULT_PATH ${_SDL2_NO_DEFAULT_PATH} + CACHE BOOL "Disable search SDL2 Library in default path") +unset(_SDL2_NO_DEFAULT_PATH) + +set(SDL2_NO_DEFAULT_PATH_CMD) +if(SDL2_NO_DEFAULT_PATH) + set(SDL2_NO_DEFAULT_PATH_CMD NO_DEFAULT_PATH) +endif() + +# Search for the SDL2 include directory +find_path(SDL2_INCLUDE_DIR SDL.h + HINTS + ENV SDL2DIR + ${SDL2_NO_DEFAULT_PATH_CMD} + PATH_SUFFIXES SDL2 + # path suffixes to search inside ENV{SDL2DIR} + include/SDL2 include + PATHS ${SDL2_PATH} + DOC "Where the SDL2 headers can be found" +) + +set(SDL2_INCLUDE_DIRS "${SDL2_INCLUDE_DIR}") + +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(VC_LIB_PATH_SUFFIX lib/x64) +else() + set(VC_LIB_PATH_SUFFIX lib/x86) +endif() + +# SDL-2.0 is the name used by FreeBSD ports... +# don't confuse it for the version number. +find_library(SDL2_LIBRARY + NAMES SDL2 SDL-2.0 + HINTS + ENV SDL2DIR + ${SDL2_NO_DEFAULT_PATH_CMD} + PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} + PATHS ${SDL2_PATH} + DOC "Where the SDL2 Library can be found" +) + +if (APPLE AND SDL2_LIBRARY MATCHES "\.framework$" AND EXISTS "${SDL2_LIBRARY}/SDL2" AND NOT IS_DIRECTORY "${SDL2_LIBRARY}/SDL2") + set(SDL2_LIBRARY "${SDL2_LIBRARY}/SDL2") +endif () + +set(SDL2_LIBRARIES "${SDL2_LIBRARY}") + +# SDL2 may require threads on your system. +# The Apple build may not need an explicit flag because one of the +# frameworks may already provide it. +# But for non-OSX systems, I will use the CMake Threads package. +if(NOT APPLE) + find_package(Threads QUIET) + if(NOT Threads_FOUND) + set(SDL2_THREADS_NOT_FOUND "Could NOT find Threads (Threads is required by SDL2).") + if(SDL2_FIND_REQUIRED) + message(FATAL_ERROR ${SDL2_THREADS_NOT_FOUND}) + else() + if(NOT SDL2_FIND_QUIETLY) + message(STATUS ${SDL2_THREADS_NOT_FOUND}) + endif() + return() + endif() + unset(SDL2_THREADS_NOT_FOUND) + endif() +endif() + +# MinGW needs an additional link flag, -mwindows +# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows +if(MINGW) + set(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "link flags for MinGW") +endif() + +if(SDL2_LIBRARY) + # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. + # CMake doesn't display the -framework Cocoa string in the UI even + # though it actually is there if I modify a pre-used variable. + # I think it has something to do with the CACHE STRING. + # So I use a temporary variable until the end so I can set the + # "real" variable in one-shot. + if(APPLE) + set(SDL2_LIBRARIES ${SDL2_LIBRARIES} -framework Cocoa) + endif() + + # For threads, as mentioned Apple doesn't need this. + # In fact, there seems to be a problem if I used the Threads package + # and try using this line, so I'm just skipping it entirely for OS X. + if(NOT APPLE) + set(SDL2_LIBRARIES ${SDL2_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) + endif() + + # For MinGW library + if(MINGW) + set(SDL2_LIBRARIES ${MINGW32_LIBRARY} ${SDL2_LIBRARIES}) + endif() + +endif() + +# Read SDL2 version +if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h") + file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$") + string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MAJOR "${SDL2_VERSION_MAJOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MINOR "${SDL2_VERSION_MINOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_PATCH "${SDL2_VERSION_PATCH_LINE}") + set(SDL2_VERSION_STRING ${SDL2_VERSION_MAJOR}.${SDL2_VERSION_MINOR}.${SDL2_VERSION_PATCH}) + unset(SDL2_VERSION_MAJOR_LINE) + unset(SDL2_VERSION_MINOR_LINE) + unset(SDL2_VERSION_PATCH_LINE) + unset(SDL2_VERSION_MAJOR) + unset(SDL2_VERSION_MINOR) + unset(SDL2_VERSION_PATCH) +endif() + +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 + REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR + VERSION_VAR SDL2_VERSION_STRING) + + +mark_as_advanced(SDL2_PATH + SDL2_NO_DEFAULT_PATH + SDL2_LIBRARY + SDL2MAIN_LIBRARY + SDL2_INCLUDE_DIR + SDL2_BUILDING_LIBRARY) + + +# SDL2:: targets (SDL2::Core and SDL2::Main) +if(SDL2_FOUND) + + # SDL2::Core target + if(SDL2_LIBRARY AND NOT TARGET SDL2::Core) + add_library(SDL2::Core UNKNOWN IMPORTED) + set_target_properties(SDL2::Core PROPERTIES + IMPORTED_LOCATION "${SDL2_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}") + + if(APPLE) + # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. + # For more details, please see above. + set_property(TARGET SDL2::Core APPEND PROPERTY + INTERFACE_LINK_OPTIONS -framework Cocoa) + else() + # For threads, as mentioned Apple doesn't need this. + # For more details, please see above. + set_property(TARGET SDL2::Core APPEND PROPERTY + INTERFACE_LINK_LIBRARIES Threads::Threads) + endif() + endif() + + # SDL2::Main target + # Applications should link to SDL2::Main instead of SDL2::Core + # For more details, please see above. + if(NOT SDL2_BUILDING_LIBRARY AND NOT TARGET SDL2::Main) + + if(SDL2_INCLUDE_DIR MATCHES ".framework" OR NOT SDL2MAIN_LIBRARY) + add_library(SDL2::Main INTERFACE IMPORTED) + set_property(TARGET SDL2::Main PROPERTY + INTERFACE_LINK_LIBRARIES SDL2::Core) + elseif(SDL2MAIN_LIBRARY) + # MinGW requires that the mingw32 library is specified before the + # libSDL2main.a static library when linking. + # The SDL2::MainInternal target is used internally to make sure that + # CMake respects this condition. + add_library(SDL2::MainInternal UNKNOWN IMPORTED) + set_property(TARGET SDL2::MainInternal PROPERTY + IMPORTED_LOCATION "${SDL2MAIN_LIBRARY}") + set_property(TARGET SDL2::MainInternal PROPERTY + INTERFACE_LINK_LIBRARIES SDL2::Core) + + add_library(SDL2::Main INTERFACE IMPORTED) + + if(MINGW) + # MinGW needs an additional link flag '-mwindows' and link to mingw32 + set_property(TARGET SDL2::Main PROPERTY + INTERFACE_LINK_LIBRARIES "mingw32" "-mwindows") + endif() + + set_property(TARGET SDL2::Main APPEND PROPERTY + INTERFACE_LINK_LIBRARIES SDL2::MainInternal) + endif() + + endif() +endif() diff --git a/cmake/FindSDL2_mixer.cmake b/cmake/FindSDL2_mixer.cmake new file mode 100644 index 00000000000..a71f26a83b6 --- /dev/null +++ b/cmake/FindSDL2_mixer.cmake @@ -0,0 +1,220 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +# Copyright 2019 Amine Ben Hassouna +# Copyright 2000-2019 Kitware, Inc. and Contributors +# All rights reserved. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: + +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. + +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. + +# * Neither the name of Kitware, Inc. nor the names of Contributors +# may be used to endorse or promote products derived from this +# software without specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#[=======================================================================[.rst: +FindSDL2_mixer +-------------- + +Locate SDL2_mixer library + +This module defines the following 'IMPORTED' target: + +:: + + SDL2::Mixer + The SDL2_mixer library, if found. + Have SDL2::Core as a link dependency. + + + +This module will set the following variables in your project: + +:: + + SDL2_MIXER_LIBRARIES, the name of the library to link against + SDL2_MIXER_INCLUDE_DIRS, where to find the headers + SDL2_MIXER_FOUND, if false, do not try to link against + SDL2_MIXER_VERSION_STRING - human-readable string containing the + version of SDL2_mixer + +This module responds to the following cache variables: + +:: + + SDL2_MIXER_PATH + Set a custom SDL2_mixer Library path (default: empty) + + SDL2_MIXER_NO_DEFAULT_PATH + Disable search SDL2_mixer Library in default path. + If SDL2_MIXER_PATH (default: ON) + Else (default: OFF) + + SDL2_MIXER_INCLUDE_DIR + SDL2_mixer headers path. + + SDL2_MIXER_LIBRARY + SDL2_mixer Library (.dll, .so, .a, etc) path. + + +Additional Note: If you see an empty SDL2_MIXER_LIBRARY in your project +configuration, it means CMake did not find your SDL2_mixer library +(SDL2_mixer.dll, libsdl2_mixer.so, etc). Set SDL2_MIXER_LIBRARY to point +to your SDL2_mixer library, and configure again. This value is used to +generate the final SDL2_MIXER_LIBRARIES variable and the SDL2::Mixer target, +but when this value is unset, SDL2_MIXER_LIBRARIES and SDL2::Mixer does not +get created. + + +$SDL2MIXERDIR is an environment variable that would correspond to the +./configure --prefix=$SDL2MIXERDIR used in building SDL2_mixer. + +$SDL2DIR is an environment variable that would correspond to the +./configure --prefix=$SDL2DIR used in building SDL2. + + + +Created by Amine Ben Hassouna: + Adapt FindSDL_mixer.cmake to SDL2_mixer (FindSDL2_mixer.cmake). + Add cache variables for more flexibility: + SDL2_MIXER_PATH, SDL2_MIXER_NO_DEFAULT_PATH (for details, see doc above). + Add SDL2 as a required dependency. + Modernize the FindSDL2_mixer.cmake module by creating a specific target: + SDL2::Mixer (for details, see doc above). + +Original FindSDL_mixer.cmake module: + Created by Eric Wing. This was influenced by the FindSDL.cmake + module, but with modifications to recognize OS X frameworks and + additional Unix paths (FreeBSD, etc). +#]=======================================================================] + +# SDL2 Library required +find_package(SDL2 QUIET) +if(NOT SDL2_FOUND) + set(SDL2_MIXER_SDL2_NOT_FOUND "Could NOT find SDL2 (SDL2 is required by SDL2_mixer).") + if(SDL2_mixer_FIND_REQUIRED) + message(FATAL_ERROR ${SDL2_MIXER_SDL2_NOT_FOUND}) + else() + if(NOT SDL2_mixer_FIND_QUIETLY) + message(STATUS ${SDL2_MIXER_SDL2_NOT_FOUND}) + endif() + return() + endif() + unset(SDL2_MIXER_SDL2_NOT_FOUND) +endif() + + +# Define options for searching SDL2_mixer Library in a custom path + +set(SDL2_MIXER_PATH "" CACHE STRING "Custom SDL2_mixer Library path") + +set(_SDL2_MIXER_NO_DEFAULT_PATH OFF) +if(SDL2_MIXER_PATH) + set(_SDL2_MIXER_NO_DEFAULT_PATH ON) +endif() + +set(SDL2_MIXER_NO_DEFAULT_PATH ${_SDL2_MIXER_NO_DEFAULT_PATH} + CACHE BOOL "Disable search SDL2_mixer Library in default path") +unset(_SDL2_MIXER_NO_DEFAULT_PATH) + +set(SDL2_MIXER_NO_DEFAULT_PATH_CMD) +if(SDL2_MIXER_NO_DEFAULT_PATH) + set(SDL2_MIXER_NO_DEFAULT_PATH_CMD NO_DEFAULT_PATH) +endif() + +# Search for the SDL2_mixer include directory +find_path(SDL2_MIXER_INCLUDE_DIR SDL_mixer.h + HINTS + ENV SDL2MIXERDIR + ENV SDL2DIR + ${SDL2_MIXER_NO_DEFAULT_PATH_CMD} + PATH_SUFFIXES SDL2 + # path suffixes to search inside ENV{SDL2DIR} + # and ENV{SDL2MIXERDIR} + include/SDL2 include + PATHS ${SDL2_MIXER_PATH} + DOC "Where the SDL2_mixer headers can be found" +) + +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(VC_LIB_PATH_SUFFIX lib/x64) +else() + set(VC_LIB_PATH_SUFFIX lib/x86) +endif() + +# Search for the SDL2_mixer library +find_library(SDL2_MIXER_LIBRARY + NAMES SDL2_mixer + HINTS + ENV SDL2MIXERDIR + ENV SDL2DIR + ${SDL2_MIXER_NO_DEFAULT_PATH_CMD} + PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} + PATHS ${SDL2_MIXER_PATH} + DOC "Where the SDL2_mixer Library can be found" +) + +# Read SDL2_mixer version +if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h") + file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$") + file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$") + string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}") + string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}") + set(SDL2_MIXER_VERSION_STRING ${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH}) + unset(SDL2_MIXER_VERSION_MAJOR_LINE) + unset(SDL2_MIXER_VERSION_MINOR_LINE) + unset(SDL2_MIXER_VERSION_PATCH_LINE) + unset(SDL2_MIXER_VERSION_MAJOR) + unset(SDL2_MIXER_VERSION_MINOR) + unset(SDL2_MIXER_VERSION_PATCH) +endif() + +set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY}) +set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer + REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIRS + VERSION_VAR SDL2_MIXER_VERSION_STRING) + + +mark_as_advanced(SDL2_MIXER_PATH + SDL2_MIXER_NO_DEFAULT_PATH + SDL2_MIXER_LIBRARY + SDL2_MIXER_INCLUDE_DIR) + + +if(SDL2_MIXER_FOUND) + + # SDL2::Mixer target + if(SDL2_MIXER_LIBRARY AND NOT TARGET SDL2::Mixer) + add_library(SDL2::Mixer UNKNOWN IMPORTED) + set_target_properties(SDL2::Mixer PROPERTIES + IMPORTED_LOCATION "${SDL2_MIXER_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_MIXER_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES SDL2::Core) + endif() +endif() diff --git a/cmake/FindZSTD.cmake b/cmake/FindZSTD.cmake new file mode 100644 index 00000000000..121f3fdb558 --- /dev/null +++ b/cmake/FindZSTD.cmake @@ -0,0 +1,54 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# +# +# - Find zstd compression library. +# +# This module defines the following variables: +# ZSTD_FOUND - true if zstd was found +# ZSTD_INCLUDE_DIRS - Include directories needed for zstd +# ZSTD_LIBRARIES - Libraries to link to when using zstd +# +# Additionally, this module defines the IMPORTED target ZSTD::ZSTD, +# if zstd has been found. +# + +include(FindPackageHandleStandardArgs) + +if (ZSTD_INCLUDE_DIRS AND ZSTD_LIBRARIES) + # already in cache, be silent + set(ZSTD_FIND_QUIETLY TRUE) +endif (ZSTD_INCLUDE_DIRS AND ZSTD_LIBRARIES) + +find_path(ZSTD_INCLUDE_DIR zstd.h + /usr/local/include + /usr/include + $ENV{MINGDIR}/include +) + +set(ZSTD_NAMES zstd) +find_library(ZSTD_LIBRARY + NAMES ${ZSTD_NAMES} + PATHS /usr/local/lib /usr/lib $ENV{MINGDIR}/lib +) + +find_package_handle_standard_args(ZSTD + FOUND_VAR ZSTD_FOUND + REQUIRED_VARS ZSTD_LIBRARY ZSTD_INCLUDE_DIR +) + +set(ZSTD_INCLUDE_DIRS "${ZSTD_INCLUDE_DIR}") +set(ZSTD_LIBRARIES "${ZSTD_LIBRARY}") + +if (ZSTD_FOUND OR NOT ZSTD_FIND_REQUIRED) + # Only show variables when zstd is required and not found + mark_as_advanced(ZSTD_INCLUDE_DIRS ZSTD_LIBRARIES ZSTD_INCLUDE_DIR ZSTD_LIBRARY) +endif (ZSTD_FOUND OR NOT ZSTD_FIND_REQUIRED) + +if (ZSTD_FOUND AND NOT TARGET ZSTD::ZSTD) + add_library(ZSTD::ZSTD UNKNOWN IMPORTED) + + set_target_properties(ZSTD::ZSTD PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${ZSTD_INCLUDE_DIRS}") + set_property(TARGET ZSTD::ZSTD APPEND PROPERTY IMPORTED_LOCATION "${ZSTD_LIBRARIES}") +endif (ZSTD_FOUND AND NOT TARGET ZSTD::ZSTD) diff --git a/cmake/SimutransBackend.cmake b/cmake/SimutransBackend.cmake new file mode 100644 index 00000000000..34386a57f00 --- /dev/null +++ b/cmake/SimutransBackend.cmake @@ -0,0 +1,26 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +find_package(SDL2 MODULE) +find_package(SDL2_mixer MODULE) + +if (SDL2_FOUND) + list(APPEND AVAILABLE_BACKENDS "sdl2") + mark_as_advanced(SDL2_DIR) + + if (SDL2_mixer_FOUND) + list(APPEND AVAILABLE_BACKENDS "mixer_sdl2") + endif (SDL2_mixer_FOUND) +endif (SDL2_FOUND) + +if (WIN32) + list(APPEND AVAILABLE_BACKENDS "gdi") +endif () + +list(APPEND AVAILABLE_BACKENDS "none") + +string(REGEX MATCH "^[^;][^;]*" FIRST_BACKEND "${AVAILABLE_BACKENDS}") +set(SIMUTRANS_BACKEND "${FIRST_BACKEND}" CACHE STRING "Graphics backend") +set_property(CACHE SIMUTRANS_BACKEND PROPERTY STRINGS ${AVAILABLE_BACKENDS}) diff --git a/cmake/SimutransCommitInfo.cmake b/cmake/SimutransCommitInfo.cmake new file mode 100644 index 00000000000..e876bb77b5b --- /dev/null +++ b/cmake/SimutransCommitInfo.cmake @@ -0,0 +1,34 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +find_package(Git) + +if (Git_FOUND) + option(SIMUTRANS_WITH_REVISION "Build executable with git commit information" ON) +endif (Git_FOUND) + +if (Git_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short=7 HEAD + OUTPUT_VARIABLE SIMUTRANS_SHA_SHORT + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD + OUTPUT_VARIABLE SIMUTRANS_BRANCH_NAME + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +endif (Git_FOUND) + + +if (SIMUTRANS_SHA_SHORT AND SIMUTRANS_BRANCH_NAME) + message(STATUS "Configuring Simutrans-Extended (commit ${SIMUTRANS_SHA_SHORT} on ${SIMUTRANS_BRANCH_NAME}) ...") +else () + message(WARNING "Could not find revision information because this repository " + "is not a Git repository. Commit and branch information will be unavailable.") +endif () diff --git a/cmake/SimutransCompileOptions.cmake b/cmake/SimutransCompileOptions.cmake new file mode 100644 index 00000000000..ab05f142224 --- /dev/null +++ b/cmake/SimutransCompileOptions.cmake @@ -0,0 +1,76 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +include(CheckCXXCompilerFlag) + + +# +# This function adds all supported compiler flags to result_list +# Example: SIMUTRANS_CHECK_CXX_COMPILER_FLAGS(COMMON_COMPILE_OPTIONS -Wall -Wextra -Werror) +# will add -Wall -Wextra -Werror to COMMON_COMPILE_OPTIONS. +# +function(SIMUTRANS_CHECK_CXX_COMPILER_FLAGS result_list) + set(temp_list "") + foreach (flag ${ARGN}) + # We cannot check for -Wno-* or -fno-* as this won't throw a warning so we must check for -W* or -f* directly + string(REGEX REPLACE "^(-[Wf])no-" "\\1" sanitizedFlag ${flag}) + set(cachedVarName ${sanitizedFlag}) + string(REPLACE "+" "X" cachedVarName ${cachedVarName}) + string(REGEX REPLACE "[-=]" "_" cachedVarName ${cachedVarName}) + + if (NOT ${CMAKE_CXX_COMPILER_ID}_${cachedVarName}_CHECKED) + check_cxx_compiler_flag(${sanitizedFlag} CXX_FLAG_${cachedVarName}_SUPPORTED) + set(${CMAKE_CXX_COMPILER_ID}_${cachedVarName}_CHECKED YES CACHE INTERNAL "") + endif() + + if (CXX_FLAG_${cachedVarName}_SUPPORTED) + list(APPEND temp_list ${flag}) + endif (CXX_FLAG_${cachedVarName}_SUPPORTED) + + unset(cachedVarName) + unset(sanitizedFlag) + endforeach () + + if (NOT ${result_list}) + set(${result_list} ${temp_list} PARENT_SCOPE) + elseif (temp_list) + set(${result_list} "${${result_list}};${temp_list}" PARENT_SCOPE) + endif () +endfunction() + +if (MSVC) + SIMUTRANS_CHECK_CXX_COMPILER_FLAGS(SIMUTRANS_COMMON_COMPILE_OPTIONS + /W3 + + /wd4244 # C4244: 'conversion_type': conversion from 'type1' to 'type2', possible loss of data + /wd4267 # C4267: '=': conversion from 'type1' to 'type2', possible loss of data + /wd4068 # C4068: unknown pragma + ) + + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + add_definitions(-D_SCL_SECURE_NO_WARNINGS) + add_definitions(-DNOMINMAX) + add_definitions(-DWIN32_LEAN_AND_MEAN) + +else (MSVC) # Assume GCC/Clang + SIMUTRANS_CHECK_CXX_COMPILER_FLAGS(SIMUTRANS_COMMON_COMPILE_OPTIONS + -Wall + -Wextra + -Wformat=2 + -Wundef + -Wmissing-include-dirs + -Wcast-qual + -Wpointer-arith + -Wcast-align + -Walloca + -Wduplicated-cond + ) + + if (SIMUTRANS_PROFILE) + SIMUTRANS_CHECK_CXX_COMPILER_FLAGS(SIMUTRANS_COMMON_COMPILE_OPTIONS + -pg -fno-inline -fno-schedule-insns + ) + endif (SIMUTRANS_PROFILE) +endif (MSVC) diff --git a/cmake/SimutransDependencies.cmake b/cmake/SimutransDependencies.cmake new file mode 100644 index 00000000000..e299568f6db --- /dev/null +++ b/cmake/SimutransDependencies.cmake @@ -0,0 +1,15 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +find_package(ZLIB REQUIRED) +find_package(BZip2 REQUIRED) +find_package(PNG REQUIRED) +find_package(Freetype) +find_package(MiniUPNP) +find_package(ZSTD) +find_package(FluidSynth) + +set(CMAKE_THREAD_PREFER_PTHREAD ON) +find_package(Threads) diff --git a/cmake/SimutransPack.cmake b/cmake/SimutransPack.cmake new file mode 100644 index 00000000000..689ce1b8e88 --- /dev/null +++ b/cmake/SimutransPack.cmake @@ -0,0 +1,55 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +include(InstallRequiredSystemLibraries) + +if (WIN32 AND NOT UNIX) + set(CPACK_GENERATOR "ZIP;NSIS") +else () + set(CPACK_GENERATOR "ZIP;TGZ") +endif() + +set(SIMUTRANS_PKG_NAME "simutrans-extended") + +if (WIN32 AND NOT UNIX) + set(SIMUTRANS_PKG_PLATFORM "win") +elseif (APPLE) + set(SIMUTRANS_PKG_PLATFORM "mac") +else () + set(SIMUTRANS_PKG_PLATFORM "linux") +endif () + +math(EXPR SIMUTRANS_PKG_BITNESS "${CMAKE_SIZEOF_VOID_P} * 8") + +# actual configuration +set(SIMUTRANS_VERSION "${SIMUTRANS_SHA_SHORT}-nightly") + +set(CPACK_PACKAGE_NAME ${SIMUTRANS_PKG_NAME}) +set(CPACK_PACKAGE_VERSION "${SIMUTRANS_VERSION}") +set(CPACK_PACKAGE_VENDOR "Simutrans-Extended developers") +set(CPACK_PACKAGE_CONTACT "https://forum.simutrans.com/index.php/board,53.0.html") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Simutrans-Extended - an extended version of the popular game Simutrans") +set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/readme.txt") +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt") + +set(CPACK_PACKAGE_FILE_NAME "${SIMUTRANS_PKG_NAME}-${SIMUTRANS_VERSION}-${SIMUTRANS_PKG_PLATFORM}${SIMUTRANS_PKG_BITNESS}") + +if (WIN32 AND NOT UNIX) + # There is a bug in NSI that does not handle full unix paths properly. + # Make sure there is at least one set of four (4) backslashes. + set(CPACK_PACKAGE_INSTALL_DIRECTORY "${SIMUTRANS_PKG_NAME}\\\\${SIMUTRANS_VERSION}\\\\") + set(CPACK_NSIS_DISPLAY_NAME "Simutrans Extended") + set(CPACK_NSIS_MODIFY_PATH ON) + +else (WIN32 AND NOT UNIX) + set(CPACK_PACKAGE_INSTALL_DIRECTORY "") + set(CPACK_STRIP_FILES "simutrans/simutrans-extended") + set(CPACK_SOURCE_STRIP_FILES "") + + # deb specific + string(REGEX REPLACE "^v" "" CPACK_DEBIAN_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}") +endif (WIN32 AND NOT UNIX) + +include(CPack) diff --git a/configs/config.makeobj-linux b/configs/config.makeobj-linux new file mode 100644 index 00000000000..2909b09fba1 --- /dev/null +++ b/configs/config.makeobj-linux @@ -0,0 +1,16 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +CC=gcc-10 +CXX=g++-10 + +BACKEND=posix +COLOUR_DEPTH=0 +OSTYPE=linux + +DEBUG=0 +OPTIMISE=1 + +FLAGS = -DUSE_C -fno-delete-null-pointer-checks -fno-strict-aliasing -std=c++11 diff --git a/configs/config.makeobj-mac b/configs/config.makeobj-mac new file mode 100644 index 00000000000..eae44df763a --- /dev/null +++ b/configs/config.makeobj-mac @@ -0,0 +1,12 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +DEBUG=0 +OPTIMISE=1 +BACKEND=posix +COLOUR_DEPTH=0 +OSTYPE=mac + +FLAGS = -DUSE_C -fno-delete-null-pointer-checks -fno-strict-aliasing -std=c++11 diff --git a/configs/config.makeobj-mingw b/configs/config.makeobj-mingw new file mode 100644 index 00000000000..227c8447259 --- /dev/null +++ b/configs/config.makeobj-mingw @@ -0,0 +1,16 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +CC=x86_64-w64-mingw32-gcc +CXX=x86_64-w64-mingw32-g++ + +BACKEND=posix +COLOUR_DEPTH=0 +OSTYPE=mingw64 + +DEBUG=0 +OPTIMISE=1 + +FLAGS = -DUSE_C -fno-delete-null-pointer-checks -fno-strict-aliasing -std=c++11 diff --git a/configs/config.nettool-linux b/configs/config.nettool-linux new file mode 100644 index 00000000000..14f45b52e1b --- /dev/null +++ b/configs/config.nettool-linux @@ -0,0 +1,16 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +CC=gcc-10 +CXX=g++-10 + +DEBUG=0 +OPTIMISE=1 + +BACKEND=posix +COLOUR_DEPTH=0 +OSTYPE=linux + +FLAGS = -DUSE_C -fno-delete-null-pointer-checks -fno-strict-aliasing -std=c++11 diff --git a/configs/config.nettool-mac b/configs/config.nettool-mac new file mode 100644 index 00000000000..eae44df763a --- /dev/null +++ b/configs/config.nettool-mac @@ -0,0 +1,12 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +DEBUG=0 +OPTIMISE=1 +BACKEND=posix +COLOUR_DEPTH=0 +OSTYPE=mac + +FLAGS = -DUSE_C -fno-delete-null-pointer-checks -fno-strict-aliasing -std=c++11 diff --git a/configs/config.nettool-mingw b/configs/config.nettool-mingw new file mode 100644 index 00000000000..0eb2a005ee0 --- /dev/null +++ b/configs/config.nettool-mingw @@ -0,0 +1,18 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +CC=x86_64-w64-mingw32-gcc +CXX=x86_64-w64-mingw32-g++ + +BACKEND=posix +COLOUR_DEPTH=0 +OSTYPE=mingw64 + +DEBUG=0 +OPTIMISE=1 + +FLAGS = -DUSE_C -fno-delete-null-pointer-checks -fno-strict-aliasing -std=c++11 + +LDFLAGS += -lws2_32 diff --git a/configs/config.sim-linux-debug-sdl2 b/configs/config.sim-linux-debug-sdl2 new file mode 100644 index 00000000000..5520542509a --- /dev/null +++ b/configs/config.sim-linux-debug-sdl2 @@ -0,0 +1,17 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +CC=clang-10 +CXX=clang++-10 + +DEBUG=1 +OPTIMISE=0 +MULTI_THREAD=1 + +BACKEND=sdl2 +COLOUR_DEPTH=16 +OSTYPE=linux + +FLAGS = -DUSE_C -fno-delete-null-pointer-checks -fno-strict-aliasing -std=c++11 diff --git a/configs/config.sim-linux-posix b/configs/config.sim-linux-posix new file mode 100644 index 00000000000..1db149f36e2 --- /dev/null +++ b/configs/config.sim-linux-posix @@ -0,0 +1,18 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +CC=clang-10 +CXX=clang++-10 + +BACKEND=posix +COLOUR_DEPTH=0 +OSTYPE=linux + +DEBUG=0 +OPTIMISE=1 +MULTI_THREAD=0 +USE_FREETYPE=0 + +FLAGS = -DUSE_C -fno-delete-null-pointer-checks -fno-strict-aliasing -std=c++11 diff --git a/configs/config.sim-linux-sdl2mixer b/configs/config.sim-linux-sdl2mixer new file mode 100644 index 00000000000..fe6565947bd --- /dev/null +++ b/configs/config.sim-linux-sdl2mixer @@ -0,0 +1,18 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +CC=clang-10 +CXX=clang++-10 + +BACKEND=mixer_sdl2 +COLOUR_DEPTH=16 +OSTYPE=linux + +DEBUG=0 +OPTIMISE=1 +MULTI_THREAD=1 +USE_FREETYPE=1 + +FLAGS = -DUSE_C -fno-delete-null-pointer-checks -fno-strict-aliasing -std=c++11 diff --git a/configs/config.sim-mac-sdl2 b/configs/config.sim-mac-sdl2 new file mode 100644 index 00000000000..d37b19c3f38 --- /dev/null +++ b/configs/config.sim-mac-sdl2 @@ -0,0 +1,17 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +BACKEND=sdl2 +COLOUR_DEPTH=0 +OSTYPE=mac + +AV_FOUNDATION=1 +DEBUG=0 +OPTIMISE=1 + +FLAGS = -DUSE_C -fno-delete-null-pointer-checks -fno-strict-aliasing -std=c++11 + +CFLAGS += -F /Library/Frameworks +LDFLAGS += -framework SDL2 -F /Library/Frameworks -I /Library/Frameworks/SDL2.framework/Headers diff --git a/configs/config.sim-mingw-gdi b/configs/config.sim-mingw-gdi new file mode 100644 index 00000000000..bc863f117cc --- /dev/null +++ b/configs/config.sim-mingw-gdi @@ -0,0 +1,20 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +CC=x86_64-w64-mingw32-gcc +CXX=x86_64-w64-mingw32-g++ + +BACKEND=gdi +COLOUR_DEPTH=16 +OSTYPE=mingw64 + +DEBUG=0 +OPTIMISE=1 +MULTI_THREAD=1 +USE_FREETYPE=1 +STATIC=1 + +FLAGS = -DUSE_C -fno-delete-null-pointer-checks -fno-strict-aliasing -std=c++11 +FREETYPE_CONFIG=x86_64-w64-mingw32-pkg-config freetype2 diff --git a/configs/config.sim-mingw-posix b/configs/config.sim-mingw-posix new file mode 100644 index 00000000000..b26a631c523 --- /dev/null +++ b/configs/config.sim-mingw-posix @@ -0,0 +1,18 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +CC=x86_64-w64-mingw32-gcc +CXX=x86_64-w64-mingw32-g++ + +BACKEND=posix +COLOUR_DEPTH=0 +OSTYPE=mingw64 + +DEBUG=0 +OPTIMISE=1 +MULTI_THREAD=0 +STATIC=1 + +FLAGS = -DUSE_C -fno-delete-null-pointer-checks -fno-strict-aliasing -std=c++11 diff --git a/configs/config.sim-mingw-sdl2 b/configs/config.sim-mingw-sdl2 new file mode 100644 index 00000000000..4e214948edd --- /dev/null +++ b/configs/config.sim-mingw-sdl2 @@ -0,0 +1,22 @@ +# +# This file is part of the Simutrans-Extended project under the Artistic License. +# (see LICENSE.txt) +# + +CC=x86_64-w64-mingw32-gcc +CXX=x86_64-w64-mingw32-g++ + +BACKEND=sdl2 +COLOUR_DEPTH=16 +OSTYPE=mingw64 + +DEBUG=0 +OPTIMISE=1 +MULTI_THREAD=1 +USE_FREETYPE=1 +STATIC=1 + +FLAGS = -DUSE_C -fno-delete-null-pointer-checks -fno-strict-aliasing -std=c++11 + +SDL2_CONFIG=x86_64-w64-mingw32-pkg-config sdl2 +FREETYPE_CONFIG=x86_64-w64-mingw32-pkg-config freetype2 diff --git a/makeobj/CMakeLists.txt b/makeobj/CMakeLists.txt new file mode 100644 index 00000000000..7b9e67317f0 --- /dev/null +++ b/makeobj/CMakeLists.txt @@ -0,0 +1,81 @@ +# +# This file is part of the Simutrans project under the artistic licence. +# (see licence.txt) +# + +add_executable(makeobj + makeobj.cc +) + +target_compile_options(makeobj PRIVATE ${SIMUTRANS_COMMON_COMPILE_OPTIONS}) +target_compile_definitions(makeobj PRIVATE MAKEOBJ=1 COLOUR_DEPTH=0) +target_compile_definitions(makeobj PRIVATE MSG_LEVEL=${SIMUTRANS_MSG_LEVEL}) + +if (SIMUTRANS_USE_SYSLOG) + target_compile_definitions(simutrans PRIVATE SYSLOG=1) +endif () + +if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4 AND SIMUTRANS_BUILD_32BIT) + target_compile_options(makeobj PRIVATE -m32) + set_target_properties(makeobj PROPERTIES LINK_FLAGS "-m32") +endif () + +target_link_libraries(makeobj + PNG::PNG +) + + +# These source files are unique to makeobj +target_sources(makeobj PRIVATE + ../descriptor/writer/bridge_writer.cc + ../descriptor/writer/building_writer.cc + ../descriptor/writer/citycar_writer.cc + ../descriptor/writer/crossing_writer.cc + ../descriptor/writer/factory_writer.cc + ../descriptor/writer/get_climate.cc + ../descriptor/writer/get_waytype.cc + ../descriptor/writer/good_writer.cc + ../descriptor/writer/groundobj_writer.cc + ../descriptor/writer/ground_writer.cc + ../descriptor/writer/image_writer.cc + ../descriptor/writer/imagelist2d_writer.cc + ../descriptor/writer/imagelist_writer.cc + ../descriptor/writer/obj_node.cc + ../descriptor/writer/obj_writer.cc + ../descriptor/writer/pedestrian_writer.cc + ../descriptor/writer/roadsign_writer.cc + ../descriptor/writer/root_writer.cc + ../descriptor/writer/sim_writer.cc + ../descriptor/writer/skin_writer.cc + ../descriptor/writer/sound_writer.cc + ../descriptor/writer/text_writer.cc + ../descriptor/writer/tree_writer.cc + ../descriptor/writer/tunnel_writer.cc + ../descriptor/writer/vehicle_writer.cc + ../descriptor/writer/way_writer.cc + ../descriptor/writer/way_obj_writer.cc + ../descriptor/writer/xref_writer.cc +) + +# These source files produce the same object code in makeobj and simutrans +target_sources(makeobj PRIVATE + ../descriptor/image.cc + ../dataobj/freelist.cc + ../io/raw_image.cc + ../simio.cc + ../simdebug.cc + ../simmem.cc + ../utils/simstring.cc + ../utils/searchfolder.cc +) + +# These source files produce different object code in makeobj and simutrans +target_sources(makeobj PRIVATE + ../dataobj/tabfile.cc + ../io/classify_file.cc + ../io/raw_image_bmp.cc + ../io/raw_image_png.cc + ../io/raw_image_ppm.cc + ../utils/log.cc +) + diff --git a/nettools/CMakeLists.txt b/nettools/CMakeLists.txt new file mode 100644 index 00000000000..73f33fa93a6 --- /dev/null +++ b/nettools/CMakeLists.txt @@ -0,0 +1,52 @@ +# +# This file is part of the Simutrans project under the artistic licence. +# (see licence.txt) +# + +add_executable(nettool + nettool.cc +) + +target_compile_options(nettool PRIVATE ${SIMUTRANS_COMMON_COMPILE_OPTIONS}) +target_compile_definitions(nettool PRIVATE NETTOOL=1 COLOUR_DEPTH=0) +target_compile_definitions(nettool PRIVATE MSG_LEVEL=${SIMUTRANS_MSG_LEVEL}) + +if (SIMUTRANS_USE_SYSLOG) + target_compile_definitions(nettool PRIVATE SYSLOG=1) +endif () + +if (NOT SIMUTRANS_USE_IPV6) + target_compile_definitions(nettool PRIVATE USE_IP4_ONLY=1) +endif () + +if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4 AND SIMUTRANS_BUILD_32BIT) + target_compile_options(nettool PRIVATE -m32) + set_target_properties(nettool PROPERTIES LINK_FLAGS "-m32") +endif () + +# these source files produce the same object code in nettool and simutrans +target_sources(nettool PRIVATE + ../dataobj/freelist.cc + ../network/memory_rw.cc + ../network/network_address.cc + ../network/network_cmd.cc + ../network/network_packet.cc + ../network/network_socket_list.cc + ../simdebug.cc + ../simmem.cc + ../utils/simstring.cc + ../utils/fetchopt.cc + ../utils/sha1.cc + ../utils/sha1_hash.cc +) + +# these source files produce different object code in nettool and simutrans +target_sources(nettool PRIVATE + ../utils/log.cc + ../network/network.cc + ../network/network_file_transfer.cc +) + +if (WIN32) + target_link_libraries(nettool PRIVATE ws2_32) +endif (WIN32) diff --git a/simdebug.h b/simdebug.h index b686ba2d916..e2467e2005b 100644 --- a/simdebug.h +++ b/simdebug.h @@ -31,7 +31,7 @@ extern log_t *dbg; */ void init_logging(const char *logname, bool force_flush, bool log_debug, const char *greeting, const char* syslogtag ); -#ifdef MSG_LEVEL +#if defined(MSG_LEVEL) && MSG_LEVEL >= 1 #if MSG_LEVEL >= 4 #define DBG_DEBUG4 dbg->debug @@ -43,7 +43,7 @@ void init_logging(const char *logname, bool force_flush, bool log_debug, const c #define DBG_MESSAGE dbg->message #define DBG_DEBUG dbg->message -#elif MSG_LEVEL >= 1 +#else // MSG_LEVEL >= 1 #define DBG_DEBUG4(i,...) ; #define DBG_MESSAGE(i,...) ; #define DBG_DEBUG dbg->message @@ -52,9 +52,6 @@ void init_logging(const char *logname, bool force_flush, bool log_debug, const c #elif defined(DEBUG) -// default level in undefinded -#define MSG_LEVEL (3) - //#define DBG_MESSAGE(i,...) dbg->message(i,__VA_ARGS__) //#define DBG_DEBUG(i,...) dbg->message(i,__VA_ARGS__) #define DBG_MESSAGE dbg->message diff --git a/simio.cc b/simio.cc index c7f97e1b6b9..f391c260e2a 100644 --- a/simio.cc +++ b/simio.cc @@ -5,6 +5,7 @@ #include + char *read_line(char *s, int size, FILE *file) { char *r; diff --git a/vehicle/water_vehicle.cc b/vehicle/water_vehicle.cc index 967ba74d222..6c511ee3b1a 100644 --- a/vehicle/water_vehicle.cc +++ b/vehicle/water_vehicle.cc @@ -10,6 +10,9 @@ #include "../bauer/vehikelbauer.h" #include "../obj/crossing.h" #include "../dataobj/schedule.h" +#include "../obj/roadsign.h" +#include "../simconvoi.h" + water_vehicle_t::water_vehicle_t(koord3d pos, const vehicle_desc_t* desc, player_t* player, convoi_t* cn) :