[CMake] changing C/C++ compiler: from CMakeLists/for some sources only, and more

Szilárd Páll szilard.pall at cbr.su.se
Wed May 18 15:15:29 EDT 2011


Hi,

I need to do some funky things to get my code compiled and I'd like to
have some opinion on whether these things are possible or not and
what's the best way to do it.


1. Change the C/C++ compiler from CMakeList.txt without triggering the
re-generation of the entire cache. I know it sounds strange and not
very reasonable, but this would be the best quick/short-term solution
for my problem.

2. Is it possible to somehow use multiple C/C++ compilers at the same
time in an elegant way? Ideally what I would like to do is to use gcc
for most files, but for some swap gcc with another (pretty much
compatible) compiler and do something like this:

set_source_files_properties(file1 file2 file3 PROPERTIES COMPILER
"path_to_new_compiler").

Is it possible to do something like this? (Of course, the "COMPILER"
property doesn't exist. :)


3. (How) Can I globally override the CMAKE_SHARED_LIBRARY_[CREATE|
LINK|RUNTIME]_C_FLAGS variables without modifying files withing the
CMake distribution (e.g. Modules/Platform/Linux.cmake)?


4. Finally, if I want to add support for a new compiler which from
CMake's point of view behaves almost like gcc, how do I do that? I
fear this is not very easy and I could even live with dirty-ish hacks
solved by (some of) 1+3.


Tips and tricks are all welcome. Thanks in advance!

Cheers,
--
Szilárd


More information about the CMake mailing list