[CMake] Compile flags for a single file

Alexander Neundorf a.neundorf-work at gmx.net
Mon Apr 18 15:52:31 EDT 2011


On Monday 18 April 2011, The Novice Coder wrote:
>  I've been trying most things I can think of, but have been unable to
>  come up with a solution.. the basic gist is I need to change the compile
>  flags for a SINGLE file within a project. Specifically, disabling all
>  compile warnings for that file.
>
>  add_definitions() seems to effect the whole project, so that's not
>  helping..
>
>  Also couldn't use set_property() to do it either. (I could have been
>  using it wrong).

set_source_files_properties() should be able to set COMPILE_FLAGS for single 
files.
* you might also write a file which only does some #define/#undef's and then 
includes the file in question ?
* you might build a static library consisting only of that one file, if 
necessary in an own subdirectory (which has only the CMakeLists.txt  with 
add_library(foo STATIC ../the_file.c), basically)

Alex


More information about the CMake mailing list