asrob-uc3m / robotDevastation

A new-generation shooter with augmented reality and real robots. You can play online with other users with your PC, moving robots in championships and campaigns: all 24/7!
http://asrob-uc3m.github.io/workgroups/2017-05-28-robot-devastation.html
GNU Lesser General Public License v2.1
9 stars 4 forks source link

SDL_MAIN_HANDLED vs CMake target property #138

Open PeterBowman opened 6 years ago

PeterBowman commented 6 years ago

We need to define a SDL_MAIN_HANDLED on executable targets in order to make them work on Windows: https://github.com/asrob-uc3m/robotDevastation/commit/9e36c06061b7d4da9b8a3d8ebf9038904f3649cf. I just found today this answer in the CMake FAQ that could render useful here: the WIN32_EXECUTABLE property target which can be set through add_executable(<name> WIN32 ...) (docs).

PeterBowman commented 5 years ago

If SDL_MAIN_HANDLED is not defined, SDL2 redefines main as SDL_main so that it's handled internally (CLI parsing and so on). Compilations errors are expected if the main entry point is not given the full, standard signature (e.g. int main(void) instead of int main(int argc, char ** argv)). I managed to overcome that via https://github.com/asrob-uc3m/robotDevastation/commit/edf35f487401be4198292c3354734e572ab76508, but tests are failing now with SDL not found.

PeterBowman commented 5 years ago

The game starts successfully if I use add_executable(robotDevastation WIN32 ...). However, no input/output is allowed through the console since it's now a pure windowed application.

PeterBowman commented 5 years ago

Per https://stackoverflow.com/a/11976179/10404307:

SDL requires initialization, so it injects its own main function that runs its initialization before calling your "main" function, which it renames to SDL_main so that it does not conflict with the actual main function.

As Captain Obvious said in the comment section, this is a massive pain in the patooty. I'd like to check why SDL fails to initialize before closing this as invalid (no action needed). Probably unrelated, but SDL_SetMainReady() is mentioned here.

PeterBowman commented 5 years ago

Moar links: