compiler-specific.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # This file is included from the def.cmake CMakeLists.txt file.
  2. # It sets up the compiler specific flags.
  3. # Define the common flags and options for GCC
  4. option(PROFILE "Enable profiling" OFF)
  5. add_library(common_compiler_flags INTERFACE)
  6. # Define the flags for the C compiler
  7. if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64")
  8. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  9. target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
  10. target_compile_options(
  11. common_compiler_flags INTERFACE -Wall -funroll-loops -Wcast-align
  12. -Werror=implicit-function-declaration -Werror=implicit-int
  13. )
  14. # If GCC version is greater than 4.2.0, enable the following flags
  15. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2.0)
  16. target_compile_options(
  17. common_compiler_flags INTERFACE -m64 -minline-all-stringops -falign-loops -ftree-vectorize
  18. -fno-strict-overflow -mtune=generic
  19. )
  20. target_link_options(common_compiler_flags INTERFACE -m64)
  21. endif()
  22. elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
  23. target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
  24. target_compile_options(common_compiler_flags INTERFACE -m64)
  25. target_link_options(common_compiler_flags INTERFACE -m64)
  26. endif()
  27. elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i486|i586|i686")
  28. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  29. target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
  30. target_compile_options(
  31. common_compiler_flags INTERFACE -Wall -funroll-loops -Wcast-align
  32. -Werror=implicit-function-declaration -Werror=implicit-int
  33. )
  34. # If GCC version is greater than 4.2.0, enable the following flags
  35. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2.0)
  36. target_compile_options(
  37. common_compiler_flags INTERFACE -m32 -minline-all-stringops -falign-loops -ftree-vectorize
  38. -fno-strict-overflow -mtune=generic
  39. )
  40. endif()
  41. elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
  42. target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
  43. target_compile_options(common_compiler_flags INTERFACE -m32)
  44. target_link_options(common_compiler_flags INTERFACE -m32)
  45. endif()
  46. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
  47. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  48. target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
  49. # target_compile_options(common INTERFACE -O0 # <$<$<BOOL:${PROFILE}>:-pg> )
  50. # target_compile_options( common INTERFACE -marm -march=armv5t
  51. # -funroll-loops -fsigned-char )
  52. # # If GCC version is greater than 4.2.0, enable the following flags
  53. # if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2.0) target_compile_options(
  54. # common INTERFACE -ftree-vectorize -fno-strict-overflow ) endif()
  55. endif()
  56. elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64$")
  57. # PowerPC 64-bit specific flags
  58. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  59. target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
  60. target_compile_options(common_compiler_flags INTERFACE -funroll-loops -fsigned-char)
  61. # Try to get CPUTYPE from the environment, fallback to "powerpc64" if not set
  62. if(DEFINED ENV{CPUTYPE} AND NOT "$ENV{CPUTYPE}" STREQUAL "")
  63. set(CPUTYPE "$ENV{CPUTYPE}")
  64. else()
  65. set(CPUTYPE "powerpc64")
  66. endif()
  67. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.2)
  68. target_compile_options(
  69. common_compiler_flags INTERFACE -ftree-vectorize -fno-strict-overflow -mtune=${CPUTYPE}
  70. -maltivec
  71. )
  72. elseif(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.0)
  73. target_compile_options(
  74. common_compiler_flags INTERFACE -ftree-vectorize -mtune=${CPUTYPE} -maltivec
  75. )
  76. elseif(CMAKE_C_COMPILER_VERSION VERSION_LESS 3.0)
  77. message(
  78. WARNING
  79. "GCC version ${CMAKE_C_COMPILER_VERSION} is too old for ppc64. Try GCC 3.0 or newer."
  80. )
  81. endif()
  82. # else()
  83. # message(FATAL_ERROR "Unsupported compiler (${CMAKE_C_COMPILER_ID}) for ppc64. Try GCC.")
  84. endif()
  85. endif()