Quantcast

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

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Erwin Coumans-2
Hi,

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.

I searched and tried some previous suggestions, but it seems only able
to add, but not remove definitions such as _WINDOWS.
http://www.mail-archive.com/cmake@.../msg16551.html

Is there an option to remove _WINDOWS from those definitions, for both
library and executable projects?
Thanks a lot,
Erwin
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to remove _WINDOWS for MSVC preprocessor definitions for library & executable projects?

Tyler Roscoe
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
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to remove _WINDOWS for MSVC preprocessor definitions for library & executable projects?

Erwin Coumans-2
> string (REPLACE "/D_WINDOWS" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})

Great, that did the job.

Thanks!
Erwin


2009/7/14 Tyler Roscoe <[hidden email]>:

> 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
>
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to remove _WINDOWS for MSVC preprocessor definitions for library & executable projects?

Eric Noulard
2009/7/14 Erwin Coumans <[hidden email]>:
>> string (REPLACE "/D_WINDOWS" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
>
> Great, that did the job.
>

Don't know if it can work for your case but you have the
'remove_definitions' command too:

  remove_definitions
       Removes -D define flags added by add_definitions.

         remove_definitions(-DFOO -DBAR ...)

       Removes flags (added by add_definitions) from the compiler command
       line for sources in the current directory and below.


--
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to remove _WINDOWS for MSVC preprocessor definitions for library & executable projects?

Erwin Coumans-2
remove_definitions(-D_WINDOWS ) didn't work, possibly because it
wasn't added using add_definitions (but a built-in).

I'm happy with string (REPLACE "/D_WINDOWS" "" CMAKE_CXX_FLAGS
${CMAKE_CXX_FLAGS})



2009/7/14 Eric Noulard <[hidden email]>:

> 2009/7/14 Erwin Coumans <[hidden email]>:
>>> string (REPLACE "/D_WINDOWS" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
>>
>> Great, that did the job.
>>
>
> Don't know if it can work for your case but you have the
> 'remove_definitions' command too:
>
>  remove_definitions
>       Removes -D define flags added by add_definitions.
>
>         remove_definitions(-DFOO -DBAR ...)
>
>       Removes flags (added by add_definitions) from the compiler command
>       line for sources in the current directory and below.
>
>
> --
> Erk
> Membre de l'April - « promouvoir et défendre le logiciel libre » -
> http://www.april.org
>
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Loading...