[CMake] VC++10 change WIN32_EXECUTABLE per configuration
Steve deRosier
derosier at gmail.com
Mon Jul 30 20:05:01 EDT 2012
I need a way to have the WIN32_EXECUTABLE property set off for debug
builds and on for release builds when using the IDE.
Here's the deal: For debug our code uses the standard main()
construct, and for release we use the WinMain(). Lets just say there's
a reason and leave it at that...
The obvious solution is to be able to specify the '/subsystem:windows'
flag myself in LINK_FLAGS_DEBUG and LINK_FLAGS_RELEASE.
But, the generator overrides these settings for me. So, I found the
WIN32 for add_executable(), but of course you can't specify that
differently for debug vs release.
For a make-file generator, I could just utilize:
if( "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" )
...
elseif( "${CMAKE_BUILD_TYPE}" STREQUAL "Release" )
...
endif()
but of course this doesn't work when generating for VS10 IDE.
I found the CMAKE_CREATE_WIN32_EXE variable, but overriding it to ""
does nothing, so I resorted to looking at cmake's source code, which
totally ignores that variable, and hard codes the linker flag in the
output based on the WIN32_EXECUTABLE property! (see line 1409 of
cmVisualStudio10TargetGenerator.cxx).
OK, other than hacking the cmake source and rolling our own, so is
there any way to:
1. Override the setting after-the-fact but before the project files
are actually written?
2. Set the WIN32_EXECUTABLE property on a per-configuration basis?
At the moment I see four options-> hack the cmake source and roll our
own; do some post-processing on the produced project files; Force
everyone to manually change the flag in the IDE; convince my client to
restructure some code so we don't encounter this problem in the first
place.
I'm hoping there's more options out there that are pure project.cmake
file-based. Anyone?
Thanks,
- Steve
More information about the CMake
mailing list