include(CheckSymbolExists)
check_symbol_exists(le16toh endian.h LE16TOH)
check_symbol_exists(le32toh endian.h LE32TOH)
check_symbol_exists(le64toh endian.h LE64TOH)
check_symbol_exists(htole16 endian.h HTOLE16)
check_symbol_exists(htole32 endian.h HTOLE32)
check_symbol_exists(htole64 endian.h HTOLE64)
check_symbol_exists(be16toh endian.h BE16TOH)
check_symbol_exists(be32toh endian.h BE32TOH)
check_symbol_exists(be64toh endian.h BE64TOH)
check_symbol_exists(htobe16 endian.h HTOBE16)
check_symbol_exists(htobe32 endian.h HTOBE32)
check_symbol_exists(htobe64 endian.h HTOBE64)
if (LE16TOH AND LE32TOH AND LE64TOH AND HTOLE16 AND HTOLE32 AND HTOLE64 AND BE16TOH AND BE32TOH AND BE64TOH AND HTOBE16 AND HTOBE32 AND HTOBE64)
    add_compile_definitions(HAVE_ENDIAN_H)
elseif(LE16TOH AND LE32TOH AND LE64TOH AND HTOLE16 AND HTOLE32 AND HTOLE64 AND BE16TOH AND BE32TOH AND BE64TOH AND HTOBE16 AND HTOBE32 AND HTOBE64)
    check_symbol_exists(le16toh sys/endian.h LE16TOHSYS)
    check_symbol_exists(le32toh sys/endian.h LE32TOHSYS)
    check_symbol_exists(le64toh sys/endian.h LE64TOHSYS)
    check_symbol_exists(htole16 sys/endian.h HTOLE16SYS)
    check_symbol_exists(htole32 sys/endian.h HTOLE32SYS)
    check_symbol_exists(htole64 sys/endian.h HTOLE64SYS)
    check_symbol_exists(be16toh sys/endian.h BE16TOHSYS)
    check_symbol_exists(be32toh sys/endian.h BE32TOHSYS)
    check_symbol_exists(be64toh sys/endian.h BE64TOHSYS)
    check_symbol_exists(htobe16 sys/endian.h HTOBE16SYS)
    check_symbol_exists(htobe32 sys/endian.h HTOBE32SYS)
    check_symbol_exists(htobe64 sys/endian.h HTOBE64SYS)
    if(LE16TOHSYS AND LE32TOHSYS AND LE64TOHSYS AND HTOLE16SYS AND HTOLE32SYS AND HTOLE64SYS AND BE16TOHSYS AND BE32TOHSYS AND BE64TOHSYS AND HTOBE16SYS AND HTOBE32SYS AND HTOBE64SYS)
        add_compile_definitions(HAVE_SYS_ENDIAN_H)
    endif(LE16TOHSYS AND LE32TOHSYS AND LE64TOHSYS AND HTOLE16SYS AND HTOLE32SYS AND HTOLE64SYS AND BE16TOHSYS AND BE32TOHSYS AND BE64TOHSYS AND HTOBE16SYS AND HTOBE32SYS AND HTOBE64SYS)
endif(LE16TOH AND LE32TOH AND LE64TOH AND HTOLE16 AND HTOLE32 AND HTOLE64 AND BE16TOH AND BE32TOH AND BE64TOH AND HTOBE16 AND HTOBE32 AND HTOBE64)