Portable compiler flags¶
To ease with the development of code that is portable across different architectures
and compilers, BLT provides the
which allows users to easily place a compiler dependent flag into a CMake variable.
To use this macro, supply a cmake variable in which to append a flag (
and the appropriate flag for each of our supported compilers.
This macro currently supports the following compilers:
- XL (IBM compiler)
- INTEL (Intel compiler)
- MSVC (Microsoft Visual Studio)
Here is an example for setting the appropriate flag to treat warnings as errors:
blt_append_custom_compiler_flag( FLAGS_VAR BLT_WARNINGS_AS_ERRORS_FLAG DEFAULT "-Werror" MSVC "/WX" XL "qhalt=w" )
Since values for
INTEL are not supplied,
they will get the default value (
which is supplied by the macro’s
BLT also provides a simple macro to add compiler flags to a target.
You can append the above compiler flag to an already defined executable,
example_1 with the following line:
blt_add_target_compile_flags(TO example_1 FLAGS BLT_WARNINGS_AS_ERRORS_FLAG )
Here is another example to disable warnings about unknown OpenMP pragmas in the code:
# Flag for disabling warnings about omp pragmas in the code blt_append_custom_compiler_flag( FLAGS_VAR DISABLE_OMP_PRAGMA_WARNINGS_FLAG DEFAULT "-Wno-unknown-pragmas" XL "-qignprag=omp" INTEL "-diag-disable 3180" MSVC "/wd4068" )
Note that GNU does not have a way to only disable warnings about openmp pragmas, so one must disable warnings about all unknown pragmas on this compiler.