[CMake] Suppressing a compilation option for one file?
Bill Hoffman
bill.hoffman at kitware.com
Fri Feb 1 15:14:01 EST 2008
Bryan O'Sullivan wrote:
> I know that I can use set_source_files_properties to add to the
> compilation flags used to build a single source file, but is there a way
> to *remove* a compilation flag for one file?
>
> My problem is that I build the source tree with -Wall -Werror, but one
> source file contains a use of a bad macro from a third party package for
> which there's no gcc option to override the warning that gets generated,
> so I need to turn off -Werror instead.
>
Not easily....
You could do something like remove the -Werror from the flags, and add
it into the files that need it.
Something like:
# remove -Werror from CMAKE_CXX_FLAGS and save it
# in EXTRA_FLAG if found
if(CMAKE_CXX_FLAGS MATCHES -Werror)
replace -Werror in CMAKE_CXX_FLAGS with ""
set(EXTRA_FLAG -Werror)
...
# if there is an EXTRA_FLAG, add it to all the source files
# except the ones that don't need it.
if(EXTRA_FLAG)
foreach(f ${SOURCES})
if(f NOT somefile)
set_source_files_properties(f1 COMPILE_FLAGS ${EXTRA_FLAG})
-Bill
More information about the CMake
mailing list