MantisBT - CMake
View Issue Details
0008851CMakeCMakepublic2009-04-06 10:592016-06-10 14:30
Alexandre Feblot 
Bill Hoffman 
normalminorhave not tried
closedmoved 
 
 
0008851: Allow to globally set which compiler to use with a given file extension
CMAKE_CXX_SOURCE_FILE_EXTENSIONS and CMAKE_C_SOURCE_FILE_EXTENSIONS are currently read-only variables, as they are:
   - overwritten by project() or enable_language() if they are set before calling these functions.
   - not taken into account anymore after calling these functions.

So the current and ugly way to let cmake know that you want, let's say all .c files considered as C++ is to set the LANGUAGE property for all of them.

Modifications to CMAKE_CXX_SOURCE_FILE_EXTENSIONS and CMAKE_C_SOURCE_FILE_EXTENSIONS values should be honored after calling project() or enable_language().

Typical use case:

project(MY_PROJECT C CXX) # also add "C" because a specific lib might need to be compiled in pure C.
list(APPEND CMAKE_CXX_SOURCE_FILE_EXTENSIONS "c")
list(REMOVE_ITEM CMAKE_C_SOURCE_FILE_EXTENSIONS "c")
add_subdirectory(...)
No tags attached.
Issue History
2009-04-06 10:59Alexandre FeblotNew Issue
2009-04-06 11:03Bill HoffmanStatusnew => assigned
2009-04-06 11:03Bill HoffmanAssigned To => Bill Hoffman
2015-06-02 07:04FlorianMNote Added: 0038873
2015-06-02 07:07FlorianMNote Edited: 0038873bug_revision_view_page.php?bugnote_id=38873#r1794
2015-06-02 07:08FlorianMNote Edited: 0038873bug_revision_view_page.php?bugnote_id=38873#r1795
2015-06-02 07:15FlorianMNote Edited: 0038873bug_revision_view_page.php?bugnote_id=38873#r1796
2016-06-10 14:27Kitware RobotNote Added: 0041538
2016-06-10 14:27Kitware RobotStatusassigned => resolved
2016-06-10 14:27Kitware RobotResolutionopen => moved
2016-06-10 14:30Kitware RobotStatusresolved => closed

Notes
(0038873)
FlorianM   
2015-06-02 07:04   
(edited on: 2015-06-02 07:15)
I also would have needed this before and like to propose a quite simple solution for this:

If CMAKE_<LANG>_SOURCE_FILE_EXTENSIONS and CMAKE_<LANG>_IGNORE_EXTENSIONS would be defined as cached variables (without FORCE) I could change/pre-define its value as I could do with CMAKE_<LANG>_FLAGS (including the possibility to set it in a toolchain file).

E.g. changing CMakeCXXCompiler.cmake.in to:

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

That would still need to be defined before the project()/enable_language() commands, but at least I could change the values.

Possible workaround with current versions: using one of the "hooks"/configuration variables inside e.g. CMakeCXXCompiler.cmake.in:

cmake_minimum_required(VERSION 2.8)

set(CMAKE_CXX_SYSROOT_FLAG_CODE "list(APPEND CMAKE_CXX_SOURCE_FILE_EXTENSIONS xyz)")

project(Test CXX)

add_executable(Test SomeOtherFile.xyz)

(0041538)
Kitware Robot   
2016-06-10 14:27   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.