mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 21:45:16 +01:00
* feat(physics): the motion of a derailed vehicle on the ground With physics.derailment new a vehicle off the rails gets a motion of its own on the ground (vehicle/derailmotion.h, in eu07_core): it runs on along its heading, turned out of the curve by the sideways speed it left the rail with, slides across it down slopes steeper than the friction holds, follows the height and the slope of the ground under its supports, and tips over about the wheels of one side (while still guided by the curve, or on a slope, or sliding sideways) until it lies on its side. The vehicle holds the motion and what derailed it (the cause, the lateral acceleration out of the curve, the side a coupling pulled it to). While the motion runs, its friction (0.1 tipping on the outer wheels, 0.3 upright, up to 0.5 on its side) and the grade under it go into the longitudinal force. Off the end of the track the vehicle now slides on with the friction of the ballast instead of stopping within g, and a coupling can pull a vehicle off the rails (pull_off). Nothing of it with physics.derailment monitor, old or off. * feat(physics): a derailed vehicle leaves the track in the scenery TDynamicObject begins the motion of vehicle/derailmotion.h once its vehicle derails with physics.derailment new, and from then on places the model by it: off the axis of the track, pitched and rolled by the ground, on its side once it falls over, the bogies straight under the body. The ground is the scenery's terrain around the place (its opaque shapes and the heightmap terrain), with the ballast bed of the track over it; level ground at the top of the ballast where the scenery has none. The axles keep going along the track by the projection of the move, so the vehicle stays on the track nearest to it for its neighbours, the events and the drawing. A coupled vehicle still on the rails is pulled off when the sideways part of the coupler force puts its leading wheel over the climbing limit over 2 m. An uncoupled vehicle on the track and one off it run into each other only when in line. The derail sound loops while the vehicle scrapes along, and the log tells where it is every second and where it came to rest. Move() is split into move_axles() and place_by_axles(), the code of both unchanged. * feat(blackbox): a vehicle leaving the track and coming to rest off it A new record of the black box, 0x38 derailment, written when a vehicle leaves the track (physics.derailment new) and when it comes to rest off it: what derailed it, its position, heading, speed, offset from the axis of the track, roll, the distance it went and whether it lies on its side (blackbox_doc.md). The scenario runner reads it with the leaves_track check, and seven cases run it on td.scn: an EU07 with coaches into the buckled curve at 46 km/h (the AI) and at 133 km/h, over the overturning speed of the R 600 m curve at 190 km/h, off the end of a track, and overturning at 150 km/h on a curve of R 300 m on level ground, on an embankment and in a cutting. The runner also drops the cached geometry of a case's scenery (.sbt) once the case's fragment is newer than it, as it did for the base scenery: the curve cases carry their own terrain. * feat(physics): the yaw of a derailed body, and what differs between vehicles The body off the track (physics.derailment new) now turns about its vertical axis by itself, apart from the way it travels. Its heading is the way the vehicle goes, along which the Mover's speed runs; its axis is the way its front faces, with a yaw rate and the inertia of a box of its length and width. The friction of the ground holds it: under the two ends of its base while upright, along all of its length on its side, 0.3 to 0.5 along the body and 0.5 across it, each point against the way it slides there. Turning resists the yaw; a body going askew slides harder (mu along cos^2 + mu across sin^2 of the slip, which the Mover takes), its heading is drawn to the body and the sideways scrubbing trips it over. At a standstill it doesn't turn while the friction holds. The forces of the couplings at its ends turn it: two ends meet along the bisector of the bend between the bodies, the push goes through the inner buffer of the bend, off the middle of the beam by up to half the buffer spacing, as far as the buffers meet in height (a derailed body is lower than one on the rails, a rolled one misses them) and as much as a buffer takes (1 MN). Pushed from behind past what the buffers hold, a train of bodies bends further at each joint, the next one the other way: the zigzag of a train folding up. The gap of two ends is taken where they are, not from the distance between the middles, which would press the buffers of every bent pair. Past a right angle the heading turns about with the speed, so the Mover's front stays the body's front. Each vehicle draws its own scatter from the seed of the run and its name: the departure angle +-0.01 rad, yaw +-0.02 rad and +-0.02 rad/s, the friction under each half of it 0.85..1.15, and in two vehicles of three its leading end digging in 0.2..1.5 s after it left the rails, for 0.3..0.8 s, two to four times the friction under that half at one wheel or corner. The same seed gives the same outcome. * feat(physics): a derailed train folds up, and the derailment watches its own cost TDynamicObject gives the body off the track the forces of its couplings as vectors: the gap of a coupling with a vehicle off the track (coupled or meeting it) is that of the two ends as they are, and the force of each end goes to the body at the buffer it pushes through, or towards the other beam it is pulled to. A vehicle still on the rails coupled to one off it is taken off by the part of that force across its axis on its leading wheels (Y/Q over 1.2 over 2 m), pushed by the buffers as well as pulled by the coupling, to the side the force goes. Each vehicle off the track draws its scatter from the seed of the run and its name, and the model and the coupling points follow the yaw of the body. What a derailment costs is watched: the terrain is gathered again at most once a second per vehicle and kept to the nearest 400 000 triangles, the axles of a vehicle off the track follow it along the track by 10 cm steps (a body rocking in place moved them to and fro over the ends of tracks, firing their events every frame), and the gathering, a frame of the motion and the whole update of a vehicle off the track write a warning to the log when they take over 20 ms. The scenario runner gets the consist_folds check: the headings of a train's vehicles at rest off the track differ by a given angle at a given number of joints, optionally alternating, optionally on both sides of the track. eu07_td_off_track_buckle_fast checks the folding, eu07_td_off_track_buckle the coupled coach pulled off at an angle to the locomotive, and the bounds of the other cases are narrowed to the new outcomes. * feat(physics): derailed bodies run into each other instead of through With physics.derailment new the bodies of the vehicles off the track no longer go into each other, nor into the vehicles near them: once a frame, before the vehicles update, every vehicle off the track is checked against those around it (its own train coupled or not, a vehicle still on the rails, another train), by bounding circles and then by the footprints of their bodies: the box of each, less its buffers, rolled and pitched as it lies, seen from above, with the height it reaches. Two footprints in each other are separated along the axis they overlap least across. A hit is an impulse at the point of contact, which takes away the speed the two close in with there (they part with a fifth of it) with the mass, the vertical inertia and the arm of each, and the friction of their sides sliding along each other (0.3). It goes into the velocity and the yaw rate of a body off the track, which then goes the way it is thrown, and into the speed of a vehicle on the rails along them; across the rails it pushes on the leading wheels of that vehicle, which is pushed off when the Y/Q passes 1.2 over 2 m of sliding, or three times that at once. What the bodies still overlap by is taken out by moving them apart. The buffers of two ends keep meeting through meet() and force_on(); the bodies, shorter by the buffers, touch only once the ends are pressed past them or folded corner to corner. The log has the most any two bodies overlapped by every second, and the runner checks it with no_overlap in all off-track cases: before this the coaches went up to 1.64 m into each other at 190 km/h and 0.68 m stayed in each other at rest at 133 km/h; now at most 0.10 m on the way and none at rest. * fix(sonar): the reliability and security issues of the derailment SonarCloud failed the quality gate of the pull request on the new reliability and security ratings: - cpp:S836 (dereference of an undefined pointer value) in the timing watch of TDynamicObject::Update: the analyser lost the reference held in a std::optional. The watch is now always made, with a null vehicle when it is on the track, and does nothing then; copying it is deleted. Only the timing of the update off the track and its warning use it, the physics is the same. - cpp:S2245 (pseudorandom number generator) on the std::mt19937 of draw_scatter: it is seeded on purpose so that a derailment repeats, and nothing secret is drawn; marked NOSONAR like the seeded generators of the editor self tests. - cpp:S2193 (a for loop counter of floating type) in three loops of tests/unit/test_derail_motion.cpp: they count integer steps now. * fix(physics): the scraping of a derailed vehicle stops when it is put back on the rails The derail: sound loops while a vehicle off the track slides, and it was stopped only while the vehicle was still off the track, once it came to rest. rerail() (resetconsist, SetDamage taking dtrain_out off) ends the motion off the track at once, also while the vehicle still slides, and the scraping then went on for good. The vehicle now remembers that it plays the loop and stops it as soon as it isn't sliding off the track any more, at rest or back on the rails. The one-shot derail: sound of the other derailment models is not touched. * fix(physics): a vehicle put back on the rails forgets what derailed it rerail() reset only the side a coupling pulled the vehicle off to, and kept the cause and the lateral acceleration of the derailment. A vehicle that is put back on the rails and later leaves them in a way which doesn't set those (as the fork derailment of #496 does now) would leave the track with the cause and the acceleration of the earlier derailment. rerail() resets both now; the unit tests check it after repair_damage(). * fix(physics): the neighbour scan goes on past a derailed vehicle beside the line update_neighbours() took the nearest vehicle the scan of the track found, and when one of the two was off the track and the other not in line with it, gave up on that end. A vehicle lying beside the line so hid the vehicles beyond it: in a pile-up a wagon still on the rails had no front neighbour while running into a wagon in line further on, until the bodies were already deep in each other. The scan now passes such a vehicle and goes on to the next one (ABuFindObject() with InLine, only from update_neighbours(); the obstacle scan of the AI is as it was). * fix(physics): the moves out of other bodies go into the axles of a derailed vehicle The axles of a vehicle off the track follow it along the track by the displacement of the body, which move_off_track() measured from where the body was at the start of its own step. The contacts of the bodies move it out of the others between the frames, after that, so those moves never reached the axles, and the axles drifted along the track away from the body (the track it is registered on, the events it fires). The displacement is now measured from where the body was when its move went into the axles last. * perf(physics): derailed vehicles share the terrain and let it go at rest Each vehicle off the track gathered its own copy of the terrain, up to 600 m around it and 400 000 triangles (some 30-50 MB with the cell index), and kept it until the scenery unloaded: not let go at rest nor when put back on the rails, and gathered again for every vehicle of a pile-up, with a stall of tens of ms each. - The terrain gathered for a vehicle is kept in vehicle_table as a weak reference. A vehicle leaving the track (or gathering again near the edge) takes one which covers the way it may slide - around it and around where it stops going straight on, by its length and the margin the terrain is gathered again at - instead of gathering its own. A terrain cut down to the nearest triangles of a dense scenery is not shared. - At rest a vehicle keeps only the triangles under it (half its length and 40 m around, mesh_ground::cropped()); the big terrain goes once no vehicle holds it. Moving again, it gathers the terrain anew as before. - Back on the rails (rerail()) the vehicle lets its terrain go. The ground under a vehicle is the same as before: a shared terrain holds every triangle of the scenery reaching into its area. Unit tests: mesh_ground::covers() of an area and cropped().
937 lines
32 KiB
CMake
937 lines
32 KiB
CMake
cmake_minimum_required(VERSION 3.26)
|
|
if(POLICY CMP0058)
|
|
cmake_policy(SET CMP0058 NEW)
|
|
endif()
|
|
if(POLICY CMP0074)
|
|
cmake_policy(SET CMP0074 NEW)
|
|
endif()
|
|
if(POLICY CMP0069)
|
|
cmake_policy(SET CMP0069 NEW)
|
|
endif()
|
|
|
|
include(CheckCXXSymbolExists)
|
|
|
|
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake_modules/")
|
|
|
|
set(DEPS_DIR ${DEPS_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/ref")
|
|
project("eu07")
|
|
|
|
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=undefined")
|
|
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined -Wformat")
|
|
#set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -fsanitize=address -fsanitize=undefined")
|
|
|
|
string(TIMESTAMP VERSION_YEAR "%y")
|
|
string(TIMESTAMP VERSION_MONTH "%m")
|
|
string(TIMESTAMP VERSION_DAY "%d")
|
|
|
|
# Use these as version numbers
|
|
set(VERSION_MAJOR ${VERSION_YEAR})
|
|
set(VERSION_MINOR ${VERSION_MONTH})
|
|
set(VERSION_PATCH ${VERSION_DAY})
|
|
|
|
set(VERSION_STRING "${VERSION_YEAR}.${VERSION_MONTH}.${VERSION_DAY}")
|
|
|
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
|
|
file(GLOB HEADERS "*.h"
|
|
"Console/*.h"
|
|
"McZapkie/*.h"
|
|
"gl/*.h"
|
|
"network/*.h"
|
|
"vr/*.h"
|
|
"network/backend/*.h"
|
|
"widgets/*.h"
|
|
"launcher/*.h"
|
|
"extras/*.h"
|
|
"global_include/*.h"
|
|
"simulation/*.h"
|
|
"scene/*.h"
|
|
"rendering/*.h"
|
|
"audio/*.h"
|
|
"environment/*.h"
|
|
"application/*.h"
|
|
"input/*.h"
|
|
"scripting/*.h"
|
|
"model/*.h"
|
|
"utilities/*.h"
|
|
"world/*.h"
|
|
"vehicle/*.h")
|
|
|
|
set(GLOBAL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
set(GLOBAL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/global_include")
|
|
set(IMGUI_DIR "${CMAKE_CURRENT_SOURCE_DIR}/imgui")
|
|
|
|
if (APPLE)
|
|
set (CMAKE_FIND_FRAMEWORK LAST)
|
|
endif()
|
|
|
|
option(WITH_OPENGL_MODERN "Compile with OpenGL modern renderer" ON)
|
|
option(WITH_OPENGL_LEGACY "Compile with OpenGL legacy renderer" ON)
|
|
option(WITH_PYTHON "Python 3.14 embedded scripting" ON)
|
|
option(WITH_UART "Compile with libserialport" ON)
|
|
option(WITH_LUA "Compile with lua scripting support" ON)
|
|
option(WITH_WASM "WebAssembly script screens (wasmscreen:, wasmdestinationsign:), run by the WAMR interpreter in ref/wamr" ON)
|
|
option(WITH_OPENVR "Compile with OpenVR" OFF)
|
|
option(WITH_ZMQ "Compile with cppzmq" OFF)
|
|
option(WITH_CRASHPAD "Compile with crashpad" OFF)
|
|
option(WITH_DISCORD_RPC "Compile with DISCORD RICH PRESENCE" ON)
|
|
option(USE_LTO "Use link-time optimization" OFF)
|
|
option(WITH_TESTS "Build and run the unit tests with the game, a failing test fails the build" ON)
|
|
option(WITH_EDITOR_SELFTESTS "Run the scripts of the editor and launcher self-tests named by the EU07_EDITOR_SELFTEST and EU07_LAUNCHER_SELFTEST variables" OFF)
|
|
option(WITH_BETTER_RENDERER "Experimental multi-backend renderer based on NVRHI" OFF)
|
|
option(GENERATE_PDB "Generate executable with program debugging symbols" ON)
|
|
option(ENABLE_MCC "Enable multicore compilation" ON)
|
|
option(WITHDUMPGEN "Enable generating DMP files on crash" ON)
|
|
option(ENABLE_AVX2 "Enable AVX2 instruction set (requires AVX2-capable CPU, Haswell/2013 or newer)" ON)
|
|
option(ADD_VERSION_SUFFIX "Add date and commit hash to the executable name" ON)
|
|
option(USE_SYSTEM_JSON "Use an installed nlohmann_json (3.9 or newer) instead of the ref/json submodule" OFF)
|
|
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
|
|
|
# vcpkg init
|
|
set(VCPKG_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/ref/vcpkg")
|
|
set(VCPKG_INSTALLED_PATH "${VCPKG_ROOT}/installed/x64-windows")
|
|
list(APPEND CMAKE_PREFIX_PATH "${VCPKG_INSTALLED_PATH}")
|
|
list(APPEND CMAKE_MODULE_PATH "${VCPKG_INSTALLED_PATH}/share")
|
|
|
|
set(SOURCES
|
|
"model/Texture.cpp"
|
|
"utilities/Timer.cpp"
|
|
"world/Track.cpp"
|
|
"world/TrackSleepers.cpp"
|
|
"world/SleeperPaths.cpp"
|
|
"world/SleeperFeatures.cpp"
|
|
"world/SleeperLines.cpp"
|
|
"world/SleeperLayout.cpp"
|
|
"world/SleeperModels.cpp"
|
|
"world/SleeperWorker.cpp"
|
|
"world/GaugeLine.cpp"
|
|
"world/RailCrossings.cpp"
|
|
"world/RailMaterials.cpp"
|
|
"world/RailProfile.cpp"
|
|
"world/RailPlan.cpp"
|
|
"world/RailCarve.cpp"
|
|
"world/RailLayer.cpp"
|
|
"world/TrackUneven.cpp"
|
|
"world/TrackBuckle.cpp"
|
|
"world/Road.cpp"
|
|
"world/Sweep.cpp"
|
|
"world/RoadPoint.cpp"
|
|
"world/Traction.cpp"
|
|
"world/TractionPower.cpp"
|
|
"vehicle/Train.cpp"
|
|
"world/TrkFoll.cpp"
|
|
"vehicle/AirCoupler.cpp"
|
|
"model/AnimModel.cpp"
|
|
"vehicle/Button.cpp"
|
|
"vehicle/Camera.cpp"
|
|
"vehicle/Driver.cpp"
|
|
"vehicle/crewchange.cpp"
|
|
"application/driverhints.cpp"
|
|
"vehicle/DynObj.cpp"
|
|
"EU07.cpp"
|
|
"export_e3d_standalone.cpp"
|
|
"export_btf_standalone.cpp"
|
|
"nodebank_previews_standalone.cpp"
|
|
"world/Event.cpp"
|
|
"world/EvLaunch.cpp"
|
|
"utilities/Float3d.cpp"
|
|
"vehicle/Gauge.cpp"
|
|
"utilities/Globals.cpp"
|
|
"utilities/Logs.cpp"
|
|
"model/MdlMngr.cpp"
|
|
"world/MemCell.cpp"
|
|
"model/Model3d.cpp"
|
|
"world/mtable.cpp"
|
|
"rendering/nullrenderer.cpp"
|
|
"rendering/renderer.cpp"
|
|
"model/ResourceManager.cpp"
|
|
"world/Segment.cpp"
|
|
"environment/sky.cpp"
|
|
"environment/sun.cpp"
|
|
"environment/stars.cpp"
|
|
"rendering/lightarray.cpp"
|
|
"environment/skydome.cpp"
|
|
"audio/sound.cpp"
|
|
"world/Spring.cpp"
|
|
"rendering/frustum.cpp"
|
|
"application/uilayer.cpp"
|
|
"rendering/openglmatrixstack.cpp"
|
|
"environment/moon.cpp"
|
|
"input/command.cpp"
|
|
"input/keyboardinput.cpp"
|
|
"input/gamepadinput.cpp"
|
|
"input/drivermouseinput.cpp"
|
|
"utilities/translation.cpp"
|
|
"model/material.cpp"
|
|
"stdafx.cpp"
|
|
"input/messaging.cpp"
|
|
"scene/scene.cpp"
|
|
"scene/scenenode.cpp"
|
|
"simulation/simulation.cpp"
|
|
"simulation/blackboxrecorder.cpp"
|
|
"model/vertex.cpp"
|
|
"audio/audio.cpp"
|
|
"audio/audiorenderer.cpp"
|
|
"utilities/motiontelemetry.cpp"
|
|
"application/uitranscripts.cpp"
|
|
"world/station.cpp"
|
|
"application/application.cpp"
|
|
"simulation/simulationtime.cpp"
|
|
"simulation/simulationtest.cpp"
|
|
"scene/sceneeditor.cpp"
|
|
"rendering/screenshot.cpp"
|
|
"input/driverkeyboardinput.cpp"
|
|
"application/drivermode.cpp"
|
|
"application/consistviews.cpp"
|
|
"application/driveruilayer.cpp"
|
|
"application/driveruipanels.cpp"
|
|
"input/editorkeyboardinput.cpp"
|
|
"editor/editorSettings.cpp"
|
|
"editor/editorModelSets.cpp"
|
|
"editor/editorTrackPresets.cpp"
|
|
"editor/editorIncludeInfo.cpp"
|
|
"editor/editorSwitchDrives.cpp"
|
|
"editor/editorTerrain.cpp"
|
|
"editor/editorTrack.cpp"
|
|
"editor/editorTrackTrace.cpp"
|
|
"editor/editorFouling.cpp"
|
|
"editor/editorRoad.cpp"
|
|
"editor/editorAlignment.cpp"
|
|
"editor/editorTrackShape.cpp"
|
|
"editor/editorGroundFollow.cpp"
|
|
"editor/editorAlignmentStore.cpp"
|
|
"editor/editorSwitchStore.cpp"
|
|
"editor/editorSwitchCurve.cpp"
|
|
"editor/editorKilometrage.cpp"
|
|
"editor/editorStation.cpp"
|
|
"editor/editorSwitchDesign.cpp"
|
|
"editor/editorConnections.cpp"
|
|
"application/editormodeconnection.cpp"
|
|
"application/editormodeconnectioncurve.cpp"
|
|
"application/editormodedigitize.cpp"
|
|
"editor/editorSpeed.cpp"
|
|
"editor/editorProfile.cpp"
|
|
"editor/editorGauge.cpp"
|
|
"editor/editorInfra.cpp"
|
|
"editor/editorTerrainStreamer.cpp"
|
|
"editor/editorOrthophoto.cpp"
|
|
"editor/editorHttp.cpp"
|
|
"editor/editorNmt.cpp"
|
|
"editor/editorGeoMap.cpp"
|
|
"editor/editorPreviews.cpp"
|
|
"editor/editorIcons.cpp"
|
|
"editor/editorClips.cpp"
|
|
"application/editormode.cpp"
|
|
"application/editormodetrack.cpp"
|
|
"application/editormoderoute.cpp"
|
|
"application/editormodestraights.cpp"
|
|
"application/editormodelay.cpp"
|
|
"application/editormodeswitchplace.cpp"
|
|
"application/editormodetrackgizmo.cpp"
|
|
"application/editormoderecords.cpp"
|
|
"application/editormodeswitchdrive.cpp"
|
|
"application/editormodeswitchtool.cpp"
|
|
"application/editormodeswitchtemplate.cpp"
|
|
"application/editormodenmt.cpp"
|
|
"application/editormodegradeline.cpp"
|
|
"application/editormodeswitchslide.cpp"
|
|
"application/editormodeswitchdesign.cpp"
|
|
"application/editormodetrackbed.cpp"
|
|
"application/editormodetrackux.cpp"
|
|
"application/editormodetrackprops.cpp"
|
|
"application/editormoderoad.cpp"
|
|
"application/editormodeprofile.cpp"
|
|
"application/editormodetextures.cpp"
|
|
"application/editormodegauge.cpp"
|
|
"application/editormoderide.cpp"
|
|
"application/editormodeminimap.cpp"
|
|
"application/editormodeinfra.cpp"
|
|
"application/editormodespeed.cpp"
|
|
"application/editormodesrk.cpp"
|
|
"application/editormodekm.cpp"
|
|
"application/editormodejoints.cpp"
|
|
"application/editormodeparallel.cpp"
|
|
"application/editormodelineside.cpp"
|
|
"application/editormodevehicle.cpp"
|
|
"application/editormodeselection.cpp"
|
|
"application/editormodeviewport.cpp"
|
|
"application/editormodesignal.cpp"
|
|
"application/editormodesweep.cpp"
|
|
"application/editormodeturntable.cpp"
|
|
"application/editormodeselftest.cpp"
|
|
"application/editormodeselftestscene.cpp"
|
|
"application/editormodeselftestsleepers.cpp"
|
|
"application/editormodeselftestsweep.cpp"
|
|
"application/editormodeselftesttrack.cpp"
|
|
"application/editormodeselftestswitch.cpp"
|
|
"application/editormodeselftestjoin.cpp"
|
|
"application/editormodeselftestsignal.cpp"
|
|
"application/editormodeselftestterrain.cpp"
|
|
"application/editormodeselftestrails.cpp"
|
|
"application/editormodeselftestmonkey.cpp"
|
|
"application/scriptedinput.cpp"
|
|
"input/editormouseinput.cpp"
|
|
"application/editoruilayer.cpp"
|
|
"application/editoruipanels.cpp"
|
|
"application/scenarioloadermode.cpp"
|
|
"application/scenarioloaderuilayer.cpp"
|
|
"scene/scenenodegroups.cpp"
|
|
"scene/scenelayers.cpp"
|
|
"scene/scenelayerssave.cpp"
|
|
"scene/sceneterrain.cpp"
|
|
"scene/heightmapterrain.cpp"
|
|
"scene/scenemodelentries.cpp"
|
|
"simulation/simulationenvironment.cpp"
|
|
"simulation/simulationstateserializer.cpp"
|
|
"rendering/precipitation.cpp"
|
|
"scripting/pythonscreenviewer.cpp"
|
|
"utilities/dictionary.cpp"
|
|
"rendering/particles.cpp"
|
|
"utilities/headtrack.cpp"
|
|
"utilities/hardwareprobe.cpp"
|
|
"rendering/geometrybank.cpp"
|
|
"rendering/openglcolor.cpp"
|
|
"simulation/simulationsounds.cpp"
|
|
"rendering/openglcamera.cpp"
|
|
|
|
"network/network.cpp"
|
|
"network/message.cpp"
|
|
"network/manager.cpp"
|
|
"network/backend/asio.cpp"
|
|
|
|
"widgets/vehiclelist.cpp"
|
|
"widgets/map.cpp"
|
|
"widgets/map_objects.cpp"
|
|
"widgets/popup.cpp"
|
|
"widgets/time.cpp"
|
|
"widgets/vehicleparams.cpp"
|
|
"widgets/trainingcard.cpp"
|
|
"widgets/perfgraphs.cpp"
|
|
|
|
"${DEPS_DIR}/glad/src/glad.c"
|
|
"${DEPS_DIR}/dds-ktx/src/dds-ktx.c"
|
|
"${DEPS_DIR}/zstd/zstd.c"
|
|
|
|
"gl/shader.cpp"
|
|
"gl/vao.cpp"
|
|
"gl/ubo.cpp"
|
|
"gl/framebuffer.cpp"
|
|
"gl/renderbuffer.cpp"
|
|
"gl/postfx.cpp"
|
|
"gl/cubemap.cpp"
|
|
"gl/glsl_common.cpp"
|
|
"gl/buffer.cpp"
|
|
"gl/fence.cpp"
|
|
"gl/pbo.cpp"
|
|
"gl/query.cpp"
|
|
|
|
"imgui/imgui.cpp"
|
|
"imgui/imgui_demo.cpp"
|
|
"imgui/imgui_draw.cpp"
|
|
"imgui/imgui_widgets.cpp"
|
|
"imgui/imgui_tables.cpp"
|
|
"imgui/imgui_impl_glfw.cpp"
|
|
"imgui/ImGuizmo.cpp"
|
|
|
|
"stb/stb_image.c"
|
|
|
|
"launcher/launchermode.cpp"
|
|
"launcher/scenery_list.cpp"
|
|
"launcher/launcheruilayer.cpp"
|
|
"launcher/vehicle_picker.cpp"
|
|
"launcher/keymapper.cpp"
|
|
"launcher/textures_scanner.cpp"
|
|
"launcher/scenery_scanner.cpp"
|
|
"launcher/scenery_wizard.cpp"
|
|
|
|
"vr/vr_interface.cpp"
|
|
)
|
|
|
|
set(DEFINITIONS)
|
|
set(SOURCES ${SOURCES} "imgui/imgui_impl_opengl3.cpp")
|
|
set(SOURCES ${SOURCES} "imgui/imgui_impl_opengl2.cpp")
|
|
set_source_files_properties("imgui/imgui_impl_opengl3.cpp" PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE)
|
|
set_source_files_properties("imgui/imgui_impl_opengl2.cpp" PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE)
|
|
|
|
if (WITH_CRASHPAD)
|
|
set(DEFINITIONS ${DEFINITIONS} "WITH_CRASHPAD")
|
|
set(SOURCES ${SOURCES} "utilities/crashreporter.cpp")
|
|
if (WIN32)
|
|
include_directories("${DEPS_DIR}/crashpad/include" "${DEPS_DIR}/crashpad/include/mini_chromium")
|
|
else()
|
|
include_directories("${DEPS_DIR}/crashpad/crashpad" "${DEPS_DIR}/crashpad/crashpad/third_party/mini_chromium/mini_chromium")
|
|
endif()
|
|
endif()
|
|
|
|
if(WITH_PYTHON)
|
|
set(DEFINITIONS ${DEFINITIONS} "WITH_PYTHON")
|
|
set(SOURCES ${SOURCES} "scripting/PyInt.cpp")
|
|
else()
|
|
set(SOURCES ${SOURCES} "scripting/PyIntStub.cpp")
|
|
endif()
|
|
|
|
if (WITH_UART)
|
|
set(DEFINITIONS ${DEFINITIONS} "WITH_UART")
|
|
set(SOURCES ${SOURCES} "utilities/uart.cpp")
|
|
endif()
|
|
|
|
if (WITH_ZMQ)
|
|
set(DEFINITIONS ${DEFINITIONS} "WITH_ZMQ")
|
|
set(SOURCES ${SOURCES} "input/zmq_input.cpp")
|
|
endif()
|
|
|
|
if (WITH_OPENVR)
|
|
set(DEFINITIONS ${DEFINITIONS} "WITH_OPENVR")
|
|
set(SOURCES ${SOURCES} "vr/openvr_imp.cpp")
|
|
endif()
|
|
|
|
if (WITH_LUA)
|
|
set(DEFINITIONS ${DEFINITIONS} "WITH_LUA")
|
|
# the scenery scripts (lua.cpp) and the Lua screens (luaprogram.cpp) share the sandbox of luasandbox.cpp
|
|
set(SOURCES ${SOURCES} "scripting/lua.cpp" "scripting/luasandbox.cpp")
|
|
endif()
|
|
|
|
# the script screens (scripting/scriptscreens.cpp), with the Lua and the WebAssembly runtime when they're built
|
|
set(SOURCES ${SOURCES} "scripting/scriptscreens.cpp")
|
|
if (WITH_LUA)
|
|
set(SOURCES ${SOURCES} "scripting/luaprogram.cpp")
|
|
endif()
|
|
if (WITH_WASM)
|
|
set(DEFINITIONS ${DEFINITIONS} "WITH_WASM")
|
|
set(SOURCES ${SOURCES} "scripting/wasmprogram.cpp")
|
|
endif()
|
|
|
|
if (WITHDUMPGEN)
|
|
set(DEFINITIONS ${DEFINITIONS} "WITHDUMPGEN")
|
|
endif()
|
|
|
|
if (WITH_OPENGL_MODERN)
|
|
set(SOURCES ${SOURCES}
|
|
"rendering/opengl33geometrybank.cpp"
|
|
"rendering/opengl33light.cpp"
|
|
"rendering/opengl33skydome.cpp"
|
|
"rendering/opengl33precipitation.cpp"
|
|
"rendering/opengl33particles.cpp"
|
|
"rendering/opengl33terrain.cpp"
|
|
"rendering/opengl33screenpost.cpp"
|
|
"rendering/opengl33renderer.cpp")
|
|
set(DEFINITIONS ${DEFINITIONS} "WITH_OPENGL_MODERN")
|
|
endif()
|
|
|
|
if (WITH_OPENGL_LEGACY)
|
|
set(SOURCES ${SOURCES}
|
|
"rendering/openglgeometrybank.cpp"
|
|
"rendering/opengllight.cpp"
|
|
"rendering/openglskydome.cpp"
|
|
"rendering/openglprecipitation.cpp"
|
|
"rendering/openglparticles.cpp"
|
|
"rendering/openglrenderer.cpp")
|
|
set(DEFINITIONS ${DEFINITIONS} "WITH_OPENGL_LEGACY")
|
|
endif()
|
|
|
|
add_subdirectory("${DEPS_DIR}/glfw/" EXCLUDE_FROM_ALL)
|
|
|
|
set(SOURCES ${SOURCES} "extras/piped_proc.cpp" "widgets/cameraview_extcam.cpp")
|
|
|
|
find_package(Git)
|
|
|
|
if (GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
|
|
execute_process(
|
|
COMMAND ${GIT_EXECUTABLE} describe --match=DUMMY --always --dirty
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
OUTPUT_VARIABLE GIT_HASH
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
)
|
|
|
|
execute_process(
|
|
COMMAND ${GIT_EXECUTABLE} show -s --format=%ci
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
OUTPUT_VARIABLE SRC_DATE
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
)
|
|
|
|
execute_process(
|
|
COMMAND ${GIT_EXECUTABLE} show -s --format=%cs
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
OUTPUT_VARIABLE SRC_SHORT_DATE
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
)
|
|
else()
|
|
string(TIMESTAMP SRC_SHORT_DATE %Y-%m-%d UTC)
|
|
string(TIMESTAMP SRC_DATE UTC)
|
|
set(GIT_HASH "(unknown)")
|
|
endif()
|
|
|
|
configure_file("${CMAKE_SOURCE_DIR}/version_info.h.in" "${CMAKE_BINARY_DIR}/geninc/version_info.h")
|
|
|
|
# the icons of the editor are built into the executable: the png is written out as the bytes of an array, see editor/editorIcons.cpp
|
|
set(EDITOR_ICONS "${CMAKE_SOURCE_DIR}/editor/icons/editor_icons.png")
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${EDITOR_ICONS}")
|
|
file(READ "${EDITOR_ICONS}" EDITOR_ICONS_HEX HEX)
|
|
string(REGEX REPLACE "(................................)" "\\1\n" EDITOR_ICONS_HEX "${EDITOR_ICONS_HEX}")
|
|
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," EDITOR_ICONS_HEX "${EDITOR_ICONS_HEX}")
|
|
file(CONFIGURE OUTPUT "${CMAKE_BINARY_DIR}/geninc/editor_icons_png.inc" CONTENT "${EDITOR_ICONS_HEX}\n")
|
|
|
|
set (PREFIX "")
|
|
set (SUFFIX "")
|
|
|
|
if (ADD_VERSION_SUFFIX)
|
|
set (SUFFIX "_${SRC_SHORT_DATE}_${GIT_HASH}")
|
|
endif()
|
|
|
|
# a build without AVX2 says so in its name, so a starter can pick it on a CPU without AVX2
|
|
if (NOT ENABLE_AVX2)
|
|
set (SUFFIX "${SUFFIX}_noavx2")
|
|
endif()
|
|
|
|
set(OPENVR_LIBRARY "openvr_api")
|
|
set(OPENVR_INCLUDE_DIR "")
|
|
|
|
if (WIN32)
|
|
set(DEFINITIONS ${DEFINITIONS} "HAVE_ROUND") # to make pymath to not redefine round
|
|
# set(DEFINITIONS ${DEFINITIONS} "GLFW_DLL")
|
|
|
|
set(SOURCES ${SOURCES} "windows.cpp" "Console.cpp" "Console/LPT.cpp" "Console/PoKeys55.cpp")
|
|
#set(GLFW3_INCLUDE_DIR ${GLFW3_INCLUDE_DIR} "${DEPS_DIR}/glfw/include/")
|
|
set(PNG_INCLUDE_DIRS ${PNG_INCLUDE_DIRS} "${DEPS_DIR}/libpng/include/")
|
|
#set(ZLIB_INCLUDE_DIR ${ZLIB_INCLUDE_DIR} "${DEPS_DIR}/zlib/")
|
|
set(OPENAL_INCLUDE_DIR ${OPENAL_INCLUDE_DIR} "${DEPS_DIR}/openal/include")
|
|
set(LIBSNDFILE_INCLUDE_DIR ${LIBSNDFILE_INCLUDE_DIR} "${DEPS_DIR}/libsndfile/include")
|
|
set(LUAJIT_INCLUDE_DIR ${LUAJIT_INCLUDE_DIR} "${DEPS_DIR}/luajit/include")
|
|
set(libserialport_INCLUDE_DIR ${LIBSERIALPORT_INCLUDE_DIR} "${DEPS_DIR}/libserialport/include")
|
|
set(OPENVR_INCLUDE_DIR "${DEPS_DIR}/openvr/include")
|
|
|
|
#if(${CMAKE_EXE_LINKER_FLAGS} STREQUAL "/machine:x64")
|
|
# set (ARCH "x64")
|
|
#else()
|
|
# set (ARCH "x86")
|
|
#endif()
|
|
|
|
set(ARCH "x64")
|
|
set (PREFIX "-${ARCH}")
|
|
|
|
#set(GLFW3_LIBRARIES ${GLFW3_LIBRARIES} "${DEPS_DIR}/glfw/lib/${ARCH}/glfw3dll.lib")
|
|
set(PNG_LIBRARIES ${PNG_LIBRARIES} "${DEPS_DIR}/libpng/lib/${ARCH}/libpng16.lib")
|
|
set(OPENAL_LIBRARY ${OPENAL_LIBRARY} "${DEPS_DIR}/openal/lib/${ARCH}/OpenAL32.lib")
|
|
set(LIBSNDFILE_LIBRARY ${LIBSNDFILE_LIBRARY} "${DEPS_DIR}/libsndfile/lib/${ARCH}/libsndfile-1.lib")
|
|
set(LUAJIT_LIBRARIES ${LUAJIT_LIBRARIES} "${DEPS_DIR}/luajit/lib/${ARCH}/lua51.lib")
|
|
set(libserialport_LIBRARY ${LIBSERIALPORT_LIBRARY} "${DEPS_DIR}/libserialport/lib/${ARCH}/libserialport-0.lib")
|
|
set(cppzmq_LIBRARY ${cppzmq_LIBRARY} "${DEPS_DIR}/cppzmq/lib/${ARCH}/libzmq.lib")
|
|
set(OPENVR_LIBRARY "${DEPS_DIR}/openvr/lib/${ARCH}/openvr_api.lib")
|
|
endif()
|
|
|
|
set(cppzmq_INCLUDE_DIR ${cppzmq_INCLUDE_DIR} "${DEPS_DIR}/cppzmq/include")
|
|
set(GLM_INCLUDE_DIR ${GLM_INCLUDE_DIR} "${DEPS_DIR}/glm/")
|
|
|
|
# Process version.rc.in into version.rc
|
|
configure_file(${CMAKE_SOURCE_DIR}/eu07.rc.in
|
|
${CMAKE_BINARY_DIR}/eu07.rc @ONLY)
|
|
|
|
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
|
|
set(SOURCES ${SOURCES} ${CMAKE_BINARY_DIR}/eu07.rc)
|
|
set(SOURCES ${SOURCES} eu07.ico)
|
|
set(SOURCES ${SOURCES} eu07.ico
|
|
editor/editorSettings.hpp)
|
|
add_compile_options("/utf-8")
|
|
endif()
|
|
|
|
# the build settings of the game: include dirs, definitions, compile options and libraries. the game,
|
|
# its core library and the unit tests all build with the same ones
|
|
add_library(eu07_settings INTERFACE)
|
|
|
|
# the parts of the simulation the game shares with the unit tests: the vehicle physics, the vehicle
|
|
# definition parser, the helpers they use and the rules of the test mode. built once, and tested as the game uses them
|
|
set(CORE_SOURCES
|
|
"audio/startsample.cpp"
|
|
"McZapkie/friction.cpp"
|
|
"McZapkie/hamulce.cpp"
|
|
"McZapkie/Mover.cpp"
|
|
"McZapkie/couplerphysics.cpp"
|
|
"McZapkie/derailment.cpp"
|
|
"McZapkie/collision.cpp"
|
|
"vehicle/derailmotion.cpp"
|
|
"world/TrackCheck.cpp"
|
|
"world/SleeperPack.cpp"
|
|
"McZapkie/Oerlikon_ESt.cpp"
|
|
"utilities/logfiles.cpp"
|
|
"utilities/parser.cpp"
|
|
"utilities/utilities.cpp"
|
|
"utilities/hardwareinfo.cpp"
|
|
"scene/sn_utils.cpp"
|
|
"scene/regionfile.cpp"
|
|
"utilities/inionlysettings.cpp"
|
|
"utilities/crashsignals.cpp"
|
|
"scripting/ladderlogic.cpp"
|
|
"scripting/scriptscreenrules.cpp"
|
|
"scripting/scriptscreenkernels.cpp"
|
|
"scripting/scriptscreendrawing.cpp"
|
|
"simulation/simulationtestrules.cpp"
|
|
"vehicle/aipower.cpp"
|
|
"vehicle/aiwire.cpp"
|
|
"vehicle/blackbox.cpp"
|
|
"utilities/physicslog.cpp"
|
|
"vehicle/enginestart.cpp"
|
|
"vehicle/brakesetting.cpp"
|
|
"vehicle/gaugewrap.cpp"
|
|
"vehicle/drivingaid.cpp"
|
|
"vehicle/brakingcurve.cpp"
|
|
"vehicle/signalpassing.cpp"
|
|
"vehicle/brakereleaser.cpp"
|
|
"vehicle/handover.cpp"
|
|
"vehicle/crew.cpp"
|
|
"vehicle/horn.cpp"
|
|
"vehicle/cameraviews.cpp"
|
|
"vehicle/linebreaker.cpp"
|
|
"vehicle/smoke.cpp"
|
|
"vehicle/odometer.cpp"
|
|
"world/timetablestart.cpp"
|
|
"vehicle/timetableservice.cpp"
|
|
"world/timetableflags.cpp"
|
|
"world/timetablereader.cpp"
|
|
"world/stationnames.cpp"
|
|
"world/eventconditions.cpp"
|
|
"utilities/wholefile.cpp"
|
|
)
|
|
add_library(eu07_core STATIC ${CORE_SOURCES})
|
|
target_link_libraries(eu07_core PUBLIC eu07_settings)
|
|
set_target_properties(eu07_core PROPERTIES
|
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
|
FOLDER "libraries")
|
|
|
|
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
|
|
target_link_libraries(${PROJECT_NAME} eu07_core)
|
|
|
|
target_compile_definitions(eu07_settings INTERFACE ${DEFINITIONS})
|
|
|
|
target_include_directories(eu07_settings INTERFACE
|
|
"."
|
|
"Console"
|
|
"McZapkie"
|
|
"gl"
|
|
"${DEPS_DIR}/glad/include"
|
|
"${DEPS_DIR}/dds-ktx/include"
|
|
"${DEPS_DIR}/zstd"
|
|
"${CMAKE_BINARY_DIR}/geninc"
|
|
"${GLOBAL_INCLUDE_DIR}")
|
|
|
|
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
|
|
# override cmake defaults
|
|
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO " /MD /Zi /O2 /DNDEBUG")
|
|
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO " /DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF")
|
|
|
|
target_link_options(${PROJECT_NAME} PRIVATE "/MAP")
|
|
|
|
# /wd4996: disable "deprecation" warnings
|
|
# /wd4244: disable warnings for conversion with possible loss of data
|
|
# /wd5033: disable because it is all over Python headers
|
|
target_compile_options(eu07_settings INTERFACE /wd4996 /wd4244 /wd5033)
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/LARGEADDRESSAWARE")
|
|
endif()
|
|
|
|
set_target_properties( ${PROJECT_NAME}
|
|
PROPERTIES
|
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
|
|
PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/pdb"
|
|
OUTPUT_NAME "${PROJECT_NAME}${PREFIX}${SUFFIX}"
|
|
DEBUG_POSTFIX "_d"
|
|
)
|
|
|
|
check_cxx_symbol_exists(__GNUC__ "" COMPILER_HAVE_GNUC)
|
|
if (COMPILER_HAVE_GNUC)
|
|
target_compile_options(eu07_settings INTERFACE -fvisibility=hidden)
|
|
endif()
|
|
|
|
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.16.0")
|
|
option(USE_PCH "Use precompiled header" ON)
|
|
|
|
if (USE_PCH)
|
|
target_precompile_headers(${PROJECT_NAME} PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/stdafx.h>")
|
|
target_precompile_headers(eu07_core PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/stdafx.h>")
|
|
set_source_files_properties("/glad/src/glad.c" "ref/dds-ktx/src/dds-ktx.c" "ref/zstd/zstd.c" "stb/stb_image.c"
|
|
"imgui/imgui.cpp" "imgui/imgui_demo.cpp" "imgui/imgui_draw.cpp" "imgui/imgui_widgets.cpp" "imgui/imgui_tables.cpp" "imgui/imgui_impl_glfw.cpp" "imgui/ImGuizmo.cpp"
|
|
PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE)
|
|
endif()
|
|
endif()
|
|
|
|
if (USE_LTO)
|
|
set_property(TARGET ${PROJECT_NAME} eu07_core PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
endif()
|
|
|
|
if (WITH_OPENVR)
|
|
target_include_directories(eu07_settings INTERFACE ${OPENVR_INCLUDE_DIR})
|
|
target_link_libraries(eu07_settings INTERFACE ${OPENVR_LIBRARY})
|
|
endif()
|
|
|
|
if (WITH_CRASHPAD)
|
|
if (WIN32)
|
|
target_link_libraries(${PROJECT_NAME} "${DEPS_DIR}/crashpad/lib_md/base.lib")
|
|
target_link_libraries(${PROJECT_NAME} "${DEPS_DIR}/crashpad/lib_md/client.lib")
|
|
target_link_libraries(${PROJECT_NAME} "${DEPS_DIR}/crashpad/lib_md/util.lib")
|
|
else()
|
|
target_link_libraries(${PROJECT_NAME} "${DEPS_DIR}/crashpad/crashpad/out/Default/obj/client/libclient.a")
|
|
target_link_libraries(${PROJECT_NAME} "${DEPS_DIR}/crashpad/crashpad/out/Default/obj/util/libutil.a")
|
|
target_link_libraries(${PROJECT_NAME} "${DEPS_DIR}/crashpad/crashpad/out/Default/obj/third_party/mini_chromium/mini_chromium/base/libbase.a")
|
|
endif()
|
|
endif()
|
|
|
|
target_link_libraries(eu07_settings INTERFACE glfw)
|
|
|
|
if(WITH_PYTHON)
|
|
find_package(Python3 3.14 REQUIRED COMPONENTS Development)
|
|
target_include_directories(eu07_settings INTERFACE ${Python3_INCLUDE_DIRS})
|
|
target_link_libraries(eu07_settings INTERFACE ${Python3_LIBRARIES})
|
|
|
|
if(WIN32)
|
|
# Python3_ROOT_DIR is only an input hint and is not populated by
|
|
# find_package(... COMPONENTS Development). Derive the install root from
|
|
# the include dir (parent of <root>/include) when it was not provided.
|
|
if(NOT Python3_ROOT_DIR)
|
|
get_filename_component(Python3_ROOT_DIR "${Python3_INCLUDE_DIRS}" DIRECTORY)
|
|
endif()
|
|
set(EU07_PY_DLL "${Python3_ROOT_DIR}/python314.dll")
|
|
set(EU07_PY_ZLIB "${Python3_ROOT_DIR}/DLLs/zlib1.dll")
|
|
set(EU07_PY_LIBDIR "${Python3_ROOT_DIR}/Lib")
|
|
set(EU07_PY_DLLSDIR "${Python3_ROOT_DIR}/DLLs")
|
|
endif()
|
|
endif()
|
|
|
|
if (NOT WIN32)
|
|
find_package(PNG 1.6 REQUIRED)
|
|
target_link_libraries(eu07_settings INTERFACE PNG::PNG)
|
|
else()
|
|
include_directories(${PNG_INCLUDE_DIRS})
|
|
target_link_libraries(eu07_settings INTERFACE ${PNG_LIBRARIES})
|
|
endif()
|
|
|
|
find_package(Threads REQUIRED)
|
|
target_link_libraries(eu07_settings INTERFACE Threads::Threads)
|
|
|
|
find_package(GLM REQUIRED)
|
|
target_include_directories(eu07_settings INTERFACE ${GLM_INCLUDE_DIR})
|
|
|
|
# JSON lib: the ref/json submodule by default, or an installed package (e.g. nlohmann-json3-dev, vcpkg nlohmann-json).
|
|
# Both give the nlohmann_json::nlohmann_json target; 3.9 is the first release with ordered_json, used by the unit tests.
|
|
if (USE_SYSTEM_JSON)
|
|
find_package(nlohmann_json 3.9 REQUIRED)
|
|
else()
|
|
add_subdirectory(ref/json)
|
|
endif()
|
|
target_link_libraries(eu07_settings INTERFACE nlohmann_json::nlohmann_json)
|
|
|
|
|
|
|
|
if (WITH_DISCORD_RPC)
|
|
add_subdirectory(ref/discord-rpc)
|
|
set_target_properties(discord-rpc PROPERTIES FOLDER "libraries")
|
|
target_link_libraries(eu07_settings INTERFACE discord-rpc)
|
|
|
|
# Add the include directory so the compiler can find discord_rpc.h
|
|
target_include_directories(eu07_settings INTERFACE
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/ref/discord-rpc/include"
|
|
)
|
|
|
|
target_compile_definitions(eu07_settings INTERFACE WITH_DISCORD_RPC=1)
|
|
else()
|
|
target_compile_definitions(eu07_settings INTERFACE WITH_DISCORD_RPC=0)
|
|
endif()
|
|
|
|
if(WITH_EDITOR_SELFTESTS)
|
|
target_compile_definitions(eu07_settings INTERFACE WITH_EDITOR_SELFTESTS=1)
|
|
else()
|
|
target_compile_definitions(eu07_settings INTERFACE WITH_EDITOR_SELFTESTS=0)
|
|
endif()
|
|
|
|
find_package(OpenAL REQUIRED)
|
|
if (TARGET OpenAL::OpenAL)
|
|
target_link_libraries(eu07_settings INTERFACE OpenAL::OpenAL)
|
|
else()
|
|
target_include_directories(eu07_settings INTERFACE ${OPENAL_INCLUDE_DIR})
|
|
target_link_libraries(eu07_settings INTERFACE ${OPENAL_LIBRARY})
|
|
endif()
|
|
|
|
find_package(SndFile REQUIRED)
|
|
target_link_libraries(eu07_settings INTERFACE SndFile::sndfile)
|
|
|
|
if (WITH_LUA)
|
|
find_package(LuaJIT REQUIRED)
|
|
target_include_directories(eu07_settings INTERFACE ${LUAJIT_INCLUDE_DIR})
|
|
target_link_libraries(eu07_settings INTERFACE ${LUAJIT_LIBRARIES})
|
|
endif()
|
|
|
|
if (WITH_UART)
|
|
find_package(libserialport REQUIRED)
|
|
target_include_directories(eu07_settings INTERFACE ${libserialport_INCLUDE_DIR})
|
|
target_link_libraries(eu07_settings INTERFACE ${libserialport_LIBRARY})
|
|
endif()
|
|
|
|
find_package(ASIO REQUIRED)
|
|
target_link_libraries(eu07_settings INTERFACE asio::asio)
|
|
|
|
if (WIN32)
|
|
target_link_libraries(eu07_settings INTERFACE ws2_32)
|
|
endif()
|
|
|
|
# http client of the editor, for the orthophoto, the terrain model and the topo map of geoportal.gov.pl: WinHTTP on Windows,
|
|
# libcurl elsewhere when available
|
|
if (WIN32)
|
|
target_link_libraries(eu07_settings INTERFACE winhttp)
|
|
else()
|
|
find_package(CURL QUIET)
|
|
if (CURL_FOUND)
|
|
target_link_libraries(eu07_settings INTERFACE CURL::libcurl)
|
|
target_compile_definitions(eu07_settings INTERFACE EU07_WITH_CURL)
|
|
else()
|
|
message(STATUS "libcurl not found: the editor's orthophoto and terrain model will only show what's cached, its topo map nothing")
|
|
endif()
|
|
endif()
|
|
|
|
if (WITH_ZMQ)
|
|
find_package(cppzmq REQUIRED)
|
|
target_include_directories(eu07_settings INTERFACE ${cppzmq_INCLUDE_DIR})
|
|
target_link_libraries(eu07_settings INTERFACE ${cppzmq_LIBRARY})
|
|
endif()
|
|
|
|
if (WIN32)
|
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:${PROJECT_NAME}> $<TARGET_RUNTIME_DLLS:${PROJECT_NAME}>
|
|
COMMAND_EXPAND_LISTS
|
|
)
|
|
endif ()
|
|
|
|
# Linux: the game loads its shared libraries from its own folder first ($ORIGIN), and the build copies them there,
|
|
# so the folder runs on a system that doesn't have them, or has other versions. the RPATH is a DT_RPATH rather
|
|
# than a DT_RUNPATH, because only that one is also used for the libraries the copied ones load (libsndfile's codecs)
|
|
if (UNIX AND NOT APPLE)
|
|
option(BUNDLE_RUNTIME_LIBS "Linux: copy the shared libraries the game needs next to it and load them from there" ON)
|
|
endif()
|
|
if (UNIX AND NOT APPLE AND BUNDLE_RUNTIME_LIBS)
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
|
BUILD_WITH_INSTALL_RPATH TRUE
|
|
INSTALL_RPATH "$ORIGIN")
|
|
target_link_options(${PROJECT_NAME} PRIVATE "LINKER:--disable-new-dtags")
|
|
|
|
# the RPATH no longer leads to libraries outside the system folders (Python from setup-python, an OpenAL Soft
|
|
# in /usr/local), so their folders are given to the script as well
|
|
set(EU07_BUNDLE_SEARCH_DIRS "")
|
|
foreach(library IN LISTS Python3_LIBRARIES OPENAL_LIBRARY LUAJIT_LIBRARIES libserialport_LIBRARY)
|
|
if (IS_ABSOLUTE "${library}")
|
|
get_filename_component(library_dir "${library}" DIRECTORY)
|
|
list(APPEND EU07_BUNDLE_SEARCH_DIRS "${library_dir}")
|
|
endif()
|
|
endforeach()
|
|
list(APPEND EU07_BUNDLE_SEARCH_DIRS ${Python3_LIBRARY_DIRS})
|
|
list(REMOVE_DUPLICATES EU07_BUNDLE_SEARCH_DIRS)
|
|
string(REPLACE ";" "|" EU07_BUNDLE_SEARCH_DIRS "${EU07_BUNDLE_SEARCH_DIRS}")
|
|
|
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND}
|
|
-DGAME=$<TARGET_FILE:${PROJECT_NAME}>
|
|
-DSEARCH_DIRS=${EU07_BUNDLE_SEARCH_DIRS}
|
|
-DCMAKE_OBJDUMP=${CMAKE_OBJDUMP}
|
|
-P "${CMAKE_CURRENT_SOURCE_DIR}/CMake_modules/bundle_runtime_libs.cmake"
|
|
COMMENT "Copying the shared libraries next to the game"
|
|
VERBATIM)
|
|
endif()
|
|
|
|
if(WIN32 AND WITH_PYTHON)
|
|
# the Python runtime next to the game, copied when it isn't there yet or the Python install changed, rather
|
|
# than after every link of the game: the library alone is thousands of files. the folder is the game's
|
|
# RUNTIME_OUTPUT_DIRECTORY, spelled out: $<TARGET_FILE_DIR:eu07> here would make this target depend on the game
|
|
get_property(EU07_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
|
if (EU07_MULTI_CONFIG)
|
|
set(EU07_PY_TARGET_DIR "${CMAKE_BINARY_DIR}/bin/$<CONFIG>")
|
|
else()
|
|
set(EU07_PY_TARGET_DIR "${CMAKE_BINARY_DIR}/bin")
|
|
endif()
|
|
set(EU07_PY_STAMP "${EU07_PY_TARGET_DIR}/python64/python_runtime.stamp")
|
|
add_custom_command(
|
|
OUTPUT "${EU07_PY_STAMP}"
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${EU07_PY_DLL}" "${EU07_PY_TARGET_DIR}"
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${EU07_PY_ZLIB}" "${EU07_PY_TARGET_DIR}"
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different "${EU07_PY_LIBDIR}" "${EU07_PY_TARGET_DIR}/python64/Lib"
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different "${EU07_PY_DLLSDIR}" "${EU07_PY_TARGET_DIR}/python64/DLLs"
|
|
COMMAND ${CMAKE_COMMAND} -E touch "${EU07_PY_STAMP}"
|
|
DEPENDS "${EU07_PY_DLL}" "${EU07_PY_ZLIB}"
|
|
COMMENT "Copying the Python runtime next to the game"
|
|
VERBATIM)
|
|
add_custom_target(eu07_python_runtime DEPENDS "${EU07_PY_STAMP}")
|
|
set_target_properties(eu07_python_runtime PROPERTIES FOLDER "libraries")
|
|
add_dependencies(${PROJECT_NAME} eu07_python_runtime)
|
|
endif()
|
|
|
|
if (WITH_WASM)
|
|
add_subdirectory("CMake_modules/wamr" "${CMAKE_CURRENT_BINARY_DIR}/wamr")
|
|
target_link_libraries(${PROJECT_NAME} eu07_wamr)
|
|
endif ()
|
|
|
|
if (WITH_BETTER_RENDERER)
|
|
add_subdirectory("betterRenderer")
|
|
set_target_properties(betterRenderer betterRenderer_fsr2 betterRenderer_shaders PROPERTIES FOLDER "renderers")
|
|
target_link_libraries(${PROJECT_NAME} "betterRenderer")
|
|
endif ()
|
|
|
|
# yaml-cpp, for the descriptions of scenery templates edited in the scenery editor.
|
|
# the experimental renderer brings in the same copy on its own, when enabled
|
|
if (NOT TARGET yaml-cpp)
|
|
add_subdirectory("betterRenderer/thirdparty/yaml-cpp" "${CMAKE_CURRENT_BINARY_DIR}/yaml-cpp" EXCLUDE_FROM_ALL)
|
|
endif ()
|
|
target_link_libraries(eu07_settings INTERFACE yaml-cpp)
|
|
|
|
|
|
# Enable compiling with debug symbols
|
|
if(GENERATE_PDB)
|
|
if (MSVC)
|
|
# Ensure Debug and Release configurations use appropriate runtime libraries
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Zi /MDd")
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi /MD")
|
|
|
|
# Add compile options for debugging
|
|
add_compile_options(/Zi) # Always enable debug symbols
|
|
add_link_options(/DEBUG /MAP)
|
|
|
|
# Ensure that the PCH is built with the correct runtime library for each configuration
|
|
set_target_properties(${PROJECT_NAME} eu07_core PROPERTIES
|
|
COMPILE_OPTIONS "$<$<CONFIG:Debug>:/MDd>$<$<CONFIG:Release>:/MD>")
|
|
else()
|
|
# GCC/Clang (ensure -g is set for all configurations)
|
|
add_compile_options(-g)
|
|
endif()
|
|
endif()
|
|
|
|
if(ENABLE_MCC AND MSVC)
|
|
message(STATUS "Enabling multi-processor compilation for MSVC.")
|
|
add_compile_options(/MP)
|
|
endif()
|
|
|
|
if(ENABLE_AVX2)
|
|
message(STATUS "Enabling AVX2 instruction set.")
|
|
if (MSVC)
|
|
target_compile_options(eu07_settings INTERFACE /arch:AVX2)
|
|
else()
|
|
target_compile_options(eu07_settings INTERFACE -mavx2)
|
|
endif()
|
|
endif()
|
|
|
|
if(WITH_TESTS)
|
|
enable_testing()
|
|
add_subdirectory(tests/unit)
|
|
# the unit tests run at the end of building the game, once it's linked: a failing one fails the build
|
|
# (and removes the game binary, so the next build links it again and reruns them)
|
|
add_dependencies(${PROJECT_NAME} eu07_unit_tests)
|
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
|
COMMAND ${CMAKE_COMMAND}
|
|
-DTESTS=$<TARGET_FILE:eu07_unit_tests>
|
|
-DGAME=$<TARGET_FILE:${PROJECT_NAME}>
|
|
-P "${CMAKE_CURRENT_SOURCE_DIR}/tests/unit/run_tests.cmake"
|
|
COMMENT "Running the unit tests"
|
|
VERBATIM)
|
|
# a change of the tests alone links the game again, so they run (Ninja and Makefile generators;
|
|
# Visual Studio builds rerun them with the next change of the game)
|
|
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY LINK_DEPENDS
|
|
$<TARGET_FILE:eu07_unit_tests> ${UNIT_TEST_DATA} "${CMAKE_CURRENT_SOURCE_DIR}/tests/unit/run_tests.cmake")
|
|
endif()
|