[CMake] Specifying compilers?

David Cole david.cole at kitware.com
Thu Aug 23 13:54:06 EDT 2012


On Thu, Aug 23, 2012 at 11:14 AM, Jason T. Slack-Moehrle <
slackmoehrle at gmail.com> wrote:

> >> I am trying to use come C++v11 features and am trying to get the
> >> compiling to work.
>
> >> SET( CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++" )
> >>
> >> PROJECT( ${PROJECT_NAME} )
> >
> > PROJECT will set up the compiler and stuff. And in this process it will
> set
> > CMAKE_CXX_FLAGS, i.e. will overwrite your lines. Exchange the lines and
> make
> > sure not to overwrite the existing flags, but append to them.
>
> This worked.
>
> Can you explain how I would/should have known that PROJECT will
> specify compiler and stuff when I am passing it in with the cmake
> command as well as using the SET statement above?
>
>

Unfortunately, it's just one of those things that "everybody knows" -- at
least those who have stuck with it through the hard-knocks school of CMake
learning...

What did you read and where did you look before you got to this point?

If you can answer that, then I can say where we should put the following
documentation:

In one of those places, we should state, uncategorically:

The first two lines of any CMakeLists.txt file should be:
cmake_minimum_required
project

Only people who know how it all works should do anything other than that.

We should also state on one of those places that the project command sets
up a lot of stuff for you internally, including compiler selection, and
that the "right" way to override that is by environment variables CC and
CXX before the initial call to CMake.

And that the right way to adjust flags is to append them to CMAKE_CXX_FLAGS
*after* the project command.

In the end, you found your way to the CMake mailing list, and we try to be
fairly useful in our responses here. Hope you found it reasonable despite
the frustrations in getting there.


Cheers,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120823/6bdde2a3/attachment.htm>


More information about the CMake mailing list