Skip to content
Snippets Groups Projects
CMakeLists.txt 59 KiB
Newer Older
  • Learn to ignore specific revisions
  • # ***** 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,
    
    Campbell Barton's avatar
    Campbell Barton committed
    # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    
    #
    # The Original Code is Copyright (C) 2006, Blender Foundation
    # All rights reserved.
    #
    # The Original Code is: all of this file.
    #
    # Contributor(s): Jacques Beaurain.
    #
    
    # ***** END GPL LICENSE BLOCK *****
    
    #-----------------------------------------------------------------------------
    
    Campbell Barton's avatar
    Campbell Barton 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.
    
    if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
    
    Campbell Barton's avatar
    Campbell Barton committed
    	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.:"
    
    Campbell Barton's avatar
    Campbell Barton committed
    			"\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()
    
    Jörg Müller's avatar
    Jörg Müller committed
    cmake_minimum_required(VERSION 3.5)
    
    	set(FIRST_RUN TRUE)
    else()
    	set(FIRST_RUN FALSE)
    
    list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
    
    list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/platform")
    
    # avoid having empty buildtype
    
    if(NOT DEFINED CMAKE_BUILD_TYPE_INIT)
    	set(CMAKE_BUILD_TYPE_INIT "Release")
    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.
    
    
    if(NOT (${CMAKE_VERSION} VERSION_LESS 3.0))
    	set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
    		$<$<CONFIG:Debug>:DEBUG;_DEBUG>
    		$<$<CONFIG:Release>:NDEBUG>
    		$<$<CONFIG:MinSizeRel>:NDEBUG>
    		$<$<CONFIG:RelWithDebInfo>:NDEBUG>
    	)
    else()
    	# keep until CMake-3.0 is min requirement
    	set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG           DEBUG _DEBUG)
    	set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE         NDEBUG)
    	set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL      NDEBUG)
    	set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO  NDEBUG)
    endif()
    
    #-----------------------------------------------------------------------------
    # Set policy
    
    
    # see "cmake --help-policy CMP0003"
    # So library linking is more sane
    cmake_policy(SET CMP0003 NEW)
    
    # So BUILDINFO and BLENDERPATH strings are automatically quoted
    cmake_policy(SET CMP0005 NEW)
    
    # So syntax problems are errors
    cmake_policy(SET CMP0010 NEW)
    
    # Input directories must have CMakeLists.txt
    cmake_policy(SET CMP0014 NEW)
    
    Campbell Barton's avatar
    Campbell Barton committed
    #-----------------------------------------------------------------------------
    # Load some macros.
    include(build_files/cmake/macros.cmake)
    
    Campbell Barton's avatar
    Campbell Barton committed
    #-----------------------------------------------------------------------------
    # Initialize project.
    
    Campbell Barton's avatar
    Campbell Barton committed
    blender_project_hack_pre()
    
    Campbell Barton's avatar
    Campbell Barton committed
    project(Blender)
    
    Campbell Barton's avatar
    Campbell Barton committed
    blender_project_hack_post()
    
    #-----------------------------------------------------------------------------
    # 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)
    
    set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests CACHE INTERNAL "" FORCE)
    
    
    #-----------------------------------------------------------------------------
    # Set default config options
    
    Campbell Barton's avatar
    Campbell Barton committed
    
    
    
    #-----------------------------------------------------------------------------
    # Platform Specific Defaults
    
    # list of var-names
    set(_init_vars)
    
    # initialize to ON
    macro(option_defaults_init)
    	foreach(_var ${ARGV})
    		set(${_var} ON)
    		list(APPEND _init_vars "${_var}")
    	endforeach()
    
    endmacro()
    
    # remove from namespace
    macro(option_defaults_clear)
    	foreach(_var ${_init_vars})
    		unset(${_var})
    	endforeach()
    	unset(_var)
    	unset(_init_vars)
    endmacro()
    
    
    # values to initialize WITH_****
    option_defaults_init(
    	_init_BUILDINFO
    	_init_CODEC_FFMPEG
    	_init_CYCLES_OSL
    
    	_init_IMAGE_OPENEXR
    	_init_INPUT_NDOF
    	_init_JACK
    	_init_OPENCOLLADA
    	_init_OPENCOLORIO
    	_init_SDL
    	_init_FFTW3
    	_init_GAMEENGINE
    
    Campbell Barton's avatar
    Campbell Barton committed
    if(UNIX AND NOT APPLE)
    
    	# some of these libraries are problematic on Linux
    	# disable less important dependencies by default
    	set(_init_CODEC_FFMPEG                   OFF)
    	set(_init_CYCLES_OSL                     OFF)
    
    	set(_init_IMAGE_OPENEXR                  OFF)
    	set(_init_JACK                           OFF)
    	set(_init_OPENCOLLADA                    OFF)
    	set(_init_OPENCOLORIO                    OFF)
    	set(_init_SDL                            OFF)
    	set(_init_FFTW3                          OFF)
    
    elseif(WIN32)
    	set(_init_JACK                           OFF)
    elseif(APPLE)
    	set(_init_JACK                           OFF)
    
    
    #-----------------------------------------------------------------------------
    # Options
    
    
    Campbell Barton's avatar
    Campbell Barton committed
    # First platform specific non-cached vars
    
    Campbell Barton's avatar
    Campbell Barton committed
    if(UNIX AND NOT (APPLE OR HAIKU))
    
    Campbell Barton's avatar
    Campbell Barton 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)  # dont 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 effeciency, 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)
    
    	option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
    endif()
    
    
    option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ${_init_BUILDINFO})
    
    if(${CMAKE_VERSION} VERSION_LESS 2.8.8)
    	# add_library OBJECT arg unsupported
    	set(WITH_BUILDINFO OFF)
    endif()
    
    set(BUILDINFO_OVERRIDE_DATE "" CACHE STRING "Use instead of the current date for reproducable builds (empty string disables this option)")
    set(BUILDINFO_OVERRIDE_TIME "" CACHE STRING "Use instead of the current time for reproducable 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)" ${_init_FFTW3})
    
    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_GAMEENGINE    "Enable Game Engine" ${_init_GAMEENGINE})
    
    if(APPLE)
    	set(WITH_GAMEENGINE_DECKLINK OFF)
    else()
    	option(WITH_GAMEENGINE_DECKLINK "Support BlackMagicDesign DeckLink cards in the Game Engine" ON)
    endif()
    
    option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ${_init_OPENCOLORIO})
    
    option(WITH_CLAY_ENGINE    "Enable Clay engine" ON)
    
    # Compositor
    option(WITH_COMPOSITOR         "Enable the tile based nodal compositor" ON)
    
    option(WITH_OPENSUBDIV    "Enable OpenSubdiv for surface subdivision" _init_OPENSUBDIV)
    
    option(WITH_OPENVDB       "Enable features relying on OpenVDB" OFF)
    option(WITH_OPENVDB_BLOSC "Enable blosc compression for OpenVDB, only enable if OpenVDB was built with blosc support" OFF)
    
    
    # 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()
    
    
    option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
    mark_as_advanced(WITH_HEADLESS)
    
    
    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()
    
    Campbell Barton's avatar
    Campbell Barton committed
    
    
    Jason Wilkins's avatar
    Jason Wilkins committed
    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)
    
    Jason Wilkins's avatar
    Jason Wilkins committed
    endif()
    
    if(UNIX AND NOT APPLE)
    
    	option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" OFF)
    
    Jason Wilkins's avatar
    Jason Wilkins committed
    	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)
    
    Jason Wilkins's avatar
    Jason Wilkins committed
    	set(WITH_SYSTEM_GLES OFF)
    
    option(WITH_SYSTEM_OPENJPEG "Use the operating systems OpenJPEG library" OFF)
    
    Campbell Barton's avatar
    Campbell Barton committed
    if(UNIX AND NOT APPLE)
    	option(WITH_SYSTEM_EIGEN3 "Use the systems Eigen3 library" OFF)
    endif()
    
    
    option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
    option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
    option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
    
    # option(WITH_MOD_CLOTH_ELTOPO    "Enable Experimental cloth solver" OFF)  # this is now only available in a branch
    # mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
    
    option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
    
    Campbell Barton's avatar
    Campbell Barton committed
    # 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)" ${_init_IMAGE_OPENEXR})
    
    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)
    
    option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
    
    Campbell Barton's avatar
    Campbell Barton committed
    
    
    option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
    
    option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" ${_init_CODEC_FFMPEG})
    
    option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
    
    Kévin Dietrich's avatar
    Kévin Dietrich committed
    # Alembic support
    option(WITH_ALEMBIC             "Enable Alembic Support" OFF)
    option(WITH_ALEMBIC_HDF5        "Enable Legacy Alembic Support (not officially supported)" OFF)
    
    
    Campbell Barton's avatar
    Campbell Barton committed
    # 3D format support
    
    # Disable opencollada when we don't have precompiled libs
    
    option(WITH_OPENCOLLADA   "Enable OpenCollada Support (http://www.opencollada.org)" ${_init_OPENCOLLADA})
    
    Campbell Barton's avatar
    Campbell Barton committed
    # Sound output
    
    option(WITH_SDL           "Enable SDL for sound and joystick support" ${_init_SDL})
    
    option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
    
    option(WITH_JACK          "Enable JACK Support (http://www.jackaudio.org)" ${_init_JACK})
    
    	option(WITH_JACK_DYNLOAD  "Enable runtime dynamic JACK libraries loading" OFF)
    
    if(UNIX AND NOT APPLE)
    	option(WITH_SDL_DYNLOAD  "Enable runtime dynamic SDL libraries loading" OFF)
    endif()
    
    Campbell Barton's avatar
    Campbell Barton 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)
    
    Campbell Barton's avatar
    Campbell Barton committed
    	option(WITH_SYSTEM_LZO    "Use the system LZO library" OFF)
    
    endif()
    
    Campbell Barton's avatar
    Campbell Barton committed
    
    
    # Camera/motion tracking
    
    option(WITH_LIBMV         "Enable Libmv structure from motion library" ON)
    
    option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." OFF)
    
    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)
    
    
    Campbell Barton's avatar
    Campbell Barton committed
    # 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)" ${_init_INPUT_NDOF})
    
    Campbell Barton's avatar
    Campbell Barton committed
    option(WITH_RAYOPTIMIZATION	"Enable use of SIMD (SSE) optimizations for the raytracer" ON)
    
    Campbell Barton's avatar
    Campbell Barton committed
    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()
    
    Campbell Barton's avatar
    Campbell Barton committed
    endif()
    
    option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
    
    if(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)
    
    
    	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)
    
    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" ${_init_CYCLES_OSL})
    
    option(WITH_CYCLES_OPENSUBDIV		"Build Cycles with OpenSubdiv support" ${_init_CYCLES_OPENSUBDIV})
    
    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)
    
    set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 sm_35 sm_37 sm_50 sm_52 sm_60 sm_61 CACHE STRING "CUDA architectures to build binaries for")
    
    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)
    
    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_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)
    endif()
    
    # 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)
    
    
    option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
    
    option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
    
    option(WITH_BOOST					"Enable features depending on boost" ON)
    
    # Unit testsing
    option(WITH_GTESTS "Enable GTest unit testing" OFF)
    
    option(WITH_OPENGL_TESTS "Enable OpenGL related unit testing (Experimental)" OFF)
    
    
    # Documentation
    if(UNIX AND NOT APPLE)
    	option(WITH_DOC_MANPAGE "Create a manual page (Unix manpage)" OFF)
    endif()
    
    
    
    Jason Wilkins's avatar
    Jason Wilkins committed
    # OpenGL
    
    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. (thru either EGL or the AGL/WGL/XGL 'es20' profile)"                                  OFF)
    
    mark_as_advanced(
    	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()
    
    
    	getDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
    	set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
    endif()
    
    
    # Experimental support of C11 and C++11
    
    #
    # We default options to whatever default standard in the current compiler.
    
    if(APPLE)
    	set(_c11_init ON)
    	set(_cxx11_init ON)
    	set(WITH_C11 ON)
    	set(WITH_CXX11 ON)
    elseif(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "6.0") AND (NOT WITH_CXX11))
    
    	set(_c11_init ON)
    else()
    	set(_c11_init OFF)
    endif()
    
    set(_cxx11_init ON)
    
    
    option(WITH_C11 "Build with C11 standard enabled, for development use only!" ${_c11_init})
    
    mark_as_advanced(WITH_C11)
    
    option(WITH_CXX11 "Build with C++11 standard enabled, for development use only!" ${_cxx11_init})
    
    mark_as_advanced(WITH_CXX11)
    
    # Compiler toolchain
    if(CMAKE_COMPILER_IS_GNUCC)
    	option(WITH_LINKER_GOLD "Use ld.gold linker which is usually faster than ld.bfd" ON)
    	mark_as_advanced(WITH_LINKER_GOLD)
    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(WITH_WINDOWS_CODESIGN "Use signtool to sign the final binary." OFF)
    	mark_as_advanced(WITH_WINDOWS_CODESIGN)
    
    	set(WINDOWS_CODESIGN_PFX CACHE FILEPATH  "Path to pfx file to use for codesigning.")
    	mark_as_advanced(WINDOWS_CODESIGN_PFX)
    
    	set(WINDOWS_CODESIGN_PFX_PASSWORD CACHE STRING  "password for pfx file used for codesigning.")
    	mark_as_advanced(WINDOWS_CODESIGN_PFX_PASSWORD)
    
    
    	option(WINDOWS_USE_VISUAL_STUDIO_FOLDERS "Organize the visual studio project according to source folders." ON)
    	mark_as_advanced(WINDOWS_USE_VISUAL_STUDIO_FOLDERS)
    
    # avoid using again
    option_defaults_clear()
    
    # 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
    
    Campbell Barton's avatar
    Campbell Barton committed
    if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    
    Campbell Barton's avatar
    Campbell Barton committed
    		set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
    
    Campbell Barton's avatar
    Campbell Barton committed
    		set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
    
    Campbell Barton's avatar
    Campbell Barton committed
    		if(WITH_INSTALL_PORTABLE)
    			set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH} CACHE PATH "default install path" FORCE)
    
    Jason Wilkins's avatar
    Jason Wilkins committed
    # Apple
    
    
    Campbell Barton's avatar
    Campbell Barton committed
    
    
    #-----------------------------------------------------------------------------
    # Check for conflicting/unsupported configurations
    
    
    Thomas Dinges's avatar
    Thomas Dinges committed
    if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_STANDALONE)
    
    	message(FATAL_ERROR
    		"At least one of WITH_BLENDER or WITH_PLAYER or "
    		"WITH_CYCLES_STANDALONE must be enabled, nothing to do!"
    	)
    
    if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
    	message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
    endif()
    
    if(NOT WITH_CXX11)
    	if(WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE)
    		message(FATAL_ERROR "WITH_AUDASPACE requires WITH_CXX11")
    	endif()
    endif()
    
    
    if(NOT WITH_AUDASPACE)
    	if(WITH_OPENAL)
    		message(FATAL_ERROR "WITH_OPENAL requires WITH_AUDASPACE")
    	endif()
    	if(WITH_JACK)
    		message(FATAL_ERROR "WITH_JACK requires WITH_AUDASPACE")
    	endif()
    	if(WITH_GAMEENGINE)
    		message(FATAL_ERROR "WITH_GAMEENGINE requires WITH_AUDASPACE")
    	endif()
    
    if(NOT WITH_SDL AND WITH_GHOST_SDL)
    
    	message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
    
    # python module, needs some different options
    if(WITH_PYTHON_MODULE AND WITH_PLAYER)
    	message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
    endif()
    
    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()
    
    
    # enable boost for cycles, audaspace or i18n
    
    # otherwise if the user disabled
    if(NOT WITH_BOOST)
    	# Explicitly disabled. so disable all deps.
    
    	macro(set_and_warn
    		_setting _val)
    		if(${${_setting}})
    
    Sergej Reich's avatar
    Sergej Reich committed
    			message(STATUS "'WITH_BOOST' is disabled: forcing 'set(${_setting} ${_val})'")
    
    		set(${_setting} ${_val})
    	endmacro()
    
    	set_and_warn(WITH_CYCLES         OFF)
    	set_and_warn(WITH_INTERNATIONAL  OFF)
    
    	set_and_warn(WITH_OPENVDB        OFF)
    
    	set_and_warn(WITH_OPENCOLORIO    OFF)
    
    elseif(WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_INTERNATIONAL OR
    
    Sergey Sharybin's avatar
    Sergey Sharybin committed
           WITH_OPENVDB OR WITH_OPENCOLORIO)
    
    	# New dependency graph needs either Boost or C++11 for function bindings.
    
    		# Enabled but we don't need it
    		set(WITH_BOOST OFF)
    	endif()
    
    Brecht Van Lommel's avatar
    Brecht Van Lommel committed
    endif()
    
    
    # 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()
    
    
    Kévin Dietrich's avatar
    Kévin Dietrich committed
    # 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)
    
    Jason Wilkins's avatar
    Jason Wilkins committed
    	set(WITH_X11           OFF)
    	set(WITH_X11_XINPUT    OFF)
    
    	set(WITH_X11_XFIXES    OFF)
    
    Jason Wilkins's avatar
    Jason Wilkins committed
    	set(WITH_GHOST_XDND    OFF)
    
    	set(WITH_INPUT_IME     OFF)
    
    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")
    
    TEST_SHARED_PTR_SUPPORT()
    TEST_UNORDERED_MAP_SUPPORT()
    
    
    	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")
    
    #-----------------------------------------------------------------------------
    # Check for valid directories
    
    # ... a partial checkout may cause this.
    
    #
    # note: we need to check for a known subdir in both cases.
    #       since uninitialized git submodules will give blank dirs
    
    	if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale/languages")
    
    		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)
    
    Campbell Barton's avatar
    Campbell Barton committed
    	# 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.6")
    		message(FATAL_ERROR "At least Python 3.6 is required to build")
    	endif()
    
    
    	if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons/modules")
    
    		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 *"
    		)
    
    #-----------------------------------------------------------------------------
    # Initialize un-cached vars, avoid unused warning
    
    
    # MACOSX only, set to avoid uninitialized
    
    Campbell Barton's avatar
    Campbell Barton committed
    set(EXETYPE "")
    
    # for gcc -Wno-blah-blah
    set(CC_REMOVE_STRICT_FLAGS)
    
    
    # libraries to link the binary with passed to target_link_libraries()
    # known as LLIBS to scons
    
    Campbell Barton's avatar
    Campbell Barton committed
    set(PLATFORM_LINKLIBS "")
    
    
    # Added to linker flags in setup_liblinks
    # - CMAKE_EXE_LINKER_FLAGS
    # - CMAKE_EXE_LINKER_FLAGS_DEBUG
    
    Campbell Barton's avatar
    Campbell Barton committed
    set(PLATFORM_LINKFLAGS "")
    set(PLATFORM_LINKFLAGS_DEBUG "")
    
    #-----------------------------------------------------------------------------
    #Platform specifics
    
    
    Jason Wilkins's avatar
    Jason Wilkins committed
    if(WITH_X11)
    	find_package(X11 REQUIRED)
    
    	find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
    	mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
    
    	list(APPEND PLATFORM_LINKLIBS ${X11_X11_LIB})
    
    	if(WITH_X11_XINPUT)
    		if(X11_Xinput_LIB)
    			list(APPEND PLATFORM_LINKLIBS ${X11_Xinput_LIB})
    		else()
    			set(WITH_X11_XINPUT OFF)
    		endif()
    	endif()
    
    	if(WITH_X11_XF86VMODE)
    		# XXX, why dont cmake make this available?
    		find_library(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
    		mark_as_advanced(X11_Xxf86vmode_LIB)
    		if(X11_Xxf86vmode_LIB)
    			list(APPEND PLATFORM_LINKLIBS ${X11_Xxf86vmode_LIB})
    		else()
    			set(WITH_X11_XF86VMODE OFF)
    		endif()
    	endif()
    
    
    	if(WITH_X11_XFIXES)
    		if(X11_Xfixes_LIB)
    			list(APPEND PLATFORM_LINKLIBS ${X11_Xfixes_LIB})
    		else()
    			set(WITH_X11_XFIXES OFF)
    		endif()
    	endif()
    
    
    	if(WITH_X11_ALPHA)
    		find_library(X11_Xrender_LIB Xrender  ${X11_LIB_SEARCH_PATH})
    		mark_as_advanced(X11_Xrender_LIB)
    
    		if(X11_Xrender_LIB)
    
    			list(APPEND PLATFORM_LINKLIBS ${X11_Xrender_LIB})
    		else()
    			set(WITH_X11_ALPHA OFF)
    		endif()
    	endif()
    
    
    Jason Wilkins's avatar
    Jason Wilkins committed
    endif()
    
    
    
    # ----------------------------------------------------------------------------
    # Main Platform Checks
    #
    # - UNIX
    # - WIN32
    # - APPLE
    
    
    	include(platform_unix)
    
    	include(platform_win32)
    
    	include(platform_apple)
    
    
    #-----------------------------------------------------------------------------
    # Common.
    
    if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
    	message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
    endif()
    
    
    		message(FATAL_ERROR
    			"Cycles requires WITH_OPENIMAGEIO, the library may not have been found. "
    			"Configure OIIO or disable WITH_CYCLES"
    		)
    
    		message(FATAL_ERROR
    			"Cycles requires WITH_BOOST, the library may not have been found. "
    			"Configure BOOST or disable WITH_CYCLES"
    		)
    
    			message(FATAL_ERROR
    				"Cycles OSL requires WITH_LLVM, the library may not have been found. "
    				"Configure LLVM or disable WITH_CYCLES_OSL"
    			)
    
    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"
    		)
    
    # 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) # dont double up
    		add_definitions(-D__MMX__)
    
    Campbell Barton's avatar
    Campbell Barton committed
    
    # set the endian define
    
    	# for some reason this fails on msvc
    
    Campbell Barton's avatar
    Campbell Barton committed
    	add_definitions(-D__LITTLE_ENDIAN__)
    
    Campbell Barton's avatar
    Campbell Barton committed
    
    # OSX-Note: as we do cross-compiling with specific set architecture,
    # endianess-detection and auto-setting is counterproductive
    
    # so we just set endianess according CMAKE_OSX_ARCHITECTURES
    
    elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
    	add_definitions(-D__LITTLE_ENDIAN__)
    
    Campbell Barton's avatar
    Campbell Barton committed
    elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)
    
    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)
    
    Campbell Barton's avatar
    Campbell Barton committed
    endif()
    
    		# dealt with above
    
    		set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
    
    		set(OPENJPEG_DEFINES "-DOPJ_STATIC")
    
    	# Special handling of Windows platform where openjpeg is always static.
    	if(WIN32)
    		set(OPENJPEG_DEFINES "-DOPJ_STATIC")
    	endif()
    
    Campbell Barton's avatar
    Campbell Barton committed
    if(NOT WITH_SYSTEM_EIGEN3)
    	set(EIGEN3_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/Eigen3)
    endif()
    
    Enrico Fracasso's avatar
    Enrico Fracasso committed
    
    
    #-----------------------------------------------------------------------------
    # Configure OpenGL.
    
    blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
    
    Jason Wilkins's avatar
    Jason Wilkins committed
    
    if(WITH_SYSTEM_GLES)
    	find_package_wrapper(OpenGLES)
    endif()
    
    
    if(WITH_GL_PROFILE_ES20)
    
    Jason Wilkins's avatar
    Jason Wilkins committed
    	if(WITH_SYSTEM_GLES)
    		if(NOT OPENGLES_LIBRARY)
    
    			message(FATAL_ERROR
    				"Unable to find OpenGL ES libraries. "
    				"Install them or disable WITH_SYSTEM_GLES."
    			)
    
    Jason Wilkins's avatar
    Jason Wilkins committed
    		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}")
    
    
    Campbell Barton's avatar
    Campbell Barton committed
    		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."
    			)
    
    Jason Wilkins's avatar
    Jason Wilkins committed
    		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)
    
    		if(NOT OPENGLES_DLL)
    
    			message(FATAL_ERROR
    				"To compile WITH_GL_PROFILE_ES20 you need to set OPENGLES_DLL to the file "
    				"path of an OpenGL ES 2.0 runtime dynamic link library (DLL)."
    			)
    
    Jason Wilkins's avatar
    Jason Wilkins committed
    		endif()
    
    		if(WITH_GL_ANGLE)
    			list(APPEND GL_DEFINITIONS -DWITH_ANGLE)