[CMake] Trying to find the best way to compile C code to both C and C++ libraries

Jimi Damon jdamon at accesio.com
Sun Jul 14 18:39:19 EDT 2013


Please pardon my last message. I found a thread from 2013-01-09  that 
kgardenia42 wrote and it pretty much addresses everything that I need.

-Jimi

On 07/14/2013 01:49 PM, Jimi Damon wrote:
> Hi,
>
>
> I am new-ish to Cmake and hence might be overlooking a simple solution 
> to this problem. Here's the quick crux of my problem.
>
> I have a directory full of .C files that I want to compile to a C 
> based Shared library and compile to a C++ shared library.  In the 
> original Makefile, it was handled by a simple rule that did the following
>
> g++ $(CXX_FLAGS)  file.c -o file.cpp.o
>
> vs.
>
> gcc $(C_FLAGS)  file.c -o file.o
>
> What I tried doing in CMAKE was have two targets with one being C 
> based library, and the other a C++ based. I then tried messing around 
> with SET_SOURCE_FILES_PROPERTIES and SET_TARGET_PROPERTIES to change 
> the compiler type for each set.
>
> However, Cmake keeps track of the underlying files. So even if I had
>
> file (GLOB c_files  RELATIVE "${CMAKE_SOURCE_DIR}" 
> "${CMAKE_SOURCE_DIR}/*.c" )
> followed by
>
> file (GLOB cxx_files  RELATIVE "${CMAKE_SOURCE_DIR}" 
> "${CMAKE_SOURCE_DIR}/*.c" )
>
> ADD_LIBRARY( cxx_entries SHARED  cxx_files )
> #and
> ADD_LIBRARY( c_entries  SHARED c_files )
>
>
> Then when I used the add_library () commands, it remembered only one 
> compiler type for both, and hence either both libraries would be CXX 
> compiled or C compiled.
>
>
> So, my question is : what is the best way to handle one directory full 
> of C files so that I can compile both to a C based shared library and  
> C++ based shared library.
>
> I thought about adding a custom rule, but considering that this will 
> be migrated over to Windows , I am trying to rely on as much CMake as 
> possible to try to ensure that it will work cross-platform.
>
> Thanks for any suggestions,
>
> -Jimi
>
>
> -- 
>
> 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


-- 
Jimi Damon
ACCES I/O Products, Inc.
Linux Engineer
jdamon at accesio.com
(858) 550-9559 x3015
	

-- 
Jimi Damon
ACCES I/O Products, Inc.
Linux Engineer
jdamon at accesio.com
(858) 550-9559 x3015
	

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130714/02cb893a/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: weblogo2.png
Type: image/png
Size: 3705 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130714/02cb893a/attachment-0001.png>


More information about the CMake mailing list