EEVEE-Next: Add correct support for volume anisotropy from probe volumes
[blender.git] / CMakeLists.txt
blobc98b2d6a3e21085825cc9a10052a0a423552bc8b
1 # SPDX-FileCopyrightText: 2006 Blender Authors
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # -----------------------------------------------------------------------------
6 # Early Initialization
8 # NOTE: We don't allow in-source builds. This causes no end of troubles because
9 # all out-of-source builds will use the CMakeCache.txt file there and even
10 # build the libs and objects in it.
11 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
12   if(NOT DEFINED WITH_IN_SOURCE_BUILD)
13     message(FATAL_ERROR
14       "CMake generation for blender is not allowed within the source directory!"
15       "\n Remove \"${CMAKE_SOURCE_DIR}/CMakeCache.txt\" and try again from another folder, e.g.:"
16       "\n "
17       "\n rm -rf CMakeCache.txt CMakeFiles"
18       "\n cd .."
19       "\n mkdir cmake-make"
20       "\n cd cmake-make"
21       "\n cmake ../blender"
22       "\n "
23       "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
24     )
25   endif()
26 endif()
28 cmake_minimum_required(VERSION 3.10)
30 if(NOT EXECUTABLE_OUTPUT_PATH)
31   set(FIRST_RUN TRUE)
32 else()
33   set(FIRST_RUN FALSE)
34 endif()
36 # this starts out unset
37 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
38 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/platform")
40 # Avoid having an empty `CMAKE_BUILD_TYPE`.
41 if(NOT DEFINED CMAKE_BUILD_TYPE_INIT)
42   set(CMAKE_BUILD_TYPE_INIT "Release")
43   # Internal logic caches this variable, avoid showing it by default
44   # since it's easy to accidentally set instead of the build type.
45 endif()
46 mark_as_advanced(CMAKE_BUILD_TYPE_INIT)
48 # Omit superfluous "Up-to-date" messages.
49 if(NOT DEFINED CMAKE_INSTALL_MESSAGE)
50   set(CMAKE_INSTALL_MESSAGE "LAZY")
51 endif()
53 # quiet output for Makefiles, 'make -s' helps too
54 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
56 # Global compile definitions since add_definitions() adds for all.
57 # _DEBUG is a Visual Studio define, enabled for all platforms.
58 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
59   $<$<CONFIG:Debug>:_DEBUG>
61 # -----------------------------------------------------------------------------
62 # Set policy
64 # see "cmake --help-policy CMP0003"
65 # So library linking is more sane
66 cmake_policy(SET CMP0003 NEW)
68 # So BUILDINFO and BLENDERPATH strings are automatically quoted
69 cmake_policy(SET CMP0005 NEW)
71 # So syntax problems are errors
72 cmake_policy(SET CMP0010 NEW)
74 # Input directories must have CMakeLists.txt
75 cmake_policy(SET CMP0014 NEW)
77 # Silence draco warning on macOS, new policy works fine.
78 if(POLICY CMP0068)
79   cmake_policy(SET CMP0068 NEW)
80 endif()
82 # find_package() uses <PackageName>_ROOT variables.
83 if(POLICY CMP0074)
84   cmake_policy(SET CMP0074 NEW)
85 endif()
87 # find_package() uses uppercase <PackageName>_ROOT variables.
88 if(POLICY CMP0144)
89   cmake_policy(SET CMP0144 NEW)
90 endif()
92 # Install CODE|SCRIPT allow the use of generator expressions.
93 if(POLICY CMP0087)
94   cmake_policy(SET CMP0087 NEW)
95 endif()
98 # -----------------------------------------------------------------------------
99 # Load Blender's Local Macros
101 include(build_files/cmake/macros.cmake)
103 # -----------------------------------------------------------------------------
104 # Initialize Project
106 blender_project_hack_pre()
108 project(Blender)
110 blender_project_hack_post()
112 enable_testing()
115 # -----------------------------------------------------------------------------
116 # Test Compiler Support
118 # Keep in sync with: https://developer.blender.org/docs/handbook/building_blender/
120 if(CMAKE_COMPILER_IS_GNUCC)
121   if("${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "11.0.0")
122     message(FATAL_ERROR "\
123 The minimum supported version of GCC is 11.0.0, found ${CMAKE_C_COMPILER_VERSION}"
124     )
125   endif()
126 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
127   if(CMAKE_COMPILER_IS_GNUCC AND ("${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "8.0"))
128     message(FATAL_ERROR "\
129 The minimum supported version of CLANG is 8.0, found ${CMAKE_C_COMPILER_VERSION}"
130     )
131   endif()
132 elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
133   if(MSVC_VERSION VERSION_LESS "1928")
134     # MSVC_VERSION is an internal version number, it doesn't map to something
135     # the end user would recognize as a version. Because of this, for MSVC we do
136     # not show the found number. When using our make.bat the actual VS version
137     # will be displayed on the console before starting the build, anyway.
138     message(FATAL_ERROR "The minimum supported version of MSVC is 2019 (16.9.16)")
139   endif()
140 endif()
142 # -----------------------------------------------------------------------------
143 # Test Compiler/Library Features
145 include(build_files/cmake/have_features.cmake)
148 # -----------------------------------------------------------------------------
149 # Redirect Output Files
151 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE)
152 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE)
154 get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
155 if(GENERATOR_IS_MULTI_CONFIG)
156   set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests/$<CONFIG>/ CACHE INTERNAL "" FORCE)
157 else()
158   set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests/ CACHE INTERNAL "" FORCE)
159 endif()
162 # -----------------------------------------------------------------------------
163 # Set Default Configuration Options
165 get_blender_version()
167 if(WIN32)
168   add_definitions(
169     # This is the app ID used for file registration, given it's used from several modules
170     # there really is no nice way to get this information consistent without a global define.
171     -DBLENDER_WIN_APPID="blender.${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}"
172     # This is the name that will be shown in the taskbar and OpenWith windows UI
173     -DBLENDER_WIN_APPID_FRIENDLY_NAME="Blender ${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}"
174   )
175 endif()
178 if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.19")
179   # This changes the default value from Off to On, but will still allow people to manually change
180   # this setting through their CMakeCache.txt if they desire to do so.
181   set(CMAKE_OPTIMIZE_DEPENDENCIES ON CACHE INTERNAL "")
182 endif()
184 # -----------------------------------------------------------------------------
185 # Declare Options
187 # Blender internal features
188 option(WITH_BLENDER "Build blender (disable to build only Cycles stand-alone)." ON)
189 mark_as_advanced(WITH_BLENDER)
191 if(WIN32)
192   option(WITH_BLENDER_THUMBNAILER "\
193 Build \"BlendThumb.dll\" helper for Windows explorer integration to support extracting \
194 thumbnails from `.blend` files."
195     ON
196   )
197 else()
198   set(_option_default ON)
199   if(APPLE)
200     # In future, can be used with `quicklookthumbnailing/qlthumbnailreply`
201     # to create file thumbnails for say Finder.
202     # Turn it off for now, even though it can build on APPLE, it's not likely to be useful.
203     set(_option_default OFF)
204   endif()
205   option(WITH_BLENDER_THUMBNAILER "\
206 Build stand-alone \"blender-thumbnailer\" command-line thumbnail extraction utility, \
207 intended for use by file-managers to extract PNG images from `.blend` files."
208     ${_option_default}
209   )
210   unset(_option_default)
211 endif()
213 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
215 option(WITH_PYTHON "Enable Embedded Python API (only disable for development)" ON)
216 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default" ON)
217 # Don't want people disabling this unless they really know what they are doing.
218 mark_as_advanced(WITH_PYTHON)
219 # Some distributions see this as a security issue, rather than have them patch it,
220 # make a build option.
221 mark_as_advanced(WITH_PYTHON_SECURITY)
223 option(WITH_PYTHON_SAFETY "\
224 Enable internal API error checking to track invalid data to prevent crash on access \
225 (at the expense of some efficiency, only enable for development)."
226   OFF
228 mark_as_advanced(WITH_PYTHON_SAFETY)
229 option(WITH_PYTHON_MODULE "\
230 Enable building as a python module which runs without a user interface, \
231 like running regular blender in background mode (only enable for development), \
232 installs to PYTHON_SITE_PACKAGES (or CMAKE_INSTALL_PREFIX if WITH_INSTALL_PORTABLE is enabled)."
233   OFF
236 option(WITH_BUILDINFO "\
237 Include extra build details (only disable for development & faster builds)"
238   ON
240 set(BUILDINFO_OVERRIDE_DATE "" CACHE STRING "\
241 Use instead of the current date for reproducible builds (empty string disables this option)"
243 set(BUILDINFO_OVERRIDE_TIME "" CACHE STRING "\
244 Use instead of the current time for reproducible builds (empty string disables this option)"
246 set(CPACK_OVERRIDE_PACKAGENAME "" CACHE STRING "\
247 Use instead of the standard packagename (empty string disables this option)"
249 mark_as_advanced(CPACK_OVERRIDE_PACKAGENAME)
250 mark_as_advanced(BUILDINFO_OVERRIDE_DATE)
251 mark_as_advanced(BUILDINFO_OVERRIDE_TIME)
253 # CMAKE 3.28.2 has issues with the combination of PCH and unity builds, disable for now.
254 # upstream ticket https://gitlab.kitware.com/cmake/cmake/-/issues/25650
255 if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16" AND NOT ${CMAKE_VERSION} VERSION_EQUAL "3.28.2")
256   option(WITH_UNITY_BUILD "\
257 Enable unity build for modules that support it to improve compile times.\n\
258 WARNING: this option allows files to be built without all necessary headers!\n
259 This option should be disabled before manipulating or removing headers."
260     ON
261   )
262   mark_as_advanced(WITH_UNITY_BUILD)
263 else()
264   set(WITH_UNITY_BUILD OFF)
265 endif()
267 if(COMMAND target_precompile_headers)
268   # Disabling is needed for `./tools/utils_maintenance/code_clean.py` to function.
269   option(WITH_COMPILER_PRECOMPILED_HEADERS "\
270 Use pre-compiled headers to speed up compilation."
271     ON
272   )
273   mark_as_advanced(WITH_COMPILER_PRECOMPILED_HEADERS)
275   if(WITH_CLANG_TIDY AND CMAKE_COMPILER_IS_GNUCC)
276     if(WITH_COMPILER_PRECOMPILED_HEADERS)
277       message(STATUS
278         "Clang-Tidy and GCC precompiled headers are incompatible, disabling precompiled headers"
279       )
280       set(WITH_COMPILER_PRECOMPILED_HEADERS OFF)
281     endif()
282   endif()
284   if(NOT WITH_COMPILER_PRECOMPILED_HEADERS)
285     set(CMAKE_DISABLE_PRECOMPILE_HEADERS ON)
286   endif()
287 endif()
289 option(WITH_IK_ITASC "\
290 Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)"
291   ON
293 option(WITH_IK_SOLVER "\
294 Enable Legacy IK solver (only disable for development)"
295   ON
297 option(WITH_FFTW3 "Enable FFTW3 support (Used for smoke, ocean sim, and audio effects)" ON)
298 option(WITH_PUGIXML "Enable PugiXML support (Used for OpenImageIO, Grease Pencil SVG export)" ON)
299 option(WITH_BULLET "Enable Bullet (Physics Engine)" ON)
300 option(WITH_SYSTEM_BULLET "\
301 Use the systems bullet library (currently unsupported due to missing features in upstream!)"
302   OFF
304 mark_as_advanced(WITH_SYSTEM_BULLET)
305 option(WITH_OPENCOLORIO "Enable OpenColorIO color management" ON)
307 set(_option_default ON)
308 if(APPLE)
309   # There's no OpenXR runtime in sight for macOS, neither is code well
310   # tested there -> disable it by default.
311   set(_option_default OFF)
312 endif()
313 option(WITH_XR_OPENXR "Enable VR features through the OpenXR specification" ${_option_default})
314 if(APPLE)
315   mark_as_advanced(WITH_XR_OPENXR)
316 endif()
317 unset(_option_default)
319 option(WITH_GMP "Enable features depending on GMP (Exact Boolean)" ON)
321 # Compositor
322 option(WITH_COMPOSITOR_CPU "Enable the tile based CPU nodal compositor" ON)
323 option(WITH_OPENIMAGEDENOISE "Enable the OpenImageDenoise compositing node" ON)
325 option(WITH_OPENSUBDIV "Enable OpenSubdiv for surface subdivision" ON)
327 option(WITH_POTRACE "Enable features relying on potrace" ON)
328 option(WITH_OPENVDB "Enable features relying on OpenVDB" ON)
329 option(WITH_OPENVDB_BLOSC "\
330 Enable blosc compression for OpenVDB, only enable if OpenVDB was built with blosc support"
331   ON
333 option(WITH_OPENVDB_3_ABI_COMPATIBLE "\
334 Assume OpenVDB library has been compiled with version 3 ABI compatibility"
335   OFF
337 mark_as_advanced(WITH_OPENVDB_3_ABI_COMPATIBLE)
338 option(WITH_NANOVDB "Enable usage of NanoVDB data structure for rendering on the GPU" ON)
339 option(WITH_HARU "Enable features relying on Libharu (Grease pencil PDF export)" ON)
341 # GHOST Windowing Library Options
342 option(WITH_GHOST_DEBUG "Enable debugging output for the GHOST library" OFF)
343 mark_as_advanced(WITH_GHOST_DEBUG)
345 option(WITH_GHOST_SDL "\
346 Enable building Blender against SDL for windowing rather than the native APIs"
347   OFF
349 mark_as_advanced(WITH_GHOST_SDL)
351 if(UNIX AND NOT (APPLE OR HAIKU))
352   option(WITH_GHOST_X11 "Enable building Blender against X11 for windowing" ON)
353   mark_as_advanced(WITH_GHOST_X11)
355   option(WITH_GHOST_WAYLAND "Enable building Blender against Wayland for windowing" ON)
356   mark_as_advanced(WITH_GHOST_WAYLAND)
358   if(WITH_GHOST_WAYLAND)
359     option(WITH_GHOST_WAYLAND_LIBDECOR "Optionally build with LibDecor window decorations" ON)
360     mark_as_advanced(WITH_GHOST_WAYLAND_LIBDECOR)
362     option(WITH_GHOST_WAYLAND_DYNLOAD "Enable runtime dynamic WAYLAND libraries loading" ON)
363     mark_as_advanced(WITH_GHOST_WAYLAND_DYNLOAD)
365     set(WITH_GHOST_WAYLAND_APP_ID "" CACHE STRING "\
366 The application ID used for Blender (use default when an empty string), \
367 this can be used to differentiate Blender instances by version or branch for example."
368     )
369     mark_as_advanced(WITH_GHOST_WAYLAND_APP_ID)
370   endif()
371 endif()
373 if(WITH_GHOST_X11)
374   option(WITH_GHOST_XDND "Enable drag'n'drop support on X11 using XDND protocol" ON)
375 endif()
377 # Misc...
378 option(WITH_HEADLESS "Build without graphical support (renderfarm, server mode only)" OFF)
379 mark_as_advanced(WITH_HEADLESS)
381 option(WITH_QUADRIFLOW "Build with quadriflow remesher support" ON)
383 option(WITH_AUDASPACE "\
384 Build with blenders audio library (only disable if you know what you're doing!)"
385   ON
387 option(WITH_SYSTEM_AUDASPACE "\
388 Build with external audaspace library installed on the system \
389 (only enable if you know what you're doing!)"
390   OFF
392 mark_as_advanced(WITH_AUDASPACE)
393 mark_as_advanced(WITH_SYSTEM_AUDASPACE)
395 set_and_warn_dependency(WITH_AUDASPACE WITH_SYSTEM_AUDASPACE OFF)
397 option(WITH_OPENMP "Enable OpenMP (has to be supported by the compiler)" ON)
398 if(UNIX AND NOT APPLE)
399   option(WITH_OPENMP_STATIC "Link OpenMP statically (only used by the release environment)" OFF)
400   mark_as_advanced(WITH_OPENMP_STATIC)
401 endif()
403 if(WITH_GHOST_X11)
404   option(WITH_X11_XINPUT "Enable X11 Xinput (tablet support and unicode input)" ON)
405   option(WITH_X11_XF86VMODE "Enable X11 video mode switching" ON)
406   option(WITH_X11_XFIXES "Enable X11 XWayland cursor warping workaround" ON)
407 endif()
409 if(UNIX AND NOT APPLE)
410   option(WITH_SYSTEM_FREETYPE "Use the freetype library provided by the operating system" OFF)
411   option(WITH_SYSTEM_EIGEN3 "Use the systems Eigen3 library" OFF)
412 else()
413   set(WITH_SYSTEM_FREETYPE OFF)
414   set(WITH_SYSTEM_EIGEN3 OFF)
415 endif()
417 if((NOT WITH_PYTHON_MODULE) AND (
418       (WIN32 AND (CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")) OR
419       ((UNIX AND NOT APPLE) AND (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64"))))
420   option(WITH_CPU_CHECK "\
421 Report when a CPU is not compatible on startup \
422 instead of failing to start with an inscrutable error."
423     ON
424   )
425   mark_as_advanced(WITH_CPU_CHECK)
426 else()
427   set(WITH_CPU_CHECK OFF)
428 endif()
430 # Modifiers
431 option(WITH_MOD_FLUID "Enable Mantaflow Fluid Simulation Framework" ON)
432 option(WITH_MOD_REMESH "Enable Remesh Modifier" ON)
433 option(WITH_MOD_OCEANSIM "Enable Ocean Modifier" ON)
435 # Image format support
436 option(WITH_IMAGE_OPENEXR "Enable OpenEXR Support (http://www.openexr.com)" ON)
437 option(WITH_IMAGE_OPENJPEG "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
438 option(WITH_IMAGE_CINEON "Enable CINEON and DPX Image Support" ON)
439 option(WITH_IMAGE_WEBP "Enable WebP Image Support" ON)
441 # Audio/Video format support
442 option(WITH_CODEC_FFMPEG "Enable FFMPeg Support (http://ffmpeg.org)" ON)
443 option(WITH_CODEC_SNDFILE "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" ON)
445 # Alembic support
446 option(WITH_ALEMBIC "Enable Alembic Support" ON)
448 # Universal Scene Description support
449 option(WITH_USD "Enable Universal Scene Description (USD) Support" ON)
451 # MaterialX
452 option(WITH_MATERIALX "Enable MaterialX Support" ON)
454 # Hydra render engine
455 option(WITH_HYDRA "Enable Hydra render engine" ON)
457 # RTL Languages, Complex Shaping, OpenType Features
458 option(WITH_FRIBIDI "Enable features relying on fribidi" OFF)
459 option(WITH_HARFBUZZ "Enable features relying on harfbuzz" OFF)
461 # 3D format support
462 # Disable opencollada when we don't have precompiled libs
463 option(WITH_OPENCOLLADA "Enable OpenCollada Support (http://www.opencollada.org)" ON)
464 option(WITH_IO_WAVEFRONT_OBJ "Enable Wavefront-OBJ 3D file format support (*.obj)" ON)
465 option(WITH_IO_PLY "Enable PLY 3D file format support (*.ply)" ON)
466 option(WITH_IO_STL "Enable STL 3D file format support (*.stl)" ON)
467 option(WITH_IO_GPENCIL "Enable grease-pencil file format IO (*.svg, *.pdf)" ON)
469 # Sound output
470 option(WITH_SDL "Enable SDL for sound" ON)
471 option(WITH_OPENAL "Enable OpenAL Support (http://www.openal.org)" ON)
472 if(APPLE)
473   option(WITH_COREAUDIO "Enable CoreAudio for audio support on macOS" ON)
474 else()
475   set(WITH_COREAUDIO OFF)
476 endif()
477 if(NOT WIN32)
478   set(_option_default ON)
479   if(APPLE)
480     set(_option_default OFF)
481   endif()
482   option(WITH_JACK "Enable JACK Support (http://www.jackaudio.org)" ${_option_default})
483   unset(_option_default)
484   option(WITH_JACK_DYNLOAD "Enable runtime dynamic JACK libraries loading" OFF)
485 else()
486   set(WITH_JACK OFF)
487 endif()
488 if(UNIX AND NOT APPLE)
489   option(WITH_SDL_DYNLOAD "Enable runtime dynamic SDL libraries loading" OFF)
490 endif()
491 if(UNIX AND NOT APPLE)
492   option(WITH_PULSEAUDIO "Enable PulseAudio for audio support on Linux" ON)
493   option(WITH_PULSEAUDIO_DYNLOAD "Enable runtime dynamic PulseAudio libraries loading" OFF)
494 else()
495   set(WITH_PULSEAUDIO OFF)
496 endif()
497 if(WIN32)
498   option(WITH_WASAPI "Enable Windows Audio Sessions API for audio support on Windows" ON)
499 else()
500   set(WITH_WASAPI OFF)
501 endif()
503 # Compression
504 option(WITH_LZO "Enable fast LZO compression (used for pointcache)" ON)
505 option(WITH_LZMA "Enable best LZMA compression, (used for pointcache)" ON)
506 if(UNIX AND NOT APPLE)
507   option(WITH_SYSTEM_LZO "Use the system LZO library" OFF)
508 endif()
509 option(WITH_DRACO "Enable Draco mesh compression Python module (used for glTF)" ON)
511 # Camera/motion tracking
512 option(WITH_LIBMV "Enable Libmv structure from motion library" ON)
513 option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." ON)
514 mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
516 # Logging/unbit test libraries.
517 option(WITH_SYSTEM_GFLAGS "Use system-wide Gflags instead of a bundled one" OFF)
518 option(WITH_SYSTEM_GLOG "Use system-wide Glog instead of a bundled one" OFF)
519 mark_as_advanced(WITH_SYSTEM_GFLAGS)
520 mark_as_advanced(WITH_SYSTEM_GLOG)
522 # Freestyle
523 option(WITH_FREESTYLE "Enable Freestyle (advanced edges rendering)" ON)
525 # Libraries.
526 if(UNIX AND NOT APPLE)
527   # Optionally build without pre-compiled libraries.
528   # NOTE: this could be supported on all platforms however in practice UNIX is the only platform
529   # that has good support for detecting installed libraries.
530   option(WITH_LIBS_PRECOMPILED "\
531 Detect and link against pre-compiled libraries (typically found under \"../lib/\"). \
532 Disabling this option will use the system libraries although cached paths \
533 that point to pre-compiled libraries will be left as-is."
534     ON
535   )
536   mark_as_advanced(WITH_LIBS_PRECOMPILED)
538   option(WITH_STATIC_LIBS "\
539 Try to link with static libraries, as much as possible, \
540 to make blender more portable across distributions"
541     OFF
542   )
543   if(WITH_STATIC_LIBS)
544     option(WITH_BOOST_ICU "\
545 Boost uses ICU library (required for linking with static Boost built with libicu)."
546       OFF
547     )
548     mark_as_advanced(WITH_BOOST_ICU)
549   endif()
550 endif()
552 # Misc
553 if(WIN32 OR APPLE OR ((UNIX AND (NOT HAIKU)) AND WITH_GHOST_WAYLAND))
554   option(WITH_INPUT_IME "Enable Input Method Editor (IME) for complex Asian character input" ON)
555 else()
556   set(WITH_INPUT_IME OFF)
557 endif()
558 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
559 # On Windows and for the Blender application on macOS, portable install
560 # is the only supported installation type, so there is no option.
561 if(UNIX AND (NOT APPLE OR WITH_PYTHON_MODULE))
562   option(WITH_INSTALL_PORTABLE "\
563 Install redistributable runtime, otherwise install into CMAKE_INSTALL_PREFIX"
564     ON
565   )
566 endif()
568 option(WITH_PYTHON_INSTALL "Copy system python into the blender install folder" ON)
570 option(WITH_INSTALL_COPYRIGHT "\
571 Copy the official Blender Authors's copyright.txt into the Blender install folder"
572   OFF
574 mark_as_advanced(WITH_INSTALL_COPYRIGHT)
576 if((WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE) OR WITH_MOD_FLUID)
577   option(WITH_PYTHON_NUMPY "Include NumPy in Blender (used by Audaspace and Mantaflow)" ON)
578 endif()
580 if(WIN32 OR APPLE)
581   # Windows and macOS have this bundled with Python libraries.
582 elseif(WITH_PYTHON_INSTALL OR WITH_PYTHON_NUMPY)
583   set(PYTHON_NUMPY_PATH "" CACHE PATH "\
584 Path to python site-packages or dist-packages containing 'numpy' module"
585   )
586   mark_as_advanced(PYTHON_NUMPY_PATH)
587   set(PYTHON_NUMPY_INCLUDE_DIRS "" CACHE PATH "Path to the include directory of the NumPy module")
588   mark_as_advanced(PYTHON_NUMPY_INCLUDE_DIRS)
589 endif()
590 if(WITH_PYTHON_INSTALL)
591   option(WITH_PYTHON_INSTALL_NUMPY "Copy system NumPy into the blender install folder" ON)
593   if(UNIX AND NOT APPLE)
594     option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
595     set(PYTHON_REQUESTS_PATH "" CACHE PATH "\
596 Path to python site-packages or dist-packages containing 'requests' module"
597     )
598     mark_as_advanced(PYTHON_REQUESTS_PATH)
599   endif()
601   option(WITH_PYTHON_INSTALL_ZSTANDARD "Copy zstandard into the blender install folder" ON)
602   set(PYTHON_ZSTANDARD_PATH "" CACHE PATH "\
603 Path to python site-packages or dist-packages containing 'zstandard' module"
604   )
605   mark_as_advanced(PYTHON_ZSTANDARD_PATH)
606 endif()
608 option(WITH_CPU_SIMD "Enable SIMD instruction if they're detected on the host machine" ON)
609 mark_as_advanced(WITH_CPU_SIMD)
611 # Cycles
612 option(WITH_CYCLES "Enable Cycles Render Engine" ON)
613 option(WITH_CYCLES_OSL "Build Cycles with OpenShadingLanguage support" ON)
614 option(WITH_CYCLES_PATH_GUIDING "Build Cycles with path guiding support" ON)
615 option(WITH_CYCLES_EMBREE "Build Cycles with Embree support" ON)
616 option(WITH_CYCLES_LOGGING "Build Cycles with logging support" ON)
617 option(WITH_CYCLES_DEBUG "Build Cycles with options useful for debugging (e.g., MIS)" OFF)
619 option(WITH_CYCLES_STANDALONE "Build Cycles standalone application" OFF)
620 option(WITH_CYCLES_STANDALONE_GUI "Build Cycles standalone with GUI" OFF)
621 option(WITH_CYCLES_PRECOMPUTE "Build Cycles data precomputation tool" OFF)
623 option(WITH_CYCLES_HYDRA_RENDER_DELEGATE "Build Cycles Hydra render delegate" OFF)
625 option(WITH_CYCLES_DEBUG_NAN "\
626 Build Cycles with additional asserts for detecting NaNs and invalid values"
627   OFF
629 option(WITH_CYCLES_NATIVE_ONLY "\
630 Build Cycles with native kernel only (which fits current CPU, use for development only)"
631   OFF
633 option(WITH_CYCLES_KERNEL_ASAN "\
634 Build Cycles kernels with address sanitizer when WITH_COMPILER_ASAN is on, even if it's very slow"
635   OFF
637 set(CYCLES_TEST_DEVICES CPU CACHE STRING "\
638 Run regression tests on the specified device types (CPU CUDA OPTIX HIP)"
640 mark_as_advanced(WITH_CYCLES_KERNEL_ASAN)
641 mark_as_advanced(WITH_CYCLES_LOGGING)
642 mark_as_advanced(WITH_CYCLES_DEBUG_NAN)
643 mark_as_advanced(WITH_CYCLES_NATIVE_ONLY)
644 mark_as_advanced(WITH_CYCLES_PRECOMPUTE)
645 mark_as_advanced(CYCLES_TEST_DEVICES)
647 # NVIDIA CUDA & OptiX
648 if(NOT APPLE AND NOT (WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64"))
649   option(WITH_CYCLES_DEVICE_CUDA "Enable Cycles NVIDIA CUDA compute support" ON)
650   option(WITH_CYCLES_DEVICE_OPTIX "Enable Cycles NVIDIA OptiX support" ON)
651   mark_as_advanced(WITH_CYCLES_DEVICE_CUDA)
653   option(WITH_CYCLES_CUDA_BINARIES "Build Cycles NVIDIA CUDA binaries" OFF)
654   set(CYCLES_CUDA_BINARIES_ARCH
655     sm_30 sm_35 sm_37 sm_50 sm_52 sm_60 sm_61 sm_70 sm_75 sm_86 sm_89 compute_75
656     CACHE STRING "CUDA architectures to build binaries for"
657   )
658   option(WITH_CYCLES_CUDA_BUILD_SERIAL "\
659 Build cubins one after another (useful on machines with limited RAM)"
660     OFF
661   )
662   option(WITH_CUDA_DYNLOAD "\
663 Dynamically load CUDA libraries at runtime (for developers, makes cuda-gdb work)"
664     ON
665   )
667   set(OPTIX_ROOT_DIR "" CACHE PATH "\
668 Path to the OptiX SDK root directory, for building Cycles OptiX kernels."
669   )
670   set(CYCLES_RUNTIME_OPTIX_ROOT_DIR "" CACHE PATH "\
671 Path to the OptiX SDK root directory. \
672 When set, this path will be used at runtime to compile OptiX kernels."
673   )
675   mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
676   mark_as_advanced(WITH_CYCLES_CUDA_BUILD_SERIAL)
677   mark_as_advanced(WITH_CUDA_DYNLOAD)
678   mark_as_advanced(OPTIX_ROOT_DIR)
679   mark_as_advanced(CYCLES_RUNTIME_OPTIX_ROOT_DIR)
680 endif()
682 # AMD HIP
683 if(NOT APPLE AND NOT (WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64"))
684   option(WITH_CYCLES_DEVICE_HIP "Enable Cycles AMD HIP support" ON)
685   option(WITH_CYCLES_HIP_BINARIES "Build Cycles AMD HIP binaries" OFF)
686   # Radeon VII (gfx906) not currently working with HIP SDK, so left out of the list.
687   set(CYCLES_HIP_BINARIES_ARCH
688     gfx900 gfx90c gfx902
689     gfx1010 gfx1011 gfx1012
690     gfx1030 gfx1031 gfx1032 gfx1034 gfx1035 gfx1036
691     gfx1100 gfx1101 gfx1102 gfx1103
692     CACHE STRING "AMD HIP architectures to build binaries for"
693   )
694   mark_as_advanced(WITH_CYCLES_DEVICE_HIP)
695   mark_as_advanced(CYCLES_HIP_BINARIES_ARCH)
697   # HIPRT is only available on Windows for now.
698   if(WIN32)
699     option(WITH_CYCLES_DEVICE_HIPRT "Enable Cycles AMD HIPRT support" OFF)
700     mark_as_advanced(WITH_CYCLES_DEVICE_HIPRT)
701   endif()
702 endif()
704 # Apple Metal
705 if(APPLE)
706   option(WITH_CYCLES_DEVICE_METAL "Enable Cycles Apple Metal compute support" ON)
707 endif()
709 # oneAPI
710 if(NOT APPLE AND NOT (WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64"))
711   option(WITH_CYCLES_DEVICE_ONEAPI "Enable Cycles oneAPI compute support" OFF)
712   option(WITH_CYCLES_ONEAPI_BINARIES "\
713 Enable Ahead-Of-Time compilation for Cycles oneAPI device"
714     OFF
715   )
716   option(WITH_CYCLES_ONEAPI_HOST_TASK_EXECUTION "\
717 Switch target of oneAPI implementation from SYCL devices to Host Task (single thread on CPU). \
718 This option is only for debugging purposes."
719     OFF
720   )
722   # https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compilation/ahead-of-time-compilation.html
723   # The target architectures levels can be retrieved from `ocloc` output when running
724   # `ocloc compile -device {device_id} test.c` for given GPUs PCI device IDs.
725   # 12.55.8 is for Arc Alchemist GPUs. 12.70.0 for Meteor Lake iGPUs.
726   set(CYCLES_ONEAPI_INTEL_BINARIES_ARCH 12.55.8 12.70.0 CACHE STRING "\
727 oneAPI Intel GPU architectures to build binaries for"
728   )
729   set(CYCLES_ONEAPI_SYCL_TARGETS spir64 spir64_gen CACHE STRING "\
730 oneAPI targets to build AOT binaries for"
731   )
733   mark_as_advanced(WITH_CYCLES_ONEAPI_HOST_TASK_EXECUTION)
734   mark_as_advanced(CYCLES_ONEAPI_INTEL_BINARIES_ARCH)
735   mark_as_advanced(CYCLES_ONEAPI_SYCL_TARGETS)
736 endif()
738 # Draw Manager
739 option(WITH_DRAW_DEBUG "Add extra debug capabilities to Draw Manager" OFF)
740 mark_as_advanced(WITH_DRAW_DEBUG)
742 # LLVM
743 option(WITH_LLVM "Use LLVM" OFF)
744 option(LLVM_STATIC "Link with LLVM static libraries" OFF)
745 mark_as_advanced(LLVM_STATIC)
746 option(WITH_CLANG "Use Clang" OFF)
748 # disable for now, but plan to support on all platforms eventually
749 option(WITH_MEM_JEMALLOC "Enable malloc replacement (http://www.canonware.com/jemalloc)" ON)
750 mark_as_advanced(WITH_MEM_JEMALLOC)
752 # currently only used for BLI_mempool
753 option(WITH_MEM_VALGRIND "Enable extended valgrind support for better reporting" OFF)
754 mark_as_advanced(WITH_MEM_VALGRIND)
756 # Debug
757 option(WITH_CXX_GUARDEDALLOC "\
758 Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)"
759   OFF
761 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
763 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" ON)
764 mark_as_advanced(WITH_ASSERT_ABORT)
766 option(WITH_ASSERT_RELEASE "Build with asserts enabled even for non-debug configurations" OFF)
767 mark_as_advanced(WITH_ASSERT_RELEASE)
769 if((UNIX AND NOT APPLE) OR (CMAKE_GENERATOR MATCHES "^Visual Studio.+"))
770   option(WITH_CLANG_TIDY "\
771 Use Clang Tidy to analyze the source code \
772 (only enable for development on Linux using Clang, or Windows using the Visual Studio IDE)"
773     OFF
774   )
775   mark_as_advanced(WITH_CLANG_TIDY)
776 endif()
778 option(WITH_BOOST "Enable features depending on boost" ON)
779 option(WITH_TBB "\
780 Enable multi-threading. TBB is also required for features such as Cycles, OpenVDB and USD"
781   ON
784 # TBB malloc is only supported on for windows currently
785 if(WIN32)
786   option(WITH_TBB_MALLOC_PROXY "Enable the TBB malloc replacement" ON)
787 endif()
789 option(WITH_EXPERIMENTAL_FEATURES "Enable experimental features" ON)
791 # This should be turned off when Blender enter beta/rc/release
792 if("${BLENDER_VERSION_CYCLE}" STREQUAL "alpha" AND WITH_EXPERIMENTAL_FEATURES)
793   set(WITH_EXPERIMENTAL_FEATURES ON)
794 else()
795   set(WITH_EXPERIMENTAL_FEATURES OFF)
796 endif()
798 # Unit testing
799 option(WITH_GTESTS "Enable GTest unit testing" OFF)
800 option(WITH_GPU_RENDER_TESTS "\
801 Enable GPU render related unit testing (EEVEE, Workbench and Grease Pencil)"
802   OFF
804 option(WITH_GPU_RENDER_TESTS_SILENT "\
805 Run GPU render tests silently (finished tests will pass). \
806 Generated report will show failing tests"
807   ON
809 option(WITH_GPU_DRAW_TESTS "\
810 Enable GPU drawing related unit testing (GPU backends and draw manager)"
811   OFF
813 option(WITH_COMPOSITOR_REALTIME_TESTS "Enable regression testing for realtime compositor" OFF)
814 if(UNIX AND NOT (APPLE OR HAIKU))
815   option(WITH_UI_TESTS "\
816 Enable user-interface tests using a headless display server. \
817 Currently this depends on WITH_GHOST_WAYLAND and the weston compositor \
818 (Experimental)"
819     OFF
820   )
821 else()
822   # TODO: support running GUI tests on other platforms.
823   set(WITH_UI_TESTS OFF)
824 endif()
826 # Enabled by default for typical use cases to speed up development cycles. However, when looking
827 # into threading or memory related issues (in dependency graph, out-of-bounds, etc) forcing single
828 # test per Blender instance could give much better clues about the root of the problem.
829 option(WITH_TESTS_BATCHED "\
830 Run multiple tests in a single Blender invocation, for faster test execution"
831   ON
833 mark_as_advanced(WITH_TESTS_BATCHED)
835 option(WITH_TESTS_SINGLE_BINARY "\
836 Link GTest tests into a single binary. \
837 For faster overall build and less disk space, but slower individual test build"
838   ON
840 mark_as_advanced(WITH_TESTS_SINGLE_BINARY)
842 # NOTE: All callers of this must add `TEST_PYTHON_EXE_EXTRA_ARGS` before any other arguments.
843 set(TEST_PYTHON_EXE "" CACHE PATH "Python executable to run unit tests")
844 mark_as_advanced(TEST_PYTHON_EXE)
846 # Documentation
847 if(UNIX AND NOT APPLE)
848   option(WITH_DOC_MANPAGE "Create a manual page (Unix manpage)" OFF)
849 endif()
852 # GPU Module
853 option(WITH_GPU_BUILDTIME_SHADER_BUILDER "\
854 Shader builder is a developer option enabling linting on GLSL during compilation"
855   OFF
857 option(WITH_RENDERDOC "Use Renderdoc API to capture frames" OFF)
859 mark_as_advanced(
860   WITH_GPU_BUILDTIME_SHADER_BUILDER
861   WITH_RENDERDOC
864 # OpenGL
865 if(NOT APPLE)
866   option(WITH_OPENGL_BACKEND "Enable OpenGL support as graphic backend" ON)
867   mark_as_advanced(WITH_OPENGL_BACKEND)
868 else()
869   set(WITH_OPENGL_BACKEND OFF)
870 endif()
872 # Vulkan
873 if(NOT APPLE)
874   option(WITH_VULKAN_BACKEND "Enable Vulkan as graphics backend (experimental)" ON)
875   option(WITH_VULKAN_GUARDEDALLOC "\
876 Use guardedalloc for host allocations done inside Vulkan (development option)"
877     OFF
878   )
879   mark_as_advanced(
880     WITH_VULKAN_BACKEND
881     WITH_VULKAN_GUARDEDALLOC
882   )
883   if(NOT WITH_EXPERIMENTAL_FEATURES)
884     set(WITH_VULKAN_BACKEND OFF)
885   endif()
886 endif()
888 # Metal
889 if(APPLE)
890   option(WITH_METAL_BACKEND "\
891 Use Metal for graphics instead of (or as well as) OpenGL on macOS."
892     ON
893   )
894   mark_as_advanced(WITH_METAL_BACKEND)
895 else()
896   set(WITH_METAL_BACKEND OFF)
897 endif()
899 if(WIN32)
900   getDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
901   set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
902 endif()
904 option(WITH_STRSIZE_DEBUG "\
905 Ensure string operations on fixed size buffers \
906 (works well with with \"WITH_COMPILER_ASAN\" & valgrind to detect incorrect buffer size arguments)"
907   OFF)
908 mark_as_advanced(WITH_STRSIZE_DEBUG)
910 # Compiler tool-chain.
911 if(UNIX)
912   if(CMAKE_COMPILER_IS_GNUCC)
913     option(WITH_LINKER_GOLD "Use ld.gold linker which is usually faster than ld.bfd" ON)
914     mark_as_advanced(WITH_LINKER_GOLD)
915   endif()
916   if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
917     option(WITH_LINKER_LLD "Use ld.lld linker which is usually faster than ld.gold" OFF)
918     mark_as_advanced(WITH_LINKER_LLD)
919     option(WITH_LINKER_MOLD "Use ld.mold linker which is usually faster than ld.gold & ld.lld" OFF)
920     mark_as_advanced(WITH_LINKER_MOLD)
921   endif()
922 endif()
924 option(WITH_COMPILER_ASAN "\
925 Build and link against address sanitizer (only for Debug & RelWithDebInfo targets)."
926   OFF
928 mark_as_advanced(WITH_COMPILER_ASAN)
929 option(WITH_COMPILER_ASAN_EXTERN "\
930 Build `extern` dependencies with address sanitizer when WITH_COMPILER_ASAN is on. \
931 Can cause linking issues due to too large binary size."
932   OFF
934 mark_as_advanced(WITH_COMPILER_ASAN_EXTERN)
936 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
937   if(WITH_COMPILER_ASAN)
938     set(_asan_defaults "\
939 -fsanitize=address \
940 -fsanitize=bool \
941 -fsanitize=bounds \
942 -fsanitize=enum \
943 -fsanitize=float-cast-overflow \
944 -fsanitize=float-divide-by-zero \
945 -fsanitize=nonnull-attribute \
946 -fsanitize=returns-nonnull-attribute \
947 -fsanitize=signed-integer-overflow \
948 -fsanitize=undefined \
949 -fsanitize=vla-bound \
950 -fno-sanitize=alignment \
953     if(MSVC)
954       # clang-cl doesn't support all sanitizers, but leak and object-size give errors/warnings.
955       set(_asan_defaults "${_asan_defaults}")
956     elseif(APPLE)
957       # AppleClang doesn't support all sanitizers, but leak gives error.
958       # Build type is not known for multi-config generator, so don't add object-size sanitizer.
959       if(CMAKE_BUILD_TYPE MATCHES "Debug" OR GENERATOR_IS_MULTI_CONFIG)
960         # Silence the warning that object-size is not effective in -O0.
961         set(_asan_defaults "${_asan_defaults}")
962       else()
963         string(APPEND _asan_defaults " -fsanitize=object-size")
964       endif()
965     elseif(CMAKE_COMPILER_IS_GNUCC)
966       string(APPEND _asan_defaults " -fsanitize=leak -fsanitize=object-size")
967     else()
968       string(APPEND _asan_defaults " -fsanitize=leak")
969     endif()
971     set(COMPILER_ASAN_CFLAGS "${_asan_defaults}" CACHE STRING "C flags for address sanitizer")
972     mark_as_advanced(COMPILER_ASAN_CFLAGS)
973     set(COMPILER_ASAN_CXXFLAGS "${_asan_defaults}" CACHE STRING "C++ flags for address sanitizer")
974     mark_as_advanced(COMPILER_ASAN_CXXFLAGS)
976     unset(_asan_defaults)
978     if(MSVC)
979       find_library(
980         COMPILER_ASAN_LIBRARY NAMES clang_rt.asan-x86_64
981         PATHS
982         [HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\LLVM\\LLVM;]/lib/clang/7.0.0/lib/windows
983         [HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\LLVM\\LLVM;]/lib/clang/6.0.0/lib/windows
984       )
985       mark_as_advanced(COMPILER_ASAN_LIBRARY)
986     elseif(APPLE)
987       execute_process(COMMAND ${CMAKE_CXX_COMPILER}
988         -print-file-name=lib
989         OUTPUT_VARIABLE CLANG_LIB_DIR
990       )
991       string(STRIP "${CLANG_LIB_DIR}" CLANG_LIB_DIR)
992       find_library(
993         COMPILER_ASAN_LIBRARY
994         NAMES
995           libclang_rt.asan_osx_dynamic.dylib
996         PATHS
997           "${CLANG_LIB_DIR}/darwin/"
998       )
999       unset(CLANG_LIB_DIR)
1000       mark_as_advanced(COMPILER_ASAN_LIBRARY)
1001     elseif(CMAKE_COMPILER_IS_GNUCC)
1002       find_library(
1003         COMPILER_ASAN_LIBRARY asan ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}
1004       )
1005       mark_as_advanced(COMPILER_ASAN_LIBRARY)
1006     endif()
1008   endif()
1009 endif()
1011 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
1012   option(WITH_COMPILER_SHORT_FILE_MACRO "\
1013 Make paths in macros like __FILE__ relative to top level source and build directories."
1014     ON
1015   )
1016   mark_as_advanced(WITH_COMPILER_SHORT_FILE_MACRO)
1017 endif()
1019 if(WIN32)
1020   # Use hardcoded paths or find_package to find externals
1021   option(WITH_WINDOWS_FIND_MODULES "Use find_package to locate libraries" OFF)
1022   mark_as_advanced(WITH_WINDOWS_FIND_MODULES)
1024   option(WINDOWS_PYTHON_DEBUG "\
1025 Include the files needed for debugging python scripts with visual studio 2017+."
1026     OFF
1027   )
1028   mark_as_advanced(WINDOWS_PYTHON_DEBUG)
1030   option(WITH_WINDOWS_BUNDLE_CRT "Bundle the C runtime for install free distribution." ON)
1031   mark_as_advanced(WITH_WINDOWS_BUNDLE_CRT)
1033   option(WITH_WINDOWS_SCCACHE "Use sccache to speed up builds (Ninja builder only)" OFF)
1034   mark_as_advanced(WITH_WINDOWS_SCCACHE)
1036   option(WITH_WINDOWS_RELEASE_PDB "\
1037 Generate a pdb file for client side stacktraces for release builds"
1038     ON
1039   )
1040   mark_as_advanced(WITH_WINDOWS_RELEASE_PDB)
1042   option(WITH_WINDOWS_RELEASE_STRIPPED_PDB "Use a stripped PDB file for release builds" ON)
1043   mark_as_advanced(WITH_WINDOWS_RELEASE_STRIPPED_PDB)
1045 endif()
1047 if(WIN32 OR XCODE)
1048   option(IDE_GROUP_SOURCES_IN_FOLDERS "\
1049 Organize the source files in filters matching the source folders."
1050     ON
1051   )
1052   mark_as_advanced(IDE_GROUP_SOURCES_IN_FOLDERS)
1054   option(IDE_GROUP_PROJECTS_IN_FOLDERS "\
1055 Organize the projects according to source folder structure."
1056     ON
1057   )
1058   mark_as_advanced(IDE_GROUP_PROJECTS_IN_FOLDERS)
1060   if(IDE_GROUP_PROJECTS_IN_FOLDERS)
1061     set_property(GLOBAL PROPERTY USE_FOLDERS ON)
1062   endif()
1063 endif()
1065 if(UNIX)
1066   # See WITH_WINDOWS_SCCACHE for Windows.
1067   option(WITH_COMPILER_CCACHE "\
1068 Use ccache to improve rebuild times (Works with Ninja, Makefiles and Xcode)"
1069     OFF
1070   )
1071   mark_as_advanced(WITH_COMPILER_CCACHE)
1072 endif()
1074 # The following only works with the Ninja generator in CMake >= 3.0.
1075 if("${CMAKE_GENERATOR}" MATCHES "Ninja")
1076   option(WITH_NINJA_POOL_JOBS "\
1077 Enable Ninja pools of jobs, to try to ease building on machines with 16GB of RAM or less \
1078 (if not yet defined, will try to set best values based on detected machine specifications)."
1079     ON
1080   )
1081   mark_as_advanced(WITH_NINJA_POOL_JOBS)
1082 endif()
1084 # Installation process.
1085 set(POSTINSTALL_SCRIPT "" CACHE FILEPATH "Run given CMake script after installation process")
1086 mark_as_advanced(POSTINSTALL_SCRIPT)
1088 set(POSTCONFIGURE_SCRIPT "" CACHE FILEPATH "\
1089 Run given CMake script as the last step of CMake configuration"
1091 mark_as_advanced(POSTCONFIGURE_SCRIPT)
1093 # end option(...)
1097 # By default we want to install to the directory we are compiling our executables
1098 # unless specified otherwise, which we currently do not allow
1099 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
1100   if(WIN32)
1101     set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "\
1102 default install path"
1103       FORCE
1104     )
1105   elseif(APPLE)
1106     set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "\
1107 default install path"
1108       FORCE
1109     )
1110   else()
1111     if(WITH_INSTALL_PORTABLE)
1112       set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH} CACHE PATH "default install path" FORCE)
1113     endif()
1114   endif()
1115 endif()
1117 # Effective install path including config folder, as a generator expression.
1118 get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
1119 if(GENERATOR_IS_MULTI_CONFIG)
1120   string(
1121     REPLACE "\${BUILD_TYPE}" "$<CONFIG>"
1122     CMAKE_INSTALL_PREFIX_WITH_CONFIG ${CMAKE_INSTALL_PREFIX}
1123   )
1124 else()
1125   string(
1126     REPLACE "\${BUILD_TYPE}" ""
1127     CMAKE_INSTALL_PREFIX_WITH_CONFIG ${CMAKE_INSTALL_PREFIX}
1128   )
1129 endif()
1132 # Apple
1134 if(APPLE)
1135   include(platform_apple_xcode)
1136 endif()
1139 # -----------------------------------------------------------------------------
1140 # Check for Conflicting/Unsupported Configurations
1142 option(WITH_STRICT_BUILD_OPTIONS "\
1143 When requirements for a build option are not met, error instead of disabling the option."
1144   OFF
1147 if(NOT WITH_BLENDER AND NOT WITH_CYCLES_STANDALONE AND NOT WITH_CYCLES_HYDRA_RENDER_DELEGATE)
1148   message(FATAL_ERROR
1149     "At least one of WITH_BLENDER or WITH_CYCLES_STANDALONE "
1150     "or WITH_CYCLES_HYDRA_RENDER_DELEGATE "
1151     "must be enabled, nothing to do!"
1152   )
1153 endif()
1155 set_and_warn_dependency(WITH_AUDASPACE WITH_OPENAL OFF)
1156 set_and_warn_dependency(WITH_AUDASPACE WITH_COREAUDIO OFF)
1157 set_and_warn_dependency(WITH_AUDASPACE WITH_JACK OFF)
1158 set_and_warn_dependency(WITH_AUDASPACE WITH_PULSEAUDIO OFF)
1159 set_and_warn_dependency(WITH_AUDASPACE WITH_WASAPI OFF)
1161 if(NOT WITH_SDL AND WITH_GHOST_SDL)
1162   message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
1163 endif()
1165 # python module, needs some different options
1166 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
1167   message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
1168 endif()
1170 set_and_warn_dependency(WITH_PYTHON WITH_CYCLES        OFF)
1171 set_and_warn_dependency(WITH_PYTHON WITH_DRACO         OFF)
1172 set_and_warn_dependency(WITH_PYTHON WITH_MOD_FLUID     OFF)
1174 if(WITH_DRACO AND NOT WITH_PYTHON_INSTALL)
1175   message(STATUS "WITH_DRACO requires WITH_PYTHON_INSTALL to be ON, disabling WITH_DRACO for now")
1176   set(WITH_DRACO OFF)
1177 endif()
1179 # enable boost for cycles, audaspace or i18n
1180 # otherwise if the user disabled
1182 set_and_warn_dependency(WITH_BOOST WITH_INTERNATIONAL  OFF)
1183 set_and_warn_dependency(WITH_BOOST WITH_OPENVDB        OFF)
1184 set_and_warn_dependency(WITH_BOOST WITH_QUADRIFLOW     OFF)
1185 set_and_warn_dependency(WITH_BOOST WITH_USD            OFF)
1186 if(WITH_CYCLES)
1187   set_and_warn_dependency(WITH_BOOST   WITH_CYCLES_OSL   OFF)
1188   set_and_warn_dependency(WITH_PUGIXML WITH_CYCLES_OSL   OFF)
1189 endif()
1191 set_and_warn_dependency(WITH_TBB WITH_CYCLES            OFF)
1192 set_and_warn_dependency(WITH_TBB WITH_USD               OFF)
1193 set_and_warn_dependency(WITH_TBB WITH_OPENVDB           OFF)
1194 set_and_warn_dependency(WITH_TBB WITH_MOD_FLUID         OFF)
1196 # NanoVDB requires OpenVDB to convert the data structure
1197 set_and_warn_dependency(WITH_OPENVDB WITH_NANOVDB       OFF)
1199 # OpenVDB, Alembic and OSL uses 'half' or 'imath' from OpenEXR
1200 set_and_warn_dependency(WITH_IMAGE_OPENEXR WITH_OPENVDB OFF)
1201 set_and_warn_dependency(WITH_IMAGE_OPENEXR WITH_ALEMBIC OFF)
1202 set_and_warn_dependency(WITH_IMAGE_OPENEXR WITH_CYCLES_OSL OFF)
1204 # Hydra requires USD.
1205 set_and_warn_dependency(WITH_USD WITH_HYDRA OFF)
1207 if(NOT WITH_CYCLES)
1208   set(WITH_CYCLES_OSL OFF)
1209 endif()
1211 # don't store paths to libs for portable distribution
1212 if(WITH_INSTALL_PORTABLE)
1213   set(CMAKE_SKIP_BUILD_RPATH TRUE)
1214 endif()
1216 if(UNIX AND NOT (APPLE OR HAIKU))
1217   set_and_warn_incompatible(WITH_HEADLESS WITH_GHOST_WAYLAND OFF)
1218   set_and_warn_incompatible(WITH_HEADLESS WITH_GHOST_X11 OFF)
1219 endif()
1220 set_and_warn_incompatible(WITH_HEADLESS WITH_GHOST_SDL OFF)
1222 if(WITH_INPUT_IME)
1223   set_and_warn_incompatible(WITH_HEADLESS WITH_INPUT_IME OFF)
1224   set_and_warn_incompatible(WITH_GHOST_SDL WITH_INPUT_IME OFF)
1225 endif()
1227 set_and_warn_incompatible(WITH_HEADLESS WITH_XR_OPENXR OFF)
1228 set_and_warn_incompatible(WITH_GHOST_SDL WITH_XR_OPENXR OFF)
1230 if(WITH_UI_TESTS)
1231   set_and_warn_dependency(WITH_GHOST_WAYLAND WITH_UI_TESTS OFF)
1232 endif()
1234 if(WITH_BUILDINFO)
1235   find_package(Git)
1236   set_and_warn_library_found("Git" GIT_FOUND WITH_BUILDINFO)
1237 endif()
1239 if(WITH_AUDASPACE)
1240   if(NOT WITH_SYSTEM_AUDASPACE)
1241     set(AUDASPACE_C_INCLUDE_DIRS
1242       "${CMAKE_SOURCE_DIR}/extern/audaspace/bindings/C"
1243       "${CMAKE_BINARY_DIR}/extern/audaspace"
1244     )
1245     set(AUDASPACE_PY_INCLUDE_DIRS
1246       "${CMAKE_SOURCE_DIR}/extern/audaspace/bindings"
1247     )
1248   endif()
1249 endif()
1251 # Auto-enable CUDA dynload if toolkit is not found.
1252 if(WITH_CYCLES AND WITH_CYCLES_DEVICE_CUDA AND NOT WITH_CUDA_DYNLOAD)
1253   find_package(CUDA)
1254   if(NOT CUDA_FOUND)
1255     message(
1256       STATUS
1257       "CUDA toolkit not found, "
1258       "using dynamic runtime loading of libraries (WITH_CUDA_DYNLOAD) instead"
1259     )
1260     set(WITH_CUDA_DYNLOAD ON)
1261   endif()
1262 endif()
1264 if(WITH_CYCLES_DEVICE_HIP)
1265   # Currently HIP must be dynamically loaded, this may change in future toolkits
1266   set(WITH_HIP_DYNLOAD ON)
1267 endif()
1270 # -----------------------------------------------------------------------------
1271 # Check if Sub-modules are Cloned
1273 if(WITH_PYTHON)
1274   # While we have this as an '#error' in 'bpy_capi_utils.h',
1275   # upgrading Python tends to cause confusion for users who build.
1276   # Give the error message early to make this more obvious.
1277   #
1278   # Do this before main 'platform_*' checks,
1279   # because UNIX will search for the old Python paths which may not exist.
1280   # giving errors about missing paths before this case is met.
1281   if(DEFINED PYTHON_VERSION AND "${PYTHON_VERSION}" VERSION_LESS "3.11")
1282     message(
1283       FATAL_ERROR
1284       "At least Python 3.11 is required to build, but found Python ${PYTHON_VERSION}"
1285     )
1286   endif()
1288   file(GLOB RESULT "${CMAKE_SOURCE_DIR}/scripts/addons")
1289   list(LENGTH RESULT DIR_LEN)
1290   if(DIR_LEN EQUAL 0)
1291     message(
1292       WARNING
1293       "Addons path '${CMAKE_SOURCE_DIR}/scripts/addons' is missing. "
1294       "This is an external repository which needs to be checked out. Use `make update` to do so. "
1295       "* CONTINUING WITHOUT ADDONS *"
1296     )
1297   endif()
1298 endif()
1301 # -----------------------------------------------------------------------------
1302 # InitialIze Un-cached Vars, Avoid Unused Warning
1304 # linux only, not cached
1305 set(WITH_BINRELOC OFF)
1307 # MACOSX only, set to avoid uninitialized
1308 set(EXETYPE "")
1310 # C/C++ flags
1311 set(PLATFORM_CFLAGS)
1313 # these are added to later on.
1314 set(C_WARNINGS)
1315 set(CXX_WARNINGS)
1317 # NOTE: These flags are intended for situations where where it's impractical to
1318 # suppress warnings by modifying the code or for code which is maintained externally.
1319 # For GCC this typically means adding `-Wno-*` arguments to negate warnings
1320 # that are useful in the general case.
1321 set(C_REMOVE_STRICT_FLAGS)
1322 set(CXX_REMOVE_STRICT_FLAGS)
1324 # Libraries to link to targets in setup_platform_linker_libs
1325 set(PLATFORM_LINKLIBS "")
1327 # Added to target linker flags in setup_platform_linker_flags
1328 # - CMAKE_EXE_LINKER_FLAGS
1329 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
1330 set(PLATFORM_LINKFLAGS "")
1331 set(PLATFORM_LINKFLAGS_DEBUG "")
1332 set(PLATFORM_LINKFLAGS_RELEASE "")
1333 set(PLATFORM_LINKFLAGS_EXECUTABLE "")
1335 if(NOT CMAKE_BUILD_TYPE MATCHES "Release")
1336   if(WITH_COMPILER_ASAN)
1337     if(NOT APPLE)
1338       # Avoid passing address sanitizer compiler flags to `try_compile`.
1339       # Since linker flags are not set, all compiler checks and `find_package`
1340       # calls that rely on `try_compile` will fail.
1341       # See CMP0066 also.
1342       string(APPEND CMAKE_C_FLAGS_DEBUG " ${COMPILER_ASAN_CFLAGS}")
1343       string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO " ${COMPILER_ASAN_CFLAGS}")
1345       string(APPEND CMAKE_CXX_FLAGS_DEBUG " ${COMPILER_ASAN_CXXFLAGS}")
1346       string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " ${COMPILER_ASAN_CXXFLAGS}")
1347     endif()
1348     if(MSVC)
1349       set(COMPILER_ASAN_LINKER_FLAGS "/FUNCTIONPADMIN:6")
1350     endif()
1352     if(APPLE AND COMPILER_ASAN_LIBRARY)
1353       string(REPLACE " " ";" _list_COMPILER_ASAN_CFLAGS ${COMPILER_ASAN_CFLAGS})
1354       set(_is_CONFIG_DEBUG "$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>")
1355       add_compile_options("$<${_is_CONFIG_DEBUG}:${_list_COMPILER_ASAN_CFLAGS}>")
1357       # Skip generation of the unwind tables, as they might require a lot of space when sanitizers
1358       # are enabled and not fit into the .eh_frame section. Disabling the unwind tables might have
1359       # side effects on code which does frame walking, such as
1360       #   - backtrace()
1361       #   - __attribute__((__cleanup__(f)))
1362       #   - __builtin_return_address(n), for n > 0
1363       #   - pthread_cleanup_push when it is implemented using __attribute__((__cleanup__(f)))
1364       # It should not have affect on debugging, since it uses -g flag which generates debugging
1365       # tables in the .debug_frame section.
1366       # At the time of adding these flags calling backtrace() from C code on Apple M2 did not
1367       # affect on the printed backtrace, and exception handling was correct as well.
1368       #
1369       # Related discussion:
1370       #  https://stackoverflow.com/questions/26300819
1371       add_compile_options("$<${_is_CONFIG_DEBUG}:-fno-unwind-tables>")
1372       add_compile_options("$<${_is_CONFIG_DEBUG}:-fno-asynchronous-unwind-tables>")
1374       add_compile_options("$<${_is_CONFIG_DEBUG}:-fno-omit-frame-pointer>")
1375       add_link_options("$<${_is_CONFIG_DEBUG}:-fno-omit-frame-pointer;-fsanitize=address>")
1376       unset(_list_COMPILER_ASAN_CFLAGS)
1377       unset(_is_CONFIG_DEBUG)
1378     elseif(COMPILER_ASAN_LIBRARY)
1379       set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS};${COMPILER_ASAN_LIBRARY}")
1380       set(PLATFORM_LINKFLAGS "${COMPILER_ASAN_LIBRARY}")
1381       set(PLATFORM_LINKFLAGS_DEBUG "${COMPILER_ASAN_LIBRARY}")
1382       if(DEFINED COMPILER_ASAN_LINKER_FLAGS)
1383         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} ${COMPILER_ASAN_LINKER_FLAGS}")
1384         set(PLATFORM_LINKFLAGS_DEBUG "${PLATFORM_LINKFLAGS_DEBUG} ${COMPILER_ASAN_LINKER_FLAGS}")
1385       endif()
1386     endif()
1387   endif()
1388 endif()
1390 # Test SIMD support, before platform includes to determine if sse2neon is needed.
1391 if(WITH_CPU_SIMD)
1392   set(COMPILER_SSE_FLAG)
1393   set(COMPILER_SSE2_FLAG)
1395   # Test Neon first since macOS Arm can compile and run x86-64 SSE binaries.
1396   test_neon_support()
1397   if(NOT SUPPORT_NEON_BUILD)
1398     test_sse_support(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
1399   endif()
1400 endif()
1403 # ----------------------------------------------------------------------------
1404 # Main Platform Checks
1406 # - UNIX
1407 # - WIN32
1408 # - APPLE
1410 if(UNIX AND NOT APPLE)
1411   include(platform_unix)
1412 elseif(WIN32)
1413   include(platform_win32)
1414 elseif(APPLE)
1415   include(platform_apple)
1416 endif()
1419 # -----------------------------------------------------------------------------
1420 # Common Checks for Compatible Options
1422 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
1423   message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
1424 endif()
1426 if(WITH_INTERNATIONAL)
1427   if(NOT WITH_BOOST)
1428     message(
1429       FATAL_ERROR
1430       "Internationalization requires WITH_BOOST, the library may not have been found. "
1431       "Configure BOOST or disable WITH_INTERNATIONAL"
1432     )
1433   endif()
1434 endif()
1436 # Enable SIMD support if detected by `test_sse_support()` or `test_neon_support()`.
1438 # This is done globally, so that all modules can use it if available, and
1439 # because these are used in headers used by many modules.
1440 if(WITH_CPU_SIMD)
1441   if(SUPPORT_NEON_BUILD)
1442     # Neon
1443     if(SSE2NEON_FOUND)
1444       include_directories(SYSTEM "${SSE2NEON_INCLUDE_DIRS}")
1445       add_definitions(-DWITH_SSE2NEON)
1446     endif()
1447   else()
1448     # SSE
1449     if(SUPPORT_SSE_BUILD)
1450       string(PREPEND PLATFORM_CFLAGS "${COMPILER_SSE_FLAG} ")
1451       add_definitions(-D__SSE__ -D__MMX__)
1452     endif()
1453     if(SUPPORT_SSE2_BUILD)
1454       string(APPEND PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG}")
1455       add_definitions(-D__SSE2__)
1456       if(NOT SUPPORT_SSE_BUILD) # don't double up
1457         add_definitions(-D__MMX__)
1458       endif()
1459     endif()
1460   endif()
1461 endif()
1463 # Print instructions used on first run.
1464 if(FIRST_RUN)
1465   if(WITH_CPU_SIMD)
1466     if(SUPPORT_NEON_BUILD)
1467       if(SSE2NEON_FOUND)
1468         message(STATUS "Neon SIMD instructions enabled")
1469       else()
1470         message(STATUS "Neon SIMD instructions detected but unused, requires sse2neon")
1471       endif()
1472     elseif(SUPPORT_SSE2_BUILD)
1473       message(STATUS "SSE2 SIMD instructions enabled")
1474     elseif(SUPPORT_SSE_BUILD)
1475       message(STATUS "SSE SIMD instructions enabled")
1476     else()
1477       message(STATUS "No SIMD instructions detected")
1478     endif()
1479   else()
1480     message(STATUS "SIMD instructions disabled")
1481   endif()
1482 endif()
1484 # set the endian define
1485 if(MSVC)
1486   # for some reason this fails on msvc
1487   add_definitions(-D__LITTLE_ENDIAN__)
1489   # OSX-Note: as we do cross-compiling with specific set architecture,
1490   # endianness-detection and auto-setting is counterproductive
1491   # so we just set endianness according CMAKE_OSX_ARCHITECTURES
1493 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR
1494        CMAKE_OSX_ARCHITECTURES MATCHES x86_64 OR
1495        CMAKE_OSX_ARCHITECTURES MATCHES arm64)
1496   add_definitions(-D__LITTLE_ENDIAN__)
1497 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)
1498   add_definitions(-D__BIG_ENDIAN__)
1500 else()
1501   include(TestBigEndian)
1502   test_big_endian(_SYSTEM_BIG_ENDIAN)
1503   if(_SYSTEM_BIG_ENDIAN)
1504     add_definitions(-D__BIG_ENDIAN__)
1505   else()
1506     add_definitions(-D__LITTLE_ENDIAN__)
1507   endif()
1508   unset(_SYSTEM_BIG_ENDIAN)
1509 endif()
1510 if(WITH_IMAGE_OPENJPEG)
1511   # Special handling of Windows platform where openjpeg is always static.
1512   if(WIN32)
1513     set(OPENJPEG_DEFINES "-DOPJ_STATIC")
1514   else()
1515     set(OPENJPEG_DEFINES "")
1516   endif()
1517 endif()
1519 if(NOT WITH_SYSTEM_EIGEN3)
1520   set(EIGEN3_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/Eigen3)
1521 endif()
1523 if(WITH_OPENVDB)
1524   list(APPEND OPENVDB_DEFINITIONS -DWITH_OPENVDB)
1526   if(WITH_OPENVDB_3_ABI_COMPATIBLE)
1527     list(APPEND OPENVDB_DEFINITIONS -DOPENVDB_3_ABI_COMPATIBLE)
1528   endif()
1530   # OpenVDB headers use deprecated TBB headers, silence warning.
1531   list(APPEND OPENVDB_DEFINITIONS -DTBB_SUPPRESS_DEPRECATED_MESSAGES=1)
1533   list(APPEND OPENVDB_INCLUDE_DIRS
1534     ${BOOST_INCLUDE_DIR}
1535     ${TBB_INCLUDE_DIRS}
1536     ${OPENEXR_INCLUDE_DIRS}
1537   )
1539   list(APPEND OPENVDB_LIBRARIES ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
1541   if(WITH_OPENVDB_BLOSC)
1542     list(APPEND OPENVDB_DEFINITIONS -DWITH_OPENVDB_BLOSC)
1543     # Even when `WITH_OPENVDB_BLOSC` is set, `FindBlosc.cmake` isn't running.
1544     # As this might be used at some point, check the libraries are defined.
1545     if(DEFINED BLOSC_LIBRARIES)
1546       list(APPEND OPENVDB_LIBRARIES ${BLOSC_LIBRARIES})
1547     endif()
1548     list(APPEND OPENVDB_LIBRARIES ${ZLIB_LIBRARIES})
1549   endif()
1551   list(APPEND OPENVDB_LIBRARIES ${BOOST_LIBRARIES} ${TBB_LIBRARIES})
1552 endif()
1554 # -----------------------------------------------------------------------------
1555 # Configure Metal
1557 if(WITH_METAL_BACKEND)
1558   add_definitions(-DWITH_METAL_BACKEND)
1560   # No need to add frameworks here, all the ones we need for Metal and
1561   # Metal-OpenGL Interop are already being added by
1562   # build_files/cmake/platform/platform_apple.cmake
1563 endif()
1566 # -----------------------------------------------------------------------------
1567 # Configure OpenMP
1569 if(WITH_OPENMP)
1570   if(NOT OPENMP_CUSTOM)
1571     find_package(OpenMP)
1572   endif()
1574   set_and_warn_library_found("OpenMP" OPENMP_FOUND WITH_OPENMP)
1576   if(OPENMP_FOUND)
1577     if(NOT WITH_OPENMP_STATIC)
1578       string(APPEND CMAKE_C_FLAGS " ${OpenMP_C_FLAGS}")
1579       string(APPEND CMAKE_CXX_FLAGS " ${OpenMP_CXX_FLAGS}")
1580       if(DEFINED OpenMP_LINKER_FLAGS)
1581         string(APPEND CMAKE_EXE_LINKER_FLAGS " ${OpenMP_LINKER_FLAGS}")
1582         string(APPEND CMAKE_MODULE_LINKER_FLAGS " ${OpenMP_LINKER_FLAGS}")
1583       endif()
1584     else()
1585       # Typically avoid adding flags as defines but we can't
1586       # pass OpenMP flags to the linker for static builds, meaning
1587       # we can't add any OpenMP related flags to CFLAGS variables
1588       # since they're passed to the linker as well.
1589       add_definitions("${OpenMP_C_FLAGS}")
1591       find_library_static(OpenMP_LIBRARIES gomp ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES})
1592       mark_as_advanced(
1593         OpenMP_LIBRARIES
1594       )
1595     endif()
1596   endif()
1598   mark_as_advanced(
1599     OpenMP_C_FLAGS
1600     OpenMP_CXX_FLAGS
1601   )
1602 endif()
1605 # -----------------------------------------------------------------------------
1606 # Configure Bullet
1608 if(WITH_BULLET)
1609   if(WITH_SYSTEM_BULLET)
1610     find_package(Bullet)
1611     set_and_warn_library_found("Bullet" BULLET_FOUND WITH_BULLET)
1612   else()
1613     set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
1614     set(BULLET_LIBRARIES "extern_bullet")
1615   endif()
1616 endif()
1619 # -----------------------------------------------------------------------------
1620 # Configure Python
1622 # Not currently supported due to different required Python link flags.
1623 set_and_warn_incompatible(WITH_PYTHON_MODULE WITH_GTESTS OFF)
1626 # -----------------------------------------------------------------------------
1627 # Configure `GLog/GFlags`
1629 if(WITH_LIBMV OR WITH_GTESTS OR (WITH_CYCLES AND WITH_CYCLES_LOGGING))
1630   if(WITH_SYSTEM_GFLAGS)
1631     find_package(Gflags)
1632     if(NOT GFLAGS_FOUND)
1633       message(FATAL_ERROR "System wide Gflags is requested but was not found")
1634     endif()
1635     # `FindGflags` does not define this, and we are not even sure what to use here.
1636     set(GFLAGS_DEFINES)
1637   else()
1638     set(GFLAGS_DEFINES
1639       -DGFLAGS_DLL_DEFINE_FLAG=
1640       -DGFLAGS_DLL_DECLARE_FLAG=
1641       -DGFLAGS_DLL_DECL=
1642     )
1643     set(GFLAGS_NAMESPACE "gflags")
1644     set(GFLAGS_LIBRARIES extern_gflags)
1645     set(GFLAGS_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/extern/gflags/src")
1646   endif()
1648   if(WITH_SYSTEM_GLOG)
1649     find_package(Glog)
1650     if(NOT GLOG_FOUND)
1651       message(FATAL_ERROR "System wide Glog is requested but was not found")
1652     endif()
1653     # `FindGlog` does not define this, and we are not even sure what to use here.
1654     set(GLOG_DEFINES)
1655   else()
1656     set(GLOG_DEFINES
1657       -DGOOGLE_GLOG_DLL_DECL=
1658     )
1659     set(GLOG_LIBRARIES extern_glog)
1660     if(WIN32)
1661       set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/glog/src/windows)
1662     else()
1663       set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/glog/include)
1664     endif()
1665   endif()
1666 endif()
1669 # -----------------------------------------------------------------------------
1670 # Ninja Job Limiting
1672 # Extra limits to number of jobs running in parallel for some kind os tasks.
1673 # Only supported by Ninja build system currently.
1675 if("${CMAKE_GENERATOR}" MATCHES "Ninja" AND WITH_NINJA_POOL_JOBS)
1676   if(NOT NINJA_MAX_NUM_PARALLEL_COMPILE_JOBS AND
1677      NOT NINJA_MAX_NUM_PARALLEL_COMPILE_HEAVY_JOBS AND
1678      NOT NINJA_MAX_NUM_PARALLEL_LINK_JOBS)
1679     # Try to define good default values.
1680     # Max mem of heavy cpp files compilation: about 2.5GB
1681     # Max mem during linking: about 3.3GB
1682     cmake_host_system_information(RESULT _NUM_CORES QUERY NUMBER_OF_LOGICAL_CORES)
1683     # Note: this gives mem in MB.
1684     cmake_host_system_information(RESULT _TOT_MEM QUERY TOTAL_PHYSICAL_MEMORY)
1686     # Heuristics: Assume 8Gb of RAM is needed per heavy compile job.
1687     # Typical RAM peak usage of these is actually less than 3GB currently,
1688     # but this also accounts for the part of the physical RAM being used by other unrelated
1689     # processes on the system, and the part being used by the 'regular' compile and linking jobs.
1690     #
1691     # Also always cap heavy jobs amount to `number of available threads - 1`,
1692     # to ensure that even if there would be enough RAM, the machine never ends up
1693     # handling only heavy jobs at some point.
1694     # This can have annoying sides effects, like lack of output in the console for several
1695     # minutes, which can lead to a wrong detection of 'unresponsive' state by the build-bots e.g.
1696     #
1697     # Currently, these settings applied to a 64GB/16threads linux machine will use,
1698     # for a full build:
1699     #   - release build:
1700     #      * RAM: typically less than 20%, with some peaks at 25%.
1701     #      * CPU: over 90% of usage on average over the whole build time.
1702     #   - debug with ASAN build:
1703     #      * RAM: typically less than 40%, with some peaks at 50%.
1704     #      * CPU: over 90% of usage on average over the whole build time.
1705     math(EXPR _compile_heavy_jobs "${_TOT_MEM} / 8000")
1706     math(EXPR _compile_heavy_jobs_max "${_NUM_CORES} - 1")
1707     if(${_compile_heavy_jobs} GREATER ${_compile_heavy_jobs_max})
1708       set(_compile_heavy_jobs ${_compile_heavy_jobs_max})
1709     elseif(${_compile_heavy_jobs} LESS 1)
1710       set(_compile_heavy_jobs 1)
1711     endif()
1712     set(NINJA_MAX_NUM_PARALLEL_COMPILE_HEAVY_JOBS "${_compile_heavy_jobs}" CACHE STRING "\
1713 Define the maximum number of concurrent heavy compilation jobs, for ninja build system \
1714 (used for some targets which cpp files can take several GB each during compilation)."
1715       FORCE
1716     )
1717     mark_as_advanced(NINJA_MAX_NUM_PARALLEL_COMPILE_HEAVY_JOBS)
1718     set(_compile_heavy_jobs)
1719     set(_compile_heavy_jobs_max)
1721     # Heuristics: Assume 2Gb of RAM is needed per heavy compile job.
1722     # Typical RAM peak usage of these is actually way less than 1GB usually,
1723     # but this also accounts for the part of the physical RAM being used by other unrelated
1724     # processes on the system, and the part being used by the 'heavy' compile and linking jobs.
1725     #
1726     # If there are 'enough' cores available, cap the maximum number of regular jobs to
1727     # `number of cores - 1`, otherwise allow using all cores if there is enough RAM available.
1728     # This allows to ensure that the heavy jobs won't get starved by too many normal jobs,
1729     # since the former usually take a long time to process.
1730     math(EXPR _compile_jobs "${_TOT_MEM} / 2000")
1731     if(${_NUM_CORES} GREATER 3)
1732       math(EXPR _compile_jobs_max "${_NUM_CORES} - 1")
1733     else()
1734       set(_compile_jobs_max ${_NUM_CORES})
1735     endif()
1736     if(${_compile_jobs} GREATER ${_compile_jobs_max})
1737       set(_compile_jobs ${_compile_jobs_max})
1738     elseif(${_compile_jobs} LESS 1)
1739       set(_compile_jobs 1)
1740     endif()
1741     set(NINJA_MAX_NUM_PARALLEL_COMPILE_JOBS "${_compile_jobs}" CACHE STRING
1742         "Define the maximum number of concurrent compilation jobs, for ninja build system." FORCE)
1743     mark_as_advanced(NINJA_MAX_NUM_PARALLEL_COMPILE_JOBS)
1744     set(_compile_jobs)
1745     set(_compile_jobs_max)
1747     # In practice, even when there is RAM available,
1748     # this proves to be quicker than running in parallel (due to slow disks accesses).
1749     set(NINJA_MAX_NUM_PARALLEL_LINK_JOBS "1" CACHE STRING
1750         "Define the maximum number of concurrent link jobs, for ninja build system." FORCE)
1751     mark_as_advanced(NINJA_MAX_NUM_PARALLEL_LINK_JOBS)
1753     set(_NUM_CORES)
1754     set(_TOT_MEM)
1755   endif()
1757   if(NINJA_MAX_NUM_PARALLEL_COMPILE_JOBS)
1758     set_property(
1759       GLOBAL APPEND PROPERTY
1760       JOB_POOLS compile_job_pool=${NINJA_MAX_NUM_PARALLEL_COMPILE_JOBS}
1761     )
1762     set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
1763   endif()
1765   if(NINJA_MAX_NUM_PARALLEL_COMPILE_HEAVY_JOBS)
1766     set_property(
1767       GLOBAL APPEND PROPERTY
1768       JOB_POOLS compile_heavy_job_pool=${NINJA_MAX_NUM_PARALLEL_COMPILE_HEAVY_JOBS}
1769     )
1770   endif()
1772   if(NINJA_MAX_NUM_PARALLEL_LINK_JOBS)
1773     set_property(
1774       GLOBAL APPEND PROPERTY
1775       JOB_POOLS link_job_pool=${NINJA_MAX_NUM_PARALLEL_LINK_JOBS}
1776     )
1777     set(CMAKE_JOB_POOL_LINK link_job_pool)
1778   endif()
1779 endif()
1782 # -----------------------------------------------------------------------------
1783 # Extra Compile Flags
1785 if(CMAKE_COMPILER_IS_GNUCC)
1787   add_check_c_compiler_flags(
1788     C_WARNINGS
1790     C_WARN_ALL -Wall
1791     C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration
1793     # System headers sometimes do this, disable for now, was: `-Werror=strict-prototypes`.
1794     C_WARN_STRICT_PROTOTYPES -Wstrict-prototypes
1796     C_WARN_ERROR_RETURN_TYPE -Werror=return-type
1797     C_WARN_ERROR_VLA -Werror=vla
1798     C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes
1799     C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts
1800     C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas
1801     C_WARN_POINTER_ARITH -Wpointer-arith
1802     C_WARN_UNUSED_PARAMETER -Wunused-parameter
1803     C_WARN_WRITE_STRINGS -Wwrite-strings
1804     C_WARN_LOGICAL_OP -Wlogical-op
1805     C_WARN_UNDEF -Wundef
1807     # Needs: `-Wuninitialized`.
1808     C_WARN_INIT_SELF -Winit-self
1810     C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs
1811     C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero
1812     C_WARN_TYPE_LIMITS -Wtype-limits
1813     C_WARN_FORMAT_SIGN -Wformat-signedness
1814     C_WARN_RESTRICT -Wrestrict
1816     # Useful but too many false positives and inconvenient to suppress each occurrence.
1817     C_WARN_NO_STRINGOP_OVERREAD -Wno-stringop-overread
1818     C_WARN_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow
1820     # C-only.
1821     C_WARN_NO_NULL -Wnonnull
1822     C_WARN_ABSOLUTE_VALUE -Wabsolute-value
1824     C_WARN_UNINITIALIZED -Wuninitialized
1825     C_WARN_REDUNDANT_DECLS -Wredundant-decls
1826     C_WARN_SHADOW -Wshadow
1828     # Disable because it gives warnings for printf() & friends.
1829     # C_WARN_DOUBLE_PROMOTION "-Wdouble-promotion -Wno-error=double-promotion"
1831     # Use `ATTR_FALLTHROUGH` macro to suppress.
1832     C_WARN_IMPLICIT_FALLTHROUGH -Wimplicit-fallthrough=5
1833   )
1835   if(NOT APPLE)
1836     add_check_c_compiler_flags(
1837       C_WARNINGS
1838       C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable
1839     )
1840   endif()
1842   add_check_cxx_compiler_flags(
1843     CXX_WARNINGS
1845     CXX_WARN_UNINITIALIZED -Wuninitialized
1846     CXX_WARN_REDUNDANT_DECLS -Wredundant-decls
1848     CXX_WARN_ALL -Wall
1849     CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof
1850     CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare
1851     CXX_WARN_LOGICAL_OP -Wlogical-op
1853     # Needs: `-Wuninitialized`.
1854     CXX_WARN_INIT_SELF -Winit-self
1856     CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs
1857     CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero
1858     CXX_WARN_TYPE_LIMITS -Wtype-limits
1859     CXX_WARN_ERROR_RETURN_TYPE -Werror=return-type
1860     CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts
1861     CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas
1862     CXX_WARN_POINTER_ARITH -Wpointer-arith
1863     CXX_WARN_UNUSED_PARAMETER -Wunused-parameter
1864     CXX_WARN_WRITE_STRINGS -Wwrite-strings
1865     CXX_WARN_UNDEF -Wundef
1866     CXX_WARN_COMMA_SUBSCRIPT -Wcomma-subscript
1867     CXX_WARN_FORMAT_SIGN -Wformat-signedness
1868     CXX_WARN_RESTRICT -Wrestrict
1869     CXX_WARN_NO_SUGGEST_OVERRIDE -Wno-suggest-override
1870     CXX_WARN_UNINITIALIZED -Wuninitialized
1872     # NOTE(@ideasman42): In GCC 13.2.1 on Linux this causes internal compiler errors.
1873     # The crashes can be resolved by disabling the flag per module (but not via pragmas).
1874     # However this also causes a type mix-up FreeStyle  (Blender & FreeStyle's `Curve`)
1875     # so it seems to impact GCC's the internal state enough that it's too risky to enable.
1876     # When this is resolved the check can be enabled for fixed GCC versions.
1877     #
1878     # Prevents linking errors with MSVC.
1879     # `CXX_WARN_MISMATCHED_TAGS -Wmismatched-tags`
1881     # Useful but too many false positives and inconvenient to suppress each occurrence.
1882     CXX_WARN_NO_STRINGOP_OVERREAD -Wno-stringop-overread
1883     CXX_WARN_NO_STRINGOP_OVERFLOW -Wno-stringop-overflow
1885     # Use `[[fallthrough]]` or `ATTR_FALLTHROUGH` macro to suppress.
1886     CXX_WARN_IMPLICIT_FALLTHROUGH -Wimplicit-fallthrough=5
1887   )
1889   # causes too many warnings
1890   if(NOT APPLE)
1891     add_check_cxx_compiler_flags(
1892       CXX_WARNINGS
1893       CXX_WARN_UNDEF -Wundef
1894       CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations
1895     )
1896   endif()
1898   # ---------------------
1899   # Suppress Strict Flags
1900   #
1901   # Exclude the following warnings from this list:
1902   # - `-Wno-address`:
1903   #   This can give useful hints that point to bugs/misleading logic.
1904   # - `-Wno-strict-prototypes`:
1905   #   No need to support older C-style prototypes.
1906   #
1907   # If code in `./extern/` needs to suppress these flags that can be done on a case-by-case basis.
1909   # flags to undo strict flags
1910   add_check_c_compiler_flags(
1911     C_REMOVE_STRICT_FLAGS
1913     C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations
1914     C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter
1915     C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function
1916     C_WARN_NO_TYPE_LIMITS -Wno-type-limits
1917     C_WARN_NO_INT_IN_BOOL_CONTEXT -Wno-int-in-bool-context
1918     C_WARN_NO_FORMAT -Wno-format
1919     C_WARN_NO_SWITCH -Wno-switch
1920     C_WARN_NO_UNUSED_VARIABLE -Wno-unused-variable
1921     C_WARN_NO_UNUSED_VARIABLE -Wno-uninitialized
1922     C_WARN_NO_IMPLICIT_FALLTHROUGH -Wno-implicit-fallthrough
1923   )
1926   add_check_cxx_compiler_flags(
1927     CXX_REMOVE_STRICT_FLAGS
1929     CXX_WARN_NO_CLASS_MEMACCESS -Wno-class-memaccess
1930     CXX_WARN_NO_COMMENT -Wno-comment
1931     CXX_WARN_NO_UNUSED_TYPEDEFS -Wno-unused-local-typedefs
1932     CXX_WARN_NO_UNUSED_VARIABLE -Wno-unused-variable
1933     CXX_WARN_NO_UNUSED_VARIABLE -Wno-uninitialized
1934   )
1937   if(NOT APPLE)
1938     add_check_c_compiler_flags(
1939       C_REMOVE_STRICT_FLAGS
1940       C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable
1941     )
1942   endif()
1944 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
1945   # Matches both "Clang" & "AppleClang" on macOS.
1947   add_check_c_compiler_flags(
1948     C_WARNINGS
1950     # Strange, clang complains these are not supported, but then uses them.
1951     C_WARN_ALL -Wall
1952     C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration
1953     C_WARN_ERROR_RETURN_TYPE -Werror=return-type
1954     C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare
1955     C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas
1956     C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts
1957     C_WARN_STRICT_PROTOTYPES -Wstrict-prototypes
1958     C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes
1959     C_WARN_UNUSED_PARAMETER -Wunused-parameter
1960     C_WARN_UNDEF -Wundef
1961     C_WARN_UNDEF_PREFIX -Wundef-prefix
1963     C_WARN_ERROR_UNGUARDED_AVAILABILITY_NEW -Werror=unguarded-availability-new
1964   )
1966   add_check_cxx_compiler_flags(
1967     CXX_WARNINGS
1969     CXX_WARN_ALL -Wall
1970     # Using C++20 features while having C++17 as the project language isn't allowed by MSVC.
1971     CXX_CXX20_DESIGNATOR -Wc++20-designator
1973     CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare
1974     CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas
1975     CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts
1977     # We get a lot of these, if its a problem a dev needs to look into it.
1978     CXX_WARN_NO_OVERLOADED_VIRTUAL -Wno-overloaded-virtual
1980     CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare
1981     CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof
1983     # Apple Clang (tested on version 12) doesn't support this flag while LLVM Clang 11 does.
1984     CXX_WARN_NO_SUGGEST_OVERRIDE -Wno-suggest-override
1986     CXX_WARN_UNDEF -Wundef
1987     CXX_WARN_UNDEF_PREFIX -Wundef-prefix
1988     CXX_WARN_UNUSED_PARAMETER -Wunused-parameter
1990     # Prevents linking errors with MSVC.
1991     CXX_WARN_MISMATCHED_TAGS -Wmismatched-tags
1993     # Gives too many unfixable warnings.
1994     # `C_WARN_UNUSED_MACROS -Wunused-macros`
1995     # `CXX_WARN_UNUSED_MACROS -Wunused-macros`
1997     CXX_WARN_ERROR_UNGUARDED_AVAILABILITY_NEW -Werror=unguarded-availability-new
1998   )
2003   # ---------------------
2004   # Suppress Strict Flags
2006   # flags to undo strict flags
2008   add_check_c_compiler_flags(
2009     C_REMOVE_STRICT_FLAGS
2011     C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter
2012     C_WARN_NO_UNUSED_VARIABLE -Wno-unused-variable
2013     C_WARN_NO_UNUSED_MACROS -Wno-unused-macros
2014     C_WARN_NO_MISLEADING_INDENTATION -Wno-misleading-indentation
2016     C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations
2017     C_WARN_NO_INCOMPAT_PTR_DISCARD_QUAL -Wno-incompatible-pointer-types-discards-qualifiers
2018     C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function
2019     C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast
2020     C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes
2021     C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum
2022     C_WARN_NO_UNDEF -Wno-undef
2023     C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn
2024     C_WARN_NO_UNUSED_BUT_SET_VARIABLE -Wno-unused-but-set-variable
2025     C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations
2026     C_WARN_NO_STRICT_PROTOTYPES -Wno-strict-prototypes
2027     C_WARN_NO_BITWISE_INSTEAD_OF_LOGICAL -Wno-bitwise-instead-of-logical
2028     C_WARN_NO_IMPLICIT_CONST_INT_FLOAT_CONVERSION -Wno-implicit-const-int-float-conversion
2029     C_WARN_NO_SINGLE_BIT_BITFIELD_CONSTANT_CONVERSION -Wno-single-bit-bitfield-constant-conversion
2030   )
2032   add_check_cxx_compiler_flags(
2033     CXX_REMOVE_STRICT_FLAGS
2035     CXX_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter
2036     CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field
2037     CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing
2038     CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor
2039     CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros
2040     CXX_WARN_NO_UNUSED_VARIABLE -Wno-unused-variable
2041     CXX_WARN_NO_REORDER -Wno-reorder
2042     CXX_WARN_NO_COMMENT -Wno-comment
2043     CXX_WARN_NO_UNUSED_TYPEDEFS -Wno-unused-local-typedefs
2044     CXX_WARN_NO_UNDEFINED_VAR_TEMPLATE -Wno-undefined-var-template
2045     CXX_WARN_NO_INSTANTIATION_AFTER_SPECIALIZATION -Wno-instantiation-after-specialization
2046     CXX_WARN_NO_MISLEADING_INDENTATION -Wno-misleading-indentation
2047     CXX_WARN_NO_BITWISE_INSTEAD_OF_LOGICAL -Wno-bitwise-instead-of-logical
2048     CXX_WARN_NO_IMPLICIT_CONST_INT_FLOAT_CONVERSION -Wno-implicit-const-int-float-conversion
2049     CXX_WARN_NO_UNDEF -Wno-undef
2050     CXX_WARN_NO_UNDEF_PREFIX -Wno-undef-prefix
2051   )
2053 elseif(CMAKE_C_COMPILER_ID STREQUAL "Intel")
2055   add_check_c_compiler_flags(
2056     C_WARNINGS
2058     C_WARN_ALL -Wall
2059     C_WARN_POINTER_ARITH -Wpointer-arith
2060     C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas
2061   )
2063   add_check_cxx_compiler_flags(
2064     CXX_WARNINGS
2066     CXX_WARN_ALL -Wall
2067     CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof
2068     CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare
2069   )
2071   # Disable numbered, false positives.
2072   string(APPEND C_WARNINGS " -wd188,186,144,913,556,858,597,177,1292,167,279,592,94,2722,3199")
2073   string(APPEND CXX_WARNINGS " -wd188,186,144,913,556,858,597,177,1292,167,279,592,94,2722,3199")
2074 elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
2075   # most msvc warnings are C & C++
2076   set(_WARNINGS
2077     # warning level:
2078     "/W3"
2079     "/w34062"  # switch statement contains 'default' but no 'case' labels
2080     "/w34100"  # 'identifier' : unreferenced formal parameter
2081     "/w34115"  # 'type' : named type definition in parentheses
2082     "/w34189"  # local variable is initialized but not referenced
2083     # see https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c5038?view=vs-2017
2084     "/w35038"  # order of initialization in c++ constructors
2085     # disable:
2086     "/wd4018"  # signed/unsigned mismatch
2087     "/wd4146"  # unary minus operator applied to unsigned type, result still unsigned
2088     "/wd4065"  # switch statement contains 'default' but no 'case' labels
2089     "/wd4127"  # conditional expression is constant
2090     "/wd4181"  # qualifier applied to reference type; ignored
2091     "/wd4200"  # zero-sized array in struct/union
2092     "/wd4244"  # conversion from 'type1' to 'type2', possible loss of data
2093     "/wd4267"  # conversion from 'size_t' to 'type', possible loss of data
2094     "/wd4305"  # truncation from 'type1' to 'type2'
2095     "/wd4800"  # forcing value to bool 'true' or 'false'
2096     "/wd4828"  # The file contains a character that is illegal
2097     "/wd4996"  # identifier was declared deprecated
2098     "/wd4661"  # no suitable definition provided for explicit template instantiation request
2099     "/wd4848"  # 'no_unique_address' is a vendor extension in C++17
2100     # errors:
2101     "/we4013"  # 'function' undefined; assuming extern returning int
2102     "/we4133"  # incompatible pointer types
2103     "/we4431"  # missing type specifier - int assumed
2104     "/we4033"  # 'function' must return a value
2105   )
2107   string(REPLACE ";" " " _WARNINGS "${_WARNINGS}")
2108   set(C_WARNINGS "${_WARNINGS}")
2109   set(CXX_WARNINGS "${_WARNINGS}")
2110   unset(_WARNINGS)
2111 endif()
2113 # Xcode enables additional warning flags by default. Disable some to match
2114 # command line build and other platforms more closely.
2115 if(XCODE)
2116   set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_64_TO_32_BIT_CONVERSION NO)
2117 endif()
2119 # ensure python header is found since detection can fail, this could happen
2120 # with _any_ library but since we used a fixed python version this tends to
2121 # be most problematic.
2122 if(WITH_PYTHON)
2123   if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
2124     message(
2125       FATAL_ERROR
2126       "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
2127       "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
2128       "to a valid python include path. Containing "
2129       "Python.h for python version \"${PYTHON_VERSION}\""
2130     )
2131   endif()
2133   if(WIN32)
2134     # Always use numpy bundled in precompiled libs.
2135   elseif((WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY) OR WITH_PYTHON_NUMPY)
2136     if(("${PYTHON_NUMPY_PATH}" STREQUAL "") OR (${PYTHON_NUMPY_PATH} MATCHES NOTFOUND))
2137       find_python_package(numpy "core/include")
2138     endif()
2139   endif()
2141   if(WIN32 OR APPLE)
2142     # Always copy from precompiled libs.
2143   elseif(WITH_PYTHON_INSTALL_REQUESTS)
2144     find_python_package(requests "")
2145   endif()
2147   if(WIN32 OR APPLE)
2148     # Always copy from precompiled libs.
2149   elseif(WITH_PYTHON_INSTALL_ZSTANDARD)
2150     find_python_package(zstandard "")
2151   endif()
2152 endif()
2154 # Select C++17 as the standard for C++ projects.
2155 set(CMAKE_CXX_STANDARD 17)
2156 # If C++17 is not available, downgrading to an earlier standard is NOT OK.
2157 set(CMAKE_CXX_STANDARD_REQUIRED ON)
2158 # Do not enable compiler specific language extensions.
2159 set(CMAKE_CXX_EXTENSIONS OFF)
2161 # Visual Studio has all standards it supports available by default
2162 # Clang on windows copies this behavior and does not support these switches
2164   CMAKE_COMPILER_IS_GNUCC OR
2165   (CMAKE_C_COMPILER_ID MATCHES "Clang" AND (NOT MSVC)) OR
2166   (CMAKE_C_COMPILER_ID STREQUAL "Intel")
2168   # Use C11 + GNU extensions, works with GCC, Clang, ICC
2169   string(APPEND CMAKE_C_FLAGS " -std=gnu11")
2170 endif()
2172 if(WITH_COMPILER_SHORT_FILE_MACRO)
2173   # Use '-fmacro-prefix-map' for Clang and GCC (MSVC doesn't support this).
2174   set(C_PREFIX_MAP_FLAGS "")
2175   set(CXX_PREFIX_MAP_FLAGS "")
2176   add_check_c_compiler_flags(
2177     C_PREFIX_MAP_FLAGS
2178     C_MACRO_PREFIX_MAP -fmacro-prefix-map=foo=bar
2179   )
2180   add_check_cxx_compiler_flags(
2181     CXX_PREFIX_MAP_FLAGS
2182     CXX_MACRO_PREFIX_MAP -fmacro-prefix-map=foo=bar
2183   )
2184   if(C_MACRO_PREFIX_MAP AND CXX_MACRO_PREFIX_MAP)
2185     if(APPLE)
2186       if(XCODE AND ${XCODE_VERSION} VERSION_LESS 12.0)
2187       # Developers may have say LLVM Clang-10.0.1 toolchain (which supports the flag)
2188       # with Xcode-11 (the Clang of which doesn't support the flag).
2189         message(
2190           WARNING
2191           "-fmacro-prefix-map flag is NOT supported by Clang shipped with Xcode-${XCODE_VERSION}."
2192           " Some Xcode functionality in Product menu may not work. "
2193           "Disabling WITH_COMPILER_SHORT_FILE_MACRO."
2194         )
2195         set(WITH_COMPILER_SHORT_FILE_MACRO OFF)
2196       endif()
2197     endif()
2198     if(WITH_COMPILER_SHORT_FILE_MACRO)
2199       path_ensure_trailing_slash(_src_dir "${CMAKE_SOURCE_DIR}")
2200       path_ensure_trailing_slash(_bin_dir "${CMAKE_BINARY_DIR}")
2201       # Keep this variable so it can be stripped from build-info.
2202       set(PLATFORM_CFLAGS_FMACRO_PREFIX_MAP
2203         "-fmacro-prefix-map=\"${_src_dir}\"=\"\" -fmacro-prefix-map=\"${_bin_dir}\"=\"\"")
2204       string(APPEND PLATFORM_CFLAGS " ${PLATFORM_CFLAGS_FMACRO_PREFIX_MAP}")
2205       unset(_src_dir)
2206       unset(_bin_dir)
2207     endif()
2208   else()
2209     message(
2210       WARNING
2211       "-fmacro-prefix-map flag is NOT supported by C/C++ compiler."
2212       " Disabling WITH_COMPILER_SHORT_FILE_MACRO."
2213     )
2214     set(WITH_COMPILER_SHORT_FILE_MACRO OFF)
2215   endif()
2216   unset(C_PREFIX_MAP_FLAGS)
2217   unset(CXX_PREFIX_MAP_FLAGS)
2218 endif()
2220 # Include warnings first, so its possible to disable them with user defined flags
2221 # eg: -Wno-uninitialized
2222 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
2223 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
2225 # defined above, platform specific but shared names
2226 mark_as_advanced(
2227   CYCLES_OSL
2228   OSL_LIB_EXEC
2229   OSL_COMPILER
2230   OSL_LIB_COMP
2231   OSL_LIB_QUERY
2232   OSL_INCLUDE_DIR
2235 mark_as_advanced(
2236   LLVM_CONFIG
2237   LLVM_ROOT_DIR
2238   LLVM_LIBRARY
2239   LLVM_VERSION
2243 # -------------------------------------------------------------------------------
2244 # Global Defines
2246 # better not set includes here but this debugging option is off by default.
2247 if(WITH_CXX_GUARDEDALLOC)
2248   include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
2249   add_definitions(-DWITH_CXX_GUARDEDALLOC)
2250 endif()
2252 if(WITH_ASSERT_ABORT)
2253   add_definitions(-DWITH_ASSERT_ABORT)
2254 endif()
2256 # NDEBUG is the standard C define to disable asserts.
2257 if(WITH_ASSERT_RELEASE)
2258   # CMake seemingly be setting the NDEBUG flag on its own already on some configurations
2259   # therefore we need to remove the flags if they happen to be set.
2260   remove_cc_flag("-DNDEBUG") # GCC/CLang
2261   remove_cc_flag("/DNDEBUG") # MSVC
2262 else()
2263   set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
2264     $<$<CONFIG:Release>:NDEBUG>
2265     $<$<CONFIG:MinSizeRel>:NDEBUG>
2266     $<$<CONFIG:RelWithDebInfo>:NDEBUG>
2267   )
2268 endif()
2270 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
2271 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
2273 # -----------------------------------------------------------------------------
2274 # Testing Functions
2276 include(build_files/cmake/testing.cmake)
2278 # -----------------------------------------------------------------------------
2279 # Add Sub-Directories
2281 if(WITH_BLENDER)
2282   add_subdirectory(intern)
2283   add_subdirectory(extern)
2285   # source after intern and extern to gather all
2286   # internal and external library information first, for test linking
2287   add_subdirectory(source)
2288 elseif(WITH_CYCLES_STANDALONE OR WITH_CYCLES_HYDRA_RENDER_DELEGATE)
2289   add_subdirectory(intern/guardedalloc)
2290   add_subdirectory(intern/libc_compat)
2291   add_subdirectory(intern/sky)
2293   add_subdirectory(intern/cycles)
2294   if(WITH_CYCLES_LOGGING)
2295     if(NOT WITH_SYSTEM_GFLAGS)
2296       add_subdirectory(extern/gflags)
2297     endif()
2298     add_subdirectory(extern/glog)
2299   endif()
2300   if(WITH_CUDA_DYNLOAD)
2301     add_subdirectory(extern/cuew)
2302   endif()
2303   if(WITH_HIP_DYNLOAD)
2304     add_subdirectory(extern/hipew)
2305   endif()
2306 endif()
2309 # -----------------------------------------------------------------------------
2310 # Add Testing Directory
2312 add_subdirectory(tests)
2315 # -----------------------------------------------------------------------------
2316 # Add Blender Application
2318 if(WITH_BLENDER)
2319   add_subdirectory(source/creator)
2320 endif()
2323 # -----------------------------------------------------------------------------
2324 # Define 'heavy' sub-modules (for Ninja builder when using pools)
2325 setup_heavy_lib_pool()
2328 # -----------------------------------------------------------------------------
2329 # CPack for generating packages
2331 include(build_files/cmake/packaging.cmake)
2334 # -----------------------------------------------------------------------------
2335 # Use Dynamic Loading for OpenMP
2337 if(WITH_BLENDER)
2338   openmp_delayload(blender)
2339 endif()
2342 # -----------------------------------------------------------------------------
2343 # Print Final Configuration
2345 if(FIRST_RUN)
2347   set(_config_msg "\nBlender Configuration\n=====================")
2349   function(info_cfg_option
2350     _setting
2351     )
2353     set(_msg "  - ${_setting}")
2354     string(LENGTH "${_msg}" _len)
2355     while("36" GREATER "${_len}")
2356       string(APPEND _msg " ")
2357       math(EXPR _len "${_len} + 1")
2358     endwhile()
2360     set(_config_msg "${_config_msg}\n${_msg}${${_setting}}" PARENT_SCOPE)
2361   endfunction()
2363   function(info_cfg_text
2364     _text
2365     )
2367     set(_config_msg "${_config_msg}\n\n  ${_text}" PARENT_SCOPE)
2368   endfunction()
2370   message(STATUS "C Compiler:   \"${CMAKE_C_COMPILER_ID}\"")
2371   message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
2373   info_cfg_text("Build Options:")
2374   info_cfg_option(WITH_ALEMBIC)
2375   info_cfg_option(WITH_BULLET)
2376   info_cfg_option(WITH_CLANG)
2377   info_cfg_option(WITH_CYCLES)
2378   info_cfg_option(WITH_FFTW3)
2379   info_cfg_option(WITH_FREESTYLE)
2380   info_cfg_option(WITH_GMP)
2381   info_cfg_option(WITH_HARU)
2382   info_cfg_option(WITH_IK_ITASC)
2383   info_cfg_option(WITH_IK_SOLVER)
2384   info_cfg_option(WITH_INPUT_NDOF)
2385   info_cfg_option(WITH_INPUT_IME)
2386   info_cfg_option(WITH_INTERNATIONAL)
2387   info_cfg_option(WITH_OPENCOLLADA)
2388   info_cfg_option(WITH_OPENCOLORIO)
2389   info_cfg_option(WITH_OPENIMAGEDENOISE)
2390   info_cfg_option(WITH_OPENVDB)
2391   info_cfg_option(WITH_POTRACE)
2392   info_cfg_option(WITH_PUGIXML)
2393   info_cfg_option(WITH_QUADRIFLOW)
2394   info_cfg_option(WITH_TBB)
2395   info_cfg_option(WITH_USD)
2396   info_cfg_option(WITH_MATERIALX)
2397   info_cfg_option(WITH_XR_OPENXR)
2399   info_cfg_text("Compiler Options:")
2400   info_cfg_option(WITH_BUILDINFO)
2401   info_cfg_option(WITH_OPENMP)
2403   info_cfg_text("System Options:")
2404   info_cfg_option(WITH_INSTALL_PORTABLE)
2405   info_cfg_option(WITH_MEM_JEMALLOC)
2406   info_cfg_option(WITH_MEM_VALGRIND)
2408   info_cfg_text("GHOST Options:")
2409   info_cfg_option(WITH_GHOST_DEBUG)
2410   info_cfg_option(WITH_GHOST_SDL)
2411   if(UNIX AND NOT APPLE)
2412     info_cfg_option(WITH_GHOST_X11)
2413     info_cfg_option(WITH_GHOST_WAYLAND)
2414     if(WITH_GHOST_X11)
2415       info_cfg_option(WITH_GHOST_XDND)
2416       info_cfg_option(WITH_X11_XF86VMODE)
2417       info_cfg_option(WITH_X11_XFIXES)
2418       info_cfg_option(WITH_X11_XINPUT)
2419     endif()
2420     if(WITH_GHOST_WAYLAND)
2421       info_cfg_option(WITH_GHOST_WAYLAND_DYNLOAD)
2422       info_cfg_option(WITH_GHOST_WAYLAND_LIBDECOR)
2423     endif()
2424   endif()
2426   info_cfg_text("Image Formats:")
2427   info_cfg_option(WITH_IMAGE_CINEON)
2428   info_cfg_option(WITH_IMAGE_OPENEXR)
2429   info_cfg_option(WITH_IMAGE_OPENJPEG)
2431   info_cfg_text("Audio:")
2432   info_cfg_option(WITH_CODEC_FFMPEG)
2433   info_cfg_option(WITH_CODEC_SNDFILE)
2434   info_cfg_option(WITH_COREAUDIO)
2435   info_cfg_option(WITH_JACK)
2436   info_cfg_option(WITH_JACK_DYNLOAD)
2437   info_cfg_option(WITH_OPENAL)
2438   info_cfg_option(WITH_PULSEAUDIO)
2439   info_cfg_option(WITH_PULSEAUDIO_DYNLOAD)
2440   info_cfg_option(WITH_SDL)
2441   info_cfg_option(WITH_SDL_DYNLOAD)
2442   info_cfg_option(WITH_WASAPI)
2444   info_cfg_text("Compression:")
2445   info_cfg_option(WITH_LZMA)
2446   info_cfg_option(WITH_LZO)
2448   if(WITH_PYTHON)
2449     info_cfg_text("Python:")
2450     info_cfg_option(WITH_PYTHON_INSTALL)
2451     info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
2452     info_cfg_option(WITH_PYTHON_INSTALL_ZSTANDARD)
2453     info_cfg_option(WITH_PYTHON_MODULE)
2454     info_cfg_option(WITH_PYTHON_SAFETY)
2455   endif()
2457   info_cfg_text("Modifiers:")
2458   info_cfg_option(WITH_MOD_FLUID)
2459   info_cfg_option(WITH_MOD_OCEANSIM)
2460   info_cfg_option(WITH_MOD_REMESH)
2462   info_cfg_text("Rendering:")
2463   info_cfg_option(WITH_HYDRA)
2465   if(WITH_CYCLES)
2466     info_cfg_text("Rendering (Cycles):")
2467     info_cfg_option(WITH_CYCLES_OSL)
2468     info_cfg_option(WITH_CYCLES_EMBREE)
2469     info_cfg_option(WITH_CYCLES_PATH_GUIDING)
2470     if(NOT APPLE)
2471       info_cfg_option(WITH_CYCLES_DEVICE_OPTIX)
2472       info_cfg_option(WITH_CYCLES_DEVICE_CUDA)
2473       info_cfg_option(WITH_CYCLES_CUDA_BINARIES)
2474       info_cfg_option(WITH_CYCLES_DEVICE_ONEAPI)
2475       info_cfg_option(WITH_CYCLES_ONEAPI_BINARIES)
2476       info_cfg_option(WITH_CYCLES_DEVICE_HIP)
2477       info_cfg_option(WITH_CYCLES_HIP_BINARIES)
2478     endif()
2479     if(WIN32)
2480       info_cfg_option(WITH_CYCLES_DEVICE_HIPRT)
2481     endif()
2482   endif()
2484   info_cfg_text("")
2486   message("${_config_msg}")
2487 endif()
2489 if(0)
2490   print_all_vars()
2491 endif()
2493 # Should be the last step of configuration.
2494 if(POSTCONFIGURE_SCRIPT)
2495   include(${POSTCONFIGURE_SCRIPT})
2496 endif()