1 # This module checks against various known compilers and thier respective
2 # flags to determine any specific flags needing to be set.
4 # 1. If FPE traps are enabled either abort or disable them
5 # 2. Specify fixed form if needed
6 # 3. Ensure that Release builds use O2 instead of O3
8 #=============================================================================
11 #=============================================================================
13 macro( CheckLAPACKCompilerFlags )
18 if( CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" )
19 if( "${CMAKE_Fortran_FLAGS}" MATCHES "-ffpe-trap=[izoupd]")
24 elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
25 if( "${CMAKE_Fortran_FLAGS}" MATCHES "[-/]fpe(-all=|)0" )
30 elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
31 if( ("${CMAKE_Fortran_FLAGS}" MATCHES "-ftrap=") AND
32 NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-ftrap=(%|)none") )
34 elseif( NOT (CMAKE_Fortran_FLAGS MATCHES "-ftrap=") )
35 message( STATUS "Disabling FPE trap handlers with -ftrap=%none" )
36 set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ftrap=%none"
37 CACHE STRING "Flags for Fortran compiler." FORCE )
41 elseif( (CMAKE_Fortran_COMPILER_ID STREQUAL "VisualAge" ) OR # CMake 2.6
42 (CMAKE_Fortran_COMPILER_ID STREQUAL "XL" ) ) # CMake 2.8
43 if( "${CMAKE_Fortran_FLAGS}" MATCHES "-qflttrap=[a-zA-Z:]:enable" )
47 if( NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-qfixed") )
48 message( STATUS "Enabling fixed format F90/F95 with -qfixed" )
49 set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qfixed"
50 CACHE STRING "Flags for Fortran compiler." FORCE )
54 elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "HP" )
55 if( "${CMAKE_Fortran_FLAGS}" MATCHES "\\+fp_exception" )
59 if( NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "\\+fltconst_strict") )
60 message( STATUS "Enabling strict float conversion with +fltconst_strict" )
61 set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} +fltconst_strict"
62 CACHE STRING "Flags for Fortran compiler." FORCE )
65 # Most versions of cmake don't have good default options for the HP compiler
66 set( CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -g"
67 CACHE STRING "Flags used by the compiler during debug builds" FORCE )
68 set( CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_MINSIZEREL} +Osize"
69 CACHE STRING "Flags used by the compiler during release minsize builds" FORCE )
70 set( CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_RELEASE} +O2"
71 CACHE STRING "Flags used by the compiler during release builds" FORCE )
72 set( CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO} +O2 -g"
73 CACHE STRING "Flags used by the compiler during release with debug info builds" FORCE )
77 if( "${CMAKE_Fortran_FLAGS_RELEASE}" MATCHES "O[3-9]" )
78 message( STATUS "Reducing RELEASE optimization level to O2" )
79 string( REGEX REPLACE "O[3-9]" "O2" CMAKE_Fortran_FLAGS_RELEASE
80 "${CMAKE_Fortran_FLAGS_RELEASE}" )
81 set( CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
82 CACHE STRING "Flags used by the compiler during release builds" FORCE )
87 message( FATAL_ERROR "Floating Point Exception (FPE) trap handlers are currently explicitly enabled in the compiler flags. LAPACK is designed to check for and handle these cases internally and enabling these traps will likely cause LAPACK to crash. Please re-configure with floating point exception trapping disabled." )