Skip to content

Commit 6fb505c

Browse files
Added option to build Win32 GUI apps using console subsystem
1 parent 169ca33 commit 6fb505c

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ endif()
1111
option(DILIGENT_NO_RENDER_STATE_PACKAGER "Do not build Render State Packager" OFF)
1212
option(DILIGENT_ENABLE_DRACO "Enable Draco compression support in GLTF loader" OFF)
1313
option(DILIGENT_USE_RAPIDJSON "Use rapidjson parser in GLTF loader" OFF)
14+
option(DILIGENT_BUILD_WIN32_GUI_AS_CONSOLE "Build Windows GUI applications using the console subsystem" OFF)
1415

1516
# Clear the list
1617
set(DILIGENT_TOOLS_INSTALL_LIBS_LIST "" CACHE INTERNAL "Diligent tools libraries installation list")

NativeApp/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ if(PLATFORM_WIN32)
1717
set(INCLUDE
1818
include/Win32/Win32AppBase.hpp
1919
)
20+
if (DILIGENT_BUILD_WIN32_GUI_AS_CONSOLE)
21+
list(APPEND SOURCE src/Win32/main.cpp)
22+
endif()
2023

2124
function(add_win32_app TARGET_NAME SOURCE INCLUDE ASSETS)
22-
add_executable(${TARGET_NAME} WIN32 ${SOURCE} ${INCLUDE} ${ASSETS})
25+
add_executable(${TARGET_NAME} ${SOURCE} ${INCLUDE} ${ASSETS})
26+
if(NOT DILIGENT_BUILD_WIN32_GUI_AS_CONSOLE)
27+
set_target_properties(${TARGET_NAME} PROPERTIES WIN32_EXECUTABLE TRUE)
28+
endif()
2329

2430
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
2531
# libmingw32 must be included BEFORE Diligent-NativeAppBase that contains the definition of WinMain.

NativeApp/src/Win32/main.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2025 Diligent Graphics LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* In no event and under no legal theory, whether in tort (including negligence),
17+
* contract, or otherwise, unless required by applicable law (such as deliberate
18+
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
19+
* liable for any damages, including any direct, indirect, special, incidental,
20+
* or consequential damages of any character arising as a result of this License or
21+
* out of the use or inability to use the software (including but not limited to damages
22+
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23+
* all other commercial damages or losses), even if such Contributor has been advised
24+
* of the possibility of such damages.
25+
*/
26+
27+
#include <Windows.h>
28+
29+
int WINAPI WinMain(_In_ HINSTANCE hInstance,
30+
_In_opt_ HINSTANCE hPrevInstance,
31+
_In_ LPSTR lpCmdLine,
32+
_In_ int nShowCmd);
33+
34+
int main(int argc, char* argv[])
35+
{
36+
return WinMain(GetModuleHandle(nullptr), nullptr, GetCommandLineA(), SW_SHOWDEFAULT);
37+
}

0 commit comments

Comments
 (0)