aboutsummaryrefslogtreecommitdiff
path: root/cmake/Win32Subsystem.cmake
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2023-09-20 23:58:58 -0700
committerrtk0c <[email protected]>2023-09-20 23:58:58 -0700
commitf138311d2d2e0cc9ba0496d523bb46f2c1c9fb73 (patch)
treef96100a813a4ffb28dcd074455d3a2f8ee426430 /cmake/Win32Subsystem.cmake
Copy from the PlasticSCM repo, replace vendored glm wtih conan
Diffstat (limited to 'cmake/Win32Subsystem.cmake')
-rw-r--r--cmake/Win32Subsystem.cmake31
1 files changed, 31 insertions, 0 deletions
diff --git a/cmake/Win32Subsystem.cmake b/cmake/Win32Subsystem.cmake
new file mode 100644
index 0000000..8546fd9
--- /dev/null
+++ b/cmake/Win32Subsystem.cmake
@@ -0,0 +1,31 @@
+function(target_use_windows_subsystem TARGET_NAME)
+ if(WIN32)
+ function(handle_msvc_style_compiler)
+ target_link_options(${TARGET_NAME} PRIVATE /SUBSYSTEM:windows /ENTRY:mainCRTStartup)
+ endfunction()
+
+ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ # GCC (MinGW)
+ # Supposedly the flag -mwindows would automatically make the executable use GUI subsystem
+ # But, when subsystem is set to GUI, linker will only search WinMain and wWinMain but not the standard main (it seems like)
+ # so creating GUI executable fails and the linker silently reverts to the default, CUI subsystem
+ target_link_options(${TARGET_NAME} PRIVATE -Wl,-subsystem,windows)
+ target_link_options(${TARGET_NAME} PRIVATE -Wl,-entry,mainCRTStartup)
+ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+ if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
+ # MSVC-style argument clang (clang-cl.exe)
+ handle_msvc_style_compiler()
+ elseif(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
+ # GNU-style argument clang (clang.exe and clang++.exe)
+ target_link_options(${TARGET_NAME} PRIVATE -Wl,-subsystem:windows)
+ target_link_options(${TARGET_NAME} PRIVATE -Wl,-entry:mainCRTStartup)
+ endif()
+ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
+ handle_msvc_style_compiler()
+
+ # Use updated __cplusplus macro
+ # https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus
+ target_compile_options(${TARGET_NAME} PUBLIC /Zc:__cplusplus)
+ endif()
+ endif()
+endfunction()