TestBigEndian — CMake 4.4.3 Documentation

# TestBigEndian

Deprecated since version 3.20: Superseded by the `CMAKE_<LANG>_BYTE_ORDER` variable.

This module provides a command to check the endianness (byte order) of the target architecture.

Load this module in a CMake project with:

    include(TestBigEndian)

## Commands

This module provides the following command:

test_big_endian

  Checks if the target architecture is big-endian or little-endian:

      test_big_endian(<var>)

  This command stores in variable `<var>` either 1 or 0 indicating whether the target architecture is big or little endian.

  At least one of the supported languages must be enabled in CMake project when using this command.

  Supported languages are `C`, `CXX`.

  Changed in version 3.20: This command is now mainly a wrapper around the `CMAKE_<LANG>_BYTE_ORDER` where also `OBJC`, `OBJCXX`, and `CUDA` languages are supported.

## Examples

### Example: Checking Endianness

Checking endianness of the target architecture with this module and storing the result in a CMake variable `WORDS_BIGENDIAN`:

    include(TestBigEndian)
    test_big_endian(WORDS_BIGENDIAN)

### Example: Checking Endianness in New Code

As of CMake 3.20, this module should be replaced with the `CMAKE_<LANG>_BYTE_ORDER` variable. For example, in a project, where `C` language is one of the enabled languages:

    if(CMAKE_C_BYTE_ORDER STREQUAL "BIG_ENDIAN")
      set(WORDS_BIGENDIAN TRUE)
    elseif(CMAKE_C_BYTE_ORDER STREQUAL "LITTLE_ENDIAN")
      set(WORDS_BIGENDIAN FALSE)
    else()
      set(WORDS_BIGENDIAN FALSE)
      message(WARNING "Endianness could not be determined.")
    endif()