I've read on CMake's documentation that when calling add_executable
, you can set the executable type to be Win32 by doing add_executable(target WIN32 source.cpp)
. I also know that you should use CMake generator expressions to check for build configurations like so:
target_compile_definitions(target PUBLIC
$<$<CONFIG:Debug>:DEBUG>
$<$<CONFIG:Release>:RELEASE>
)
However this won't work with add_executable
. It treats it as a source file when I do add_executable(target $<$<CONFIG:Release>:WIN32> source.cpp)
and so it fails. What is the correct way of doing setting the executable type to WIN32 only in release mode?
CodePudding user response:
I am not really sure it makes sense given a WIN32 executable and a non-WIN32 executable do not have the same entry point, so the code would need to change as well.
Still, here is how you would do it on CMake side:
add_executable(target source.cpp)
set_target_properties(target PROPERTIES WIN32_EXECUTABLE $<CONFIG:Release>)
Key point is the WIN32
flag in add_executable
is just a shortcut to set the WIN32_EXECUTABLE
property.
Note: I cannot test this sample atm so it depends on me having read those links properly ;)