[CMake] How can I create a C executable and C++ library from the same source

Jimi Damon jdamon at accesio.com
Wed Jan 17 13:05:24 EST 2018


Hi,

I want to use Gtest for some unit tests on a number of the C functions that
comprise my C executable.  However, Gtest ( And gMock ) are C++ testing
frameworks.

What I would like to have is a project for my exe and then a separate
project for my C++ library and be able to change the source properties to
use the language CXX just before compiling.

The problem I'm having is that CMake uses the CXX compiler for the C files.


Here's what I would like to have

project(cexe)
set(SOURCES foo.c bar.c )
add_executable( cexe  ${SOURCES} )

project(cpplib)
set_source_files_properties(${SOURCES} PROPERTIES LANGUAGE CXX )
add_library( cpplib SHARED ${SOURCES} )



Is there a way to do this ?

Can target_compile_options set the compile type for a given target ?


In the past I've had to copy the .C files to some renamed .CPP equivalent
and then compile off of that.

I'm hoping that enough new functionality has been added to Cmake to allow
separation between compiles.


Thanks,




-- 

Jimi Damon
ACCES I/O Products, Inc. <http://accesio.com/go.cgi?p=/contact/contact.html>
Linux Engineer
JDamon at accesio.com
(858) 550-7320 x3015
[image: ACCES I/O Logo]
10623 Roselle Street San Diego CA 92121-1506 <http://accesio.com/>

-- 
WARNING - This e-mail or its attachments may contain controlled technical 
data or controlled technology within the definition of the International 
Traffic in Arms Regulations (ITAR) or Export Administration Regulations 
(EAR), and are subject to the export control laws of the U.S. Government. 
Transfer of this data or technology by any means to a foreign person, 
whether in the United States or abroad, without an export license or other 
approval from the U.S. Government, is prohibited. The information contained 
in this document is CONFIDENTIAL and property of ACCES I/O Products, Inc. 
Any unauthorized review, use, disclosure or distribution is prohibited 
without express written consent of ACCES I/O Products, Inc. If you are not 
the intended recipient, please contact the sender and destroy all copies of 
the original message and enclosed attachments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180117/7e2df7a8/attachment.html>


More information about the CMake mailing list