]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
cmake: make tools target the console subsystem on Windows
authorThomas Debesse <dev@illwieckz.net>
Thu, 4 Jul 2019 23:57:34 +0000 (01:57 +0200)
committerThomas Debesse <dev@illwieckz.net>
Fri, 5 Jul 2019 20:26:18 +0000 (22:26 +0200)
previously on Windows the stdout stuff was only printed on MinTTY console or SSH shell,
this change makes the tools to target the console subsystem so they also print stdout
on cmd console.

this also makes the tool spawning a cmd console windows when not started from a console,
allowing people to monitor what is printed.

this is done by adding a console_app() cmake macro that enables the -mconsole linker flag.
For exhaustivity an extraneous window_app() macro is done too that enables the -mwindows
flag. The -mwindows looks to be implicit, but making this macro explicit and using it
keeps the CMakeLists.txt file self documenting which exe has to be compiled with -mconsole,
which one has to be compiled with -mwindows, and which one has to be compiled with both.

this is a way to check if an exe targets only the windows subsystem:

$ objdump -p netradiant.exe | egrep '^Subsystem'
Subsystem 00000002 (Windows GUI)

this is a way to check if an exe targets the console subsystem:

$ objdump -p q3map2.exe | egrep '^Subsystem'
Subsystem 00000003 (Windows CUI)

note that this one targets both console and windows subsystem, only console is reported:

$ objdump -p q2map.exe | egrep '^Subsystem'
Subsystem 00000003 (Windows CUI)

CMakeLists.txt
radiant/CMakeLists.txt
tools/quake2/CMakeLists.txt
tools/quake2/qdata_heretic2/CMakeLists.txt
tools/quake3/CMakeLists.txt

index 1a414aa15ca54d811fe04400a1c221d3914f1622..6afa468ae661047d91551b8f78260aa2d8ad06a5 100644 (file)
@@ -266,6 +266,18 @@ if (BUILD_BINARIES)
         string(REGEX REPLACE "^[.]" "" RADIANT_EXECUTABLE ${CMAKE_EXECUTABLE_SUFFIX})
     endif ()
 
+    macro (console_app name)
+        if (WIN32)
+            target_link_libraries(${name} -mconsole)
+        endif ()
+    endmacro ()
+
+    macro (window_app name)
+        if (WIN32)
+            target_link_libraries(${name} -mwindows)
+        endif ()
+    endmacro ()
+
     macro (radiant_tool name)
         if (BUNDLE_LIBRARIES AND WIN32)
             add_executable(${name} ${ARGN} ${PROJECT_SOURCE_DIR}/include/lib.rc)
index 6fcb36809d27fa167e98fa8a4661672d42f47e66..144bf320a3381285307a39f31f218c3558d624bf 100644 (file)
@@ -90,6 +90,7 @@ set(RADIANTLIST
     xmlstuff.cpp xmlstuff.h
     xywindow.cpp xywindow.h
 )
+
 if (WIN32)
     list(APPEND RADIANTLIST multimon.cpp multimon.h)
 endif ()
@@ -126,6 +127,9 @@ target_link_libraries(${RADIANT_BASENAME}
     uilib
     xmllib
 )
+
+window_app(${RADIANT_BASENAME})
+
 if (X11_LIBRARIES)
     target_link_libraries(${RADIANT_BASENAME} ${X11_LIBRARIES})
 endif ()
index 6945ee674415b8fa520a9ccbed932968d390a2bd..20d7ff8247c2261089852a0c08fac5ca76740ecc 100644 (file)
@@ -46,6 +46,9 @@ radiant_tool(q2map
     q2map/writebsp.c
 )
 
+console_app(q2map)
+window_app(q2map)
+
 target_compile_definitions(q2map
     PRIVATE
 )
@@ -81,6 +84,8 @@ radiant_tool(qdata3
     qdata/video.c
 )
 
+console_app(qdata3)
+
 target_compile_definitions(qdata3
     PRIVATE
 )
index aae4659130dd1c53c0183981e8f03a43faa0fdf4..d9c5b43600cc44a0f9421742ea041eabeceede6b 100644 (file)
@@ -56,6 +56,8 @@ radiant_tool(h2data
     video.c
 )
 
+console_app(h2data)
+
 target_compile_definitions(h2data
     PRIVATE
 )
index 7ba643bfdf7529f233845cecba214901fab3ca63..d2d3ae2b342edfc4d62fa43e7e9318e84068c551 100644 (file)
@@ -127,6 +127,8 @@ radiant_tool(q3map2
         q3map2/writebsp.c
         )
 
+console_app(q3map2)
+
 if (BUILD_CRUNCH)
         set(OPTIONAL_IMAGE_LIBRARIES crnrgba)
         set(OPTIONAL_IMAGE_DEFINES BUILD_CRUNCH=1)
@@ -179,6 +181,8 @@ radiant_tool(q3data
         q3data/video.c
         )
 
+console_app(q3data)
+
 target_link_libraries(q3data
         ${GLIB_LIBRARIES}
         ${LIBXML2_LIBRARIES}