[CMake] CMake, Nmake files and APPVER

Tanner Lovelace lovelace-cmake at wayfarer.org
Tue Mar 15 09:30:51 EST 2005


Quoting Brad King <brad.king at kitware.com>:

> CMake generates a specific set of flags for each build rule.  I doubt
> APPVER could do much more than define environment variables for the
> compiler.  Does it work if you add the inclusion by hand to the makefile?

Good point.  I didn't think about the fact that CMake sets the build
flags specifically.  After testing it by hand, I see that adding the
include and setting APPVER does indeed not work.

Instead, after digging in the NMake supplied win32.mak file, I see that
setting APPVER to 5.0 (which apparently corresponds to some revision of
the Windows SDK) sets up the following variables:

NMAKE_WINVER = 0x0500
_WIN32_IE = 0x0400

which are then passed as defines to the C compiler like this:

-D_WINNT -D_WIN32_WINNT=$(NMAKE_WINVER)
-D_WIN32_IE=$(_WIN32_IE) -DWINVER=$(NMAKE_WINVER)

(Assuming an NT build.)  In addition, it sets the following
linker flags:

# for Windows applications that use the C Run-Time libraries
conlflags = $(lflags) -subsystem:console,$(APPVER)
guilflags = $(lflags) -subsystem:windows,$(APPVER)

!IF "$(CPU)" == "i386"
savlflags = $(lflags) -subsystem:windows,$(APPVER) -entry:WinMainCRTStartup
!ELSE
savlflags = $(lflags) -subsystem:windows,$(APPVER) -entry:mainCRTStartup
!ENDIF

I assume those flags eventually end up on the default link lines.

So, it looks like writing a macro to set the compiler defines automatically
is trivial.  Setting the linker flags, though, may be a bit more problematic
since it appears that CMake already generates a "-subsystem:console" or
"-subsystem:windows" based on if WIN32 is specified or not in the
ADD_EXECUTABLE definition.  I wonder what the linker will do if there are
two "-subsystem" parameters?  I don't suppose there's anything I can set
to make CMake automatically add the application version after that
parameter, sort of like all the stuff you can set for MACOSX_BUNDLEs?
If there isn't, I'm assuming I may have to hack the NMake generator
itself?  Is that the case or is there another way?

Thanks very much,
Tanner Lovelace




More information about the CMake mailing list