[CMake] Turning on warnings when compiling.

James Bigler bigler at cs.utah.edu
Tue Aug 28 09:30:01 EDT 2007


Michael Wagner wrote:
> Hi,
> 
> Whenever I'm compiling, there are no warnings shown.
> Is there a command or variable that can be used to turn on warnings?

I don't know of a specific CMake mechanism to turn on warnings.  I 
figure out which compiler I'm using and turn on flags manually by adding 
the flags to the CMAKE_CXX_FLAGS or something:

##############################################
# Sets some variables depending on which compiler you are using
#
# USING_GCC  : gcc is being used for C compiler
# USING_GPP  : g++ is being used for C++ compiler
# USING_ICC  : icc is being used for C compiler
# USING_ICPC : icpc is being used for C++ compiler

SET(MANTA_COMPILER_NAME_REGEXPR "icc.*$")

IF(NOT CMAKE_COMPILER_IS_GNUCC)
   # This regular expression also matches things like icc-9.1
   IF   (CMAKE_C_COMPILER MATCHES ${MANTA_COMPILER_NAME_REGEXPR})
     SET(USING_ICC TRUE)
   ENDIF(CMAKE_C_COMPILER MATCHES ${MANTA_COMPILER_NAME_REGEXPR})
ELSE(NOT CMAKE_COMPILER_IS_GNUCC)
   SET(USING_GCC TRUE)
ENDIF(NOT CMAKE_COMPILER_IS_GNUCC)

#  Do something similar for C++ (see code on line)

############################################
## Add flags based on compiler
IF(USING_GCC)
   # to really make this stick, set this as a forced cache variable
   SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -Wall)
ENDIF(USING_GCC)

----------------------------------------------------------------------
You might also want to add code to only set the flags on the first 
configure.  This allows users to remove flags you have set by default.

You can see the code here:
https://code.sci.utah.edu/svn/Manta/trunk/CMake/CompilerInfo.cmake
https://code.sci.utah.edu/svn/Manta/trunk/CMake/ConfigCompilerFlags.cmake

James


More information about the CMake mailing list