[CMake] Building a library for both C and C++
kgardenia42
kgardenia42 at googlemail.com
Tue Jan 8 19:17:48 EST 2013
Hi list,
I am trying to write a CMakeLists.txt where the same source files are
compiled separately to both a C library and a C++ library.
So, lets say I have foo.c, bar.c and baz.c and I would like to build
mylib.a and mylib++.a
My intuition is to use one CMakefile and add multiple targets for each
library I want to build. Does that seem like a reasonable approach?
Other suggestions welcome. Also, can anyone point me to an open
source library that uses cmake and builds both a C and C++ version.
If that approach (one CMakeLists.txt to build both libraries) seems
reasonable then how can I override the language per target?
I know that I can force the use of a C++ compiler for source files:
SET_SOURCE_FILES_PROPERTIES( ${mylib_SRCS} PROPERTIES LANGUAGE CXX )
However, this seems to set the language globally and so now all
targets use the C++ compiler.
I couldn't seem to figure out how to do the equivalent thing
per-target. Any suggestions? i.e. is there another way (other than
SET_SOURCE_FILES_PROPERTIES) which could accomplish the "set the
language per target" functionality I need here?
Thanks.
More information about the CMake
mailing list