Windows: Skip cmd for release builds (#5416)
This commit is contained in:
parent
94358a709b
commit
676951d90d
|
@ -49,7 +49,6 @@ if(NOT CMAKE_BUILD_TYPE)
|
||||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE)
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type: Debug or Release" FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
# Included stuff
|
# Included stuff
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
|
||||||
|
|
||||||
|
|
|
@ -709,7 +709,11 @@ if(MSVC)
|
||||||
# EHa enables SEH exceptions (used for catching segfaults)
|
# 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_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 /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")
|
set(CMAKE_CXX_FLAGS_SEMIDEBUG "/MDd /Zi /Ob0 /O1 /RTC1")
|
||||||
|
|
||||||
|
@ -759,6 +763,10 @@ else()
|
||||||
if(USE_GPROF)
|
if(USE_GPROF)
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg")
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(MINGW)
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mwindows")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -350,6 +350,7 @@ void set_default_settings(Settings *settings)
|
||||||
settings->setDefault("server_description", "");
|
settings->setDefault("server_description", "");
|
||||||
|
|
||||||
settings->setDefault("high_precision_fpu", "true");
|
settings->setDefault("high_precision_fpu", "true");
|
||||||
|
settings->setDefault("enable_console", "false");
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
settings->setDefault("screenW", "0");
|
settings->setDefault("screenW", "0");
|
||||||
|
|
20
src/main.cpp
20
src/main.cpp
|
@ -17,9 +17,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
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 "irrlicht.h" // createDevice
|
||||||
|
|
||||||
#include "mainmenumanager.h"
|
#include "mainmenumanager.h"
|
||||||
|
@ -44,6 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#include "gameparams.h"
|
#include "gameparams.h"
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "porting.h"
|
||||||
#if USE_CURSES
|
#if USE_CURSES
|
||||||
#include "terminal_chat_console.h"
|
#include "terminal_chat_console.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -134,7 +132,6 @@ static OptionList allowed_options;
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
debug_set_exception_handler();
|
debug_set_exception_handler();
|
||||||
|
|
||||||
g_logger.registerThread("Main");
|
g_logger.registerThread("Main");
|
||||||
|
@ -145,11 +142,15 @@ int main(int argc, char *argv[])
|
||||||
if (!cmd_args_ok
|
if (!cmd_args_ok
|
||||||
|| cmd_args.getFlag("help")
|
|| cmd_args.getFlag("help")
|
||||||
|| cmd_args.exists("nonopt1")) {
|
|| cmd_args.exists("nonopt1")) {
|
||||||
|
porting::attachOrCreateConsole();
|
||||||
print_help(allowed_options);
|
print_help(allowed_options);
|
||||||
return cmd_args_ok ? 0 : 1;
|
return cmd_args_ok ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
if (cmd_args.getFlag("console"))
|
||||||
|
porting::attachOrCreateConsole();
|
||||||
|
|
||||||
if (cmd_args.getFlag("version")) {
|
if (cmd_args.getFlag("version")) {
|
||||||
|
porting::attachOrCreateConsole();
|
||||||
print_version();
|
print_version();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -191,6 +192,9 @@ int main(int argc, char *argv[])
|
||||||
if (!init_common(cmd_args, argc, argv))
|
if (!init_common(cmd_args, argc, argv))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
if (g_settings->getBool("enable_console"))
|
||||||
|
porting::attachOrCreateConsole();
|
||||||
|
|
||||||
#ifndef __ANDROID__
|
#ifndef __ANDROID__
|
||||||
// Run unit tests
|
// Run unit tests
|
||||||
if (cmd_args.getFlag("run-unittests")) {
|
if (cmd_args.getFlag("run-unittests")) {
|
||||||
|
@ -200,9 +204,13 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
GameParams game_params;
|
GameParams game_params;
|
||||||
#ifdef SERVER
|
#ifdef SERVER
|
||||||
|
porting::attachOrCreateConsole();
|
||||||
game_params.is_dedicated_server = true;
|
game_params.is_dedicated_server = true;
|
||||||
#else
|
#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
|
#endif
|
||||||
|
|
||||||
if (!game_configure(&game_params, cmd_args))
|
if (!game_configure(&game_params, cmd_args))
|
||||||
|
@ -303,6 +311,8 @@ static void set_allowed_options(OptionList *allowed_options)
|
||||||
_("Set password"))));
|
_("Set password"))));
|
||||||
allowed_options->insert(std::make_pair("go", ValueSpec(VALUETYPE_FLAG,
|
allowed_options->insert(std::make_pair("go", ValueSpec(VALUETYPE_FLAG,
|
||||||
_("Disable main menu"))));
|
_("Disable main menu"))));
|
||||||
|
allowed_options->insert(std::make_pair("console", ValueSpec(VALUETYPE_FLAG,
|
||||||
|
_("Starts with the console (Windows only)"))));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -929,4 +929,18 @@ bool secure_rand_fill_buf(void *buf, size_t len)
|
||||||
|
|
||||||
#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
|
} //namespace porting
|
||||||
|
|
|
@ -377,6 +377,9 @@ bool setXorgWindowIconFromPath(IrrlichtDevice *device,
|
||||||
void setWin32ExceptionHandler();
|
void setWin32ExceptionHandler();
|
||||||
|
|
||||||
bool secure_rand_fill_buf(void *buf, size_t len);
|
bool secure_rand_fill_buf(void *buf, size_t len);
|
||||||
|
|
||||||
|
// This attaches to the parents process console, or creates a new one if it doesnt exist.
|
||||||
|
void attachOrCreateConsole(void);
|
||||||
} // namespace porting
|
} // namespace porting
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
|
|
Loading…
Reference in New Issue