[CMake] building c code as c++ code

Bill Hoffman bill.hoffman at kitware.com
Sun Jun 10 23:22:08 EDT 2007


John Pretz wrote:
> Oh, you're a hero.  Thank you.  I didn't even realize that gcc had an 
> option to force compilation as c++.  But that works.
>
> I'll file a bug report nonetheless.

No need for a bug report, this can be done like this:

hoffman at Discworld ~/My Builds/CMake/Tests
$ less SetLang/CMakeLists.txt
# test forcing a source file language to c++ from c
project(SetLang)
# force this to be verbose so I can debug a dashboard entry
SET(CMAKE_VERBOSE_MAKEFILE 1)
add_library(foo foo.c)
add_executable(SetLang bar.c)
set_source_files_properties(foo.c bar.c PROPERTIES LANGUAGE CXX)
target_link_libraries(SetLang foo)
set_target_properties(SetLang PROPERTIES LINKER_LANGUAGE CXX)

I do think there is a bug that breaks this in 2.4.6, but it will be 
fixed in 2.4.7.

-Bill


More information about the CMake mailing list