[CMake] Compile project as C++ if MSVC

Eric Noulard eric.noulard at gmail.com
Fri Dec 23 01:23:18 EST 2011


2011/12/23 Pau Garcia i Quiles <pgquiles at elpauer.org>:
> Hi,
>
> Visual C++ 2010 does not support C99 yet and it seems it will be a
> long time before MSVC supports it. For now, the usual work-around is
> to build the project as C++.
>
> I'd like to build as C if using mingw, and as C++ if using MSVC. How
> can I do that? project() seems not to be valid here (I can't do
> if(MSVC) before project()) and I cannot find a target property to say
> "compile as language CXX"

There is a LANGUAGE property but it is for source files not target
(which is logical because a target may contain mixed language sources)

so

set_source_files_properties(<SRC> PROPERTIES LANGUAGE C)

see
cmake --help-property LANGUAGE
cmake --help-command set_source_files_properties

you may be interested by the SOURCE target property as well
which makes its possible to retrieve all SOURCE file belonging to a
target.


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


More information about the CMake mailing list