TestBigEndian.cmake 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # - Define macro to determine endian type
  2. # Check if the system is big endian or little endian
  3. # TEST_BIG_ENDIAN(VARIABLE)
  4. # VARIABLE - variable to store the result to
  5. #
  6. MACRO(TEST_BIG_ENDIAN VARIABLE)
  7. SET(CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS 1)
  8. IF(NOT DEFINED ${VARIABLE})
  9. IF("HAVE_${VARIABLE}" MATCHES "^HAVE_${VARIABLE}$")
  10. TRY_RUN(${VARIABLE} HAVE_${VARIABLE}
  11. ${CMAKE_BINARY_DIR}
  12. ${CMAKE_ROOT}/Modules/TestBigEndian.c
  13. OUTPUT_VARIABLE OUTPUT)
  14. IF("${VARIABLE}" STREQUAL "FAILED_TO_RUN")
  15. MESSAGE(SEND_ERROR "TestBigEndian Failed to run with output: ${OUTPUT}")
  16. ENDIF("${VARIABLE}" STREQUAL "FAILED_TO_RUN")
  17. MESSAGE(STATUS "Check if the system is big endian")
  18. IF(HAVE_${VARIABLE})
  19. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  20. "Determining the endianes of the system passed. The system is ")
  21. IF(${VARIABLE})
  22. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  23. "big endian")
  24. MESSAGE(STATUS "Check if the system is big endian - big endian")
  25. ELSE(${VARIABLE})
  26. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  27. "little endian")
  28. MESSAGE(STATUS "Check if the system is big endian - little endian")
  29. ENDIF(${VARIABLE})
  30. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  31. "Test produced following output:\n${OUTPUT}\n\n")
  32. ELSE(HAVE_${VARIABLE})
  33. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  34. "Determining the endianes of the system failed with the following output:\n${OUTPUT}\n\n")
  35. MESSAGE("Check if the system is big endian - failed")
  36. ENDIF(HAVE_${VARIABLE})
  37. ENDIF("HAVE_${VARIABLE}" MATCHES "^HAVE_${VARIABLE}$")
  38. ENDIF(NOT DEFINED ${VARIABLE})
  39. SET(CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS)
  40. ENDMACRO(TEST_BIG_ENDIAN)