global_flags.cmake 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_INIT}")
  2. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT}")
  3. # workaround when old NDK toolchain that does not set CMAKE_ANDROID_NDK_VERSION is used
  4. # See for details: https://gitlab.kitware.com/cmake/cmake/-/issues/24386
  5. if(ANDROID_NDK_REVISION AND NOT CMAKE_ANDROID_NDK_VERSION)
  6. set(CMAKE_ANDROID_NDK_VERSION "${ANDROID_NDK_REVISION}")
  7. endif()
  8. if (MSVC)
  9. set(flagPrefixSymbol "/")
  10. include(global_flags.compiler.msvc)
  11. include(global_flags.linker.msvc)
  12. else()
  13. set(flagPrefixSymbol "-")
  14. include(global_flags.compiler.gnu)
  15. include(global_flags.linker.gnu)
  16. endif()
  17. if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|x86_64|AMD64)$")
  18. set(_ALL_X86_EXTENSIONS_DEFINES "\
  19. ${flagPrefixSymbol}DSSE_ENABLED=1 \
  20. ${flagPrefixSymbol}DSSE3_ENABLED=1 \
  21. ${flagPrefixSymbol}DSSSE3_ENABLED=1 \
  22. ")
  23. if ((CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$") OR (NOT ANDROID))
  24. string(APPEND _ALL_X86_EXTENSIONS_DEFINES "\
  25. ${flagPrefixSymbol}DSSE41_ENABLED=1 \
  26. ${flagPrefixSymbol}DSSE42_ENABLED=1 \
  27. ${flagPrefixSymbol}DPOPCNT_ENABLED=1 \
  28. ")
  29. if (NOT ANDROID)
  30. # older clang versions did not support this feature on Android:
  31. # https://reviews.llvm.org/rGc32d307a49f5255602e7543e64e6c38a7f536abc
  32. string(APPEND _ALL_X86_EXTENSIONS_DEFINES " ${flagPrefixSymbol}DCX16_ENABLED=1")
  33. endif()
  34. endif()
  35. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_ALL_X86_EXTENSIONS_DEFINES}")
  36. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_ALL_X86_EXTENSIONS_DEFINES}")
  37. endif()
  38. message(VERBOSE "CMAKE_C_FLAGS = \"${CMAKE_C_FLAGS}\"")
  39. message(VERBOSE "CMAKE_CXX_FLAGS = \"${CMAKE_CXX_FLAGS}\"")
  40. if (NOT CMAKE_CROSSCOMPILING)
  41. set(TOOLS_ROOT ${PROJECT_BINARY_DIR})
  42. elseif(NOT TOOLS_ROOT)
  43. message(FATAL_ERROR "TOOLS_ROOT is required for crosscompilation")
  44. endif()