[CMake] CMAKE changing Visual Studio Settings

Chuck Atkins chuck.atkins at kitware.com
Thu Jul 24 10:11:49 EDT 2014


Hi Joseph,

On Mon, Jul 21, 2014 at 4:51 PM, Joseph Rosensweig <jrosensw at gmail.com>
wrote:

> ...
>
in my CMAKE I have places where I do things like if(CMAKE_BUILD_TYPE
> STREQUAL Debug) then do this else do that.
>

This is the sort of logic best achieved through generator expressions.  How
to do it specifically really depends.  Generator expressions are used all
over CMake in various different contexts so how to apply them depends on
what exactly you are trying to achieve.



> i.e. my CXX Flags will change based on the CMAKE_BUILD_TYPE ... What am I
> missing?
>

This is actually much simpler than the general case.  CMake has specific
compiler flags for all builds, release, debug, release with debug info, and
minimum size release.  They can be set / ammended with:

# Flags that get applied to all builds
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /My /EXTRA /COMPILER /FLAGS")

# Flags that only apply to debug builds
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /ADDITIONAL /DEBUG
/ONLY /FLAGS")

# Flags that only apply to release builds
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /ADDITIONAL
/RELEASE /ONLY /FLAGS")

The resulting compiler flags that get used are a combination of the general
CMAKE_CXX_FLAGS and CMAKE_CXX_FLAGS for the current selected build
configuration.

Back to the first issue though, what other types of build-type specific
logic are you trying to achieve?  There may be a better / easier way.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140724/72ead805/attachment-0001.html>


More information about the CMake mailing list