How to add a global file extension (* .pde) to a CMake project in GCC, which is processed as C ++ code

I have a very simple CMake script. Unfortunately, the project uses a * .pde file, which is simple C ++ or C code.

CMake works with any file ending, but I get a compiler error because GCC does not know how to handle it. How to add a global file extension in GCC so that the * .pde file is compiled as a regular * .cpp file?

The -x c++ foo.pde is good if I want to use the console, but for CMake this (I think) is not applicable.

 cmake_minimum_required(VERSION 2.8) project(RPiCopter) SET( RPiCopter absdevice containers device exceptions navigation frame vehicle receiver scheduler tinycopter.pde ) message( STATUS "Include ArduPilot library directories" ) foreach( DIR ${AP_List} ${AP_List_Linux} ${AP_Headers} ) include_directories( "../libraries/${DIR}" ) endforeach() include_directories( zserge-jsmn ) # *************************************** # Build the firmware # *************************************** add_subdirectory ( zserge-jsmn ) #set(CMAKE_CXX_FLAGS "-x c++ *.pde") ADD_EXECUTABLE ( RPiCopter ${RPiCopter} ) target_link_libraries ( RPiCopter -Wl,--start-group ${AP_List} ${AP_List_Linux} jsmn -Wl,--end-group ) 
+4
gcc cmake
May 31 '15 at 10:36
source share
4 answers

You should be able to use set_source_files_properties together with LANGUAGE to mark the file as C ++ sources:

 set_source_files_properties(${TheFiles} PROPERTIES LANGUAGE CXX) 

As @steveire noted in his own answer, this error will require something like the following workaround:

 set_source_files_properties(${TheFiles} PROPERTIES LANGUAGE CXX) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") add_definitions("-x c++") endif() 
+3
May 31 '15 at 10:54
source share

I decided to use this approach. I just delete the file ending with cmake in the temporary assembly directory. Therefore, GCC is no longer embarrassed by the strange expansion of Arduino * .pde.

 # Exchange the file ending of the Arduino project file configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tinycopter.pde ${CMAKE_CURRENT_BINARY_DIR}/tinycopter.cpp) 
+2
Jun 01 '15 at 6:54
source share

Normally you should simply extend CMAKE_CXX_SOURCE_FILE_EXTENSIONS . This will help if you have many files with unknown file extensions.

But this variable is not cached - for example, CMAKE_CXX_FLAGS - so the following code in CMakeCXXCompiler.cmake.in will always overwrite / hide everything that you set:

 set(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;hpp;HPP;H;o;O;obj;OBJ;def;DEF;rc;RC) set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;mm;CPP) 

I believe that this is not a caching error in CMake , but until this changes, I was looking for a workaround considering the following

  • Normally you do not want to modify the files in your CMake installation.
  • This will have no effect if you change CMAKE_CXX_SOURCE_FILE_EXTENSIONS after project() / enable_language() (as discussed here ).

I successfully tested the following using one of the hooks / configuration variables inside CMakeCXXCompiler.cmake.in :

 cmake_minimum_required(VERSION 2.8) set(CMAKE_CXX_SYSROOT_FLAG_CODE "list(APPEND CMAKE_CXX_SOURCE_FILE_EXTENSIONS pde)") project(RPiCopter CXX) message("CMAKE_CXX_SOURCE_FILE_EXTENSIONS ${CMAKE_CXX_SOURCE_FILE_EXTENSIONS}") add_executable(RPiCopter tinycopter.pde) 
+1
Jun 02 '15 at 8:40
source share
-one
May 31 '15 at 16:39
source share



All Articles