[CMake] How to remove _WINDOWS for MSVC preprocessor definitions for library & executable projects?

Tyler Roscoe tyler at cryptio.net
Tue Jul 14 15:49:35 EDT 2009


On Tue, Jul 14, 2009 at 12:07:32PM -0700, Erwin Coumans wrote:
> By default Cmake seems to add some built-in preprocessor definitions
> for Visual Studio project files,
> such as WIN32 and _WINDOWS. WIN32 is ok, but _WINDOWS is not always desired.

Looks like it's set in Modules/Platform/Windows-cl.cmake:

SET (CMAKE_CXX_FLAGS_INIT "/DWIN32 /D_WINDOWS /W3 [...]

> Is there an option to remove _WINDOWS from those definitions, for both
> library and executable projects?

The values above end up populating CMAKE_CXX_FLAGS. So just remove them
from there at the top of your project:

string (REPLACE "/D_WINDOWS" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})


tyler


More information about the CMake mailing list