summaryrefslogtreecommitdiff
path: root/media-gfx/blender/files/blender-3.2.2-support-building-with-musl-libc.patch
blob: fb3f2584f0fe4102e638edab50dc15b1df08b3cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
CMake: support building with musl libc

Instead of using macros like GLIBC we can use the CMake build
systems internal functions to check if some header or functions are
present on the running system's libc.

Add ./build_files/cmake/have_features.cmake to add checks for
platform features which can be used to set defines for source
files that require them.

Please refer: https://github.com/blender/blender/commit/f197b1a1f1bbc0334310fb1c911327246767a1a3
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -112,6 +112,11 @@ blender_project_hack_post()

 enable_testing()

+#-----------------------------------------------------------------------------
+# Test compiler/library features.
+
+include(build_files/cmake/have_features.cmake)
+
 #-----------------------------------------------------------------------------
 # Redirect output files

--- /dev/null
+++ b/build_files/cmake/have_features.cmake
@@ -0,0 +1,33 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright 2022 Blender Foundation. All rights reserved.
+
+# This file is used to test the system for headers & symbols.
+# Variables should use the `HAVE_` prefix.
+# Defines should use the same name as the CMAKE variable.
+
+include(CheckSymbolExists)
+
+# Used for: `intern/guardedalloc/intern/mallocn_intern.h`.
+# Function `malloc_stats` is only available on GLIBC,
+# so check that before defining `HAVE_MALLOC_STATS`.
+check_symbol_exists(malloc_stats "malloc.h" HAVE_MALLOC_STATS_H)
+
+# Used for: `source/creator/creator_signals.c`.
+# The function `feenableexcept` is not present non-GLIBC systems,
+# hence we need to check if it's available in the `fenv.h` file.
+set(HAVE_FEENABLEEXCEPT OFF)
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+  check_symbol_exists(feenableexcept "fenv.h" HAVE_FEENABLEEXCEPT)
+endif()
+
+# Used for: `source/blender/blenlib/intern/system.c`.
+# `execinfo` is not available on non-GLIBC systems (at least not on MUSL-LIBC),
+# so check the presence of the header before including it and  using the it for back-trace.
+set(HAVE_EXECINFO_H OFF)
+if(NOT MSVC)
+  include(CheckIncludeFiles)
+  check_include_files("execinfo.h" HAVE_EXECINFO_H)
+  if(HAVE_EXECINFO_H)
+    add_definitions(-DHAVE_EXECINFO_H)
+  endif()
+endif()
--- a/intern/guardedalloc/CMakeLists.txt
+++ b/intern/guardedalloc/CMakeLists.txt
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright 2006 Blender Foundation. All rights reserved.

+if(HAVE_MALLOC_STATS_H)
+  add_definitions(-DHAVE_MALLOC_STATS_H)
+endif()
+
 set(INC
   .
   ../atomic
--- a/intern/guardedalloc/intern/mallocn_intern.h
+++ b/intern/guardedalloc/intern/mallocn_intern.h
@@ -17,8 +17,7 @@
 #undef HAVE_MALLOC_STATS
 #define USE_MALLOC_USABLE_SIZE /* internal, when we have malloc_usable_size() */

-#if defined(__linux__) || (defined(__FreeBSD_kernel__) && !defined(__FreeBSD__)) || \
-    defined(__GLIBC__)
+#if defined(HAVE_MALLOC_STATS_H)
 #  include <malloc.h>
 #  define HAVE_MALLOC_STATS
 #elif defined(__FreeBSD__)
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright 2006 Blender Foundation. All rights reserved.

+if(HAVE_EXECINFO_H)
+  add_definitions(-DHAVE_EXECINFO_H)
+endif()
+
 set(INC
   .
   # ../blenkernel  # don't add this back!
--- a/source/blender/blenlib/intern/system.c
+++ b/source/blender/blenlib/intern/system.c
@@ -21,7 +21,9 @@

 #  include "BLI_winstuff.h"
 #else
-#  include <execinfo.h>
+#  if defined(HAVE_EXECINFO_H)
+#    include <execinfo.h>
+#  endif
 #  include <unistd.h>
 #endif

@@ -61,9 +63,9 @@ int BLI_cpu_support_sse2(void)
 #if !defined(_MSC_VER)
 void BLI_system_backtrace(FILE *fp)
 {
-  /* ------------- */
-  /* Linux / Apple */
-#  if defined(__linux__) || defined(__APPLE__)
+  /* ----------------------- */
+  /* If system as execinfo.h */
+#  if defined(HAVE_EXECINFO_H)

 #    define SIZE 100
   void *buffer[SIZE];
--- a/source/blender/makesdna/intern/CMakeLists.txt
+++ b/source/blender/makesdna/intern/CMakeLists.txt
@@ -5,6 +5,11 @@

 add_definitions(-DWITH_DNA_GHASH)

+# Needed for `mallocn.c`.
+if(HAVE_MALLOC_STATS_H)
+  add_definitions(-DHAVE_MALLOC_STATS_H)
+endif()
+
 blender_include_dirs(
   ../../../../intern/atomic
   ../../../../intern/guardedalloc
--- a/source/blender/makesrna/intern/CMakeLists.txt
+++ b/source/blender/makesrna/intern/CMakeLists.txt
@@ -6,6 +6,11 @@ if(CMAKE_COMPILER_IS_GNUCC)
   string(APPEND CMAKE_C_FLAGS " -Werror=implicit-function-declaration")
 endif()

+# Needed for `mallocn.c`.
+if(HAVE_MALLOC_STATS_H)
+  add_definitions(-DHAVE_MALLOC_STATS_H)
+endif()
+
 # files rna_access.c rna_define.c makesrna.c intentionally excluded.
 set(DEFSRC
   rna_ID.c
--- a/source/creator/CMakeLists.txt
+++ b/source/creator/CMakeLists.txt
@@ -22,6 +22,10 @@ set(LIB
   bf_windowmanager
 )

+if(HAVE_FEENABLEEXCEPT)
+  add_definitions(-DHAVE_FEENABLEEXCEPT)
+endif()
+
 if(WITH_TBB)
   # Force TBB libraries to be in front of MKL (part of OpenImageDenoise), so
   # that it is initialized before MKL and static library initialization order
--- a/source/creator/creator_signals.c
+++ b/source/creator/creator_signals.c
@@ -258,7 +258,7 @@ void main_signal_setup_fpe(void)
    * set breakpoints on sig_handle_fpe */
   signal(SIGFPE, sig_handle_fpe);

-#    if defined(__linux__) && defined(__GNUC__)
+#    if defined(__linux__) && defined(__GNUC__) && defined(HAVE_FEENABLEEXCEPT)
   feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
 #    endif /* defined(__linux__) && defined(__GNUC__) */
 #    if defined(OSX_SSE_FPE)