[CMake] Building a library for both C and C++
Nils Gladitz
gladitz at sci-vis.de
Wed Jan 9 03:57:41 EST 2013
Why do you want to build a C library both with a C++ and a C compiler?
Wouldn't a C compiler build and an extern "C" interface suffice to use
the library with both C and C++?
In case you want to provide an additional distinct C++ specific
interface I'd assume you'd have actual C++ source files which you could
use for the C++ target and which could link to the C library.
Nils
On 01/09/2013 01:17 AM, kgardenia42 wrote:
> 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.
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
--
Nils Gladitz, B.Sc.
DICOM, Konnektivität und Entwicklung
Scivis wissenschaftliche Bildverarbeitung GmbH
Bertha-von-Suttner-Str. 5
D-37085 Göttingen
GERMANY
Handelsregister Nr. / Trade Register No. B3100 Göttingen
Geschäftsführer / Managing Directors Dr. Gernot Ebel, Dr. Uwe Engeland
Tel: 0049 (0)551 634181-28
E-Mail: gladitz at scivis.de
Web: www.scivis.de
More information about the CMake
mailing list