]> git.openstreetmap.org Git - nominatim.git/commitdiff
clean up byte order detection
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 16 Mar 2018 22:02:07 +0000 (23:02 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 16 Mar 2018 22:09:40 +0000 (23:09 +0100)
Check for existence of the expected functions and macros
and error out if nothing appropriate can be found.

nominatim/CMakeLists.txt
nominatim/postgresql.h

index 726ec4cc3007a1d8918bf2994b505e285eb9bcae..b391a342d752ca061c46e606a96809c70996a2f4 100644 (file)
@@ -1,12 +1,12 @@
 add_executable(nominatim export.c geometry.cpp import.c index.c input.c nominatim.c postgresql.c sprompt.c)
-include(CheckIncludeFile)
-CHECK_INCLUDE_FILE(byteswap.h HAVE_BYTESWAP_H)
-CHECK_INCLUDE_FILE(sys/endian.h HAVE_SYS_ENDIAN_H)
-if(HAVE_BYTESWAP_H)
-  target_compile_definitions(nominatim PRIVATE HAVE_BYTESWAP_H)
-endif(HAVE_BYTESWAP_H)
-if(HAVE_SYS_ENDIAN_H)
-  target_compile_definitions(nominatim PRIVATE HAVE_SYS_ENDIAN_H)
-endif(HAVE_SYS_ENDIAN_H)
+
+CHECK_SYMBOL_EXISTS(bswap_32 "byteswap.h" HAVE_BYTESWAP)
+CHECK_SYMBOL_EXISTS(bswap32 "sys/endian.h" HAVE_SYS_ENDIAN)
+
+target_compile_definitions(nominatim
+    PRIVATE HAVE_BYTESWAP=$<BOOL:${HAVE_BYTESWAP}>
+    PRIVATE HAVE_SYS_ENDIAN=$<BOOL:${HAVE_SYS_ENDIAN}>
+)
+
 target_link_libraries(nominatim ${LIBXML2_LIBRARIES} ${ZLIB_LIBRARIES} ${BZIP2_LIBRARIES} ${PostgreSQL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
 
index 7050fca4ed7302399097b4bbf262b32b38a2e5ec..f30e7308113b09cd85b5d9752849f829c687749e 100644 (file)
@@ -7,20 +7,32 @@
 #define PG_OID_INT8                    20
 #define PG_OID_INT4                    23
 
-#if defined(HAVE_BYTESWAP_H)
+#if HAVE_BYTESWAP
 #include <byteswap.h>
-#elif defined(HAVE_SYS_ENDIAN_H)
+#define PG_BSWAP32(x) bswap_32(x)
+#define PG_BSWAP64(x) bswap_64(x)
+#elif HAVE_SYS_ENDIAN
 #include <sys/endian.h>
+#define PG_BSWAP32(x) bswap32(x)
+#define PG_BSWAP64(x) bswap64(x)
+#else
+#error "No appropriate byteswap found for your system."
 #endif
 
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define PGint16(x)     (x)
+#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define PGint32(x)     (x)
+#define PGint64(x)     (x)
+#elif defined(__BYTE_ORDER__) &&  (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#define PGint32(x)     PG_BSWAP32(x)
+#define PGint64(x)     PG_BSWAP64(x)
+#elif defined(_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN)
 #define PGint32(x)     (x)
 #define PGint64(x)     (x)
+#elif defined(_BYTE_ORDER) &&  (_BYTE_ORDER == _LITTLE_ENDIAN)
+#define PGint32(x)     PG_BSWAP32(x)
+#define PGint64(x)     PG_BSWAP64(x)
 #else
-#define PGint16(x)     __bswap_16 (x)
-#define PGint32(x)     __bswap_32 (x)
-#define PGint64(x)     __bswap_64 (x)
+#error "Cannot determine byte order."
 #endif
 
 const char *build_conninfo(const char *db, const char *username, const char *password, const char *host, const char *port);