From 0c0685617501c70ee3e23240cd37408288554b2c Mon Sep 17 00:00:00 2001 From: Julius Trinkunas Date: Sat, 27 Apr 2024 01:29:57 +0300 Subject: [PATCH 1/3] Print cmake build command when running `axmol build` --- 1k/build.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/1k/build.ps1 b/1k/build.ps1 index a694289b313a..12654d329431 100644 --- a/1k/build.ps1 +++ b/1k/build.ps1 @@ -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 } } From 305f78f89a600df589eafe415e326cedfa8b1ee8 Mon Sep 17 00:00:00 2001 From: Julius Trinkunas Date: Sat, 27 Apr 2024 01:31:38 +0300 Subject: [PATCH 2/3] Add option to `ax_setup_app_config()` for building console applications --- cmake/Modules/AXBuildHelpers.cmake | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cmake/Modules/AXBuildHelpers.cmake b/cmake/Modules/AXBuildHelpers.cmake index 28718fbe4699..c40570541d67 100644 --- a/cmake/Modules/AXBuildHelpers.cmake +++ b/cmake/Modules/AXBuildHelpers.cmake @@ -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} @@ -395,9 +396,17 @@ function(ax_setup_app_config app_name) 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") + if(opt_CONSOLE) + set_property(TARGET ${app_name} APPEND PROPERTY LINK_FLAGS "/SUBSYSTEM:CONSOLE") + else() + set_property(TARGET ${app_name} APPEND PROPERTY LINK_FLAGS "/SUBSYSTEM:WINDOWS") + endif() elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set_property(TARGET ${app_name} APPEND PROPERTY LINK_FLAGS "-Xlinker /subsystem:windows") + if(opt_CONSOLE) + set_property(TARGET ${app_name} APPEND PROPERTY LINK_FLAGS "-Xlinker /subsystem:console") + else() + set_property(TARGET ${app_name} APPEND PROPERTY LINK_FLAGS "-Xlinker /subsystem:windows") + endif() endif() endif() # auto mark code files for IDE when mark app From abf0dfe9d6ee88b5f5561946903772c66196fdc5 Mon Sep 17 00:00:00 2001 From: halx99 Date: Sun, 28 Apr 2024 23:27:17 +0800 Subject: [PATCH 3/3] Fix console app entrypoint --- cmake/Modules/AXBuildHelpers.cmake | 29 ++++++++++-------- templates/common/proj.win32/main.cpp | 20 +++++++++---- tests/cpp-tests/proj.win32/main.cpp | 25 ++++++++++++++-- tests/fairygui-tests/proj.win32/main.cpp | 38 +++++++++++++++++------- tests/live2d-tests/proj.win32/main.cpp | 38 +++++++++++++++++------- tests/lua-tests/CMakeLists.txt | 2 +- tests/lua-tests/Source/AppDelegate.cpp | 2 ++ tests/lua-tests/proj.win32/main.cpp | 29 +++++++++++------- 8 files changed, 132 insertions(+), 51 deletions(-) diff --git a/cmake/Modules/AXBuildHelpers.cmake b/cmake/Modules/AXBuildHelpers.cmake index c40570541d67..4124ab85eb6a 100644 --- a/cmake/Modules/AXBuildHelpers.cmake +++ b/cmake/Modules/AXBuildHelpers.cmake @@ -395,18 +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) - if(opt_CONSOLE) - set_property(TARGET ${app_name} APPEND PROPERTY LINK_FLAGS "/SUBSYSTEM:CONSOLE") - else() - set_property(TARGET ${app_name} APPEND PROPERTY LINK_FLAGS "/SUBSYSTEM:WINDOWS") - endif() - elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - if(opt_CONSOLE) - set_property(TARGET ${app_name} APPEND PROPERTY LINK_FLAGS "-Xlinker /subsystem:console") - else() - set_property(TARGET ${app_name} APPEND PROPERTY LINK_FLAGS "-Xlinker /subsystem:windows") - endif() + 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 diff --git a/templates/common/proj.win32/main.cpp b/templates/common/proj.win32/main.cpp index fbafd624e420..56f8e3918d6a 100644 --- a/templates/common/proj.win32/main.cpp +++ b/templates/common/proj.win32/main.cpp @@ -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); @@ -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 diff --git a/tests/cpp-tests/proj.win32/main.cpp b/tests/cpp-tests/proj.win32/main.cpp index 65236216f98c..9a9cfa3e3afb 100644 --- a/tests/cpp-tests/proj.win32/main.cpp +++ b/tests/cpp-tests/proj.win32/main.cpp @@ -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/ @@ -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 diff --git a/tests/fairygui-tests/proj.win32/main.cpp b/tests/fairygui-tests/proj.win32/main.cpp index 3b61efc07382..b2d21c43c6ec 100644 --- a/tests/fairygui-tests/proj.win32/main.cpp +++ b/tests/fairygui-tests/proj.win32/main.cpp @@ -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 @@ -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 diff --git a/tests/live2d-tests/proj.win32/main.cpp b/tests/live2d-tests/proj.win32/main.cpp index 3b61efc07382..b2d21c43c6ec 100644 --- a/tests/live2d-tests/proj.win32/main.cpp +++ b/tests/live2d-tests/proj.win32/main.cpp @@ -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 @@ -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 diff --git a/tests/lua-tests/CMakeLists.txt b/tests/lua-tests/CMakeLists.txt index 2e659c9a3b8e..015ae2f56dae 100644 --- a/tests/lua-tests/CMakeLists.txt +++ b/tests/lua-tests/CMakeLists.txt @@ -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}") diff --git a/tests/lua-tests/Source/AppDelegate.cpp b/tests/lua-tests/Source/AppDelegate.cpp index da2f799be0e5..36af359882be 100644 --- a/tests/lua-tests/Source/AppDelegate.cpp +++ b/tests/lua-tests/Source/AppDelegate.cpp @@ -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); diff --git a/tests/lua-tests/proj.win32/main.cpp b/tests/lua-tests/proj.win32/main.cpp index 3d4f0520698e..b2d21c43c6ec 100644 --- a/tests/lua-tests/proj.win32/main.cpp +++ b/tests/lua-tests/proj.win32/main.cpp @@ -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/ @@ -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