JenyaKh
JenyaKh

Reputation: 2498

How can I set add_executable WIN32 property or not depending on the build type?

This fails with the error "Cannot find source file: WIN32. Tried extensions..."

add_executable(${PROJECT_NAME} $<$<CONFIG:Release>:WIN32> main.cpp)

I need this in order to launch the app in the console in Debug mode and being able to read information printed to the console.

And as far as I know it's wrong and is advised agains in the cmake docs to check CMAKE_BUILD_TYPE being Release directly.

Upvotes: 5

Views: 861

Answers (1)

vre
vre

Reputation: 6744

As you noticed you cannot use generator expressions for the WIN32 keyword in the add_executable command.

Instead, try setting the corresponding property WIN32_EXECUTABLE on the target:

set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE $<CONFIG:Release>)

Upvotes: 5

Related Questions