godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.98k stars 20.18k forks source link

[FreeBSD] Error compiling module basis_universal #55138

Closed robfram closed 2 years ago

robfram commented 2 years ago

Godot version

4.0.dev (c6d2768a19)

System information

FreeBSD 13.0-RELEASE-p4, clang version 13.0.0

Issue description

Compile error on FreeBSD when basis_universal module is enabled due to wrong #include directive.

[ 40%] clang++ -o thirdparty/basis_universal/encoder/basisu_enc.linuxbsd.tools.64.llvm.o -c -std=gnu++17 -w -g3 -pipe -pthread -Wall -Wno-ordered-compare-function-pointers -Werror=return-type -w -isystem thirdparty/basis_universal -DDEBUG_ENABLED -DDEV_ENABLED -D_THREAD_SAFE -DTOUCH_ENABLED -DALSA_ENABLED -DALSAMIDI_ENABLED -DPULSEAUDIO_ENABLED -D_REENTRANT -DDBUS_ENABLED -DX11_ENABLED -DUNIX_ENABLED -D_FILE_OFFSET_BITS=64 -DVULKAN_ENABLED -DGLES3_ENABLED -DTOOLS_ENABLED -DMINIZIP_ENABLED -DZSTD_STATIC_LINKING_ONLY -DUSE_VOLK -DVK_USE_PLATFORM_XLIB_KHR -DGLAD_ENABLED -DGLES_OVER_GL -DBASISU_DEVEL_MESSAGES=1 -DBASISD_ENABLE_DEBUG_FLAGS=1 -DBASISU_NO_IMG_LOADERS -Ithirdparty/libpng -Ithirdparty/glad -Ithirdparty/volk -Ithirdparty/vulkan -Ithirdparty/vulkan/include -Ithirdparty/zstd -Ithirdparty/zlib -Iplatform/linuxbsd -I. -I/usr/local/include -I/usr/local/include/dbus-1.0 -I/usr/local/lib/dbus-1.0/include thirdparty/basis_universal/encoder/basisu_enc.cpp
[ 43%] thirdparty/basis_universal/encoder/basisu_enc.cpp:215:3: error: use of undeclared identifier 'gettimeofday'
                gettimeofday(&cur_time, NULL);
                ^
[ 43%] 1 error generated.
[ 80%] scons: *** [thirdparty/basis_universal/encoder/basisu_enc.linuxbsd.tools.64.llvm.o] Error 1
scons: building terminated because of errors.

FreeBSD defines gettimeofday in <sys/time.h> (same as MacOS, as this is based on BSD), but the precompiler if-else ends up using the Linux block as __GNUC__ is also defined.

define

$ cpp -dM /dev/null  | grep -i -E '_(gnu|apple|win32|freebsd)'
#define __FreeBSD__ 13
#define __FreeBSD_cc_version 1300007
#define __GNUC_MINOR__ 2
#define __GNUC_PATCHLEVEL__ 1
#define __GNUC_STDC_INLINE__ 1
#define __GNUC__ 4

man page

GETTIMEOFDAY(2)           FreeBSD System Calls Manual          GETTIMEOFDAY(2)

NAME
     gettimeofday, settimeofday – get/set date and time

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <sys/time.h>

     int
     gettimeofday(struct timeval *tp, struct timezone *tzp);

thirdparty/basis_universal/encoder/basisu_enc.cpp:198

#elif defined(__APPLE__)
#include <sys/time.h>
        inline void query_counter(timer_ticks* pTicks)
[...]
#elif defined(__GNUC__)
#include <sys/timex.h>
        inline void query_counter(timer_ticks* pTicks)
[...]

Steps to reproduce

scons verbose=yes platform=linuxbsd use_llvm=yes use_lld=yes builtin_icu=no module_text_server_adv_enabled=no module_text_server_fb_enabled=yes module_basis_universal_enabled=yes

Minimal reproduction project

No response

akien-mga commented 2 years ago

Fixed by #59503.