22

I am trying to set up an old project using cmake and I would like to keep all flags the same as before. The old project generator has the linker flag /SUBSYSTEM with minimum subystem version number 5.01 set like this:

/SUBSYSTEM:WINDOWS,"5.01"

I tried the same in cmake by adding this:

set_target_properties(mytarget PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS,\"5.01\"")

However the result is wrong. Cmake seems to remove the (escaped) double quotes and places the linker flag to "Addition Options" in the Visual Studio project: /SUBSYSTEM:WINDOWS,5.01

This way the subsystem flag is not recognized and set to CONSOLE.

I tried several combinations how to add the min version ,"5.01" to the subsystem flag but without success.

Is there any other way to add the minimum subsystem version number to the /SUBSYSTEM flag?

bender
  • 613
  • 1
  • 8
  • 23
  • What version of Visual Studio are you using? – Marko Popovic Nov 23 '15 at 14:46
  • My Visual Studio version is 2012, but it should also work for 2003 since this my release compiler. – bender Nov 23 '15 at 14:52
  • 1
    Have you tried *double-escaping*: `\\\"5.01\\\"`. Some times ago I have seen mailing about strange escaping rules for some properties, when proper escaping depends even from generator in use. – Tsyvarev Nov 23 '15 at 17:28
  • 1
    I tried that too, the result was `\"5.01\"`. Anyway, thank you for your comment. I am now using `/SUBSYSTEM:WINDOWS` without the min version since it does not seem to work. – bender Nov 24 '15 at 08:27

2 Answers2

39

You can simply use the [WIN32] flag in the add_executable function :

add_executable(${PROJECT_NAME} WIN32 main.cpp)
cmourglia
  • 2,423
  • 1
  • 17
  • 33
7

Long time to answer but I have found a solution:

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS")
François Beaune
  • 4,270
  • 7
  • 41
  • 65
Gh0stViper
  • 97
  • 1
  • 3
  • 3
    This answer is invalid when `${CMAKE_EXE_LINKER_FLAGS}` string contains `/subsystem:console`. Better use the [solution](https://stackoverflow.com/a/57645234/4927212) provided by [@Zouch](https://stackoverflow.com/users/4717805/). – KaiserKatze Jan 24 '20 at 15:16