MantisBT - CMake
View Issue Details
0014857CMakeCMakepublic2014-04-01 10:152015-11-02 09:13
Stephen Kelly 
Stephen Kelly 
normalminorhave not tried
closedfixed 
 
CMake 3.3 
0014857: Allow COMPILE_OPTIONS to vary by source file language

Compile options like -fno-exceptions should be added for CXX files, but not for C files.

 http://thread.gmane.org/gmane.comp.kde.devel.frameworks/9222/focus=8215 [^]

 http://thread.gmane.org/gmane.comp.compilers.llvm.cvs/173869 [^]

Some methods like cmLocalGenerator::GetIncludeDirectories have a language in their API, but that is a linker language, not a source file language.

Making build properties vary by source file language is probably a large refactoring task of the existing generators.
No tags attached.
related to 0002086closed Bill Hoffman Visual stuido sends c++ flags to c code 
has duplicate 0015365closed  Allow per-language COMPILE_OPTIONS via generator expression 
Issue History
2014-04-01 10:15Stephen KellyNew Issue
2014-10-29 21:03Edward RuddNote Added: 0037107
2015-01-22 17:04Stephen KellyRelationship addedhas duplicate 0015365
2015-01-23 15:09Brad KingNote Added: 0037797
2015-01-23 15:11Brad KingNote Added: 0037798
2015-02-04 15:27Sebastian SauerNote Added: 0037912
2015-02-04 15:30Sebastian SauerNote Edited: 0037912bug_revision_view_page.php?bugnote_id=37912#r1695
2015-02-23 15:43Stephen KellyNote Added: 0038035
2015-02-26 03:39Stephen KellyRelationship addedrelated to 0002086
2015-03-11 15:52Stephen KellyNote Added: 0038204
2015-03-11 15:52Stephen KellyStatusnew => resolved
2015-03-11 15:52Stephen KellyFixed in Version => CMake 3.3
2015-03-11 15:52Stephen KellyResolutionopen => fixed
2015-03-11 15:52Stephen KellyAssigned To => Stephen Kelly
2015-11-02 09:13Robert MaynardNote Added: 0039730
2015-11-02 09:13Robert MaynardStatusresolved => closed

Notes
(0037107)
Edward Rudd   
2014-10-29 21:03   
This can be made easier in modern cmake with generator expressions.. That is once a $<COMPILER_LANG:lang> type generator expression is added.. As it would be awesome to do something like this

$<$<AND:$<COMPILER_LANG:C++>,$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNUC>>>:-std=c++11>

OR better yet.. for the target_compile_options just use the fact that the language is known and fail any $<CXX_COMPILER_ID:comp> generator expressions for C or Obj-C code. (but not C++ and Obj-C++).
(0037797)
Brad King   
2015-01-23 15:09   
Some relevant comments appear in 0015365:0037777 and 0015365:0037778.
(0037798)
Brad King   
2015-01-23 15:11   
Re 0014857:0037107: Yes, but the description of the issue explains that adding $<COMPILER_LANG:...> (or whatever name is chosen) and allowing it to work in expected contexts will require some internal API refactoring to thread the "lang" parameter through necessary call stacks.
(0037912)
Sebastian Sauer   
2015-02-04 15:27   
(edited on: 2015-02-04 15:30)
Related: http://public.kitware.com/pipermail/cmake-developers/2013-May/007210.html [^]

$<$<COMPILE_LANGUAGE:C>:C_ONLY>
$<$<COMPILE_LANGUAGE:CXX>:CXX_ONLY>
$<$<LINK_LANGUAGE:CXX>:LINK_AS_CXX>

A typical use-case, which I just run into and had/have a hard time to workaround, is Makefile code doing this on a library-target that has *.c and *.cpp files:
CFLAGS += -include c_config.h
CXXFLAGS += -include cpp_config.h

(0038035)
Stephen Kelly   
2015-02-23 15:43   
Discussion thread on the mailing list here:

 http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/12488 [^]
(0038204)
Stephen Kelly   
2015-03-11 15:52   
Done:

 http://www.cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5c559f11 [^]
 Genex: Enable use of COMPILE_LANGUAGE for compile options.
(0039730)
Robert Maynard   
2015-11-02 09:13   
Closing resolved issues that have not been updated in more than 4 months.