MantisBT - CMake
View Issue Details
0014326CMake(No Category)public2013-07-31 08:022013-12-02 08:51
Soeren Textor 
Brad King 
highminoralways
closedfixed 
WindowsWindows7
CMake 2.8.11.2 
CMake 2.8.12CMake 2.8.12 
0014326: VS2012 generator ignores /SUBSYSTEM:WNDOWS
We define for all Win and MFC projects the Subystem with "/SUBSYSTEM:WINDOWS".
This works very well for VS2003/2005 and 2008 (2010 we did not try).

But for VS2012 this flag is ignored by cmake. Only at

  add_executable( MY_TARGET WIN32 ${MY_files} )

we obtain the correct flag.

Otherwise we find

   /CONSOLE:CONSOLE"5,01

inside the link options...


first we add the link option with:

set_target_properties( MY_TARGET PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:WINDOWS")

then we set
   set(CMAKE_MFC_FLAG 1) #1 for static the static MFC library

and
   add_library( ${project_name} SHARED ${_files} )

the result in the vcxproj is:

<subsystem>console</subsystem>

At VS2008 we have something like:
AdditionalOptions=" /machine:X86 /debug /swaprun:net /LIBPATH:E:/DitecLibs/Lib nafxcwd.lib /SUBSYSTEM:WINDOWS"

and that works fine.

I think the parser somehow ignores the SUBSYSTEM command. Is that the point?
No tags attached.
Issue History
2013-07-31 08:02Soeren TextorNew Issue
2013-07-31 09:11Brad KingNote Added: 0033631
2013-07-31 09:21Soeren TextorNote Added: 0033632
2013-07-31 09:27Soeren TextorNote Added: 0033633
2013-07-31 09:57Brad KingNote Added: 0033635
2013-07-31 09:57Brad KingStatusnew => backlog
2013-07-31 10:13Brad KingNote Added: 0033636
2013-07-31 10:19Soeren TextorNote Added: 0033637
2013-07-31 10:23Brad KingNote Added: 0033638
2013-07-31 10:23Brad KingAssigned To => Brad King
2013-07-31 10:23Brad KingStatusbacklog => resolved
2013-07-31 10:23Brad KingResolutionopen => fixed
2013-07-31 10:23Brad KingFixed in Version => CMake 2.8.12
2013-07-31 10:23Brad KingTarget Version => CMake 2.8.12
2013-12-02 08:51Robert MaynardNote Added: 0034661
2013-12-02 08:51Robert MaynardStatusresolved => closed

Notes
(0033631)
Brad King   
2013-07-31 09:11   
CMake appends a hard-coded /SUBSYSTEM:... flag after the LINK_FLAGS property values before parsing out the flags:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmVisualStudio10TargetGenerator.cxx;hb=v2.8.11.2#l1429 [^]

The hard-coded value is based on the WIN32_EXECUTABLE target property which is set by the WIN32 option to add_executable. This is the documented way to get a Windows GUI binary.
(0033632)
Soeren Textor   
2013-07-31 09:21   
I see. But do you think this behavior makes sense if the user wants to select the subsystem for the case that the project is not a WIN32_EXECUTABLE?
(0033633)
Soeren Textor   
2013-07-31 09:27   
Especially for shared library projects that can be console dlls or most of the time windows dlls (inside windows) there seems no proper way to set this flag since cmake VS 2010 generator :-8
(0033635)
Brad King   
2013-07-31 09:57   
I think the order can be switched to give precedence to the user-specified flags.

Actually the VS 7-9 generators should be refactored to generate the Subsystem attribute value based on flag parsing instead of hard-coding it as it does now. It is only luck that the IDE puts the user-specified flag after that generated from the attribute.
(0033636)
Brad King   
2013-07-31 10:13   
One possible workaround:

 set_property(TARGET mysharedlib PROPERTY WIN32_EXECUTABLE 1)
(0033637)
Soeren Textor   
2013-07-31 10:19   
The latter works for me also I still think that there should be a better solution somewhen.
(0033638)
Brad King   
2013-07-31 10:23   
Fixed for VS >= 10:

 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b64e8f22 [^]

The refactoring for older versions mentioned in 0014326:0033635 is not necessary but would be a nice-to-have future cleanup.
(0034661)
Robert Maynard   
2013-12-02 08:51   
Closing resolved issues that have not been updated in more than 4 months.