compiler-specific.cmake 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Quite analogous to the Makefile.defs file This file is used to define the
  2. # common flags and options for the project The flags are defined as INTERFACE
  3. # properties of the common library The flags are then used by the other
  4. # libraries and executables
  5. cmake_minimum_required(VERSION 3.10)
  6. # Define the common flags and options for GCC
  7. option(PROFILE "Enable profiling" OFF)
  8. # Define the flags for the C compiler
  9. if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
  10. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  11. target_compile_definitions(common INTERFACE CC_GCC_LIKE_ASM)
  12. target_compile_options(
  13. common INTERFACE -O0
  14. # <$<$<BOOL:${PROFILE}>:-pg>
  15. )
  16. target_compile_options(
  17. common
  18. INTERFACE -Wall -funroll-loops -Wcast-align
  19. -Werror=implicit-function-declaration -Werror=implicit-int
  20. )
  21. # If GCC version is greater than 4.2.0, enable the following flags
  22. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2.0)
  23. target_compile_options(
  24. common INTERFACE -m64 -minline-all-stringops -falign-loops
  25. -ftree-vectorize -fno-strict-overflow -mtune=generic
  26. )
  27. endif()
  28. elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
  29. target_compile_definitions(common INTERFACE CC_GCC_LIKE_ASM)
  30. target_compile_options(common INTERFACE -m64)
  31. target_link_options(common INTERFACE -m64)
  32. endif()
  33. elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i486|i586|i686")
  34. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  35. target_compile_definitions(common INTERFACE CC_GCC_LIKE_ASM)
  36. target_compile_options(
  37. common INTERFACE -O0
  38. # <$<$<BOOL:${PROFILE}>:-pg>
  39. )
  40. target_compile_options(
  41. common
  42. INTERFACE -Wall -funroll-loops -Wcast-align
  43. -Werror=implicit-function-declaration -Werror=implicit-int
  44. )
  45. # If GCC version is greater than 4.2.0, enable the following flags
  46. if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2.0)
  47. target_compile_options(
  48. common INTERFACE -m32 -minline-all-stringops -falign-loops
  49. -ftree-vectorize -fno-strict-overflow -mtune=generic
  50. )
  51. endif()
  52. elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
  53. target_compile_definitions(common INTERFACE CC_GCC_LIKE_ASM)
  54. target_compile_options(common INTERFACE -m32)
  55. target_link_options(common INTERFACE -m32)
  56. endif()
  57. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
  58. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  59. target_compile_definitions(common INTERFACE CC_GCC_LIKE_ASM)
  60. # target_compile_options(common INTERFACE -O0 # <$<$<BOOL:${PROFILE}>:-pg> )
  61. # target_compile_options( common INTERFACE -marm -march=armv5t
  62. # -funroll-loops -fsigned-char )
  63. # # If GCC version is greater than 4.2.0, enable the following flags
  64. # if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2.0) target_compile_options(
  65. # common INTERFACE -ftree-vectorize -fno-strict-overflow ) endif()
  66. endif()
  67. endif()