Cleanup: remove compilation warning in previous commit.
[blender-staging.git] / CMakeLists.txt
1 # ***** BEGIN GPL LICENSE BLOCK *****
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # The Original Code is Copyright (C) 2006, Blender Foundation
18 # All rights reserved.
19 #
20 # ***** END GPL LICENSE BLOCK *****
21
22 #-----------------------------------------------------------------------------
23 # We don't allow in-source builds. This causes no end of troubles because
24 # all out-of-source builds will use the CMakeCache.txt file there and even
25 # build the libs and objects in it.
26
27 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
28   if(NOT DEFINED WITH_IN_SOURCE_BUILD)
29     message(FATAL_ERROR
30       "CMake generation for blender is not allowed within the source directory!"
31       "\n Remove \"${CMAKE_SOURCE_DIR}/CMakeCache.txt\" and try again from another folder, e.g.:"
32       "\n "
33       "\n rm CMakeCache.txt"
34       "\n cd .."
35       "\n mkdir cmake-make"
36       "\n cd cmake-make"
37       "\n cmake ../blender"
38       "\n "
39       "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
40     )
41   endif()
42 endif()
43
44 cmake_minimum_required(VERSION 3.10)
45
46 # Prefer LEGACY OpenGL to be compatible with all the existing releases and
47 # platforms which don't have GLVND yet. Only do it if preference was not set
48 # externally.
49 if(NOT DEFINED OpenGL_GL_PREFERENCE)
50   set(OpenGL_GL_PREFERENCE "LEGACY")
51 endif()
52
53 if(NOT EXECUTABLE_OUTPUT_PATH)
54   set(FIRST_RUN TRUE)
55 else()
56   set(FIRST_RUN FALSE)
57 endif()
58
59 # this starts out unset
60 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
61 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/platform")
62
63 # avoid having empty buildtype
64 if(NOT DEFINED CMAKE_BUILD_TYPE_INIT)
65   set(CMAKE_BUILD_TYPE_INIT "Release")
66   # Internal logic caches this variable, avoid showing it by default
67   # since it's easy to accidentally set instead of the build type.
68   mark_as_advanced(CMAKE_BUILD_TYPE_INIT)
69 endif()
70
71 # Omit superfluous "Up-to-date" messages.
72 if(NOT DEFINED CMAKE_INSTALL_MESSAGE)
73   set(CMAKE_INSTALL_MESSAGE "LAZY")
74 endif()
75
76 # quiet output for Makefiles, 'make -s' helps too
77 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
78
79 # global compile definitions since add_definitions() adds for all.
80 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
81   $<$<CONFIG:Debug>:DEBUG;_DEBUG>
82   $<$<CONFIG:Release>:NDEBUG>
83   $<$<CONFIG:MinSizeRel>:NDEBUG>
84   $<$<CONFIG:RelWithDebInfo>:NDEBUG>
85 )
86
87 #-----------------------------------------------------------------------------
88 # Set policy
89
90 # see "cmake --help-policy CMP0003"
91 # So library linking is more sane
92 cmake_policy(SET CMP0003 NEW)
93
94 # So BUILDINFO and BLENDERPATH strings are automatically quoted
95 cmake_policy(SET CMP0005 NEW)
96
97 # So syntax problems are errors
98 cmake_policy(SET CMP0010 NEW)
99
100 # Input directories must have CMakeLists.txt
101 cmake_policy(SET CMP0014 NEW)
102
103 # Silence draco warning on macOS, new policy works fine.
104 if(POLICY CMP0068)
105   cmake_policy(SET CMP0068 NEW)
106 endif()
107
108 # find_package() uses <PackageName>_ROOT variables.
109 if(POLICY CMP0074)
110   cmake_policy(SET CMP0074 NEW)
111 endif()
112
113 #-----------------------------------------------------------------------------
114 # Load some macros.
115 include(build_files/cmake/macros.cmake)
116
117
118 #-----------------------------------------------------------------------------
119 # Initialize project.
120
121 blender_project_hack_pre()
122
123 project(Blender)
124
125 blender_project_hack_post()
126
127 enable_testing()
128
129 #-----------------------------------------------------------------------------
130 # Redirect output files
131
132 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE)
133 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE)
134
135 get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
136 if(GENERATOR_IS_MULTI_CONFIG)
137   set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests/$<CONFIG>/ CACHE INTERNAL "" FORCE)
138 else()
139   set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests/ CACHE INTERNAL "" FORCE)
140 endif()
141
142 #-----------------------------------------------------------------------------
143 # Set default config options
144
145 get_blender_version()
146
147
148 #-----------------------------------------------------------------------------
149 # Options
150
151 # Blender internal features
152 option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
153 mark_as_advanced(WITH_BLENDER)
154
155 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
156
157 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
158 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default" ON)
159 mark_as_advanced(WITH_PYTHON)  # don't want people disabling this unless they really know what they are doing.
160 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distributions see this as a security issue, rather than have them patch it, make a build option.
161
162 option(WITH_PYTHON_SAFETY "Enable internal API error checking to track invalid data to prevent crash on access (at the expense of some efficiency, only enable for development)." OFF)
163 mark_as_advanced(WITH_PYTHON_SAFETY)
164 option(WITH_PYTHON_MODULE "Enable building as a python module which runs without a user interface, like running regular blender in background mode (experimental, only enable for development), installs to PYTHON_SITE_PACKAGES (or CMAKE_INSTALL_PREFIX if WITH_INSTALL_PORTABLE is enabled)." OFF)
165 if(APPLE)
166   option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
167 endif()
168
169 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ON)
170 set(BUILDINFO_OVERRIDE_DATE "" CACHE STRING "Use instead of the current date for reproducible builds (empty string disables this option)")
171 set(BUILDINFO_OVERRIDE_TIME "" CACHE STRING "Use instead of the current time for reproducible builds (empty string disables this option)")
172 set(CPACK_OVERRIDE_PACKAGENAME "" CACHE STRING "Use instead of the standard packagename (empty string disables this option)")
173 mark_as_advanced(CPACK_OVERRIDE_PACKAGENAME)
174 mark_as_advanced(BUILDINFO_OVERRIDE_DATE)
175 mark_as_advanced(BUILDINFO_OVERRIDE_TIME)
176
177 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
178 option(WITH_IK_SOLVER     "Enable Legacy IK solver (only disable for development)" ON)
179 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke, ocean sim, and audio effects)" ON)
180 option(WITH_PUGIXML       "Enable PugiXML support (Used for OpenImageIO, Grease Pencil SVG export)" ON)
181 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
182 option(WITH_SYSTEM_BULLET "Use the systems bullet library (currently unsupported due to missing features in upstream!)" )
183 mark_as_advanced(WITH_SYSTEM_BULLET)
184 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ON)
185 if(APPLE)
186   # There's no OpenXR runtime in sight for macOS, neither is code well
187   # tested there -> disable it by default.
188   option(WITH_XR_OPENXR   "Enable VR features through the OpenXR specification" OFF)
189   mark_as_advanced(WITH_XR_OPENXR)
190 else()
191   option(WITH_XR_OPENXR   "Enable VR features through the OpenXR specification" ON)
192 endif()
193 option(WITH_GMP "Enable features depending on GMP (Exact Boolean)" ON)
194
195 # Compositor
196 option(WITH_COMPOSITOR         "Enable the tile based nodal compositor" ON)
197 option(WITH_OPENIMAGEDENOISE   "Enable the OpenImageDenoise compositing node" ON)
198
199 option(WITH_OPENSUBDIV    "Enable OpenSubdiv for surface subdivision" ON)
200
201 option(WITH_POTRACE       "Enable features relying on potrace" ON)
202 option(WITH_OPENVDB       "Enable features relying on OpenVDB" ON)
203 option(WITH_OPENVDB_BLOSC "Enable blosc compression for OpenVDB, only enable if OpenVDB was built with blosc support" ON)
204 option(WITH_OPENVDB_3_ABI_COMPATIBLE "Assume OpenVDB library has been compiled with version 3 ABI compatibility" OFF)
205 mark_as_advanced(WITH_OPENVDB_3_ABI_COMPATIBLE)
206 option(WITH_NANOVDB       "Enable usage of NanoVDB data structure for rendering on the GPU" ON)
207 option(WITH_HARU          "Enable features relying on Libharu (Grease pencil PDF export)" ON)
208
209 # GHOST Windowing Library Options
210 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
211 mark_as_advanced(WITH_GHOST_DEBUG)
212
213 option(WITH_GHOST_SDL    "Enable building Blender against SDL for windowing rather than the native APIs" OFF)
214 mark_as_advanced(WITH_GHOST_SDL)
215
216 if(UNIX AND NOT (APPLE OR HAIKU))
217   option(WITH_GHOST_X11 "Enable building Blender against X11 for windowing" ON)
218   mark_as_advanced(WITH_GHOST_X11)
219
220   option(WITH_GHOST_WAYLAND "Enable building Blender against Wayland for windowing (under development)" OFF)
221   mark_as_advanced(WITH_GHOST_WAYLAND)
222 endif()
223
224 if(WITH_GHOST_X11)
225   option(WITH_GHOST_XDND    "Enable drag'n'drop support on X11 using XDND protocol" ON)
226 endif()
227
228 # Misc...
229 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
230 mark_as_advanced(WITH_HEADLESS)
231
232 option(WITH_QUADRIFLOW    "Build with quadriflow remesher support" ON)
233
234 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
235 option(WITH_SYSTEM_AUDASPACE "Build with external audaspace library installed on the system (only enable if you know what you're doing!)" OFF)
236 mark_as_advanced(WITH_AUDASPACE)
237 mark_as_advanced(WITH_SYSTEM_AUDASPACE)
238
239 set_and_warn_dependency(WITH_AUDASPACE WITH_SYSTEM_AUDASPACE OFF)
240
241 option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
242 if(UNIX AND NOT APPLE)
243   option(WITH_OPENMP_STATIC "Link OpenMP statically (only used by the release environment)" OFF)
244   mark_as_advanced(WITH_OPENMP_STATIC)
245 endif()
246
247 if(WITH_GHOST_X11)
248   option(WITH_X11_XINPUT    "Enable X11 Xinput (tablet support and unicode input)"  ON)
249   option(WITH_X11_XF86VMODE "Enable X11 video mode switching"                       ON)
250   option(WITH_X11_XFIXES    "Enable X11 XWayland cursor warping workaround"         ON)
251   option(WITH_X11_ALPHA     "Enable X11 transparent background"                     ON)
252 endif()
253
254 if(UNIX AND NOT APPLE)
255   option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" OFF)
256   option(WITH_SYSTEM_GLES "Use OpenGL ES library provided by the operating system"           ON)
257 else()
258   # not an option for other OS's
259   set(WITH_SYSTEM_GLEW OFF)
260   set(WITH_SYSTEM_GLES OFF)
261 endif()
262
263
264 if(UNIX AND NOT APPLE)
265   option(WITH_SYSTEM_EIGEN3 "Use the systems Eigen3 library" OFF)
266 endif()
267
268
269 # Modifiers
270 option(WITH_MOD_FLUID           "Enable Mantaflow Fluid Simulation Framework" ON)
271 option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
272 option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" ON)
273
274 # Image format support
275 option(WITH_OPENIMAGEIO         "Enable OpenImageIO Support (http://www.openimageio.org)" ON)
276 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
277 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
278 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
279 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
280 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
281 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
282
283 # Audio/Video format support
284 option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
285 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" ON)
286 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" ON)
287
288 # Alembic support
289 option(WITH_ALEMBIC             "Enable Alembic Support" ON)
290
291 # Universal Scene Description support
292 option(WITH_USD                 "Enable Universal Scene Description (USD) Support" ON)
293
294 # 3D format support
295 # Disable opencollada when we don't have precompiled libs
296 option(WITH_OPENCOLLADA   "Enable OpenCollada Support (http://www.opencollada.org)" ON)
297
298 # Sound output
299 option(WITH_SDL           "Enable SDL for sound and joystick support" ON)
300 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
301 if(APPLE)
302   option(WITH_COREAUDIO    "Enable CoreAudio for audio support on macOS" ON)
303 else()
304   set(WITH_COREAUDIO OFF)
305 endif()
306 if(NOT WIN32)
307   option(WITH_JACK          "Enable JACK Support (http://www.jackaudio.org)" ON)
308   if(UNIX AND NOT APPLE)
309     option(WITH_JACK_DYNLOAD  "Enable runtime dynamic JACK libraries loading" OFF)
310   endif()
311 else()
312   set(WITH_JACK OFF)
313 endif()
314 if(UNIX AND NOT APPLE)
315   option(WITH_SDL_DYNLOAD  "Enable runtime dynamic SDL libraries loading" OFF)
316 endif()
317 if(UNIX AND NOT APPLE)
318   option(WITH_PULSEAUDIO   "Enable PulseAudio for audio support on Linux" ON)
319   option(WITH_PULSEAUDIO_DYNLOAD  "Enable runtime dynamic PulseAudio libraries loading" OFF)
320 else()
321   set(WITH_PULSEAUDIO OFF)
322 endif()
323 if(WIN32)
324   option(WITH_WASAPI      "Enable Windows Audio Sessions API for audio support on Windows" ON)
325 else()
326   set(WITH_WASAPI OFF)
327 endif()
328
329 # Compression
330 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
331 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
332 if(UNIX AND NOT APPLE)
333   option(WITH_SYSTEM_LZO    "Use the system LZO library" OFF)
334 endif()
335 option(WITH_DRACO         "Enable Draco mesh compression Python module (used for glTF)" ON)
336
337 # Camera/motion tracking
338 option(WITH_LIBMV         "Enable Libmv structure from motion library" ON)
339 option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." ON)
340 mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
341
342 # Logging/unbit test libraries.
343 option(WITH_SYSTEM_GFLAGS   "Use system-wide Gflags instead of a bundled one" OFF)
344 option(WITH_SYSTEM_GLOG     "Use system-wide Glog instead of a bundled one" OFF)
345 mark_as_advanced(WITH_SYSTEM_GFLAGS)
346 mark_as_advanced(WITH_SYSTEM_GLOG)
347
348 # Freestyle
349 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
350
351 # Misc
352 if(WIN32)
353   option(WITH_INPUT_IME "Enable Input Method Editor (IME) for complex Asian character input" ON)
354 endif()
355 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
356 if(UNIX AND NOT APPLE)
357   option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
358   option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
359   if(WITH_STATIC_LIBS)
360     option(WITH_BOOST_ICU "Boost uses ICU library (required for linking with static Boost built with libicu)." OFF)
361     mark_as_advanced(WITH_BOOST_ICU)
362   endif()
363 endif()
364
365 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
366
367 if((WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE) OR WITH_MOD_FLUID)
368   option(WITH_PYTHON_NUMPY "Include NumPy in Blender (used by Audaspace and Mantaflow)"  ON)
369 endif()
370
371 if(WIN32 OR APPLE)
372   # Windows and macOS have this bundled with Python libraries.
373 elseif(WITH_PYTHON_INSTALL OR WITH_PYTHON_NUMPY)
374   set(PYTHON_NUMPY_PATH            "" CACHE PATH "Path to python site-packages or dist-packages containing 'numpy' module")
375   mark_as_advanced(PYTHON_NUMPY_PATH)
376   set(PYTHON_NUMPY_INCLUDE_DIRS    "" CACHE PATH "Path to the include directory of the NumPy module")
377   mark_as_advanced(PYTHON_NUMPY_INCLUDE_DIRS)
378 endif()
379 if(WITH_PYTHON_INSTALL)
380   option(WITH_PYTHON_INSTALL_NUMPY "Copy system NumPy into the blender install folder"  ON)
381
382   if(UNIX AND NOT APPLE)
383     option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
384     set(PYTHON_REQUESTS_PATH "" CACHE PATH "Path to python site-packages or dist-packages containing 'requests' module")
385     mark_as_advanced(PYTHON_REQUESTS_PATH)
386   endif()
387 endif()
388
389 option(WITH_CPU_SIMD              "Enable SIMD instruction if they're detected on the host machine" ON)
390 mark_as_advanced(WITH_CPU_SIMD)
391
392 # Cycles
393 option(WITH_CYCLES                  "Enable Cycles Render Engine" ON)
394 option(WITH_CYCLES_STANDALONE       "Build Cycles standalone application" OFF)
395 option(WITH_CYCLES_STANDALONE_GUI   "Build Cycles standalone with GUI" OFF)
396 option(WITH_CYCLES_OSL              "Build Cycles with OSL support" ON)
397 option(WITH_CYCLES_EMBREE           "Build Cycles with Embree support" ON)
398 option(WITH_CYCLES_CUDA_BINARIES    "Build Cycles CUDA binaries" OFF)
399 option(WITH_CYCLES_CUBIN_COMPILER   "Build cubins with nvrtc based compiler instead of nvcc" OFF)
400 option(WITH_CYCLES_CUDA_BUILD_SERIAL "Build cubins one after another (useful on machines with limited RAM)" OFF)
401 mark_as_advanced(WITH_CYCLES_CUDA_BUILD_SERIAL)
402 set(CYCLES_TEST_DEVICES CPU CACHE STRING "Run regression tests on the specified device types (CPU CUDA OPTIX OPENCL)" )
403 set(CYCLES_CUDA_BINARIES_ARCH sm_30 sm_35 sm_37 sm_50 sm_52 sm_60 sm_61 sm_70 sm_75 sm_86 compute_75 CACHE STRING "CUDA architectures to build binaries for")
404 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
405 unset(PLATFORM_DEFAULT)
406 option(WITH_CYCLES_LOGGING  "Build Cycles with logging support" ON)
407 option(WITH_CYCLES_DEBUG    "Build Cycles with extra debug capabilities" OFF)
408 option(WITH_CYCLES_NATIVE_ONLY  "Build Cycles with native kernel only (which fits current CPU, use for development only)" OFF)
409 option(WITH_CYCLES_KERNEL_ASAN  "Build Cycles kernels with address sanitizer when WITH_COMPILER_ASAN is on, even if it's very slow" OFF)
410 mark_as_advanced(WITH_CYCLES_KERNEL_ASAN)
411 mark_as_advanced(WITH_CYCLES_CUBIN_COMPILER)
412 mark_as_advanced(WITH_CYCLES_LOGGING)
413 mark_as_advanced(WITH_CYCLES_DEBUG)
414 mark_as_advanced(WITH_CYCLES_NATIVE_ONLY)
415
416 option(WITH_CYCLES_DEVICE_CUDA              "Enable Cycles CUDA compute support" ON)
417 option(WITH_CYCLES_DEVICE_OPTIX             "Enable Cycles OptiX support" OFF)
418 option(WITH_CYCLES_DEVICE_OPENCL            "Enable Cycles OpenCL compute support" ON)
419 option(WITH_CYCLES_NETWORK              "Enable Cycles compute over network support (EXPERIMENTAL and unfinished)" OFF)
420 mark_as_advanced(WITH_CYCLES_DEVICE_CUDA)
421 mark_as_advanced(WITH_CYCLES_DEVICE_OPENCL)
422 mark_as_advanced(WITH_CYCLES_NETWORK)
423
424 option(WITH_CUDA_DYNLOAD "Dynamically load CUDA libraries at runtime" ON)
425 mark_as_advanced(WITH_CUDA_DYNLOAD)
426
427 # LLVM
428 option(WITH_LLVM                    "Use LLVM" OFF)
429 if(APPLE)
430   option(LLVM_STATIC                  "Link with LLVM static libraries" ON) # we prefer static llvm build on Apple, dyn build possible though
431 else()
432   option(LLVM_STATIC                  "Link with LLVM static libraries" OFF)
433 endif()
434 mark_as_advanced(LLVM_STATIC)
435 option(WITH_CLANG                   "Use Clang" OFF)
436
437 # disable for now, but plan to support on all platforms eventually
438 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" ON)
439 mark_as_advanced(WITH_MEM_JEMALLOC)
440
441 # currently only used for BLI_mempool
442 option(WITH_MEM_VALGRIND "Enable extended valgrind support for better reporting" OFF)
443 mark_as_advanced(WITH_MEM_VALGRIND)
444
445 # Debug
446 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
447 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
448
449 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" ON)
450 mark_as_advanced(WITH_ASSERT_ABORT)
451
452 if((UNIX AND NOT APPLE) OR (CMAKE_GENERATOR MATCHES "^Visual Studio.+"))
453   option(WITH_CLANG_TIDY "Use Clang Tidy to analyze the source code (only enable for development on Linux using Clang, or Windows using the Visual Studio IDE)" OFF)
454   mark_as_advanced(WITH_CLANG_TIDY)
455 endif()
456
457 option(WITH_BOOST "Enable features depending on boost" ON)
458 option(WITH_TBB   "Enable features depending on TBB (OpenVDB, OpenImageDenoise, sculpt multithreading)" ON)
459
460 # TBB malloc is only supported on for windows currently
461 if(WIN32)
462   option(WITH_TBB_MALLOC_PROXY "Enable the TBB malloc replacement" ON)
463 endif()
464
465 # This should be turned off when Blender enter beta/rc/release
466 if("${BLENDER_VERSION_CYCLE}" STREQUAL "release" OR
467    "${BLENDER_VERSION_CYCLE}" STREQUAL "rc")
468   set(WITH_EXPERIMENTAL_FEATURES OFF)
469 else()
470   set(WITH_EXPERIMENTAL_FEATURES ON)
471 endif()
472
473 # Unit testsing
474 option(WITH_GTESTS "Enable GTest unit testing" OFF)
475 option(WITH_OPENGL_RENDER_TESTS "Enable OpenGL render related unit testing (Experimental)" OFF)
476 option(WITH_OPENGL_DRAW_TESTS "Enable OpenGL UI drawing related unit testing (Experimental)" OFF)
477 set(TEST_PYTHON_EXE "" CACHE PATH "Python executable to run unit tests")
478 mark_as_advanced(TEST_PYTHON_EXE)
479
480 # Documentation
481 if(UNIX AND NOT APPLE)
482   option(WITH_DOC_MANPAGE "Create a manual page (Unix manpage)" OFF)
483 endif()
484
485
486 # OpenGL
487
488 option(WITH_OPENGL              "When off limits visibility of the opengl headers to just bf_gpu and gawain (temporary option for development purposes)" ON)
489 option(WITH_GLEW_ES             "Switches to experimental copy of GLEW that has support for OpenGL ES. (temporary option for development purposes)" OFF)
490 option(WITH_GL_EGL              "Use the EGL OpenGL system library instead of the platform specific OpenGL system library (CGL, glX, or WGL)"       OFF)
491 option(WITH_GL_PROFILE_ES20     "Support using OpenGL ES 2.0. (through either EGL or the AGL/WGL/XGL 'es20' profile)"                               OFF)
492
493 mark_as_advanced(
494   WITH_OPENGL
495   WITH_GLEW_ES
496   WITH_GL_EGL
497   WITH_GL_PROFILE_ES20
498 )
499
500 if(WIN32)
501   option(WITH_GL_ANGLE "Link with the ANGLE library, an OpenGL ES 2.0 implementation based on Direct3D, instead of the system OpenGL library." OFF)
502   mark_as_advanced(WITH_GL_ANGLE)
503 endif()
504
505 if(WITH_GLEW_ES AND WITH_SYSTEM_GLEW)
506   message(WARNING Ignoring WITH_SYSTEM_GLEW and using WITH_GLEW_ES)
507   set(WITH_SYSTEM_GLEW OFF)
508 endif()
509
510 if(WIN32)
511   getDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
512   set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
513 endif()
514
515 # Compiler toolchain
516 if(CMAKE_COMPILER_IS_GNUCC)
517   option(WITH_LINKER_GOLD "Use ld.gold linker which is usually faster than ld.bfd" ON)
518   mark_as_advanced(WITH_LINKER_GOLD)
519   option(WITH_LINKER_LLD "Use ld.lld linker which is usually faster than ld.gold" OFF)
520   mark_as_advanced(WITH_LINKER_LLD)
521 endif()
522
523 option(WITH_COMPILER_ASAN "Build and link against address sanitizer (only for Debug & RelWithDebInfo targets)." OFF)
524 mark_as_advanced(WITH_COMPILER_ASAN)
525
526 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
527   if(WITH_COMPILER_ASAN)
528     set(_asan_defaults "\
529 -fsanitize=address \
530 -fsanitize=bool \
531 -fsanitize=bounds \
532 -fsanitize=enum \
533 -fsanitize=float-cast-overflow \
534 -fsanitize=float-divide-by-zero \
535 -fsanitize=nonnull-attribute \
536 -fsanitize=returns-nonnull-attribute \
537 -fsanitize=signed-integer-overflow \
538 -fsanitize=undefined \
539 -fsanitize=vla-bound \
540 -fno-sanitize=alignment \
541 ")
542
543     if(MSVC)
544       # clang-cl doesn't support all sanitizers, but leak and object-size give errors/warnings.
545       set(_asan_defaults "${_asan_defaults}")
546     elseif(APPLE)
547       # AppleClang doesn't support all sanitizers, but leak gives error.
548       # Build type is not known for multi-config generator, so don't add object-size sanitizer.
549       if(CMAKE_BUILD_TYPE MATCHES "Debug" OR GENERATOR_IS_MULTI_CONFIG)
550         # Silence the warning that object-size is not effective in -O0.
551         set(_asan_defaults "${_asan_defaults}")
552       else()
553         string(APPEND _asan_defaults " -fsanitize=object-size")
554       endif()
555     else()
556       string(APPEND _asan_defaults " -fsanitize=leak -fsanitize=object-size")
557     endif()
558
559     set(COMPILER_ASAN_CFLAGS "${_asan_defaults}" CACHE STRING "C flags for address sanitizer")
560     mark_as_advanced(COMPILER_ASAN_CFLAGS)
561     set(COMPILER_ASAN_CXXFLAGS "${_asan_defaults}" CACHE STRING "C++ flags for address sanitizer")
562     mark_as_advanced(COMPILER_ASAN_CXXFLAGS)
563
564     unset(_asan_defaults)
565
566     if(MSVC)
567         find_library(
568           COMPILER_ASAN_LIBRARY NAMES clang_rt.asan-x86_64
569         PATHS
570         [HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\LLVM\\LLVM;]/lib/clang/7.0.0/lib/windows
571         [HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\LLVM\\LLVM;]/lib/clang/6.0.0/lib/windows
572       )
573     elseif(APPLE)
574       execute_process(COMMAND ${CMAKE_CXX_COMPILER}
575         -print-file-name=lib
576         OUTPUT_VARIABLE CLANG_LIB_DIR
577       )
578       string(STRIP "${CLANG_LIB_DIR}" CLANG_LIB_DIR)
579       find_library(
580         COMPILER_ASAN_LIBRARY
581         NAMES
582           libclang_rt.asan_osx_dynamic.dylib
583         PATHS
584           "${CLANG_LIB_DIR}/darwin/"
585       )
586       unset(CLANG_LIB_DIR)
587     else()
588       find_library(
589         COMPILER_ASAN_LIBRARY asan ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}
590       )
591     endif()
592
593     mark_as_advanced(COMPILER_ASAN_LIBRARY)
594   endif()
595 endif()
596
597 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
598   option(WITH_COMPILER_SHORT_FILE_MACRO "Make paths in macros like __FILE__ relative to top level source and build directories." ON)
599   mark_as_advanced(WITH_COMPILER_SHORT_FILE_MACRO)
600 endif()
601
602 if(WIN32)
603   # Use hardcoded paths or find_package to find externals
604   option(WITH_WINDOWS_FIND_MODULES "Use find_package to locate libraries" OFF)
605   mark_as_advanced(WITH_WINDOWS_FIND_MODULES)
606
607   option(WINDOWS_USE_VISUAL_STUDIO_PROJECT_FOLDERS "Organize the visual studio projects according to source folder structure." ON)
608   mark_as_advanced(WINDOWS_USE_VISUAL_STUDIO_PROJECT_FOLDERS)
609
610   option(WINDOWS_USE_VISUAL_STUDIO_SOURCE_FOLDERS "Organize the source files in filters matching the source folders." ON)
611   mark_as_advanced(WINDOWS_USE_VISUAL_STUDIO_SOURCE_FOLDERS)
612
613   option(WINDOWS_PYTHON_DEBUG "Include the files needed for debugging python scripts with visual studio 2017+." OFF)
614   mark_as_advanced(WINDOWS_PYTHON_DEBUG)
615
616   option(WITH_WINDOWS_BUNDLE_CRT "Bundle the C runtime for install free distribution." ON)
617   mark_as_advanced(WITH_WINDOWS_BUNDLE_CRT)
618
619   option(WITH_WINDOWS_SCCACHE "Use sccache to speed up builds (Ninja builder only)" OFF)
620   mark_as_advanced(WITH_WINDOWS_SCCACHE)
621
622   option(WITH_WINDOWS_PDB "Generate a pdb file for client side stacktraces" ON)
623   mark_as_advanced(WITH_WINDOWS_PDB)
624
625   option(WITH_WINDOWS_STRIPPED_PDB "Use a stripped PDB file" On)
626   mark_as_advanced(WITH_WINDOWS_STRIPPED_PDB)
627
628 endif()
629
630 if(UNIX)
631   # See WITH_WINDOWS_SCCACHE for Windows.
632   option(WITH_COMPILER_CCACHE "Use ccache to improve rebuild times (Works with Ninja, Makefiles and Xcode)" OFF)
633   mark_as_advanced(WITH_COMPILER_CCACHE)
634 endif()
635
636 # The following only works with the Ninja generator in CMake >= 3.0.
637 if("${CMAKE_GENERATOR}" MATCHES "Ninja")
638   option(WITH_NINJA_POOL_JOBS
639          "Enable Ninja pools of jobs, to try to ease building on machines with 16GB of RAM or less (if not yet defined, will try to set best values based on detected machine specifications)."
640          OFF)
641   mark_as_advanced(WITH_NINJA_POOL_JOBS)
642 endif()
643
644 if(UNIX AND NOT APPLE)
645   option(WITH_CXX11_ABI "Use native C++11 ABI of compiler" ON)
646   mark_as_advanced(WITH_CXX11_ABI)
647 endif()
648
649 # Installation process.
650 option(POSTINSTALL_SCRIPT "Run given CMake script after installation process" OFF)
651 mark_as_advanced(POSTINSTALL_SCRIPT)
652
653 # end option(...)
654
655
656
657 # By default we want to install to the directory we are compiling our executables
658 # unless specified otherwise, which we currently do not allow
659 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
660   if(WIN32)
661     set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
662   elseif(APPLE)
663     set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
664   else()
665     if(WITH_INSTALL_PORTABLE)
666       set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH} CACHE PATH "default install path" FORCE)
667     endif()
668   endif()
669 endif()
670
671
672
673 # Apple
674
675 if(APPLE)
676   include(platform_apple_xcode)
677 endif()
678
679
680 #-----------------------------------------------------------------------------
681 # Check for conflicting/unsupported configurations
682
683 if(NOT WITH_BLENDER AND NOT WITH_CYCLES_STANDALONE)
684   message(FATAL_ERROR
685     "At least one of WITH_BLENDER or WITH_CYCLES_STANDALONE "
686     "must be enabled, nothing to do!"
687   )
688 endif()
689
690 set_and_warn_dependency(WITH_AUDASPACE WITH_OPENAL OFF)
691 set_and_warn_dependency(WITH_AUDASPACE WITH_COREAUDIO OFF)
692 set_and_warn_dependency(WITH_AUDASPACE WITH_JACK OFF)
693 set_and_warn_dependency(WITH_AUDASPACE WITH_PULSEAUDIO OFF)
694 set_and_warn_dependency(WITH_AUDASPACE WITH_WASAPI OFF)
695
696 if(NOT WITH_SDL AND WITH_GHOST_SDL)
697   message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
698 endif()
699
700 # python module, needs some different options
701 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
702   message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
703 endif()
704
705 set_and_warn_dependency(WITH_PYTHON WITH_CYCLES        OFF)
706 set_and_warn_dependency(WITH_PYTHON WITH_DRACO         OFF)
707
708 if(WITH_DRACO AND NOT WITH_PYTHON_INSTALL)
709   message(STATUS "WITH_DRACO requires WITH_PYTHON_INSTALL to be ON, disabling WITH_DRACO for now")
710   set(WITH_DRACO OFF)
711 endif()
712
713 # enable boost for cycles, audaspace or i18n
714 # otherwise if the user disabled
715
716 set_and_warn_dependency(WITH_BOOST WITH_CYCLES         OFF)
717 set_and_warn_dependency(WITH_BOOST WITH_INTERNATIONAL  OFF)
718 set_and_warn_dependency(WITH_BOOST WITH_OPENVDB        OFF)
719 set_and_warn_dependency(WITH_BOOST WITH_OPENCOLORIO    OFF)
720 set_and_warn_dependency(WITH_BOOST WITH_QUADRIFLOW     OFF)
721 set_and_warn_dependency(WITH_BOOST WITH_USD            OFF)
722 set_and_warn_dependency(WITH_BOOST WITH_ALEMBIC        OFF)
723 set_and_warn_dependency(WITH_PUGIXML WITH_CYCLES_OSL   OFF)
724 set_and_warn_dependency(WITH_PUGIXML WITH_OPENIMAGEIO  OFF)
725
726 if(WITH_BOOST AND NOT (WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_INTERNATIONAL OR
727    WITH_OPENVDB OR WITH_OPENCOLORIO OR WITH_USD OR WITH_ALEMBIC))
728   message(STATUS "No dependencies need 'WITH_BOOST' forcing WITH_BOOST=OFF")
729   set(WITH_BOOST OFF)
730 endif()
731
732 set_and_warn_dependency(WITH_TBB WITH_CYCLES            OFF)
733 set_and_warn_dependency(WITH_TBB WITH_USD               OFF)
734 set_and_warn_dependency(WITH_TBB WITH_OPENIMAGEDENOISE  OFF)
735 set_and_warn_dependency(WITH_TBB WITH_OPENVDB           OFF)
736 set_and_warn_dependency(WITH_TBB WITH_MOD_FLUID         OFF)
737
738 # NanoVDB requires OpenVDB to convert the data structure
739 set_and_warn_dependency(WITH_OPENVDB WITH_NANOVDB       OFF)
740
741 # OpenVDB and OpenColorIO uses 'half' type from OpenEXR
742 set_and_warn_dependency(WITH_IMAGE_OPENEXR WITH_OPENVDB OFF)
743 set_and_warn_dependency(WITH_IMAGE_OPENEXR WITH_OPENCOLORIO  OFF)
744
745 # Haru needs `TIFFFaxBlackCodes` & `TIFFFaxWhiteCodes` symbols from TIFF.
746 set_and_warn_dependency(WITH_IMAGE_TIFF WITH_HARU       OFF)
747
748 # auto enable openimageio for cycles
749 if(WITH_CYCLES)
750   set(WITH_OPENIMAGEIO ON)
751
752   # auto enable llvm for cycles_osl
753   if(WITH_CYCLES_OSL)
754     set(WITH_LLVM ON CACHE BOOL "" FORCE)
755     set(WITH_CLANG ON CACHE BOOL "" FORCE)
756   endif()
757 else()
758   set(WITH_CYCLES_OSL OFF)
759 endif()
760
761 # auto enable openimageio linking dependencies
762 if(WITH_OPENIMAGEIO)
763   set(WITH_IMAGE_OPENEXR ON)
764   set(WITH_IMAGE_TIFF ON)
765 endif()
766
767 # auto enable alembic linking dependencies
768 if(WITH_ALEMBIC)
769   set(WITH_IMAGE_OPENEXR ON)
770 endif()
771
772 # don't store paths to libs for portable distribution
773 if(WITH_INSTALL_PORTABLE)
774   set(CMAKE_SKIP_BUILD_RPATH TRUE)
775 endif()
776
777 if(WITH_GHOST_SDL OR WITH_HEADLESS)
778   message(STATUS "Disabling Ghost Wayland, X11, Input IME, and OpenXR")
779   set(WITH_GHOST_WAYLAND OFF)
780   set(WITH_GHOST_X11     OFF)
781   set(WITH_X11_XINPUT    OFF)
782   set(WITH_X11_XF86VMODE OFF)
783   set(WITH_X11_XFIXES    OFF)
784   set(WITH_X11_ALPHA     OFF)
785   set(WITH_GHOST_XDND    OFF)
786   set(WITH_INPUT_IME     OFF)
787   set(WITH_XR_OPENXR     OFF)
788 endif()
789
790 if(WITH_BUILDINFO)
791   find_package(Git)
792   if(NOT GIT_FOUND)
793     message(WARNING "Git was not found, disabling WITH_BUILDINFO")
794     set(WITH_BUILDINFO OFF)
795   endif()
796 endif()
797
798 if(WITH_AUDASPACE)
799   if(NOT WITH_SYSTEM_AUDASPACE)
800     set(AUDASPACE_C_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/audaspace/bindings/C" "${CMAKE_BINARY_DIR}/extern/audaspace")
801     set(AUDASPACE_PY_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/audaspace/bindings")
802   endif()
803 endif()
804
805 # Auto-enable CUDA dynload if toolkit is not found.
806 if(NOT WITH_CUDA_DYNLOAD)
807   find_package(CUDA)
808   if(NOT CUDA_FOUND)
809     message(STATUS "CUDA toolkit not found, using dynamic runtime loading of libraries (WITH_CUDA_DYNLOAD) instead")
810     set(WITH_CUDA_DYNLOAD ON)
811   endif()
812 endif()
813
814 #-----------------------------------------------------------------------------
815 # Check check if submodules are cloned
816
817 if(WITH_INTERNATIONAL)
818   file(GLOB RESULT "${CMAKE_SOURCE_DIR}/release/datafiles/locale")
819   list(LENGTH RESULT DIR_LEN)
820   if(DIR_LEN EQUAL 0)
821     message(WARNING
822       "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
823       "This is a 'git submodule', which are known not to work with bridges to other version "
824       "control systems, disabling 'WITH_INTERNATIONAL'."
825     )
826     set(WITH_INTERNATIONAL OFF)
827   endif()
828 endif()
829
830 if(WITH_PYTHON)
831   # While we have this as an '#error' in 'bpy_capi_utils.h',
832   # upgrading Python tends to cause confusion for users who build.
833   # Give the error message early to make this more obvious.
834   #
835   # Do this before main 'platform_*' checks,
836   # because UNIX will search for the old Python paths which may not exist.
837   # giving errors about missing paths before this case is met.
838   if(DEFINED PYTHON_VERSION AND "${PYTHON_VERSION}" VERSION_LESS "3.9")
839     message(FATAL_ERROR "At least Python 3.9 is required to build")
840   endif()
841
842   file(GLOB RESULT "${CMAKE_SOURCE_DIR}/release/scripts/addons")
843   list(LENGTH RESULT DIR_LEN)
844   if(DIR_LEN EQUAL 0)
845     message(WARNING
846       "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
847       "This is a 'git submodule', which are known not to work with bridges to other version "
848       "control systems: * CONTINUING WITHOUT ADDONS *"
849     )
850   endif()
851 endif()
852
853 #-----------------------------------------------------------------------------
854 # Initialize un-cached vars, avoid unused warning
855
856 # linux only, not cached
857 set(WITH_BINRELOC OFF)
858
859 # MACOSX only, set to avoid uninitialized
860 set(EXETYPE "")
861
862 # C/C++ flags
863 set(PLATFORM_CFLAGS)
864
865 # these are added to later on.
866 set(C_WARNINGS)
867 set(CXX_WARNINGS)
868
869 # for gcc -Wno-blah-blah
870 set(C_REMOVE_STRICT_FLAGS)
871 set(CXX_REMOVE_STRICT_FLAGS)
872
873 # Libraries to link to targets in setup_platform_linker_libs
874 set(PLATFORM_LINKLIBS "")
875
876 # Added to target linker flags in setup_platform_linker_flags
877 # - CMAKE_EXE_LINKER_FLAGS
878 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
879 set(PLATFORM_LINKFLAGS "")
880 set(PLATFORM_LINKFLAGS_DEBUG "")
881
882 if(NOT CMAKE_BUILD_TYPE MATCHES "Release")
883   if(WITH_COMPILER_ASAN)
884     if(NOT APPLE)
885       # Avoid passing address sanitizer compiler flags to `try_compile`.
886       # Since linker flags are not set, all compiler checks and `find_package`
887       # calls that rely on `try_compile` will fail.
888       # See CMP0066 also.
889       string(APPEND CMAKE_C_FLAGS_DEBUG " ${COMPILER_ASAN_CFLAGS}")
890       string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO " ${COMPILER_ASAN_CFLAGS}")
891
892       string(APPEND CMAKE_CXX_FLAGS_DEBUG " ${COMPILER_ASAN_CXXFLAGS}")
893       string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " ${COMPILER_ASAN_CXXFLAGS}")
894     endif()
895     if(MSVC)
896       set(COMPILER_ASAN_LINKER_FLAGS "/FUNCTIONPADMIN:6")
897     endif()
898
899     if(APPLE AND COMPILER_ASAN_LIBRARY)
900       string(REPLACE " " ";" _list_COMPILER_ASAN_CFLAGS ${COMPILER_ASAN_CFLAGS})
901       set(_is_CONFIG_DEBUG "$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>")
902       add_compile_options("$<${_is_CONFIG_DEBUG}:${_list_COMPILER_ASAN_CFLAGS}>")
903       add_link_options("$<${_is_CONFIG_DEBUG}:-fno-omit-frame-pointer;-fsanitize=address>")
904       unset(_list_COMPILER_ASAN_CFLAGS)
905       unset(_is_CONFIG_DEBUG)
906     elseif(COMPILER_ASAN_LIBRARY)
907       set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS};${COMPILER_ASAN_LIBRARY}")
908       set(PLATFORM_LINKFLAGS "${COMPILER_ASAN_LIBRARY} ${COMPILER_ASAN_LINKER_FLAGS}")
909       set(PLATFORM_LINKFLAGS_DEBUG "${COMPILER_ASAN_LIBRARY} ${COMPILER_ASAN_LINKER_FLAGS}")
910     endif()
911   endif()
912 endif()
913
914 # Test SIMD support, before platform includes to determine if sse2neon is needed.
915 if(WITH_CPU_SIMD)
916   set(COMPILER_SSE_FLAG)
917   set(COMPILER_SSE2_FLAG)
918
919   # Test Neon first since macOS Arm can compile and run x86-64 SSE binaries.
920   TEST_NEON_SUPPORT()
921   if(NOT SUPPORT_NEON_BUILD)
922     TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
923   endif()
924 endif()
925
926 # ----------------------------------------------------------------------------
927 # Main Platform Checks
928 #
929 # - UNIX
930 # - WIN32
931 # - APPLE
932
933 if(UNIX AND NOT APPLE)
934   include(platform_unix)
935 elseif(WIN32)
936   include(platform_win32)
937 elseif(APPLE)
938   include(platform_apple)
939 endif()
940
941 #-----------------------------------------------------------------------------
942 # Common.
943
944 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
945   message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
946 endif()
947
948 if(WITH_CYCLES)
949   if(NOT WITH_OPENIMAGEIO)
950     message(FATAL_ERROR
951       "Cycles requires WITH_OPENIMAGEIO, the library may not have been found. "
952       "Configure OIIO or disable WITH_CYCLES"
953     )
954   endif()
955   if(NOT WITH_BOOST)
956     message(FATAL_ERROR
957       "Cycles requires WITH_BOOST, the library may not have been found. "
958       "Configure BOOST or disable WITH_CYCLES"
959     )
960   endif()
961
962   if(WITH_CYCLES_OSL)
963     if(NOT WITH_LLVM)
964       message(FATAL_ERROR
965         "Cycles OSL requires WITH_LLVM, the library may not have been found. "
966         "Configure LLVM or disable WITH_CYCLES_OSL"
967       )
968     endif()
969   endif()
970 endif()
971
972 if(WITH_INTERNATIONAL)
973   if(NOT WITH_BOOST)
974     message(FATAL_ERROR
975       "Internationalization requires WITH_BOOST, the library may not have been found. "
976       "Configure BOOST or disable WITH_INTERNATIONAL"
977     )
978   endif()
979 endif()
980
981 # Enable SIMD support if detected by TEST_SSE_SUPPORT() or TEST_NEON_SUPPORT().
982 #
983 # This is done globally, so that all modules can use it if available, and
984 # because these are used in headers used by many modules.
985 if(WITH_CPU_SIMD)
986   if(SUPPORT_NEON_BUILD)
987     # Neon
988     if(SSE2NEON_FOUND)
989       blender_include_dirs_sys("${SSE2NEON_INCLUDE_DIRS}")
990       add_definitions(-DWITH_SSE2NEON)
991     endif()
992   else()
993     # SSE
994     if(SUPPORT_SSE_BUILD)
995       string(PREPEND PLATFORM_CFLAGS "${COMPILER_SSE_FLAG} ")
996       add_definitions(-D__SSE__ -D__MMX__)
997     endif()
998     if(SUPPORT_SSE2_BUILD)
999       string(APPEND PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG}")
1000       add_definitions(-D__SSE2__)
1001       if(NOT SUPPORT_SSE_BUILD) # don't double up
1002         add_definitions(-D__MMX__)
1003       endif()
1004     endif()
1005   endif()
1006
1007   # Print instructions used
1008   if(SUPPORT_NEON_BUILD)
1009     if(SSE2NEON_FOUND)
1010       message(STATUS "Neon SIMD instructions enabled")
1011     else()
1012       message(STATUS "Neon SIMD instructions detected but unused, requires sse2neon")
1013     endif()
1014   elseif(SUPPORT_SSE2_BUILD)
1015     message(STATUS "SSE2 SIMD instructions enabled")
1016   elseif(SUPPORT_SSE_BUILD)
1017     message(STATUS "SSE SIMD instructions enabled")
1018   else()
1019     message(STATUS "No SIMD instructions detected")
1020   endif()
1021 else()
1022   message(STATUS "SIMD instructions disabled")
1023 endif()
1024
1025 # set the endian define
1026 if(MSVC)
1027   # for some reason this fails on msvc
1028   add_definitions(-D__LITTLE_ENDIAN__)
1029
1030   # OSX-Note: as we do cross-compiling with specific set architecture,
1031   # endianess-detection and auto-setting is counterproductive
1032   # so we just set endianness according CMAKE_OSX_ARCHITECTURES
1033
1034 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64 OR CMAKE_OSX_ARCHITECTURES MATCHES arm64)
1035   add_definitions(-D__LITTLE_ENDIAN__)
1036 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)
1037   add_definitions(-D__BIG_ENDIAN__)
1038
1039 else()
1040   include(TestBigEndian)
1041   test_big_endian(_SYSTEM_BIG_ENDIAN)
1042   if(_SYSTEM_BIG_ENDIAN)
1043     add_definitions(-D__BIG_ENDIAN__)
1044   else()
1045     add_definitions(-D__LITTLE_ENDIAN__)
1046   endif()
1047   unset(_SYSTEM_BIG_ENDIAN)
1048 endif()
1049 if(WITH_IMAGE_OPENJPEG)
1050   # Special handling of Windows platform where openjpeg is always static.
1051   if(WIN32)
1052     set(OPENJPEG_DEFINES "-DOPJ_STATIC")
1053   else()
1054     set(OPENJPEG_DEFINES "")
1055   endif()
1056 endif()
1057
1058 if(NOT WITH_SYSTEM_EIGEN3)
1059   set(EIGEN3_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/Eigen3)
1060 endif()
1061
1062 if(WITH_OPENVDB)
1063   list(APPEND OPENVDB_DEFINITIONS -DWITH_OPENVDB)
1064
1065   if(WITH_OPENVDB_3_ABI_COMPATIBLE)
1066     list(APPEND OPENVDB_DEFINITIONS -DOPENVDB_3_ABI_COMPATIBLE)
1067   endif()
1068
1069   # OpenVDB headers use deprecated TBB headers, silence warning.
1070   list(APPEND OPENVDB_DEFINITIONS -DTBB_SUPPRESS_DEPRECATED_MESSAGES=1)
1071
1072   list(APPEND OPENVDB_INCLUDE_DIRS
1073     ${BOOST_INCLUDE_DIR}
1074     ${TBB_INCLUDE_DIRS}
1075     ${OPENEXR_INCLUDE_DIRS})
1076
1077   list(APPEND OPENVDB_LIBRARIES ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
1078
1079   if(WITH_OPENVDB_BLOSC)
1080     list(APPEND OPENVDB_DEFINITIONS -DWITH_OPENVDB_BLOSC)
1081     list(APPEND OPENVDB_LIBRARIES ${BLOSC_LIBRARIES} ${ZLIB_LIBRARIES})
1082   endif()
1083
1084   list(APPEND OPENVDB_LIBRARIES ${BOOST_LIBRARIES} ${TBB_LIBRARIES})
1085 endif()
1086
1087 #-----------------------------------------------------------------------------
1088 # Configure OpenGL.
1089
1090 find_package(OpenGL)
1091 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
1092
1093 if(WITH_OPENGL)
1094   add_definitions(-DWITH_OPENGL)
1095 endif()
1096
1097 if(WITH_SYSTEM_GLES)
1098   find_package_wrapper(OpenGLES)
1099 endif()
1100
1101 if(WITH_GL_PROFILE_ES20)
1102   if(WITH_SYSTEM_GLES)
1103     if(NOT OPENGLES_LIBRARY)
1104       message(FATAL_ERROR
1105         "Unable to find OpenGL ES libraries. "
1106         "Install them or disable WITH_SYSTEM_GLES."
1107       )
1108     endif()
1109
1110     list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}")
1111
1112   else()
1113     set(OPENGLES_LIBRARY "" CACHE FILEPATH "OpenGL ES 2.0 library file")
1114     mark_as_advanced(OPENGLES_LIBRARY)
1115
1116     list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}")
1117
1118     if(NOT OPENGLES_LIBRARY)
1119       message(FATAL_ERROR
1120         "To compile WITH_GL_EGL you need to set OPENGLES_LIBRARY "
1121         "to the file path of an OpenGL ES 2.0 library."
1122       )
1123     endif()
1124
1125   endif()
1126
1127   if(WIN32)
1128     # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
1129
1130     set(OPENGLES_DLL "" CACHE FILEPATH "OpenGL ES 2.0 redistributable DLL file")
1131     mark_as_advanced(OPENGLES_DLL)
1132
1133     if(NOT OPENGLES_DLL)
1134       message(FATAL_ERROR
1135         "To compile WITH_GL_PROFILE_ES20 you need to set OPENGLES_DLL to the file "
1136         "path of an OpenGL ES 2.0 runtime dynamic link library (DLL)."
1137       )
1138     endif()
1139
1140     if(WITH_GL_ANGLE)
1141       list(APPEND GL_DEFINITIONS -DWITH_ANGLE)
1142
1143       set(D3DCOMPILER_DLL "" CACHE FILEPATH "Direct3D Compiler redistributable DLL file (needed by ANGLE)")
1144
1145       get_filename_component(D3DCOMPILER_FILENAME "${D3DCOMPILER_DLL}" NAME)
1146       list(APPEND GL_DEFINITIONS "-DD3DCOMPILER=\"\\\"${D3DCOMPILER_FILENAME}\\\"\"")
1147
1148       mark_as_advanced(D3DCOMPILER_DLL)
1149
1150       if(D3DCOMPILER_DLL STREQUAL "")
1151         message(FATAL_ERROR
1152           "To compile WITH_GL_ANGLE you need to set D3DCOMPILER_DLL to the file "
1153           "path of a copy of the DirectX redistributable DLL file: D3DCompiler_46.dll"
1154         )
1155       endif()
1156
1157     endif()
1158
1159   endif()
1160
1161 else()
1162   if(OpenGL_GL_PREFERENCE STREQUAL "LEGACY" AND OPENGL_gl_LIBRARY)
1163     list(APPEND BLENDER_GL_LIBRARIES ${OPENGL_gl_LIBRARY})
1164   else()
1165     list(APPEND BLENDER_GL_LIBRARIES ${OPENGL_opengl_LIBRARY} ${OPENGL_glx_LIBRARY})
1166   endif()
1167 endif()
1168
1169 if(WITH_GL_EGL)
1170   find_package(OpenGL REQUIRED EGL)
1171   list(APPEND BLENDER_GL_LIBRARIES OpenGL::EGL)
1172
1173   list(APPEND GL_DEFINITIONS -DWITH_GL_EGL -DGLEW_EGL -DGLEW_INC_EGL)
1174
1175   if(WITH_SYSTEM_GLES)
1176     if(NOT OPENGLES_EGL_LIBRARY)
1177       message(FATAL_ERROR
1178         "Unable to find OpenGL ES libraries. "
1179         "Install them or disable WITH_SYSTEM_GLES."
1180       )
1181     endif()
1182
1183     list(APPEND BLENDER_GL_LIBRARIES ${OPENGLES_EGL_LIBRARY})
1184
1185   else()
1186     set(OPENGLES_EGL_LIBRARY "" CACHE FILEPATH "EGL library file")
1187     mark_as_advanced(OPENGLES_EGL_LIBRARY)
1188
1189     list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}" "${OPENGLES_EGL_LIBRARY}")
1190
1191     if(NOT OPENGLES_EGL_LIBRARY)
1192       message(FATAL_ERROR
1193         "To compile WITH_GL_EGL you need to set OPENGLES_EGL_LIBRARY "
1194         "to the file path of an EGL library."
1195       )
1196     endif()
1197
1198   endif()
1199
1200   if(WIN32)
1201     # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
1202
1203     set(OPENGLES_EGL_DLL "" CACHE FILEPATH "EGL redistributable DLL file")
1204     mark_as_advanced(OPENGLES_EGL_DLL)
1205
1206     if(NOT OPENGLES_EGL_DLL)
1207       message(FATAL_ERROR
1208         "To compile WITH_GL_EGL you need to set OPENGLES_EGL_DLL "
1209         "to the file path of an EGL runtime dynamic link library (DLL)."
1210       )
1211     endif()
1212
1213   endif()
1214
1215 endif()
1216
1217 if(WITH_GL_PROFILE_ES20)
1218   list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_ES20)
1219 else()
1220   list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_CORE)
1221 endif()
1222
1223 #-----------------------------------------------------------------------------
1224 # Configure OpenMP.
1225 if(WITH_OPENMP)
1226   if(NOT OPENMP_CUSTOM)
1227     find_package(OpenMP)
1228   endif()
1229
1230   if(OPENMP_FOUND)
1231     if(NOT WITH_OPENMP_STATIC)
1232       string(APPEND CMAKE_C_FLAGS " ${OpenMP_C_FLAGS}")
1233       string(APPEND CMAKE_CXX_FLAGS " ${OpenMP_CXX_FLAGS}")
1234       string(APPEND CMAKE_EXE_LINKER_FLAGS " ${OpenMP_LINKER_FLAGS}")
1235       string(APPEND CMAKE_MODULE_LINKER_FLAGS " ${OpenMP_LINKER_FLAGS}")
1236     else()
1237       # Typically avoid adding flags as defines but we can't
1238       # pass OpenMP flags to the linker for static builds, meaning
1239       # we can't add any OpenMP related flags to CFLAGS variables
1240       # since they're passed to the linker as well.
1241       add_definitions("${OpenMP_C_FLAGS}")
1242
1243       find_library_static(OpenMP_LIBRARIES gomp ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES})
1244     endif()
1245   else()
1246     message(STATUS "OpenMP not found, disabling WITH_OPENMP")
1247     set(WITH_OPENMP OFF)
1248   endif()
1249
1250   mark_as_advanced(
1251     OpenMP_C_FLAGS
1252     OpenMP_CXX_FLAGS
1253   )
1254 endif()
1255
1256 #-----------------------------------------------------------------------------
1257 # Configure GLEW
1258
1259 if(WITH_SYSTEM_GLEW)
1260   find_package(GLEW)
1261
1262   # Note: There is an assumption here that the system GLEW is not a static library.
1263
1264   if(NOT GLEW_FOUND)
1265     message(FATAL_ERROR "GLEW is required to build Blender. Install it or disable WITH_SYSTEM_GLEW.")
1266   endif()
1267
1268   set(GLEW_INCLUDE_PATH "${GLEW_INCLUDE_DIR}")
1269   set(BLENDER_GLEW_LIBRARIES ${GLEW_LIBRARY})
1270 else()
1271   if(WITH_GLEW_ES)
1272     set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew-es/include")
1273
1274     list(APPEND GL_DEFINITIONS -DGLEW_STATIC -DWITH_GLEW_ES)
1275
1276     # These definitions remove APIs from glew.h, making GLEW smaller, and catching unguarded API usage
1277     if(WITH_GL_PROFILE_ES20)
1278       list(APPEND GL_DEFINITIONS -DGLEW_ES_ONLY)
1279     else()
1280       # No ES functions are needed
1281       list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
1282     endif()
1283
1284     if(WITH_GL_PROFILE_ES20)
1285       if(WITH_GL_EGL)
1286         list(APPEND GL_DEFINITIONS -DGLEW_USE_LIB_ES20)
1287       endif()
1288
1289       # ToDo: This is an experiment to eliminate ES 1 symbols,
1290       # GLEW doesn't really properly provide this level of control
1291       # (for example, without modification it eliminates too many symbols)
1292       # so there are lots of modifications to GLEW to make this work,
1293       # and no attempt to make it work beyond Blender at this point.
1294       list(APPEND GL_DEFINITIONS -DGL_ES_VERSION_1_0=0 -DGL_ES_VERSION_CL_1_1=0 -DGL_ES_VERSION_CM_1_1=0)
1295     endif()
1296
1297     set(BLENDER_GLEW_LIBRARIES extern_glew_es bf_intern_glew_mx)
1298
1299   else()
1300     set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1301
1302     list(APPEND GL_DEFINITIONS -DGLEW_STATIC)
1303
1304     # This won't affect the non-experimental glew library,
1305     # but is used for conditional compilation elsewhere.
1306     list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
1307
1308     set(BLENDER_GLEW_LIBRARIES extern_glew)
1309
1310   endif()
1311
1312 endif()
1313
1314 list(APPEND GL_DEFINITIONS -DGLEW_NO_GLU)
1315
1316 #-----------------------------------------------------------------------------
1317 # Configure Bullet
1318
1319 if(WITH_BULLET AND WITH_SYSTEM_BULLET)
1320   find_package(Bullet)
1321   if(NOT BULLET_FOUND)
1322     message(STATUS "Bullet not found, disabling WITH_BULLET")
1323     set(WITH_BULLET OFF)
1324   endif()
1325 else()
1326   set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
1327   # set(BULLET_LIBRARIES "")
1328 endif()
1329
1330 #-----------------------------------------------------------------------------
1331 # Configure Python.
1332
1333 if(WITH_PYTHON_MODULE)
1334   add_definitions(-DPy_ENABLE_SHARED)
1335 endif()
1336
1337 #-----------------------------------------------------------------------------
1338 # Configure GLog/GFlags
1339
1340 if(WITH_LIBMV OR WITH_GTESTS OR (WITH_CYCLES AND WITH_CYCLES_LOGGING))
1341   if(WITH_SYSTEM_GFLAGS)
1342     find_package(Gflags)
1343     if(NOT GFLAGS_FOUND)
1344       message(FATAL_ERROR "System wide Gflags is requested but was not found")
1345     endif()
1346     # FindGflags does not define this, and we are not even sure what to use here.
1347     set(GFLAGS_DEFINES)
1348   else()
1349     set(GFLAGS_DEFINES
1350       -DGFLAGS_DLL_DEFINE_FLAG=
1351       -DGFLAGS_DLL_DECLARE_FLAG=
1352       -DGFLAGS_DLL_DECL=
1353     )
1354     set(GFLAGS_NAMESPACE "gflags")
1355     set(GFLAGS_LIBRARIES extern_gflags)
1356     set(GFLAGS_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/extern/gflags/src")
1357   endif()
1358
1359   if(WITH_SYSTEM_GLOG)
1360     find_package(Glog)
1361     if(NOT GLOG_FOUND)
1362       message(FATAL_ERROR "System wide Glog is requested but was not found")
1363     endif()
1364     # FindGlog does not define this, and we are not even sure what to use here.
1365     set(GLOG_DEFINES)
1366   else()
1367     set(GLOG_DEFINES
1368       -DGOOGLE_GLOG_DLL_DECL=
1369     )
1370     set(GLOG_LIBRARIES extern_glog)
1371     if(WIN32)
1372       set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/glog/src/windows)
1373     else()
1374       set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/glog/include)
1375     endif()
1376   endif()
1377 endif()
1378
1379 #-----------------------------------------------------------------------------
1380 # Configure Ceres
1381
1382 if(WITH_LIBMV)
1383   # We always have C++11 which includes unordered_map.
1384   set(CERES_DEFINES "-DCERES_STD_UNORDERED_MAP;-DCERES_USE_CXX_THREADS")
1385 endif()
1386
1387 #-----------------------------------------------------------------------------
1388 # Extra limits to number of jobs running in parallel for some kind os tasks.
1389 # Only supported by Ninja build system currently.
1390 if("${CMAKE_GENERATOR}" MATCHES "Ninja" AND WITH_NINJA_POOL_JOBS)
1391   if(NOT NINJA_MAX_NUM_PARALLEL_COMPILE_JOBS AND
1392      NOT NINJA_MAX_NUM_PARALLEL_COMPILE_HEAVY_JOBS AND
1393      NOT NINJA_MAX_NUM_PARALLEL_LINK_JOBS)
1394     # Try to define good default values.
1395     # Max mem of heavy cpp files compilation: about 2.5GB
1396     # Max mem during linking: about 3.3GB
1397     cmake_host_system_information(RESULT _NUM_CORES QUERY NUMBER_OF_LOGICAL_CORES)
1398     # Note: this gives mem in MB.
1399     cmake_host_system_information(RESULT _TOT_MEM QUERY TOTAL_PHYSICAL_MEMORY)
1400
1401     # Heuristics... the more cores we have, the more free mem we have to keep for the non-heavy tasks too.
1402     if(${_TOT_MEM} LESS 8000 AND ${_NUM_CORES} GREATER 2)
1403       set(_compile_heavy_jobs "1")
1404     elseif(${_TOT_MEM} LESS 16000 AND ${_NUM_CORES} GREATER 4)
1405       set(_compile_heavy_jobs "2")
1406     elseif(${_TOT_MEM} LESS 24000 AND ${_NUM_CORES} GREATER 8)
1407       set(_compile_heavy_jobs "3")
1408     elseif(${_TOT_MEM} LESS 32000 AND ${_NUM_CORES} GREATER 16)
1409       set(_compile_heavy_jobs "4")
1410     elseif(${_TOT_MEM} LESS 64000 AND ${_NUM_CORES} GREATER 32)
1411       set(_compile_heavy_jobs "8")
1412     else()
1413       set(_compile_heavy_jobs "")
1414     endif()
1415
1416     set(NINJA_MAX_NUM_PARALLEL_COMPILE_HEAVY_JOBS "${_compile_heavy_jobs}" CACHE STRING
1417         "Define the maximum number of concurrent heavy compilation jobs, for ninja build system (used for some targets which cpp files can take several GB each during compilation)." FORCE)
1418     mark_as_advanced(NINJA_MAX_NUM_PARALLEL_COMPILE_HEAVY_JOBS)
1419     set(_compile_heavy_jobs)
1420
1421     # Only set regular compile jobs if we set heavy jobs, otherwise default (using all cores) if fine.
1422     if(NINJA_MAX_NUM_PARALLEL_COMPILE_HEAVY_JOBS)
1423       math(EXPR _compile_jobs "${_NUM_CORES} - 1")
1424     else()
1425       set(_compile_jobs "")
1426     endif()
1427     set(NINJA_MAX_NUM_PARALLEL_COMPILE_JOBS "${_compile_jobs}" CACHE STRING
1428         "Define the maximum number of concurrent compilation jobs, for ninja build system." FORCE)
1429     mark_as_advanced(NINJA_MAX_NUM_PARALLEL_COMPILE_JOBS)
1430     set(_compile_jobs)
1431
1432     # In practice, even when there is RAM available, this proves to be quicker than running in parallel
1433     # (due to slow disks accesses).
1434     set(NINJA_MAX_NUM_PARALLEL_LINK_JOBS "1" CACHE STRING
1435         "Define the maximum number of concurrent link jobs, for ninja build system." FORCE)
1436     mark_as_advanced(NINJA_MAX_NUM_PARALLEL_LINK_JOBS)
1437
1438     set(_NUM_CORES)
1439     set(_TOT_MEM)
1440   endif()
1441
1442   if(NINJA_MAX_NUM_PARALLEL_COMPILE_JOBS)
1443     set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${NINJA_MAX_NUM_PARALLEL_COMPILE_JOBS})
1444     set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
1445   endif()
1446
1447   if(NINJA_MAX_NUM_PARALLEL_COMPILE_HEAVY_JOBS)
1448     set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_heavy_job_pool=${NINJA_MAX_NUM_PARALLEL_COMPILE_HEAVY_JOBS})
1449   endif()
1450
1451   if(NINJA_MAX_NUM_PARALLEL_LINK_JOBS)
1452     set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${NINJA_MAX_NUM_PARALLEL_LINK_JOBS})
1453     set(CMAKE_JOB_POOL_LINK link_job_pool)
1454   endif()
1455 endif()
1456
1457 #-----------------------------------------------------------------------------
1458 # Extra compile flags
1459
1460 if(CMAKE_COMPILER_IS_GNUCC)
1461
1462   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1463   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1464   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1465   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1466   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_VLA -Werror=vla)
1467   # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1468   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1469   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1470   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1471   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1472   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1473   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1474   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1475   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
1476   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
1477   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1478   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1479   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1480   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_TYPE_LIMITS -Wtype-limits)
1481   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_FORMAT_SIGN -Wformat-signedness)
1482   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_RESTRICT -Wrestrict)
1483
1484   # C-only.
1485   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)
1486   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ABSOLUTE_VALUE -Wabsolute-value)
1487
1488   # gcc 4.2 gives annoying warnings on every file with this
1489   if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1490     ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
1491     ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
1492   endif()
1493
1494   # versions before gcc4.6 give many BLI_math warnings
1495   if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
1496     ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
1497     ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
1498   endif()
1499
1500   # versions before gcc4.8 include global name-space.
1501   if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.8")
1502     ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_SHADOW -Wshadow)
1503   endif()
1504
1505   # disable because it gives warnings for printf() & friends.
1506   # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1507
1508   if(NOT APPLE)
1509     ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1510   endif()
1511
1512   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1513   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1514   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1515   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
1516   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1517   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1518   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1519   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
1520   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1521   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1522   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1523   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_POINTER_ARITH -Wpointer-arith)
1524   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_PARAMETER -Wunused-parameter)
1525   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_WRITE_STRINGS -Wwrite-strings)
1526   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1527   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_FORMAT_SIGN -Wformat-signedness)
1528   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_RESTRICT -Wrestrict)
1529   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SUGGEST_OVERRIDE  -Wno-suggest-override)
1530
1531   # gcc 4.2 gives annoying warnings on every file with this
1532   if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1533     ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
1534   endif()
1535
1536   # causes too many warnings
1537   if(NOT APPLE)
1538     ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1539     ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
1540   endif()
1541
1542   # Use 'ATTR_FALLTHROUGH' macro to suppress.
1543   if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "7.0"))
1544     ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_IMPLICIT_FALLTHROUGH -Wimplicit-fallthrough=5)
1545     ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_IMPLICIT_FALLTHROUGH -Wimplicit-fallthrough=5)
1546   endif()
1547
1548   # flags to undo strict flags
1549   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
1550   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
1551   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION         -Wno-unused-function)
1552   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_TYPE_LIMITS             -Wno-type-limits)
1553   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_INT_IN_BOOL_CONTEXT     -Wno-int-in-bool-context)
1554   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_FORMAT                  -Wno-format)
1555   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_SWITCH                  -Wno-switch)
1556   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_VARIABLE         -Wno-unused-variable)
1557   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_VARIABLE         -Wno-uninitialized)
1558
1559   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_CLASS_MEMACCESS     -Wno-class-memaccess)
1560   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_COMMENT             -Wno-comment)
1561   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_TYPEDEFS     -Wno-unused-local-typedefs)
1562   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_VARIABLE     -Wno-unused-variable)
1563   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_VARIABLE     -Wno-uninitialized)
1564
1565   if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "7.0"))
1566     ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_IMPLICIT_FALLTHROUGH    -Wno-implicit-fallthrough)
1567   endif()
1568
1569   if(NOT APPLE)
1570     ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1571   endif()
1572
1573 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
1574
1575   # strange, clang complains these are not supported, but then uses them.
1576   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1577   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1578   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1579   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1580   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1581   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1582   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1583   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1584   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1585
1586   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1587   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1588   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
1589   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
1590   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_OVERLOADED_VIRTUAL  -Wno-overloaded-virtual)  # we get a lot of these, if its a problem a dev needs to look into it.
1591   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
1592   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
1593   # Apple Clang (tested on version 12) doesn't support this flag while LLVM Clang 11 does.
1594   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SUGGEST_OVERRIDE    -Wno-suggest-override)
1595
1596   # gives too many unfixable warnings
1597   # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
1598   # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
1599
1600   # flags to undo strict flags
1601   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
1602   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_VARIABLE  -Wno-unused-variable)
1603   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
1604   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_MISLEADING_INDENTATION    -Wno-misleading-indentation)
1605
1606   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations)
1607   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_INCOMPAT_PTR_DISCARD_QUAL -Wno-incompatible-pointer-types-discards-qualifiers)
1608   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function)
1609   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast)
1610   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes)
1611   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum)
1612   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNDEF -Wno-undef)
1613   ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn)
1614
1615   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
1616   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field)
1617   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing)
1618   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor)
1619   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
1620   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_VARIABLE  -Wno-unused-variable)
1621   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_REORDER -Wno-reorder)
1622   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_COMMENT -Wno-comment)
1623   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_TYPEDEFS -Wno-unused-local-typedefs)
1624   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNDEFINED_VAR_TEMPLATE -Wno-undefined-var-template)
1625   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_INSTANTIATION_AFTER_SPECIALIZATION -Wno-instantiation-after-specialization)
1626   ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_MISLEADING_INDENTATION    -Wno-misleading-indentation)
1627
1628 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1629
1630   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1631   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1632   ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1633
1634   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1635   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1636   ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1637
1638   # disable numbered, false positives
1639   string(APPEND C_WARNINGS " -wd188,186,144,913,556,858,597,177,1292,167,279,592,94,2722,3199")
1640   string(APPEND CXX_WARNINGS " -wd188,186,144,913,556,858,597,177,1292,167,279,592,94,2722,3199")
1641 elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
1642   # most msvc warnings are C & C++
1643   set(_WARNINGS
1644     # warning level:
1645     "/W3"
1646     "/w34062"  # switch statement contains 'default' but no 'case' labels
1647     "/w34115"  # 'type' : named type definition in parentheses
1648     "/w34189"  # local variable is initialized but not referenced
1649     # disable:
1650     "/wd4018"  # signed/unsigned mismatch
1651     "/wd4146"  # unary minus operator applied to unsigned type, result still unsigned
1652     "/wd4065"  # switch statement contains 'default' but no 'case' labels
1653     "/wd4127"  # conditional expression is constant
1654     "/wd4181"  # qualifier applied to reference type; ignored
1655     "/wd4200"  # zero-sized array in struct/union
1656     "/wd4244"  # conversion from 'type1' to 'type2', possible loss of data
1657     "/wd4267"  # conversion from 'size_t' to 'type', possible loss of data
1658     "/wd4305"  # truncation from 'type1' to 'type2'
1659     "/wd4800"  # forcing value to bool 'true' or 'false'
1660     "/wd4828"  # The file contains a character that is illegal
1661     "/wd4996"  # identifier was declared deprecated
1662     "/wd4661"  # no suitable definition provided for explicit template instantiation request
1663     # errors:
1664     "/we4013"  # 'function' undefined; assuming extern returning int
1665     "/we4133"  # incompatible pointer types
1666     "/we4431"  # missing type specifier - int assumed
1667   )
1668
1669   if(MSVC_VERSION GREATER_EQUAL 1911)
1670     # see https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c5038?view=vs-2017
1671     string(APPEND _WARNINGS " /w35038") # order of initialization in c++ constructors
1672   endif()
1673
1674   string(REPLACE ";" " " _WARNINGS "${_WARNINGS}")
1675   set(C_WARNINGS "${_WARNINGS}")
1676   set(CXX_WARNINGS "${_WARNINGS}")
1677   unset(_WARNINGS)
1678 endif()
1679
1680 # ensure python header is found since detection can fail, this could happen
1681 # with _any_ library but since we used a fixed python version this tends to
1682 # be most problematic.
1683 if(WITH_PYTHON)
1684   if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
1685     message(FATAL_ERROR
1686       "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
1687       "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
1688       "to a valid python include path. Containing "
1689       "Python.h for python version \"${PYTHON_VERSION}\""
1690     )
1691   endif()
1692
1693   if(WIN32 OR APPLE)
1694     # Windows and macOS have this bundled with Python libraries.
1695   elseif((WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY) OR WITH_PYTHON_NUMPY)
1696     if(("${PYTHON_NUMPY_PATH}" STREQUAL "") OR (${PYTHON_NUMPY_PATH} MATCHES NOTFOUND))
1697       find_python_package(numpy "core/include")
1698     endif()
1699   endif()
1700
1701   if(WIN32 OR APPLE)
1702     # pass, we have this in lib/python/site-packages
1703   elseif(WITH_PYTHON_INSTALL_REQUESTS)
1704     find_python_package(requests "")
1705   endif()
1706 endif()
1707
1708 if(MSVC)
1709   string(APPEND CMAKE_CXX_FLAGS " /std:c++17")
1710   # Make MSVC properly report the value of the __cplusplus preprocessor macro
1711   # Available MSVC 15.7 (1914) and up, without this it reports 199711L regardless
1712   # of the C++ standard chosen above
1713   if(MSVC_VERSION GREATER 1913)
1714     string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus")
1715   endif()
1716 elseif(
1717   CMAKE_COMPILER_IS_GNUCC OR
1718   CMAKE_C_COMPILER_ID MATCHES "Clang" OR
1719   CMAKE_C_COMPILER_ID MATCHES "Intel"
1720 )
1721   string(APPEND CMAKE_CXX_FLAGS " -std=c++17")
1722 else()
1723   message(FATAL_ERROR "Unknown compiler ${CMAKE_C_COMPILER_ID}, can't enable C++17 build")
1724 endif()
1725
1726 # Visual Studio has all standards it supports available by default
1727 # Clang on windows copies this behavior and does not support these switches
1728 if(
1729   CMAKE_COMPILER_IS_GNUCC OR
1730   (CMAKE_C_COMPILER_ID MATCHES "Clang" AND (NOT MSVC)) OR
1731   (CMAKE_C_COMPILER_ID MATCHES "Intel")
1732 )
1733   # Use C11 + GNU extensions, works with GCC, Clang, ICC
1734   string(APPEND CMAKE_C_FLAGS " -std=gnu11")
1735 endif()
1736
1737 if(UNIX AND NOT APPLE)
1738   if(NOT WITH_CXX11_ABI)
1739     string(APPEND PLATFORM_CFLAGS " -D_GLIBCXX_USE_CXX11_ABI=0")
1740   endif()
1741 endif()
1742
1743 if(WITH_COMPILER_SHORT_FILE_MACRO)
1744   # Use '-fmacro-prefix-map' for Clang and GCC (MSVC doesn't support this).
1745   ADD_CHECK_C_COMPILER_FLAG(C_PREFIX_MAP_FLAGS C_MACRO_PREFIX_MAP -fmacro-prefix-map=foo=bar)
1746   ADD_CHECK_CXX_COMPILER_FLAG(CXX_PREFIX_MAP_FLAGS CXX_MACRO_PREFIX_MAP -fmacro-prefix-map=foo=bar)
1747   if(C_MACRO_PREFIX_MAP AND CXX_MACRO_PREFIX_MAP)
1748     if(APPLE)
1749       if(XCODE AND ${XCODE_VERSION} VERSION_LESS 12.0)
1750       # Developers may have say LLVM Clang-10.0.1 toolchain (which supports the flag)
1751       # with Xcode-11 (the Clang of which doesn't support the flag).
1752         message(WARNING
1753           "-fmacro-prefix-map flag is NOT supported by Clang shipped with Xcode-${XCODE_VERSION}."
1754           " Some Xcode functionality in Product menu may not work. Disabling WITH_COMPILER_SHORT_FILE_MACRO."
1755         )
1756         set(WITH_COMPILER_SHORT_FILE_MACRO OFF)
1757       endif()
1758     endif()
1759     if(WITH_COMPILER_SHORT_FILE_MACRO)
1760       path_ensure_trailing_slash(_src_dir "${CMAKE_SOURCE_DIR}")
1761       path_ensure_trailing_slash(_bin_dir "${CMAKE_BINARY_DIR}")
1762       # Keep this variable so it can be stripped from build-info.
1763       set(PLATFORM_CFLAGS_FMACRO_PREFIX_MAP
1764         "-fmacro-prefix-map=\"${_src_dir}\"=\"\" -fmacro-prefix-map=\"${_bin_dir}\"=\"\"")
1765       string(APPEND PLATFORM_CFLAGS " ${PLATFORM_CFLAGS_FMACRO_PREFIX_MAP}")
1766       unset(_src_dir)
1767       unset(_bin_dir)
1768     endif()
1769   else()
1770     message(WARNING
1771       "-fmacro-prefix-map flag is NOT supported by C/C++ compiler."
1772       " Disabling WITH_COMPILER_SHORT_FILE_MACRO."
1773     )
1774     set(WITH_COMPILER_SHORT_FILE_MACRO OFF)
1775   endif()
1776 endif()
1777
1778 # Include warnings first, so its possible to disable them with user defined flags
1779 # eg: -Wno-uninitialized
1780 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
1781 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
1782
1783 # defined above, platform specific but shared names
1784 mark_as_advanced(
1785   CYCLES_OSL
1786   OSL_LIB_EXEC
1787   OSL_COMPILER
1788   OSL_LIB_COMP
1789   OSL_LIB_QUERY
1790   OSL_INCLUDE_DIR
1791 )
1792
1793 mark_as_advanced(
1794   LLVM_CONFIG
1795   LLVM_ROOT_DIR
1796   LLVM_LIBRARY
1797   LLVM_VERSION
1798 )
1799
1800 #-------------------------------------------------------------------------------
1801 # Global Defines
1802
1803 # better not set includes here but this debugging option is off by default.
1804 if(WITH_CXX_GUARDEDALLOC)
1805   include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
1806   add_definitions(-DWITH_CXX_GUARDEDALLOC)
1807 endif()
1808
1809 if(WITH_ASSERT_ABORT)
1810   add_definitions(-DWITH_ASSERT_ABORT)
1811 endif()
1812
1813 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
1814 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
1815
1816 #-----------------------------------------------------------------------------
1817 # Libraries
1818
1819 if(WITH_BLENDER)
1820   add_subdirectory(intern)
1821   add_subdirectory(extern)
1822
1823   # source after intern and extern to gather all
1824   # internal and external library information first, for test linking
1825   add_subdirectory(source)
1826 elseif(WITH_CYCLES_STANDALONE)
1827   add_subdirectory(intern/glew-mx)
1828   add_subdirectory(intern/guardedalloc)
1829   add_subdirectory(intern/libc_compat)
1830   add_subdirectory(intern/numaapi)
1831   add_subdirectory(intern/sky)
1832
1833   add_subdirectory(intern/cycles)
1834   add_subdirectory(extern/clew)
1835   if(WITH_CYCLES_LOGGING)
1836     if(NOT WITH_SYSTEM_GFLAGS)
1837       add_subdirectory(extern/gflags)
1838     endif()
1839     add_subdirectory(extern/glog)
1840   endif()
1841   if(WITH_CUDA_DYNLOAD)
1842     add_subdirectory(extern/cuew)
1843   endif()
1844   if(NOT WITH_SYSTEM_GLEW)
1845     add_subdirectory(extern/glew)
1846   endif()
1847 endif()
1848
1849 #-----------------------------------------------------------------------------
1850 # Testing
1851 add_subdirectory(tests)
1852
1853 #-----------------------------------------------------------------------------
1854 # Blender Application
1855 if(WITH_BLENDER)
1856   add_subdirectory(source/creator)
1857 endif()
1858
1859
1860 #-----------------------------------------------------------------------------
1861 # Define 'heavy' submodules (for Ninja builder when using pools).
1862 setup_heavy_lib_pool()
1863
1864
1865 #-----------------------------------------------------------------------------
1866 # CPack for generating packages
1867 include(build_files/cmake/packaging.cmake)
1868
1869 #-----------------------------------------------------------------------------
1870 # Use dynamic loading for OpenMP
1871 if(WITH_BLENDER)
1872   openmp_delayload(blender)
1873 endif()
1874
1875 #-----------------------------------------------------------------------------
1876 # Print Final Configuration
1877
1878 if(FIRST_RUN)
1879
1880   set(_config_msg "\nBlender Configuration\n=====================")
1881
1882   function(info_cfg_option
1883     _setting
1884     )
1885
1886     set(_msg "  - ${_setting}")
1887     string(LENGTH "${_msg}" _len)
1888     while("32" GREATER "${_len}")
1889       string(APPEND _msg " ")
1890       math(EXPR _len "${_len} + 1")
1891     endwhile()
1892
1893     set(_config_msg "${_config_msg}\n${_msg}${${_setting}}" PARENT_SCOPE)
1894   endfunction()
1895
1896   function(info_cfg_text
1897     _text
1898     )
1899
1900     set(_config_msg "${_config_msg}\n\n  ${_text}" PARENT_SCOPE)
1901   endfunction()
1902
1903   message(STATUS "C Compiler:   \"${CMAKE_C_COMPILER_ID}\"")
1904   message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
1905
1906   info_cfg_text("Build Options:")
1907   info_cfg_option(WITH_ALEMBIC)
1908   info_cfg_option(WITH_BULLET)
1909   info_cfg_option(WITH_CLANG)
1910   info_cfg_option(WITH_CYCLES)
1911   info_cfg_option(WITH_FFTW3)
1912   info_cfg_option(WITH_FREESTYLE)
1913   info_cfg_option(WITH_GMP)
1914   info_cfg_option(WITH_HARU)
1915   info_cfg_option(WITH_IK_ITASC)
1916   info_cfg_option(WITH_IK_SOLVER)
1917   info_cfg_option(WITH_INPUT_NDOF)
1918   info_cfg_option(WITH_INTERNATIONAL)
1919   info_cfg_option(WITH_OPENCOLLADA)
1920   info_cfg_option(WITH_OPENCOLORIO)
1921   info_cfg_option(WITH_OPENIMAGEDENOISE)
1922   info_cfg_option(WITH_OPENVDB)
1923   info_cfg_option(WITH_POTRACE)
1924   info_cfg_option(WITH_PUGIXML)
1925   info_cfg_option(WITH_QUADRIFLOW)
1926   info_cfg_option(WITH_TBB)
1927   info_cfg_option(WITH_USD)
1928   info_cfg_option(WITH_XR_OPENXR)
1929
1930   info_cfg_text("Compiler Options:")
1931   info_cfg_option(WITH_BUILDINFO)
1932   info_cfg_option(WITH_OPENMP)
1933
1934   info_cfg_text("System Options:")
1935   info_cfg_option(WITH_INSTALL_PORTABLE)
1936   info_cfg_option(WITH_MEM_JEMALLOC)
1937   info_cfg_option(WITH_MEM_VALGRIND)
1938   info_cfg_option(WITH_SYSTEM_GLEW)
1939   info_cfg_option(WITH_X11_ALPHA)
1940   info_cfg_option(WITH_X11_XF86VMODE)
1941   info_cfg_option(WITH_X11_XFIXES)
1942   info_cfg_option(WITH_X11_XINPUT)
1943
1944   info_cfg_text("Image Formats:")
1945   info_cfg_option(WITH_IMAGE_CINEON)
1946   info_cfg_option(WITH_IMAGE_DDS)
1947   info_cfg_option(WITH_IMAGE_HDR)
1948   info_cfg_option(WITH_IMAGE_OPENEXR)
1949   info_cfg_option(WITH_IMAGE_OPENJPEG)
1950   info_cfg_option(WITH_IMAGE_TIFF)
1951   info_cfg_option(WITH_OPENIMAGEIO)
1952
1953   info_cfg_text("Audio:")
1954   info_cfg_option(WITH_CODEC_AVI)
1955   info_cfg_option(WITH_CODEC_FFMPEG)
1956   info_cfg_option(WITH_CODEC_SNDFILE)
1957   info_cfg_option(WITH_COREAUDIO)
1958   info_cfg_option(WITH_JACK)
1959   info_cfg_option(WITH_JACK_DYNLOAD)
1960   info_cfg_option(WITH_OPENAL)
1961   info_cfg_option(WITH_PULSEAUDIO)
1962   info_cfg_option(WITH_PULSEAUDIO_DYNLOAD)
1963   info_cfg_option(WITH_SDL)
1964   info_cfg_option(WITH_SDL_DYNLOAD)
1965   info_cfg_option(WITH_WASAPI)
1966
1967   info_cfg_text("Compression:")
1968   info_cfg_option(WITH_LZMA)
1969   info_cfg_option(WITH_LZO)
1970
1971   info_cfg_text("Python:")
1972   if(APPLE)
1973     info_cfg_option(WITH_PYTHON_FRAMEWORK)
1974   endif()
1975   info_cfg_option(WITH_PYTHON_INSTALL)
1976   info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
1977   info_cfg_option(WITH_PYTHON_MODULE)
1978   info_cfg_option(WITH_PYTHON_SAFETY)
1979
1980   info_cfg_text("Modifiers:")
1981   info_cfg_option(WITH_MOD_FLUID)
1982   info_cfg_option(WITH_MOD_OCEANSIM)
1983   info_cfg_option(WITH_MOD_REMESH)
1984
1985   info_cfg_text("OpenGL:")
1986   if(WIN32)
1987     info_cfg_option(WITH_GL_ANGLE)
1988   endif()
1989   info_cfg_option(WITH_GL_EGL)
1990   info_cfg_option(WITH_GL_PROFILE_ES20)
1991   info_cfg_option(WITH_GLEW_ES)
1992
1993   info_cfg_text("")
1994
1995   message("${_config_msg}")
1996 endif()
1997
1998 if(0)
1999   print_all_vars()
2000 endif()