Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to create console apps #1859

Merged
merged 3 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1k/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,7 @@ if (!$setupOnly) {
}
$b1k.println("BUILD_ALL_OPTIONS=$BUILD_ALL_OPTIONS, Count={0}" -f $BUILD_ALL_OPTIONS.Count)

$b1k.println("cmake --build $BUILD_DIR $BUILD_ALL_OPTIONS")
cmake --build $BUILD_DIR $BUILD_ALL_OPTIONS | Out-Host
}
}
Expand Down
26 changes: 20 additions & 6 deletions cmake/Modules/AXBuildHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,9 @@ endfunction()

# setup a ax application
function(ax_setup_app_config app_name)
set(options RUNTIME_OUTPUT_DIR opt_RUNTIME_OUTPUT_DIR)
cmake_parse_arguments(opt "" "${options}" ""
set(options CONSOLE)
set(oneValueArgs RUNTIME_OUTPUT_DIR)
cmake_parse_arguments(opt "${options}" "${oneValueArgs}" ""
"" ${ARGN} )
if (WINRT)
target_include_directories(${app_name}
Expand Down Expand Up @@ -394,10 +395,23 @@ function(ax_setup_app_config app_name)
endif()
elseif(WINDOWS)
# windows: visual studio/LLVM-clang default is Console app, but we need Windows app
if(MSVC)
set_property(TARGET ${app_name} APPEND PROPERTY LINK_FLAGS "/SUBSYSTEM:WINDOWS")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set_property(TARGET ${app_name} APPEND PROPERTY LINK_FLAGS "-Xlinker /subsystem:windows")
set(_win32_linker_flags "")
set(_win32_console_app FALSE)

if (NOT opt_CONSOLE OR WINRT)
set(_win32_linker_flags "/SUBSYSTEM:WINDOWS")
else()
set(_win32_linker_flags "/SUBSYSTEM:CONSOLE")
set(_win32_console_app TRUE)
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(_win32_linker_flags "-Xlinker ${_win32_linker_flags}")
endif()

set_property(TARGET ${app_name} APPEND PROPERTY LINK_FLAGS "${_win32_linker_flags}")
if (_win32_console_app)
set_source_files_properties(proj.win32/main.cpp PROPERTIES COMPILE_DEFINITIONS _CONSOLE=1)
endif()
endif()
# auto mark code files for IDE when mark app
Expand Down
20 changes: 15 additions & 5 deletions templates/common/proj.win32/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@
#include "axmol.h"

// Uncomment to enable win32 console
// #define USE_WIN32_CONSOLE
#define USE_WIN32_CONSOLE

USING_NS_AX;

int axmol_main() {
// create the application instance
AppDelegate app;
int ret = Application::getInstance()->run();
return ret;
}

#if !defined(_CONSOLE)
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
Expand All @@ -43,8 +51,10 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdL
#endif

// create the application instance
AppDelegate app;
int ret = Application::getInstance()->run();

return ret;
return axmol_main();
}
#else
int main(int, char**) {
return axmol_main();
}
#endif
25 changes: 22 additions & 3 deletions tests/cpp-tests/proj.win32/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).

https://axmolengine.github.io/

Expand All @@ -24,17 +25,35 @@

#include "main.h"
#include "AppDelegate.h"
#include "axmol.h"

// Uncomment to enable win32 console
#define USE_WIN32_CONSOLE

USING_NS_AX;

static int axmol_main() {
// create the application instance
AppDelegate app;
return Application::getInstance()->run();
}

#if !defined(_CONSOLE)
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

#include "platform/win32/EmbedConsole.h"
// create the application instance
#ifdef USE_WIN32_CONSOLE
# include "platform/win32/EmbedConsole.h"
#endif

// create the application instance
AppDelegate app;
return Application::getInstance()->run();
return axmol_main();
}
#else
int main(int, char**) {
return axmol_main();
}
#endif
38 changes: 28 additions & 10 deletions tests/fairygui-tests/proj.win32/main.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.

Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).

https://axmolengine.github.io/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -24,18 +25,35 @@

#include "main.h"
#include "AppDelegate.h"
#include "axmol.h"

// Uncomment to enable win32 console
// #define USE_WIN32_CONSOLE

USING_NS_AX;

int WINAPI _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
static int axmol_main() {
// create the application instance
AppDelegate app;
return Application::getInstance()->run();
}

#if !defined(_CONSOLE)
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// create the application instance
AppDelegate app;
return Application::getInstance()->run();
#ifdef USE_WIN32_CONSOLE
# include "platform/win32/EmbedConsole.h"
#endif

// create the application instance
return axmol_main();
}
#else
int main(int, char**) {
return axmol_main();
}
#endif
38 changes: 28 additions & 10 deletions tests/live2d-tests/proj.win32/main.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.

Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).

https://axmolengine.github.io/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -24,18 +25,35 @@

#include "main.h"
#include "AppDelegate.h"
#include "axmol.h"

// Uncomment to enable win32 console
// #define USE_WIN32_CONSOLE

USING_NS_AX;

int WINAPI _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
static int axmol_main() {
// create the application instance
AppDelegate app;
return Application::getInstance()->run();
}

#if !defined(_CONSOLE)
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// create the application instance
AppDelegate app;
return Application::getInstance()->run();
#ifdef USE_WIN32_CONSOLE
# include "platform/win32/EmbedConsole.h"
#endif

// create the application instance
return axmol_main();
}
#else
int main(int, char**) {
return axmol_main();
}
#endif
2 changes: 1 addition & 1 deletion tests/lua-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ target_include_directories(${APP_NAME} PRIVATE ${GAME_INC_DIRS})
if(NOT _AX_USE_PREBUILT)
target_link_libraries(${APP_NAME} ${_AX_LUA_LIB})
endif()
ax_setup_app_config(${APP_NAME})
ax_setup_app_config(${APP_NAME} CONSOLE)

if(APPLE)
set_target_properties(${APP_NAME} PROPERTIES RESOURCE "${APP_UI_RES}")
Expand Down
2 changes: 2 additions & 0 deletions tests/lua-tests/Source/AppDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void AppDelegate::initGLContextAttrs()

bool AppDelegate::applicationDidFinishLaunching()
{
ax::setLogFmtFlag(ax::LogFmtFlag::Colored);

// register lua engine
LuaEngine* pEngine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
Expand Down
29 changes: 19 additions & 10 deletions tests/lua-tests/proj.win32/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).

https://axmolengine.github.io/

Expand All @@ -24,27 +25,35 @@

#include "main.h"
#include "AppDelegate.h"
#include "cocos2d.h"
#include "axmol.h"

// Uncomment to enable win32 console
// #define USE_WIN32_CONSOLE

USING_NS_AX;

// uncomment below line, open debug console
#define USE_WIN32_CONSOLE
static int axmol_main() {
// create the application instance
AppDelegate app;
return Application::getInstance()->run();
}

#if !defined(_CONSOLE)
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// create the application instance
#ifdef USE_WIN32_CONSOLE
ax::setLogFmtFlag(ax::LogFmtFlag::Colored);
#include "platform/win32/EmbedConsole.h"
# include "platform/win32/EmbedConsole.h"
#endif

// create the application instance
AppDelegate app;

int ret = Application::getInstance()->run();

return ret;
return axmol_main();
}
#else
int main(int, char**) {
return axmol_main();
}
#endif
Loading