Skip to content
Snippets Groups Projects
CMakeLists.txt 66.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • Milan Jaros's avatar
    Milan Jaros committed
    # ***** BEGIN GPL LICENSE BLOCK *****
    #
    # This program is free software; you can redistribute it and/or
    # modify it under the terms of the GNU General Public License
    # as published by the Free Software Foundation; either version 2
    # of the License, or (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program; if not, write to the Free Software Foundation,
    # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    #
    # The Original Code is Copyright (C) 2006, Blender Foundation
    # All rights reserved.
    #
    # ***** END GPL LICENSE BLOCK *****
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    #-----------------------------------------------------------------------------
    # We don't allow in-source builds. This causes no end of troubles because
    # all out-of-source builds will use the CMakeCache.txt file there and even
    # build the libs and objects in it.
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
      if(NOT DEFINED WITH_IN_SOURCE_BUILD)
        message(FATAL_ERROR
          "CMake generation for blender is not allowed within the source directory!"
          "\n Remove \"${CMAKE_SOURCE_DIR}/CMakeCache.txt\" and try again from another folder, e.g.:"
          "\n "
          "\n rm CMakeCache.txt"
          "\n cd .."
          "\n mkdir cmake-make"
          "\n cd cmake-make"
          "\n cmake ../blender"
          "\n "
          "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
        )
      endif()
    endif()
    
    cmake_minimum_required(VERSION 3.5)
    
    # Prever LEGACY OpenGL to eb compatible with all the existing releases and
    # platforms which don't hare GLVND yet. Only do it if preference was not set
    # externally.
    if(NOT DEFINED OpenGL_GL_PREFERENCE)
      set(OpenGL_GL_PREFERENCE "LEGACY")
    endif()
    
    if(NOT EXECUTABLE_OUTPUT_PATH)
      set(FIRST_RUN TRUE)
    else()
      set(FIRST_RUN FALSE)
    endif()
    
    # this starts out unset
    list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
    list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/platform")
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    # avoid having empty buildtype
    if(NOT DEFINED CMAKE_BUILD_TYPE_INIT)
      set(CMAKE_BUILD_TYPE_INIT "Release")
    endif()
    
    # Omit superfluous "Up-to-date" messages.
    if(NOT DEFINED CMAKE_INSTALL_MESSAGE)
      set(CMAKE_INSTALL_MESSAGE "LAZY")
    endif()
    
    # quiet output for Makefiles, 'make -s' helps too
    # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
    
    # global compile definitions since add_definitions() adds for all.
    set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
      $<$<CONFIG:Debug>:DEBUG;_DEBUG>
      $<$<CONFIG:Release>:NDEBUG>
      $<$<CONFIG:MinSizeRel>:NDEBUG>
      $<$<CONFIG:RelWithDebInfo>:NDEBUG>
    
    Milan Jaros's avatar
    Milan Jaros committed
    )
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    #-----------------------------------------------------------------------------
    # Set policy
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    # see "cmake --help-policy CMP0003"
    # So library linking is more sane
    cmake_policy(SET CMP0003 NEW)
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    # So BUILDINFO and BLENDERPATH strings are automatically quoted
    cmake_policy(SET CMP0005 NEW)
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    # So syntax problems are errors
    cmake_policy(SET CMP0010 NEW)
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    # Input directories must have CMakeLists.txt
    cmake_policy(SET CMP0014 NEW)
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    # Silence draco warning on macOS, new policy works fine.
    if(POLICY CMP0068)
      cmake_policy(SET CMP0068 NEW)
    endif()
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    #-----------------------------------------------------------------------------
    # Load some macros.
    include(build_files/cmake/macros.cmake)
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    #-----------------------------------------------------------------------------
    # Initialize project.
    
    blender_project_hack_pre()
    
    project(Blender)
    
    blender_project_hack_post()
    
    enable_testing()
    
    #-----------------------------------------------------------------------------
    # Redirect output files
    
    set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE)
    set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE)
    if(MSVC)
      set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests/$<CONFIG>/ CACHE INTERNAL "" FORCE)
    else()
      set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests/ CACHE INTERNAL "" FORCE)
    
    Milan Jaros's avatar
    Milan Jaros committed
    endif()
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    #-----------------------------------------------------------------------------
    # Set default config options
    
    get_blender_version()
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    #-----------------------------------------------------------------------------
    # Options
    
    # First platform specific non-cached vars
    if(UNIX AND NOT (APPLE OR HAIKU))
      set(WITH_X11 ON)
    
    Milan Jaros's avatar
    Milan Jaros committed
    endif()
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    # Blender internal features
    option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
    mark_as_advanced(WITH_BLENDER)
    
    option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
    
    option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
    option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default" ON)
    mark_as_advanced(WITH_PYTHON)  # don't want people disabling this unless they really know what they are doing.
    mark_as_advanced(WITH_PYTHON_SECURITY)  # some distributions see this as a security issue, rather than have them patch it, make a build option.
    
    option(WITH_PYTHON_SAFETY "Enable internal API error checking to track invalid data to prevent crash on access (at the expense of some efficiency, only enable for development)." OFF)
    mark_as_advanced(WITH_PYTHON_SAFETY)
    option(WITH_PYTHON_MODULE "Enable building as a python module which runs without a user interface, like running regular blender in background mode (experimental, only enable for development), installs to PYTHON_SITE_PACKAGES (or CMAKE_INSTALL_PREFIX if WITH_INSTALL_PORTABLE is enabled)." OFF)
    if(APPLE)
      option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
    
    Milan Jaros's avatar
    Milan Jaros committed
    endif()
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ON)
    if(${CMAKE_VERSION} VERSION_LESS 2.8.8)
      # add_library OBJECT arg unsupported
      set(WITH_BUILDINFO OFF)
    
    Milan Jaros's avatar
    Milan Jaros committed
    endif()
    
    Milan Jaros's avatar
    Milan Jaros committed
    set(BUILDINFO_OVERRIDE_DATE "" CACHE STRING "Use instead of the current date for reproducible builds (empty string disables this option)")
    set(BUILDINFO_OVERRIDE_TIME "" CACHE STRING "Use instead of the current time for reproducible builds (empty string disables this option)")
    set(CPACK_OVERRIDE_PACKAGENAME "" CACHE STRING "Use instead of the standard packagename (empty string disables this option)")
    mark_as_advanced(CPACK_OVERRIDE_PACKAGENAME)
    mark_as_advanced(BUILDINFO_OVERRIDE_DATE)
    mark_as_advanced(BUILDINFO_OVERRIDE_TIME)
    
    option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
    option(WITH_IK_SOLVER     "Enable Legacy IK solver (only disable for development)" ON)
    option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke, ocean sim, and audio effects)" ON)
    option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
    option(WITH_SYSTEM_BULLET "Use the systems bullet library (currently unsupported due to missing features in upstream!)" )
    mark_as_advanced(WITH_SYSTEM_BULLET)
    option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ON)
    if(APPLE)
      # There's no OpenXR runtime in sight for macOS, neither is code well
      # tested there -> disable it by default.
      option(WITH_XR_OPENXR   "Enable VR features through the OpenXR specification" OFF)
      mark_as_advanced(WITH_XR_OPENXR)
    else()
      option(WITH_XR_OPENXR   "Enable VR features through the OpenXR specification" ON)
    endif()
    
    # Compositor
    option(WITH_COMPOSITOR         "Enable the tile based nodal compositor" ON)
    option(WITH_OPENIMAGEDENOISE   "Enable the OpenImageDenoise compositing node" ON)
    
    option(WITH_OPENSUBDIV    "Enable OpenSubdiv for surface subdivision" ON)
    
    option(WITH_OPENVDB       "Enable features relying on OpenVDB" ON)
    option(WITH_OPENVDB_BLOSC "Enable blosc compression for OpenVDB, only enable if OpenVDB was built with blosc support" ON)
    option(WITH_OPENVDB_3_ABI_COMPATIBLE "Assume OpenVDB library has been compiled with version 3 ABI compatibility" OFF)
    mark_as_advanced(WITH_OPENVDB_3_ABI_COMPATIBLE)
    
    # GHOST Windowing Library Options
    option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
    mark_as_advanced(WITH_GHOST_DEBUG)
    
    option(WITH_GHOST_SDL    "Enable building Blender against SDL for windowing rather than the native APIs" OFF)
    mark_as_advanced(WITH_GHOST_SDL)
    
    if(WITH_X11)
      option(WITH_GHOST_XDND    "Enable drag'n'drop support on X11 using XDND protocol" ON)
    endif()
    
    # Misc...
    option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
    mark_as_advanced(WITH_HEADLESS)
    
    option(WITH_QUADRIFLOW    "Build with quadriflow remesher support" ON)
    
    option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
    option(WITH_SYSTEM_AUDASPACE "Build with external audaspace library installed on the system (only enable if you know what you're doing!)" OFF)
    mark_as_advanced(WITH_AUDASPACE)
    mark_as_advanced(WITH_SYSTEM_AUDASPACE)
    
    if(NOT WITH_AUDASPACE)
      set(WITH_SYSTEM_AUDASPACE OFF)
    endif()
    
    option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
    if(UNIX AND NOT APPLE)
      option(WITH_OPENMP_STATIC "Link OpenMP statically (only used by the release environment)" OFF)
      mark_as_advanced(WITH_OPENMP_STATIC)
    endif()
    
    if(WITH_X11)
      option(WITH_X11_XINPUT    "Enable X11 Xinput (tablet support and unicode input)"  ON)
      option(WITH_X11_XF86VMODE "Enable X11 video mode switching"                       ON)
      option(WITH_X11_XFIXES    "Enable X11 XWayland cursor warping workaround"         ON)
      option(WITH_X11_ALPHA     "Enable X11 transparent background"                     ON)
    endif()
    
    if(UNIX AND NOT APPLE)
      option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" OFF)
      option(WITH_SYSTEM_GLES "Use OpenGL ES library provided by the operating system"           ON)
    else()
      # not an option for other OS's
      set(WITH_SYSTEM_GLEW OFF)
      set(WITH_SYSTEM_GLES OFF)
    endif()
    
    # MPI
    option(WITH_CLIENT_MPI                     "Enable MPI (has to be supported by the compiler)" OFF)
    option(WITH_CLIENT_MPI_SOCKET              "Enable MPI_SOCKET" OFF)
    option(WITH_CLIENT_FILE              	   "Enable FILE" OFF)
    option(WITH_CLIENT_CUDA              	   "Enable CUDA" OFF)
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    if(WITH_CLIENT_MPI_SOCKET)
    
    Milan Jaros's avatar
    Milan Jaros committed
      set(WITH_CLIENT_MPI OFF)
    endif()
    
    if(WITH_CLIENT_MPI)
        find_package(MPI)
    endif()
    
    if(UNIX AND NOT APPLE)
      option(WITH_SYSTEM_EIGEN3 "Use the systems Eigen3 library" OFF)
    endif()
    
    
    # Modifiers
    option(WITH_MOD_FLUID           "Enable Mantaflow Fluid Simulation Framework" ON)
    option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
    option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" ON)
    
    # Image format support
    option(WITH_OPENIMAGEIO         "Enable OpenImageIO Support (http://www.openimageio.org)" ON)
    option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
    option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
    option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
    option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
    option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
    option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
    
    # Audio/Video format support
    option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
    option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" ON)
    option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" ON)
    
    # Alembic support
    option(WITH_ALEMBIC             "Enable Alembic Support" ON)
    option(WITH_ALEMBIC_HDF5        "Enable Legacy Alembic Support (not officially supported)" OFF)
    
    # Universal Scene Description support
    option(WITH_USD                 "Enable Universal Scene Description (USD) Support" OFF)
    
    # 3D format support
    # Disable opencollada when we don't have precompiled libs
    option(WITH_OPENCOLLADA   "Enable OpenCollada Support (http://www.opencollada.org)" ON)
    
    # Sound output
    option(WITH_SDL           "Enable SDL for sound and joystick support" ON)
    option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
    if(NOT WIN32)
      option(WITH_JACK          "Enable JACK Support (http://www.jackaudio.org)" ON)
      if(UNIX AND NOT APPLE)
        option(WITH_JACK_DYNLOAD  "Enable runtime dynamic JACK libraries loading" OFF)
      endif()
    endif()
    if(UNIX AND NOT APPLE)
      option(WITH_SDL_DYNLOAD  "Enable runtime dynamic SDL libraries loading" OFF)
    
    Milan Jaros's avatar
    Milan Jaros committed
    endif()
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    # Compression
    option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
    option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
    if(UNIX AND NOT APPLE)
      option(WITH_SYSTEM_LZO    "Use the system LZO library" OFF)
    
    Milan Jaros's avatar
    Milan Jaros committed
    endif()
    
    Milan Jaros's avatar
    Milan Jaros committed
    option(WITH_DRACO         "Enable Draco mesh compression Python module (used for glTF)" ON)
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    # Camera/motion tracking
    option(WITH_LIBMV         "Enable Libmv structure from motion library" ON)
    option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." ON)
    mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
    
    # Logging/unbit test libraries.
    option(WITH_SYSTEM_GFLAGS   "Use system-wide Gflags instead of a bundled one" OFF)
    option(WITH_SYSTEM_GLOG     "Use system-wide Glog instead of a bundled one" OFF)
    mark_as_advanced(WITH_SYSTEM_GFLAGS)
    mark_as_advanced(WITH_SYSTEM_GLOG)
    
    # Freestyle
    option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
    
    # New object types
    option(WITH_NEW_OBJECT_TYPES "Enable new hair and pointcloud objects (use for development only, don't save in files)" OFF)
    mark_as_advanced(WITH_NEW_OBJECT_TYPES)
    
    # Misc
    if(WIN32)
      option(WITH_INPUT_IME "Enable Input Method Editor (IME) for complex Asian character input" ON)
    endif()
    option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
    if(UNIX AND NOT APPLE)
      option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
      option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
      if(WITH_STATIC_LIBS)
        option(WITH_BOOST_ICU "Boost uses ICU library (required for linking with static Boost built with libicu)." OFF)
        mark_as_advanced(WITH_BOOST_ICU)
      endif()
    
    Milan Jaros's avatar
    Milan Jaros committed
    endif()
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
    if(WIN32 OR APPLE)
      # Windows and macOS have this bundled with Python libraries.
    elseif(WITH_PYTHON_INSTALL OR (WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE))
      set(PYTHON_NUMPY_PATH            "" CACHE PATH "Path to python site-packages or dist-packages containing 'numpy' module")
      mark_as_advanced(PYTHON_NUMPY_PATH)
      set(PYTHON_NUMPY_INCLUDE_DIRS ${PYTHON_NUMPY_PATH}/numpy/core/include CACHE PATH "Path to the include directory of the numpy module")
      mark_as_advanced(PYTHON_NUMPY_INCLUDE_DIRS)
    endif()
    if(WITH_PYTHON_INSTALL)
      option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    
    Milan Jaros's avatar
    Milan Jaros committed
      if(UNIX AND NOT APPLE)
        option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
        set(PYTHON_REQUESTS_PATH "" CACHE PATH "Path to python site-packages or dist-packages containing 'requests' module")
        mark_as_advanced(PYTHON_REQUESTS_PATH)
      endif()
    endif()
    
    option(WITH_CPU_SSE              "Enable SIMD instruction if they're detected on the host machine" ON)
    mark_as_advanced(WITH_CPU_SSE)
    
    # Cycles
    option(WITH_CYCLES                  "Enable Cycles Render Engine" ON)
    option(WITH_CYCLES_STANDALONE       "Build Cycles standalone application" OFF)
    option(WITH_CYCLES_STANDALONE_GUI   "Build Cycles standalone with GUI" OFF)
    option(WITH_CYCLES_OSL              "Build Cycles with OSL support" ON)
    option(WITH_CYCLES_EMBREE           "Build Cycles with Embree support" OFF)
    option(WITH_CYCLES_CUDA_BINARIES    "Build Cycles CUDA binaries" OFF)
    option(WITH_CYCLES_CUBIN_COMPILER   "Build cubins with nvrtc based compiler instead of nvcc" OFF)
    option(WITH_CYCLES_CUDA_BUILD_SERIAL "Build cubins one after another (useful on machines with limited RAM)" OFF)
    mark_as_advanced(WITH_CYCLES_CUDA_BUILD_SERIAL)
    set(CYCLES_CUDA_BINARIES_ARCH sm_30 sm_35 sm_37 sm_50 sm_52 sm_60 sm_61 sm_70 sm_75 CACHE STRING "CUDA architectures to build binaries for")
    mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
    unset(PLATFORM_DEFAULT)
    option(WITH_CYCLES_LOGGING  "Build Cycles with logging support" ON)
    option(WITH_CYCLES_DEBUG    "Build Cycles with extra debug capabilities" OFF)
    option(WITH_CYCLES_NATIVE_ONLY  "Build Cycles with native kernel only (which fits current CPU, use for development only)" OFF)
    option(WITH_CYCLES_KERNEL_ASAN  "Build Cycles kernels with address sanitizer when WITH_COMPILER_ASAN is on, even if it's very slow" OFF)
    mark_as_advanced(WITH_CYCLES_KERNEL_ASAN)
    mark_as_advanced(WITH_CYCLES_CUBIN_COMPILER)
    mark_as_advanced(WITH_CYCLES_LOGGING)
    mark_as_advanced(WITH_CYCLES_DEBUG)
    mark_as_advanced(WITH_CYCLES_NATIVE_ONLY)
    
    option(WITH_CYCLES_DEVICE_CUDA              "Enable Cycles CUDA compute support" ON)
    option(WITH_CYCLES_DEVICE_OPTIX             "Enable Cycles OptiX support" OFF)
    option(WITH_CYCLES_DEVICE_OPENCL            "Enable Cycles OpenCL compute support" ON)
    option(WITH_CYCLES_NETWORK              "Enable Cycles compute over network support (EXPERIMENTAL and unfinished)" OFF)
    option(WITH_CYCLES_CLIENT                               "Enable Cycles Client support" OFF)
    mark_as_advanced(WITH_CYCLES_DEVICE_CUDA)
    mark_as_advanced(WITH_CYCLES_DEVICE_OPENCL)
    mark_as_advanced(WITH_CYCLES_NETWORK)
    mark_as_advanced(WITH_CYCLES_CLIENT)
    
    option(WITH_CUDA_DYNLOAD "Dynamically load CUDA libraries at runtime" ON)
    mark_as_advanced(WITH_CUDA_DYNLOAD)
    
    # LLVM
    option(WITH_LLVM                    "Use LLVM" OFF)
    if(APPLE)
      option(LLVM_STATIC                  "Link with LLVM static libraries" ON) # we prefer static llvm build on Apple, dyn build possible though
    else()
      option(LLVM_STATIC                  "Link with LLVM static libraries" OFF)
    
    Milan Jaros's avatar
    Milan Jaros committed
    endif()
    
    Milan Jaros's avatar
    Milan Jaros committed
    mark_as_advanced(LLVM_STATIC)
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    # disable for now, but plan to support on all platforms eventually
    option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" ON)
    mark_as_advanced(WITH_MEM_JEMALLOC)
    
    # currently only used for BLI_mempool
    option(WITH_MEM_VALGRIND "Enable extended valgrind support for better reporting" OFF)
    mark_as_advanced(WITH_MEM_VALGRIND)
    
    # Debug
    option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
    mark_as_advanced(WITH_CXX_GUARDEDALLOC)
    
    option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" ON)
    mark_as_advanced(WITH_ASSERT_ABORT)
    
    option(WITH_BOOST "Enable features depending on boost" ON)
    option(WITH_TBB   "Enable features depending on TBB (OpenVDB, OpenImageDenoise, sculpt multithreading)" ON)
    
    # TBB malloc is only supported on for windows currently
    if(WIN32)
      option(WITH_TBB_MALLOC_PROXY "Enable the TBB malloc replacement" ON)
    
    Milan Jaros's avatar
    Milan Jaros committed
    endif()
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    # Unit testsing
    option(WITH_GTESTS "Enable GTest unit testing" OFF)
    option(WITH_OPENGL_RENDER_TESTS "Enable OpenGL render related unit testing (Experimental)" OFF)
    option(WITH_OPENGL_DRAW_TESTS "Enable OpenGL UI drawing related unit testing (Experimental)" OFF)
    
    # Documentation
    if(UNIX AND NOT APPLE)
      option(WITH_DOC_MANPAGE "Create a manual page (Unix manpage)" OFF)
    
    Milan Jaros's avatar
    Milan Jaros committed
    endif()
    
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    # OpenGL
    
    option(WITH_OPENGL              "When off limits visibility of the opengl headers to just bf_gpu and gawain (temporary option for development purposes)" ON)
    option(WITH_GLEW_ES             "Switches to experimental copy of GLEW that has support for OpenGL ES. (temporary option for development purposes)" OFF)
    option(WITH_GL_EGL              "Use the EGL OpenGL system library instead of the platform specific OpenGL system library (CGL, glX, or WGL)"       OFF)
    option(WITH_GL_PROFILE_ES20     "Support using OpenGL ES 2.0. (through either EGL or the AGL/WGL/XGL 'es20' profile)"                               OFF)
    
    Milan Jaros's avatar
    Milan Jaros committed
    
    
    Milan Jaros's avatar
    Milan Jaros committed
    mark_as_advanced(
      WITH_OPENGL
      WITH_GLEW_ES
      WITH_GL_EGL
      WITH_GL_PROFILE_ES20
    )
    
    if(WIN32)
      option(WITH_GL_ANGLE "Link with the ANGLE library, an OpenGL ES 2.0 implementation based on Direct3D, instead of the system OpenGL library." OFF)
      mark_as_advanced(WITH_GL_ANGLE)
    endif()
    
    if(WITH_GLEW_ES AND WITH_SYSTEM_GLEW)
      message(WARNING Ignoring WITH_SYSTEM_GLEW and using WITH_GLEW_ES)
      set(WITH_SYSTEM_GLEW OFF)
    endif()
    
    if(WIN32)
      getDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
      set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
    endif()
    
    # Compiler toolchain
    
    Milan Jaros's avatar
    Milan Jaros committed
    if(CMAKE_COMPILER_IS_GNUCC)
    
    Milan Jaros's avatar
    Milan Jaros committed
    485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
      option(WITH_LINKER_GOLD "Use ld.gold linker which is usually faster than ld.bfd" ON)
      mark_as_advanced(WITH_LINKER_GOLD)
    endif()
    
    if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
      option(WITH_COMPILER_ASAN "Build and link against address sanitizer (only for Debug & RelWithDebInfo targets)." OFF)
      mark_as_advanced(WITH_COMPILER_ASAN)
    
      if(WITH_COMPILER_ASAN)
        set(_asan_defaults "\
    -fsanitize=address \
    -fsanitize=bool \
    -fsanitize=bounds \
    -fsanitize=enum \
    -fsanitize=float-cast-overflow \
    -fsanitize=float-divide-by-zero \
    -fsanitize=nonnull-attribute \
    -fsanitize=returns-nonnull-attribute \
    -fsanitize=signed-integer-overflow \
    -fsanitize=undefined \
    -fsanitize=vla-bound \
    -fno-sanitize=alignment \
    ")
    
        if(NOT MSVC) # not all sanitizers are supported with clang-cl, these two however are very vocal about it
          set(_asan_defaults "${_asan_defaults} -fsanitize=leak -fsanitize=object-size" )
        endif()
        set(COMPILER_ASAN_CFLAGS "${_asan_defaults}" CACHE STRING "C flags for address sanitizer")
        mark_as_advanced(COMPILER_ASAN_CFLAGS)
        set(COMPILER_ASAN_CXXFLAGS "${_asan_defaults}" CACHE STRING "C++ flags for address sanitizer")
        mark_as_advanced(COMPILER_ASAN_CXXFLAGS)
    
        unset(_asan_defaults)
    
        if(NOT MSVC)
          find_library(COMPILER_ASAN_LIBRARY asan ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
        else()
          find_library(
            COMPILER_ASAN_LIBRARY NAMES clang_rt.asan-x86_64
            PATHS
            [HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\LLVM\\LLVM;]/lib/clang/7.0.0/lib/windows
            [HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\LLVM\\LLVM;]/lib/clang/6.0.0/lib/windows
          )
        endif()
        mark_as_advanced(COMPILER_ASAN_LIBRARY)
      endif()
    endif()
    
    if(WIN32)
      # Use hardcoded paths or find_package to find externals
      option(WITH_WINDOWS_FIND_MODULES "Use find_package to locate libraries" OFF)
      mark_as_advanced(WITH_WINDOWS_FIND_MODULES)
    
      option(WINDOWS_USE_VISUAL_STUDIO_PROJECT_FOLDERS "Organize the visual studio projects according to source folder structure." ON)
      mark_as_advanced(WINDOWS_USE_VISUAL_STUDIO_PROJECT_FOLDERS)
    
      option(WINDOWS_USE_VISUAL_STUDIO_SOURCE_FOLDERS "Organize the source files in filters matching the source folders." ON)
      mark_as_advanced(WINDOWS_USE_VISUAL_STUDIO_SOURCE_FOLDERS)
    
      option(WINDOWS_PYTHON_DEBUG "Include the files needed for debugging python scripts with visual studio 2017+." OFF)
      mark_as_advanced(WINDOWS_PYTHON_DEBUG)
    
      option(WITH_WINDOWS_BUNDLE_CRT "Bundle the C runtime for install free distribution." ON)
      mark_as_advanced(WITH_WINDOWS_BUNDLE_CRT)
    
    endif()
    
    # The following only works with the Ninja generator in CMake >= 3.0.
    if("${CMAKE_GENERATOR}" MATCHES "Ninja")
      option(WITH_NINJA_POOL_JOBS
             "Enable Ninja pools of jobs, to try to ease building on machines with 16GB of RAM or less (if not yet defined, will try to set best values based on detected machine specifications)."
             OFF)
      mark_as_advanced(WITH_NINJA_POOL_JOBS)
    endif()
    
    if(UNIX AND NOT APPLE)
      option(WITH_CXX11_ABI "Use native C++11 ABI of compiler" ON)
      mark_as_advanced(WITH_CXX11_ABI)
    endif()
    
    # Installation process.
    option(POSTINSTALL_SCRIPT "Run given CMake script after installation process" OFF)
    mark_as_advanced(POSTINSTALL_SCRIPT)
    
    # end option(...)
    
    
    
    # By default we want to install to the directory we are compiling our executables
    # unless specified otherwise, which we currently do not allow
    if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
      if(WIN32)
        set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
      elseif(APPLE)
        set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
      else()
        if(WITH_INSTALL_PORTABLE)
          set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH} CACHE PATH "default install path" FORCE)
        endif()
      endif()
    endif()
    
    
    
    # Apple
    
    if(APPLE)
      include(platform_apple_xcode)
    endif()
    
    
    #-----------------------------------------------------------------------------
    # Check for conflicting/unsupported configurations
    
    if(NOT WITH_BLENDER AND NOT WITH_CYCLES_STANDALONE)
      message(FATAL_ERROR
        "At least one of WITH_BLENDER or WITH_CYCLES_STANDALONE "
        "must be enabled, nothing to do!"
      )
    endif()
    
    if(NOT WITH_AUDASPACE)
      if(WITH_OPENAL)
        message(WARNING "WITH_OPENAL requires WITH_AUDASPACE which is disabled")
        set(WITH_OPENAL OFF)
      endif()
      if(WITH_JACK)
        message(WARNING "WITH_JACK requires WITH_AUDASPACE which is disabled")
        set(WITH_JACK OFF)
      endif()
    endif()
    
    if(NOT WITH_SDL AND WITH_GHOST_SDL)
      message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
    endif()
    
    # python module, needs some different options
    if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
      message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
    endif()
    
    
    # may as well build python module without a UI
    if(WITH_PYTHON_MODULE)
      set(WITH_HEADLESS ON)
    endif()
    
    if(NOT WITH_PYTHON)
      set(WITH_CYCLES OFF)
      set(WITH_DRACO OFF)
    endif()
    
    if(WITH_DRACO AND NOT WITH_PYTHON_INSTALL)
      message(STATUS "WITH_DRACO requires WITH_PYTHON_INSTALL to be ON, disabling WITH_DRACO for now")
      set(WITH_DRACO OFF)
    endif()
    
    # enable boost for cycles, audaspace or i18n
    # otherwise if the user disabled
    
    set_and_warn_dependency(WITH_BOOST WITH_CYCLES         OFF)
    set_and_warn_dependency(WITH_BOOST WITH_INTERNATIONAL  OFF)
    set_and_warn_dependency(WITH_BOOST WITH_OPENVDB        OFF)
    set_and_warn_dependency(WITH_BOOST WITH_OPENCOLORIO    OFF)
    set_and_warn_dependency(WITH_BOOST WITH_QUADRIFLOW     OFF)
    set_and_warn_dependency(WITH_BOOST WITH_USD            OFF)
    set_and_warn_dependency(WITH_BOOST WITH_ALEMBIC        OFF)
    
    if(WITH_BOOST AND NOT (WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_INTERNATIONAL OR
       WITH_OPENVDB OR WITH_OPENCOLORIO OR WITH_USD OR WITH_ALEMBIC))
      message(STATUS "No dependencies need 'WITH_BOOST' forcing WITH_BOOST=OFF")
      set(WITH_BOOST OFF)
    endif()
    
    set_and_warn_dependency(WITH_TBB WITH_USD               OFF)
    set_and_warn_dependency(WITH_TBB WITH_OPENIMAGEDENOISE  OFF)
    set_and_warn_dependency(WITH_TBB WITH_OPENVDB           OFF)
    set_and_warn_dependency(WITH_TBB WITH_MOD_FLUID         OFF)
    
    # OpenVDB uses 'half' type from OpenEXR & fails to link without OpenEXR enabled.
    set_and_warn_dependency(WITH_IMAGE_OPENEXR WITH_OPENVDB OFF)
    
    # auto enable openimageio for cycles
    if(WITH_CYCLES)
      set(WITH_OPENIMAGEIO ON)
    
      # auto enable llvm for cycles_osl
      if(WITH_CYCLES_OSL)
        set(WITH_LLVM ON CACHE BOOL "" FORCE)
      endif()
    else()
      set(WITH_CYCLES_OSL OFF)
    endif()
    
    # auto enable openimageio linking dependencies
    if(WITH_OPENIMAGEIO)
      set(WITH_IMAGE_OPENEXR ON)
      set(WITH_IMAGE_TIFF ON)
    endif()
    
    # auto enable alembic linking dependencies
    if(WITH_ALEMBIC)
      set(WITH_IMAGE_OPENEXR ON)
    endif()
    
    # don't store paths to libs for portable distribution
    if(WITH_INSTALL_PORTABLE)
      set(CMAKE_SKIP_BUILD_RPATH TRUE)
    endif()
    
    if(WITH_GHOST_SDL OR WITH_HEADLESS)
      set(WITH_X11           OFF)
      set(WITH_X11_XINPUT    OFF)
      set(WITH_X11_XF86VMODE OFF)
      set(WITH_X11_XFIXES    OFF)
      set(WITH_X11_ALPHA     OFF)
      set(WITH_GHOST_XDND    OFF)
      set(WITH_INPUT_IME     OFF)
      set(WITH_XR_OPENXR     OFF)
    endif()
    
    if(WITH_CPU_SSE)
      TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
    else()
      message(STATUS "SSE and SSE2 optimizations are DISABLED!")
      set(COMPILER_SSE_FLAG)
      set(COMPILER_SSE2_FLAG)
    endif()
    
    if(WITH_BUILDINFO)
      find_package(Git)
      if(NOT GIT_FOUND)
        message(WARNING "Git was not found, disabling WITH_BUILDINFO")
        set(WITH_BUILDINFO OFF)
      endif()
    endif()
    
    if(WITH_AUDASPACE)
      if(NOT WITH_SYSTEM_AUDASPACE)
        set(AUDASPACE_C_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/audaspace/bindings/C" "${CMAKE_BINARY_DIR}/extern/audaspace")
        set(AUDASPACE_PY_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/audaspace/bindings")
      endif()
    endif()
    
    # Auto-enable CUDA dynload if toolkit is not found.
    if(NOT WITH_CUDA_DYNLOAD)
      find_package(CUDA)
      if(NOT CUDA_FOUND)
        message("CUDA toolkit not found, using dynamic runtime loading of libraries instead")
        set(WITH_CUDA_DYNLOAD ON)
      endif()
    endif()
    
    #-----------------------------------------------------------------------------
    # Check check if submodules are cloned
    
    if(WITH_INTERNATIONAL)
      file(GLOB RESULT "${CMAKE_SOURCE_DIR}/release/datafiles/locale")
      list(LENGTH RESULT DIR_LEN)
      if(DIR_LEN EQUAL 0)
        message(WARNING
          "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
          "This is a 'git submodule', which are known not to work with bridges to other version "
          "control systems, disabling 'WITH_INTERNATIONAL'."
        )
        set(WITH_INTERNATIONAL OFF)
      endif()
    endif()
    
    if(WITH_PYTHON)
      # While we have this as an '#error' in 'bpy_capi_utils.h',
      # upgrading Python tends to cause confusion for users who build.
      # Give the error message early to make this more obvious.
      #
      # Do this before main 'platform_*' checks,
      # because UNIX will search for the old Python paths which may not exist.
      # giving errors about missing paths before this case is met.
      if(DEFINED PYTHON_VERSION AND "${PYTHON_VERSION}" VERSION_LESS "3.7")
        message(FATAL_ERROR "At least Python 3.7 is required to build")
      endif()
    
      file(GLOB RESULT "${CMAKE_SOURCE_DIR}/release/scripts/addons")
      list(LENGTH RESULT DIR_LEN)
      if(DIR_LEN EQUAL 0)
        message(WARNING
          "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
          "This is a 'git submodule', which are known not to work with bridges to other version "
          "control systems: * CONTINUING WITHOUT ADDONS *"
        )
      endif()
    endif()
    
    #-----------------------------------------------------------------------------
    # Initialize un-cached vars, avoid unused warning
    
    # linux only, not cached
    set(WITH_BINRELOC OFF)
    
    # MACOSX only, set to avoid uninitialized
    set(EXETYPE "")
    
    # C/C++ flags
    set(PLATFORM_CFLAGS)
    
    # these are added to later on.
    set(C_WARNINGS)
    set(CXX_WARNINGS)
    
    # for gcc -Wno-blah-blah
    set(C_REMOVE_STRICT_FLAGS)
    set(CXX_REMOVE_STRICT_FLAGS)
    
    # libraries to link the binary with passed to target_link_libraries()
    # known as LLIBS to scons
    set(PLATFORM_LINKLIBS "")
    
    # Added to linker flags in setup_liblinks
    # - CMAKE_EXE_LINKER_FLAGS
    # - CMAKE_EXE_LINKER_FLAGS_DEBUG
    set(PLATFORM_LINKFLAGS "")
    set(PLATFORM_LINKFLAGS_DEBUG "")
    
    if(NOT CMAKE_BUILD_TYPE MATCHES "Release")
      if(WITH_COMPILER_ASAN)
        set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COMPILER_ASAN_CFLAGS}")
        set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${COMPILER_ASAN_CFLAGS}")
    
        set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COMPILER_ASAN_CXXFLAGS}")
        set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${COMPILER_ASAN_CXXFLAGS}")
        if(MSVC)
          set(COMPILER_ASAN_LINKER_FLAGS "/FUNCTIONPADMIN:6")
        endif()
        if(COMPILER_ASAN_LIBRARY)
          set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS};${COMPILER_ASAN_LIBRARY}")
          set(PLATFORM_LINKFLAGS "${COMPILER_ASAN_LIBRARY} ${COMPILER_ASAN_LINKER_FLAGS}")
          set(PLATFORM_LINKFLAGS_DEBUG "${COMPILER_ASAN_LIBRARY} ${COMPILER_ASAN_LINKER_FLAGS}")
        endif()
      endif()
    endif()
    
    # ----------------------------------------------------------------------------
    # Main Platform Checks
    #
    # - UNIX
    # - WIN32
    # - APPLE
    
    if(UNIX AND NOT APPLE)
      include(platform_unix)
    elseif(WIN32)
      include(platform_win32)
    elseif(APPLE)
      include(platform_apple)
    endif()
    
    #-----------------------------------------------------------------------------
    # Common.
    
    if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
      message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
    endif()
    
    if(WITH_CYCLES)
      if(NOT WITH_OPENIMAGEIO)
        message(FATAL_ERROR
          "Cycles requires WITH_OPENIMAGEIO, the library may not have been found. "
          "Configure OIIO or disable WITH_CYCLES"
        )
      endif()
      if(NOT WITH_BOOST)
        message(FATAL_ERROR
          "Cycles requires WITH_BOOST, the library may not have been found. "
          "Configure BOOST or disable WITH_CYCLES"
        )
      endif()
    
      if(WITH_CYCLES_OSL)
        if(NOT WITH_LLVM)
          message(FATAL_ERROR
            "Cycles OSL requires WITH_LLVM, the library may not have been found. "
            "Configure LLVM or disable WITH_CYCLES_OSL"
          )
        endif()
      endif()
    endif()
    
    if(WITH_INTERNATIONAL)
      if(NOT WITH_BOOST)
        message(FATAL_ERROR
          "Internationalization requires WITH_BOOST, the library may not have been found. "
          "Configure BOOST or disable WITH_INTERNATIONAL"
        )
      endif()
    endif()
    
    # See TEST_SSE_SUPPORT() for how this is defined.
    
    # Do it globally, SSE2 is required for quite some time now.
    # Doing it now allows to use SSE/SSE2 in inline headers.
    if(SUPPORT_SSE_BUILD)
      set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
      add_definitions(-D__SSE__ -D__MMX__)
    endif()
    if(SUPPORT_SSE2_BUILD)
      set(PLATFORM_CFLAGS " ${PLATFORM_CFLAGS} ${COMPILER_SSE2_FLAG}")
      add_definitions(-D__SSE2__)
      if(NOT SUPPORT_SSE_BUILD) # don't double up
        add_definitions(-D__MMX__)
      endif()
    endif()
    
    
    # set the endian define
    if(MSVC)
      # for some reason this fails on msvc
      add_definitions(-D__LITTLE_ENDIAN__)
    
      # OSX-Note: as we do cross-compiling with specific set architecture,
      # endianess-detection and auto-setting is counterproductive
      # so we just set endianness according CMAKE_OSX_ARCHITECTURES
    
    elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
      add_definitions(-D__LITTLE_ENDIAN__)
    elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)
      add_definitions(-D__BIG_ENDIAN__)
    
    else()
      include(TestBigEndian)
      test_big_endian(_SYSTEM_BIG_ENDIAN)
      if(_SYSTEM_BIG_ENDIAN)
        add_definitions(-D__BIG_ENDIAN__)
      else()
        add_definitions(-D__LITTLE_ENDIAN__)
      endif()
      unset(_SYSTEM_BIG_ENDIAN)
    endif()
    if(WITH_IMAGE_OPENJPEG)
      # Special handling of Windows platform where openjpeg is always static.
      if(WIN32)
        set(OPENJPEG_DEFINES "-DOPJ_STATIC")
      else()
        set(OPENJPEG_DEFINES "")
      endif()
    endif()
    
    if(NOT WITH_SYSTEM_EIGEN3)
      set(EIGEN3_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/Eigen3)
    endif()
    
    if(WITH_OPENVDB)
      list(APPEND OPENVDB_DEFINITIONS -DWITH_OPENVDB)
    
      if(WITH_OPENVDB_3_ABI_COMPATIBLE)
        list(APPEND OPENVDB_DEFINITIONS -DOPENVDB_3_ABI_COMPATIBLE)
      endif()
    
      list(APPEND OPENVDB_INCLUDE_DIRS
        ${BOOST_INCLUDE_DIR}
        ${TBB_INCLUDE_DIRS}
        ${OPENEXR_INCLUDE_DIRS})
    
      list(APPEND OPENVDB_LIBRARIES ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
    
      if(WITH_OPENVDB_BLOSC)
        list(APPEND OPENVDB_DEFINITIONS -DWITH_OPENVDB_BLOSC)
        list(APPEND OPENVDB_LIBRARIES ${BLOSC_LIBRARIES} ${ZLIB_LIBRARIES})
      endif()
    
      list(APPEND OPENVDB_LIBRARIES ${BOOST_LIBRARIES} ${TBB_LIBRARIES})
    endif()
    
    #-----------------------------------------------------------------------------
    # Configure OpenGL.
    
    find_package(OpenGL)
    blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
    
    if(WITH_OPENGL)
      add_definitions(-DWITH_OPENGL)
    endif()
    
    if(WITH_SYSTEM_GLES)
      find_package_wrapper(OpenGLES)
    endif()
    
    if(WITH_GL_PROFILE_ES20)
      if(WITH_SYSTEM_GLES)
        if(NOT OPENGLES_LIBRARY)
          message(FATAL_ERROR
            "Unable to find OpenGL ES libraries. "
            "Install them or disable WITH_SYSTEM_GLES."
          )
        endif()
    
        list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}")
    
      else()
        set(OPENGLES_LIBRARY "" CACHE FILEPATH "OpenGL ES 2.0 library file")
        mark_as_advanced(OPENGLES_LIBRARY)
    
        list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}")
    
        if(NOT OPENGLES_LIBRARY)
          message(FATAL_ERROR
            "To compile WITH_GL_EGL you need to set OPENGLES_LIBRARY "
            "to the file path of an OpenGL ES 2.0 library."
          )
        endif()
    
      endif()
    
      if(WIN32)
        # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
    
        set(OPENGLES_DLL "" CACHE FILEPATH "OpenGL ES 2.0 redistributable DLL file")
        mark_as_advanced(OPENGLES_DLL)