quotschmacher
quotschmacher

Reputation: 69

Set /SUBSYSTEM:WINDOWS on executable target

I would like to create a solution for VS 2019 that contains two targets with one CMakeLists file. That is not the problem. My problem is: one is a console application and the other one a gui app and both need different linker options.

For the gui project it is no problem: set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS")

But if i add the other executable i cannot get it managed to set the subsystem to console.

I even tried to set the linker options explicit for the target

set_target_porperties(hexToArray [BEFORE] CMAKE_EXE_LINKER_FLAGS "/SUBSYSTEM:CONSOLE")

but it doesn't work either. The subsystem is still "Windows".

Is there any possibility to achieve what i want to do?

Upvotes: 0

Views: 1714

Answers (1)

Botje
Botje

Reputation: 31020

CMAKE_EXE_LINKER_FLAGS is global, don't change that.

For the GUI target, simply do:

add_executable(TheGuiTarget WIN32 Gui.cpp ...)

or set the WIN32_EXECUTABLE property on TheGuiTarget afterwards.

The console target should receive /subsystem:console by default.

Upvotes: 2

Related Questions