Add support for FreeBSD
authorAustin Shafer <ashafer@nvidia.com>
Tue, 23 Jun 2020 20:45:28 +0000 (16:45 -0400)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Thu, 27 Aug 2020 13:04:54 +0000 (09:04 -0400)
The FreeBSD build is similar to the generic Unix build, with
a couple differences in the available functions.

FreeBSD needs certain flags defined for all the correct symbol
declarations to be visible (__BSD_VISIBLE, __XOPEN_SOURCE=600)

To keep the diff small, a new DE_OS_* macro for FreeBSD was not
made, since FreeBSD only differs from DE_OS_UNIX in a few places.
Where it differs the __FreeBSD__ macro is used, since there is
no good way to tell unices apart with the DE_OS_* macros.

Change-Id: I58fe857c898e9735762ffddb1fdd8e893460322f

framework/delibs/debase/deDefs.c
framework/delibs/debase/deMemory.c
framework/delibs/dethread/CMakeLists.txt
framework/delibs/dethread/unix/deThreadUnix.c
framework/qphelper/CMakeLists.txt
targets/default/default.cmake

index 18cf1bf..09c1348 100644 (file)
@@ -52,7 +52,7 @@ DE_STATIC_ASSERT(DE_PTR_SIZE          == sizeof(void*));
 #include <assert.h>
 #include <string.h>
 
-#if (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_IOS)
+#if (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_IOS) || defined(__FreeBSD__)
 #      include <signal.h>
 #      include <stdlib.h>
 #endif
@@ -122,16 +122,16 @@ void deAssertFail (const char* reason, const char* file, int line)
        }
 #elif ((DE_OS == DE_OS_WIN32) && (DE_COMPILER == DE_COMPILER_CLANG))
        _assert(reason, file, line);
+#elif (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_IOS) || defined(__FreeBSD__)
+       fprintf(stderr, "Assertion '%s' failed at %s:%d\n", reason, file, line);
+       raise(SIGTRAP);
+       abort();
 #elif (DE_OS == DE_OS_UNIX)
        __assert_fail(reason, file, (unsigned int)line, "Unknown function");
 #elif (DE_OS == DE_OS_QNX)
     __assert(reason, file, (unsigned int)line, "Unknown function");
 #elif (DE_OS == DE_OS_SYMBIAN)
        __assert("Unknown function", file, line, reason);
-#elif (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_IOS)
-       fprintf(stderr, "Assertion '%s' failed at %s:%d\n", reason, file, line);
-       raise(SIGTRAP);
-       abort();
 #elif (DE_OS == DE_OS_ANDROID)
        __android_log_print(ANDROID_LOG_ERROR, "delibs", "Assertion '%s' failed at %s:%d", reason, file, line);
        __assert(file, line, reason);
index 90795a0..05b89c1 100644 (file)
 
 #if (DE_OS == DE_OS_UNIX) || ((DE_OS == DE_OS_ANDROID) && (DE_ANDROID_API >= 21))
 #      define DE_ALIGNED_MALLOC DE_ALIGNED_MALLOC_POSIX
-#      include <malloc.h>
+#       if defined(__FreeBSD__)
+#              include <stdlib.h>
+#       else
+#              include <malloc.h>
+#       endif
 #elif (DE_OS == DE_OS_WIN32)
 #      define DE_ALIGNED_MALLOC DE_ALIGNED_MALLOC_WIN32
 #      include <malloc.h>
index 227bb71..6c14556 100644 (file)
@@ -38,7 +38,12 @@ include_directories(
        )
 
 if (DE_OS_IS_UNIX)
+       if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
+               add_definitions(-D__BSD_VISIBLE)
+               add_definitions(-D_XOPEN_SOURCE=600)
+       endif ()
        add_definitions(-D_GNU_SOURCE)
+
        set(DETHREAD_LIBS ${DETHREAD_LIBS} pthread)
 endif ()
 
index 2837291..4dd94fa 100644 (file)
@@ -164,6 +164,7 @@ void deYield (void)
 
 deUint32 deGetNumAvailableLogicalCores (void)
 {
+#if !defined(__FreeBSD__)
        unsigned long           mask            = 0;
        const unsigned int      maskSize        = sizeof(mask);
        long                            ret;
@@ -178,6 +179,7 @@ deUint32 deGetNumAvailableLogicalCores (void)
        }
        else
        {
+#endif
 #if defined(_SC_NPROCESSORS_ONLN)
                const long count = sysconf(_SC_NPROCESSORS_ONLN);
 
@@ -188,7 +190,10 @@ deUint32 deGetNumAvailableLogicalCores (void)
 #else
                return 1;
 #endif
+
+#if !defined(__FreeBSD__)
        }
+#endif
 }
 
 #else
index b3847b9..65eddb5 100644 (file)
@@ -37,6 +37,11 @@ endif ()
 add_library(qphelper STATIC ${QPHELPER_SRCS})
 target_link_libraries(qphelper ${QPHELPER_LIBS})
 
+# freebsd needs libexecinfo for backtrace symbols
+if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
+       target_link_libraries(qphelper execinfo)
+endif ()
+
 # Should qpInfo.c attempt to include qpReleaseInfo.inl
 set(USE_RELEASE_INFO_FILE OFF)
 
index 3685cf6..d6e3e4d 100644 (file)
@@ -23,6 +23,10 @@ message("*** Default target")
 
 set(DEQP_TARGET_NAME   "Default")
 
+if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
+link_directories(/usr/local/lib)
+endif ()
+
 # For static linking
 find_library(GLES2_LIBRARY             NAMES libGLESv2 GLESv2)
 find_library(EGL_LIBRARY               NAMES libEGL EGL)