You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

CheckLAPACKCompilerFlags.cmake 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # This module checks against various known compilers and their respective
  2. # flags to determine any specific flags needing to be set.
  3. #
  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
  7. #
  8. #=============================================================================
  9. # Author: Chuck Atkins
  10. # Copyright 2011
  11. #=============================================================================
  12. macro( CheckLAPACKCompilerFlags )
  13. set( FPE_EXIT FALSE )
  14. # GNU Fortran
  15. if( CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" )
  16. if( "${CMAKE_Fortran_FLAGS}" MATCHES "-ffpe-trap=[izoupd]")
  17. set( FPE_EXIT TRUE )
  18. endif()
  19. # Intel Fortran
  20. elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
  21. if( "${CMAKE_Fortran_FLAGS}" MATCHES "[-/]fpe(-all=|)0" )
  22. set( FPE_EXIT TRUE )
  23. endif()
  24. # SunPro F95
  25. elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
  26. if( ("${CMAKE_Fortran_FLAGS}" MATCHES "-ftrap=") AND
  27. NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-ftrap=(%|)none") )
  28. set( FPE_EXIT TRUE )
  29. elseif( NOT (CMAKE_Fortran_FLAGS MATCHES "-ftrap=") )
  30. message( STATUS "Disabling FPE trap handlers with -ftrap=%none" )
  31. set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ftrap=%none"
  32. CACHE STRING "Flags for Fortran compiler." FORCE )
  33. endif()
  34. # IBM XL Fortran
  35. elseif( (CMAKE_Fortran_COMPILER_ID STREQUAL "VisualAge" ) OR # CMake 2.6
  36. (CMAKE_Fortran_COMPILER_ID STREQUAL "XL" ) ) # CMake 2.8
  37. if( "${CMAKE_Fortran_FLAGS}" MATCHES "-qflttrap=[a-zA-Z:]:enable" )
  38. set( FPE_EXIT TRUE )
  39. endif()
  40. if( NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "-qfixed") )
  41. message( STATUS "Enabling fixed format F90/F95 with -qfixed" )
  42. set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qfixed"
  43. CACHE STRING "Flags for Fortran compiler." FORCE )
  44. endif()
  45. # HP Fortran
  46. elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "HP" )
  47. if( "${CMAKE_Fortran_FLAGS}" MATCHES "\\+fp_exception" )
  48. set( FPE_EXIT TRUE )
  49. endif()
  50. if( NOT ("${CMAKE_Fortran_FLAGS}" MATCHES "\\+fltconst_strict") )
  51. message( STATUS "Enabling strict float conversion with +fltconst_strict" )
  52. set( CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} +fltconst_strict"
  53. CACHE STRING "Flags for Fortran compiler." FORCE )
  54. endif()
  55. # Most versions of cmake don't have good default options for the HP compiler
  56. set( CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -g"
  57. CACHE STRING "Flags used by the compiler during debug builds" FORCE )
  58. set( CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_MINSIZEREL} +Osize"
  59. CACHE STRING "Flags used by the compiler during release minsize builds" FORCE )
  60. set( CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_RELEASE} +O2"
  61. CACHE STRING "Flags used by the compiler during release builds" FORCE )
  62. set( CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO} +O2 -g"
  63. CACHE STRING "Flags used by the compiler during release with debug info builds" FORCE )
  64. else()
  65. endif()
  66. if( "${CMAKE_Fortran_FLAGS_RELEASE}" MATCHES "O[3-9]" )
  67. message( STATUS "Reducing RELEASE optimization level to O2" )
  68. string( REGEX REPLACE "O[3-9]" "O2" CMAKE_Fortran_FLAGS_RELEASE
  69. "${CMAKE_Fortran_FLAGS_RELEASE}" )
  70. set( CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}"
  71. CACHE STRING "Flags used by the compiler during release builds" FORCE )
  72. endif()
  73. if( FPE_EXIT )
  74. 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." )
  75. endif()
  76. endmacro()