Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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>)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading