🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.5 KiB

  1. include(CheckCSourceCompiles)
  2. include(CMakePushCheckState)
  3. function(_internal_check_cpu_architecture macro_check NAME VARIABLE)
  4. cmake_push_check_state(RESET)
  5. string(TOUPPER "${NAME}" UPPER_NAME)
  6. set(CACHE_VARIABLE "CHECK_CPU_ARCHITECTURE_${UPPER_NAME}")
  7. set(test_src "
  8. int main(int argc, char *argv[]) {
  9. #if ${macro_check}
  10. return 0;
  11. #else
  12. choke
  13. #endif
  14. }
  15. ")
  16. check_c_source_compiles("${test_src}" "${CACHE_VARIABLE}")
  17. cmake_pop_check_state()
  18. if(${CACHE_VARIABLE})
  19. set(${VARIABLE} "TRUE" PARENT_SCOPE)
  20. else()
  21. set(${VARIABLE} "FALSE" PARENT_SCOPE)
  22. endif()
  23. endfunction()
  24. function(check_cpu_architecture ARCH VARIABLE)
  25. if(ARCH STREQUAL "x86")
  26. _internal_check_cpu_architecture("defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) ||defined( __i386) || defined(_M_IX86)" x86 ${VARIABLE})
  27. elseif(ARCH STREQUAL "x64")
  28. _internal_check_cpu_architecture("defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)" x64 ${VARIABLE})
  29. elseif(ARCH STREQUAL "arm32")
  30. _internal_check_cpu_architecture("defined(__arm__) || defined(_M_ARM)" arm32 ${VARIABLE})
  31. elseif(ARCH STREQUAL "arm64")
  32. _internal_check_cpu_architecture("defined(__aarch64__) || defined(_M_ARM64)" arm64 ${VARIABLE})
  33. else()
  34. message(WARNING "Unknown CPU architectures (${ARCH}).")
  35. set(${VARIABLE} FALSE)
  36. endif()
  37. set("${VARIABLE}" "${${VARIABLE}}" PARENT_SCOPE)
  38. endfunction()