[Cmake] Forcing the use of C++ compiler for .c files

William A. Hoffman billlist at nycap.rr.com
Wed Aug 11 12:03:30 EDT 2004


Assuming the files are under some sort of revision control, and they have
to stay .c files, you could try using the CONFIGURE_FILE command to copy them
into .cxx files.

SET( SOURCES foo.c bar.c car.c)
FOREACH(f ${SOURCES})
  SET( CXX_SOURCES ${CXX_SOURCES} ${project_BINARY_DIR}/${f}xx)
  CONFIGURE_FILE(${project_SOURCE_DIR}/$f ${project_BINARY_DIR}/${f}xx COPYONLY)
ENDFOREACH(f)

ADD_LIBRARY(foocpp ${CXX_SOURCES})

-Bill


At 11:52 AM 8/11/2004, Matt Valerio wrote:
>On second thought, this one is a little more readable:
>
>for i in `ls *.c`; do mv $i `echo $i | sed -e 's/\.c/\.cpp/'`; done
>
>
>Matt Valerio wrote:
>
>>I know it's a kludge, but you could just rename all of your .c files to .cpp (assuming you are using a bash shell):
>>for i in `ls *.c`; do mv $i `echo $i | sed -e 's/\(.*\)\.c/\1\.cpp/'`; done
>>-Matt
>>
>>Dekeyser, Kris wrote:
>>
>>>Hi,
>>>
>>>We currently have some legacy C++ code. Most of these files use extension
>>>.c, but they really contain C++ code. CMake however automatically selects
>>>the CMAKE_C_COMPILER to compile the files, which causes an error. Forcing
>>>CMake to use the C++ compiler doesn't work either, because CMake detects
>>>that it is not a C Compiler, but C++ compiler.
>>>
>>>The only solution I found is to hack the
>>>${CMAKE_ROOT}/Modules/CMakeTestCCompiler.cmake and disable the C++ check.
>>>
>>>However, we do need to compile another project with the C Compiler and not
>>>with the C++ compiler, so we end up to hack/unhack the test file all the
>>>time.
>>>
>>>Is there another - better - way to force the usuage of the C++ compiler in
>>>CMake for certain files? If not, could it be added?
>>>
>>>Best regards,
>>>Kris
>>>+-+-+- Email Confidentiality Footer +-+-+- Privileged/Confidential Information may be contained in this message. If you
>>>are not the addressee indicated in this message (or responsible for delivery
>>>of the message to such person), you may not print, retain, copy nor
>>>disseminate this message or any part of it to anyone and you should notify
>>>the sender by reply email and destroy this message. Neglecting this clause
>>>could be a breach of confidence. Please advise immediately if you or your
>>>employer does not consent to Internet email for messages of this kind.
>>>Opinions, conclusions and other information in this message that are not
>>>related to the official business of my firm shall be understood as neither
>>>given nor endorsed by it.
>>>
>>>_______________________________________________
>>>Cmake mailing list
>>>Cmake at www.cmake.org
>>>http://www.cmake.org/mailman/listinfo/cmake
>>_______________________________________________
>>Cmake mailing list
>>Cmake at www.cmake.org
>>http://www.cmake.org/mailman/listinfo/cmake
>_______________________________________________
>Cmake mailing list
>Cmake at www.cmake.org
>http://www.cmake.org/mailman/listinfo/cmake



More information about the Cmake mailing list