# EHa enables SEH exceptions (used for catching segfaults)
set(CMAKE_CXX_FLAGS_RELEASE "/EHa /Ox /GL /FD /MT /GS- /Zi /arch:SSE /fp:fast /D NDEBUG /D _HAS_ITERATOR_DEBUGGING=0 /TP")
#set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /NODEFAULTLIB:\"libcmtd.lib\" /NODEFAULTLIB:\"libcmt.lib\"")
- set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /DEBUG /OPT:REF /OPT:ICF")
+ set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF")
+
+
+ set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
+
set(CMAKE_CXX_FLAGS_SEMIDEBUG "/MDd /Zi /Ob0 /O1 /RTC1")
if(USE_GPROF)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg")
endif()
+
+ if(MINGW)
+ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mwindows")
+ endif()
endif()
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-// This would get rid of the console window
-//#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
-
#include "irrlicht.h" // createDevice
#include "mainmenumanager.h"
#include "gameparams.h"
#include "database.h"
#include "config.h"
+#include "porting.h"
#if USE_CURSES
#include "terminal_chat_console.h"
#endif
int main(int argc, char *argv[])
{
int retval;
-
debug_set_exception_handler();
g_logger.registerThread("Main");
if (!cmd_args_ok
|| cmd_args.getFlag("help")
|| cmd_args.exists("nonopt1")) {
+ porting::attachOrCreateConsole();
print_help(allowed_options);
return cmd_args_ok ? 0 : 1;
}
+ if (cmd_args.getFlag("console"))
+ porting::attachOrCreateConsole();
if (cmd_args.getFlag("version")) {
+ porting::attachOrCreateConsole();
print_version();
return 0;
}
if (!init_common(cmd_args, argc, argv))
return 1;
+ if (g_settings->getBool("enable_console"))
+ porting::attachOrCreateConsole();
+
#ifndef __ANDROID__
// Run unit tests
if (cmd_args.getFlag("run-unittests")) {
GameParams game_params;
#ifdef SERVER
+ porting::attachOrCreateConsole();
game_params.is_dedicated_server = true;
#else
- game_params.is_dedicated_server = cmd_args.getFlag("server");
+ const bool isServer = cmd_args.getFlag("server");
+ if (isServer)
+ porting::attachOrCreateConsole();
+ game_params.is_dedicated_server = isServer;
#endif
if (!game_configure(&game_params, cmd_args))
_("Set password"))));
allowed_options->insert(std::make_pair("go", ValueSpec(VALUETYPE_FLAG,
_("Disable main menu"))));
+ allowed_options->insert(std::make_pair("console", ValueSpec(VALUETYPE_FLAG,
+ _("Starts with the console (Windows only)"))));
#endif
}
#endif
+void attachOrCreateConsole(void)
+{
+#ifdef _WIN32
+ static bool consoleAllocated = false;
+ const bool redirected = (_fileno(stdout) == -2 || _fileno(stdout) == -1); // If output is redirected to e.g a file
+ if (!consoleAllocated && redirected && (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())) {
+ freopen("CONOUT$", "w", stdout);
+ freopen("CONOUT$", "w", stderr);
+ consoleAllocated = true;
+ }
+#endif
+}
+
+
} //namespace porting