CMakeLists.txt 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774
  1. # ***** BEGIN GPL LICENSE BLOCK *****
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software Foundation,
  15. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # The Original Code is Copyright (C) 2006, Blender Foundation
  18. # All rights reserved.
  19. #
  20. # The Original Code is: all of this file.
  21. #
  22. # Contributor(s): Jacques Beaurain.
  23. #
  24. # ***** END GPL LICENSE BLOCK *****
  25. #-----------------------------------------------------------------------------
  26. # We don't allow in-source builds. This causes no end of troubles because
  27. # all out-of-source builds will use the CMakeCache.txt file there and even
  28. # build the libs and objects in it.
  29. if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
  30. if(NOT DEFINED WITH_IN_SOURCE_BUILD)
  31. message(FATAL_ERROR
  32. "CMake generation for blender is not allowed within the source directory!"
  33. "\n Remove \"${CMAKE_SOURCE_DIR}/CMakeCache.txt\" and try again from another folder, e.g.:"
  34. "\n "
  35. "\n rm CMakeCache.txt"
  36. "\n cd .."
  37. "\n mkdir cmake-make"
  38. "\n cd cmake-make"
  39. "\n cmake ../blender"
  40. "\n "
  41. "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
  42. )
  43. endif()
  44. endif()
  45. cmake_minimum_required(VERSION 2.8)
  46. if(NOT EXECUTABLE_OUTPUT_PATH)
  47. set(FIRST_RUN TRUE)
  48. else()
  49. set(FIRST_RUN FALSE)
  50. endif()
  51. # this starts out unset
  52. list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
  53. list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/platform")
  54. # avoid having empty buildtype
  55. if(NOT DEFINED CMAKE_BUILD_TYPE_INIT)
  56. set(CMAKE_BUILD_TYPE_INIT "Release")
  57. endif()
  58. # quiet output for Makefiles, 'make -s' helps too
  59. # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
  60. # global compile definitions since add_definitions() adds for all.
  61. if(NOT (${CMAKE_VERSION} VERSION_LESS 3.0))
  62. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
  63. $<$<CONFIG:Debug>:DEBUG;_DEBUG>
  64. $<$<CONFIG:Release>:NDEBUG>
  65. $<$<CONFIG:MinSizeRel>:NDEBUG>
  66. $<$<CONFIG:RelWithDebInfo>:NDEBUG>
  67. )
  68. else()
  69. # keep until CMake-3.0 is min requirement
  70. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUG _DEBUG)
  71. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE NDEBUG)
  72. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL NDEBUG)
  73. set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO NDEBUG)
  74. endif()
  75. #-----------------------------------------------------------------------------
  76. # Set policy
  77. # see "cmake --help-policy CMP0003"
  78. # So library linking is more sane
  79. cmake_policy(SET CMP0003 NEW)
  80. # So BUILDINFO and BLENDERPATH strings are automatically quoted
  81. cmake_policy(SET CMP0005 NEW)
  82. # So syntax problems are errors
  83. cmake_policy(SET CMP0010 NEW)
  84. # Input directories must have CMakeLists.txt
  85. cmake_policy(SET CMP0014 NEW)
  86. #-----------------------------------------------------------------------------
  87. # Load some macros.
  88. include(build_files/cmake/macros.cmake)
  89. #-----------------------------------------------------------------------------
  90. # Initialize project.
  91. blender_project_hack_pre()
  92. project(Blender)
  93. blender_project_hack_post()
  94. enable_testing()
  95. #-----------------------------------------------------------------------------
  96. # Redirect output files
  97. set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE)
  98. set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE)
  99. set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests CACHE INTERNAL "" FORCE)
  100. #-----------------------------------------------------------------------------
  101. # Set default config options
  102. get_blender_version()
  103. #-----------------------------------------------------------------------------
  104. # Platform Specific Defaults
  105. # list of var-names
  106. set(_init_vars)
  107. # initialize to ON
  108. macro(option_defaults_init)
  109. foreach(_var ${ARGV})
  110. set(${_var} ON)
  111. list(APPEND _init_vars "${_var}")
  112. endforeach()
  113. unset(_var)
  114. endmacro()
  115. # remove from namespace
  116. macro(option_defaults_clear)
  117. foreach(_var ${_init_vars})
  118. unset(${_var})
  119. endforeach()
  120. unset(_var)
  121. unset(_init_vars)
  122. endmacro()
  123. # values to initialize WITH_****
  124. option_defaults_init(
  125. _init_BUILDINFO
  126. _init_CODEC_FFMPEG
  127. _init_CYCLES_OSL
  128. _init_CYCLES_OPENSUBDIV
  129. _init_IMAGE_OPENEXR
  130. _init_INPUT_NDOF
  131. _init_JACK
  132. _init_OPENCOLLADA
  133. _init_OPENCOLORIO
  134. _init_SDL
  135. _init_FFTW3
  136. _init_GAMEENGINE
  137. _init_OPENSUBDIV
  138. )
  139. # customize...
  140. if(UNIX AND NOT APPLE)
  141. # some of these libraries are problematic on Linux
  142. # disable less important dependencies by default
  143. set(_init_CODEC_FFMPEG OFF)
  144. set(_init_CYCLES_OSL OFF)
  145. set(_init_CYCLES_OPENSUBDIV OFF)
  146. set(_init_IMAGE_OPENEXR OFF)
  147. set(_init_JACK OFF)
  148. set(_init_OPENCOLLADA OFF)
  149. set(_init_OPENCOLORIO OFF)
  150. set(_init_SDL OFF)
  151. set(_init_FFTW3 OFF)
  152. set(_init_OPENSUBDIV OFF)
  153. elseif(WIN32)
  154. set(_init_JACK OFF)
  155. elseif(APPLE)
  156. set(_init_JACK OFF)
  157. set(_init_OPENSUBDIV OFF)
  158. endif()
  159. #-----------------------------------------------------------------------------
  160. # Options
  161. # First platform specific non-cached vars
  162. if(UNIX AND NOT APPLE)
  163. set(WITH_X11 ON)
  164. endif()
  165. # Blender internal features
  166. option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
  167. mark_as_advanced(WITH_BLENDER)
  168. option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
  169. option(WITH_PYTHON "Enable Embedded Python API (only disable for development)" ON)
  170. option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default" ON)
  171. mark_as_advanced(WITH_PYTHON) # dont want people disabling this unless they really know what they are doing.
  172. mark_as_advanced(WITH_PYTHON_SECURITY) # some distributions see this as a security issue, rather than have them patch it, make a build option.
  173. 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)
  174. mark_as_advanced(WITH_PYTHON_SAFETY)
  175. 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)
  176. if(APPLE)
  177. option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
  178. endif()
  179. option(WITH_BUILDINFO "Include extra build details (only disable for development & faster builds)" ${_init_BUILDINFO})
  180. if(${CMAKE_VERSION} VERSION_LESS 2.8.8)
  181. # add_library OBJECT arg unsupported
  182. set(WITH_BUILDINFO OFF)
  183. endif()
  184. set(BUILDINFO_OVERRIDE_DATE "" CACHE STRING "Use instead of the current date for reproducable builds (empty string disables this option)")
  185. set(BUILDINFO_OVERRIDE_TIME "" CACHE STRING "Use instead of the current time for reproducable builds (empty string disables this option)")
  186. set(CPACK_OVERRIDE_PACKAGENAME "" CACHE STRING "Use instead of the standard packagename (empty string disables this option)")
  187. mark_as_advanced(CPACK_OVERRIDE_PACKAGENAME)
  188. mark_as_advanced(BUILDINFO_OVERRIDE_DATE)
  189. mark_as_advanced(BUILDINFO_OVERRIDE_TIME)
  190. option(WITH_IK_ITASC "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
  191. option(WITH_IK_SOLVER "Enable Legacy IK solver (only disable for development)" ON)
  192. option(WITH_FFTW3 "Enable FFTW3 support (Used for smoke, ocean sim, and audio effects)" ${_init_FFTW3})
  193. option(WITH_BULLET "Enable Bullet (Physics Engine)" ON)
  194. option(WITH_SYSTEM_BULLET "Use the systems bullet library (currently unsupported due to missing features in upstream!)" )
  195. mark_as_advanced(WITH_SYSTEM_BULLET)
  196. option(WITH_GAMEENGINE "Enable Game Engine" ${_init_GAMEENGINE})
  197. if(APPLE)
  198. set(WITH_GAMEENGINE_DECKLINK OFF)
  199. else()
  200. option(WITH_GAMEENGINE_DECKLINK "Support BlackMagicDesign DeckLink cards in the Game Engine" ON)
  201. endif()
  202. option(WITH_PLAYER "Build Player" OFF)
  203. option(WITH_OPENCOLORIO "Enable OpenColorIO color management" ${_init_OPENCOLORIO})
  204. # Compositor
  205. option(WITH_COMPOSITOR "Enable the tile based nodal compositor" ON)
  206. option(WITH_OPENSUBDIV "Enable OpenSubdiv for surface subdivision" _init_OPENSUBDIV)
  207. option(WITH_OPENVDB "Enable features relying on OpenVDB" OFF)
  208. option(WITH_OPENVDB_BLOSC "Enable blosc compression for OpenVDB, only enable if OpenVDB was built with blosc support" OFF)
  209. # GHOST Windowing Library Options
  210. option(WITH_GHOST_DEBUG "Enable debugging output for the GHOST library" OFF)
  211. mark_as_advanced(WITH_GHOST_DEBUG)
  212. option(WITH_GHOST_SDL "Enable building Blender against SDL for windowing rather than the native APIs" OFF)
  213. mark_as_advanced(WITH_GHOST_SDL)
  214. if(WITH_X11)
  215. option(WITH_GHOST_XDND "Enable drag'n'drop support on X11 using XDND protocol" ON)
  216. endif()
  217. # Misc...
  218. option(WITH_HEADLESS "Build without graphical support (renderfarm, server mode only)" OFF)
  219. mark_as_advanced(WITH_HEADLESS)
  220. option(WITH_AUDASPACE "Build with blenders audio library (only disable if you know what you're doing!)" ON)
  221. option(WITH_SYSTEM_AUDASPACE "Build with external audaspace library installed on the system (only enable if you know what you're doing!)" OFF)
  222. mark_as_advanced(WITH_AUDASPACE)
  223. mark_as_advanced(WITH_SYSTEM_AUDASPACE)
  224. if(NOT WITH_AUDASPACE)
  225. set(WITH_SYSTEM_AUDASPACE OFF)
  226. endif()
  227. option(WITH_OPENMP "Enable OpenMP (has to be supported by the compiler)" ON)
  228. if(UNIX AND NOT APPLE)
  229. option(WITH_OPENMP_STATIC "Link OpenMP statically (only used by the release environment)" OFF)
  230. mark_as_advanced(WITH_OPENMP_STATIC)
  231. endif()
  232. if(WITH_X11)
  233. option(WITH_X11_XINPUT "Enable X11 Xinput (tablet support and unicode input)" ON)
  234. option(WITH_X11_XF86VMODE "Enable X11 video mode switching" ON)
  235. option(WITH_X11_XFIXES "Enable X11 XWayland cursor warping workaround" ON)
  236. option(WITH_X11_ALPHA "Enable X11 transparent background" ON)
  237. endif()
  238. if(UNIX AND NOT APPLE)
  239. option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" ON)
  240. option(WITH_SYSTEM_GLES "Use OpenGL ES library provided by the operating system" ON)
  241. else()
  242. # not an option for other OS's
  243. set(WITH_SYSTEM_GLEW OFF)
  244. set(WITH_SYSTEM_GLES OFF)
  245. endif()
  246. # (unix defaults to System OpenJPEG On)
  247. option(WITH_SYSTEM_OPENJPEG "Use the operating systems OpenJPEG library" OFF)
  248. if(UNIX AND NOT APPLE)
  249. option(WITH_SYSTEM_EIGEN3 "Use the systems Eigen3 library" OFF)
  250. endif()
  251. # Modifiers
  252. option(WITH_MOD_FLUID "Enable Elbeem Modifier (Fluid Simulation)" ON)
  253. option(WITH_MOD_SMOKE "Enable Smoke Modifier (Smoke Simulation)" ON)
  254. option(WITH_MOD_BOOLEAN "Enable Boolean Modifier" ON)
  255. option(WITH_MOD_REMESH "Enable Remesh Modifier" ON)
  256. # option(WITH_MOD_CLOTH_ELTOPO "Enable Experimental cloth solver" OFF) # this is now only available in a branch
  257. # mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
  258. option(WITH_MOD_OCEANSIM "Enable Ocean Modifier" OFF)
  259. # Image format support
  260. option(WITH_OPENIMAGEIO "Enable OpenImageIO Support (http://www.openimageio.org)" ON)
  261. option(WITH_IMAGE_OPENEXR "Enable OpenEXR Support (http://www.openexr.com)" ${_init_IMAGE_OPENEXR})
  262. option(WITH_IMAGE_OPENJPEG "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
  263. option(WITH_IMAGE_TIFF "Enable LibTIFF Support" ON)
  264. option(WITH_IMAGE_DDS "Enable DDS Image Support" ON)
  265. option(WITH_IMAGE_CINEON "Enable CINEON and DPX Image Support" ON)
  266. option(WITH_IMAGE_HDR "Enable HDR Image Support" ON)
  267. option(WITH_IMAGE_FRAMESERVER "Enable image FrameServer Support for rendering" ON)
  268. # Audio/Video format support
  269. option(WITH_CODEC_AVI "Enable Blenders own AVI file support (raw/jpeg)" ON)
  270. option(WITH_CODEC_FFMPEG "Enable FFMPeg Support (http://ffmpeg.org)" ${_init_CODEC_FFMPEG})
  271. option(WITH_CODEC_SNDFILE "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
  272. # Alembic support
  273. option(WITH_ALEMBIC "Enable Alembic Support" OFF)
  274. option(WITH_ALEMBIC_HDF5 "Enable Legacy Alembic Support (not officially supported)" OFF)
  275. if(APPLE)
  276. option(WITH_CODEC_QUICKTIME "Enable Quicktime Support" OFF)
  277. endif()
  278. # 3D format support
  279. # Disable opencollada when we don't have precompiled libs
  280. option(WITH_OPENCOLLADA "Enable OpenCollada Support (http://www.opencollada.org)" ${_init_OPENCOLLADA})
  281. # Sound output
  282. option(WITH_SDL "Enable SDL for sound and joystick support" ${_init_SDL})
  283. option(WITH_OPENAL "Enable OpenAL Support (http://www.openal.org)" ON)
  284. option(WITH_JACK "Enable JACK Support (http://www.jackaudio.org)" ${_init_JACK})
  285. if(UNIX AND NOT APPLE)
  286. option(WITH_JACK_DYNLOAD "Enable runtime dynamic JACK libraries loading" OFF)
  287. endif()
  288. if(UNIX AND NOT APPLE)
  289. option(WITH_SDL_DYNLOAD "Enable runtime dynamic SDL libraries loading" OFF)
  290. endif()
  291. # Compression
  292. option(WITH_LZO "Enable fast LZO compression (used for pointcache)" ON)
  293. option(WITH_LZMA "Enable best LZMA compression, (used for pointcache)" ON)
  294. if(UNIX AND NOT APPLE)
  295. option(WITH_SYSTEM_LZO "Use the system LZO library" OFF)
  296. endif()
  297. # Camera/motion tracking
  298. option(WITH_LIBMV "Enable Libmv structure from motion library" ON)
  299. option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." OFF)
  300. mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
  301. # Logging/unbit test libraries.
  302. option(WITH_SYSTEM_GFLAGS "Use system-wide Gflags instead of a bundled one" OFF)
  303. option(WITH_SYSTEM_GLOG "Use system-wide Glog instead of a bundled one" OFF)
  304. mark_as_advanced(WITH_SYSTEM_GFLAGS)
  305. mark_as_advanced(WITH_SYSTEM_GLOG)
  306. # Freestyle
  307. option(WITH_FREESTYLE "Enable Freestyle (advanced edges rendering)" ON)
  308. # Misc
  309. if(WIN32)
  310. option(WITH_INPUT_IME "Enable Input Method Editor (IME) for complex Asian character input" ON)
  311. endif()
  312. option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ${_init_INPUT_NDOF})
  313. option(WITH_RAYOPTIMIZATION "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
  314. if(UNIX AND NOT APPLE)
  315. option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
  316. option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
  317. if(WITH_STATIC_LIBS)
  318. option(WITH_BOOST_ICU "Boost uses ICU library (required for linking with static Boost built with libicu)." OFF)
  319. mark_as_advanced(WITH_BOOST_ICU)
  320. endif()
  321. endif()
  322. option(WITH_PYTHON_INSTALL "Copy system python into the blender install folder" ON)
  323. if(WITH_PYTHON_INSTALL)
  324. option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder" ON)
  325. set(PYTHON_NUMPY_PATH "" CACHE PATH "Path to python site-packages or dist-packages containing 'numpy' module")
  326. mark_as_advanced(PYTHON_NUMPY_PATH)
  327. if(UNIX AND NOT APPLE)
  328. option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
  329. set(PYTHON_REQUESTS_PATH "" CACHE PATH "Path to python site-packages or dist-packages containing 'requests' module")
  330. mark_as_advanced(PYTHON_REQUESTS_PATH)
  331. endif()
  332. endif()
  333. option(WITH_CPU_SSE "Enable SIMD instruction if they're detected on the host machine" ON)
  334. mark_as_advanced(WITH_CPU_SSE)
  335. # Cycles
  336. option(WITH_CYCLES "Enable Cycles Render Engine" ON)
  337. option(WITH_CYCLES_STANDALONE "Build Cycles standalone application" OFF)
  338. option(WITH_CYCLES_STANDALONE_GUI "Build Cycles standalone with GUI" OFF)
  339. option(WITH_CYCLES_OSL "Build Cycles with OSL support" ${_init_CYCLES_OSL})
  340. option(WITH_CYCLES_OPENSUBDIV "Build Cycles with OpenSubdiv support" ${_init_CYCLES_OPENSUBDIV})
  341. option(WITH_CYCLES_CUDA_BINARIES "Build Cycles CUDA binaries" OFF)
  342. 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")
  343. mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
  344. unset(PLATFORM_DEFAULT)
  345. option(WITH_CYCLES_LOGGING "Build Cycles with logging support" ON)
  346. option(WITH_CYCLES_DEBUG "Build Cycles with extra debug capabilities" OFF)
  347. option(WITH_CYCLES_NATIVE_ONLY "Build Cycles with native kernel only (which fits current CPU, use for development only)" OFF)
  348. mark_as_advanced(WITH_CYCLES_LOGGING)
  349. mark_as_advanced(WITH_CYCLES_DEBUG)
  350. mark_as_advanced(WITH_CYCLES_NATIVE_ONLY)
  351. option(WITH_CUDA_DYNLOAD "Dynamically load CUDA libraries at runtime" ON)
  352. mark_as_advanced(WITH_CUDA_DYNLOAD)
  353. # LLVM
  354. option(WITH_LLVM "Use LLVM" OFF)
  355. if(APPLE)
  356. option(LLVM_STATIC "Link with LLVM static libraries" ON) # we prefer static llvm build on Apple, dyn build possible though
  357. else()
  358. option(LLVM_STATIC "Link with LLVM static libraries" OFF)
  359. endif()
  360. mark_as_advanced(LLVM_STATIC)
  361. # disable for now, but plan to support on all platforms eventually
  362. option(WITH_MEM_JEMALLOC "Enable malloc replacement (http://www.canonware.com/jemalloc)" ON)
  363. mark_as_advanced(WITH_MEM_JEMALLOC)
  364. # currently only used for BLI_mempool
  365. option(WITH_MEM_VALGRIND "Enable extended valgrind support for better reporting" OFF)
  366. mark_as_advanced(WITH_MEM_VALGRIND)
  367. # Debug
  368. option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
  369. mark_as_advanced(WITH_CXX_GUARDEDALLOC)
  370. option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
  371. mark_as_advanced(WITH_ASSERT_ABORT)
  372. option(WITH_BOOST "Enable features depending on boost" ON)
  373. # Unit testsing
  374. option(WITH_GTESTS "Enable GTest unit testing" OFF)
  375. option(WITH_OPENGL_TESTS "Enable OpenGL related unit testing (Experimental)" OFF)
  376. # Documentation
  377. if(UNIX AND NOT APPLE)
  378. option(WITH_DOC_MANPAGE "Create a manual page (Unix manpage)" OFF)
  379. endif()
  380. # OpenGL
  381. option(WITH_GLEW_MX "Support multiple GLEW contexts (experimental)" OFF )
  382. option(WITH_GLEW_ES "Switches to experimental copy of GLEW that has support for OpenGL ES. (temporary option for development purposes)" OFF)
  383. option(WITH_GL_EGL "Use the EGL OpenGL system library instead of the platform specific OpenGL system library (CGL, glX, or WGL)" OFF)
  384. option(WITH_GL_PROFILE_COMPAT "Support using the OpenGL 'compatibility' profile. (deprecated)" ON )
  385. option(WITH_GL_PROFILE_CORE "Support using the OpenGL 3.2+ 'core' profile." OFF)
  386. option(WITH_GL_PROFILE_ES20 "Support using OpenGL ES 2.0. (thru either EGL or the AGL/WGL/XGL 'es20' profile)" OFF)
  387. mark_as_advanced(
  388. WITH_GLEW_MX
  389. WITH_GLEW_ES
  390. WITH_GL_EGL
  391. WITH_GL_PROFILE_COMPAT
  392. WITH_GL_PROFILE_CORE
  393. WITH_GL_PROFILE_ES20
  394. )
  395. if(WITH_GL_PROFILE_COMPAT)
  396. set(WITH_GLU ON)
  397. else()
  398. set(WITH_GLU OFF)
  399. endif()
  400. if(WIN32)
  401. 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)
  402. mark_as_advanced(WITH_GL_ANGLE)
  403. endif()
  404. if(WITH_GLEW_ES AND WITH_SYSTEM_GLEW)
  405. message(WARNING Ignoring WITH_SYSTEM_GLEW and using WITH_GLEW_ES)
  406. set(WITH_SYSTEM_GLEW OFF)
  407. endif()
  408. if(WIN32)
  409. getDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
  410. set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
  411. endif()
  412. # Experimental support of C11 and C++11
  413. #
  414. # We default options to whatever default standard in the current compiler.
  415. if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "6.0") AND (NOT WITH_CXX11))
  416. set(_c11_init ON)
  417. set(_cxx11_init ON)
  418. else()
  419. set(_c11_init OFF)
  420. set(_cxx11_init OFF)
  421. endif()
  422. option(WITH_C11 "Build with C11 standard enabled, for development use only!" ${_c11_init})
  423. mark_as_advanced(WITH_C11)
  424. option(WITH_CXX11 "Build with C++11 standard enabled, for development use only!" ${_cxx11_init})
  425. mark_as_advanced(WITH_CXX11)
  426. # Compiler toolchain
  427. if(CMAKE_COMPILER_IS_GNUCC)
  428. option(WITH_LINKER_GOLD "Use ld.gold linker which is usually faster than ld.bfd" ON)
  429. mark_as_advanced(WITH_LINKER_GOLD)
  430. endif()
  431. # Dependency graph
  432. option(WITH_LEGACY_DEPSGRAPH "Build Blender with legacy dependency graph" ON)
  433. mark_as_advanced(WITH_LEGACY_DEPSGRAPH)
  434. if(WIN32)
  435. # Use hardcoded paths or find_package to find externals
  436. option(WITH_WINDOWS_FIND_MODULES "Use find_package to locate libraries" OFF)
  437. mark_as_advanced(WITH_WINDOWS_FIND_MODULES)
  438. option(WITH_WINDOWS_CODESIGN "Use signtool to sign the final binary." OFF)
  439. mark_as_advanced(WITH_WINDOWS_CODESIGN)
  440. set(WINDOWS_CODESIGN_PFX CACHE FILEPATH "Path to pfx file to use for codesigning.")
  441. mark_as_advanced(WINDOWS_CODESIGN_PFX)
  442. set(WINDOWS_CODESIGN_PFX_PASSWORD CACHE STRING "password for pfx file used for codesigning.")
  443. mark_as_advanced(WINDOWS_CODESIGN_PFX_PASSWORD)
  444. endif()
  445. # avoid using again
  446. option_defaults_clear()
  447. # end option(...)
  448. # By default we want to install to the directory we are compiling our executables
  449. # unless specified otherwise, which we currently do not allow
  450. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  451. if(WIN32)
  452. set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
  453. elseif(APPLE)
  454. set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
  455. else()
  456. if(WITH_INSTALL_PORTABLE)
  457. set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH} CACHE PATH "default install path" FORCE)
  458. endif()
  459. endif()
  460. endif()
  461. # Apple
  462. if(APPLE)
  463. include(platform_apple_xcode)
  464. endif()
  465. #-----------------------------------------------------------------------------
  466. # Check for conflicting/unsupported configurations
  467. if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_STANDALONE)
  468. message(FATAL_ERROR
  469. "At least one of WITH_BLENDER or WITH_PLAYER or "
  470. "WITH_CYCLES_STANDALONE must be enabled, nothing to do!"
  471. )
  472. endif()
  473. if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
  474. message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
  475. endif()
  476. if(NOT WITH_AUDASPACE)
  477. if(WITH_OPENAL)
  478. message(FATAL_ERROR "WITH_OPENAL requires WITH_AUDASPACE")
  479. endif()
  480. if(WITH_JACK)
  481. message(FATAL_ERROR "WITH_JACK requires WITH_AUDASPACE")
  482. endif()
  483. if(WITH_GAMEENGINE)
  484. message(FATAL_ERROR "WITH_GAMEENGINE requires WITH_AUDASPACE")
  485. endif()
  486. endif()
  487. if(NOT WITH_SDL AND WITH_GHOST_SDL)
  488. message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
  489. endif()
  490. # python module, needs some different options
  491. if(WITH_PYTHON_MODULE AND WITH_PLAYER)
  492. message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
  493. endif()
  494. if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
  495. message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
  496. endif()
  497. # may as well build python module without a UI
  498. if(WITH_PYTHON_MODULE)
  499. set(WITH_HEADLESS ON)
  500. endif()
  501. if(NOT WITH_PYTHON)
  502. set(WITH_CYCLES OFF)
  503. endif()
  504. # enable boost for cycles, audaspace or i18n
  505. # otherwise if the user disabled
  506. if(NOT WITH_BOOST)
  507. # Explicitly disabled. so disable all deps.
  508. macro(set_and_warn
  509. _setting _val)
  510. if(${${_setting}})
  511. message(STATUS "'WITH_BOOST' is disabled: forcing 'set(${_setting} ${_val})'")
  512. endif()
  513. set(${_setting} ${_val})
  514. endmacro()
  515. set_and_warn(WITH_CYCLES OFF)
  516. set_and_warn(WITH_AUDASPACE OFF)
  517. set_and_warn(WITH_INTERNATIONAL OFF)
  518. set_and_warn(WITH_OPENVDB OFF)
  519. set_and_warn(WITH_OPENCOLORIO OFF)
  520. set_and_warn(WITH_MOD_BOOLEAN OFF)
  521. set_and_warn(WITH_OPENAL OFF) # depends on AUDASPACE
  522. set_and_warn(WITH_GAMEENGINE OFF) # depends on AUDASPACE
  523. set_and_warn(WITH_PLAYER OFF) # depends on GAMEENGINE
  524. elseif(WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_AUDASPACE OR WITH_INTERNATIONAL OR
  525. WITH_OPENVDB OR WITH_OPENCOLORIO OR WITH_MOD_BOOLEAN)
  526. # Keep enabled
  527. else()
  528. # New dependency graph needs either Boost or C++11 for function bindings.
  529. if(NOT WITH_CXX11)
  530. # Enabled but we don't need it
  531. set(WITH_BOOST OFF)
  532. endif()
  533. endif()
  534. # auto enable openimageio for cycles
  535. if(WITH_CYCLES)
  536. set(WITH_OPENIMAGEIO ON)
  537. # auto enable llvm for cycles_osl
  538. if(WITH_CYCLES_OSL)
  539. set(WITH_LLVM ON CACHE BOOL "" FORCE)
  540. endif()
  541. else()
  542. set(WITH_CYCLES_OSL OFF)
  543. endif()
  544. # auto enable openimageio linking dependencies
  545. if(WITH_OPENIMAGEIO)
  546. set(WITH_IMAGE_OPENEXR ON)
  547. set(WITH_IMAGE_TIFF ON)
  548. endif()
  549. # auto enable alembic linking dependencies
  550. if(WITH_ALEMBIC)
  551. set(WITH_IMAGE_OPENEXR ON)
  552. endif()
  553. # don't store paths to libs for portable distribution
  554. if(WITH_INSTALL_PORTABLE)
  555. set(CMAKE_SKIP_BUILD_RPATH TRUE)
  556. endif()
  557. if(WITH_GHOST_SDL OR WITH_HEADLESS)
  558. set(WITH_X11 OFF)
  559. set(WITH_X11_XINPUT OFF)
  560. set(WITH_X11_XF86VMODE OFF)
  561. set(WITH_X11_XFIXES OFF)
  562. set(WITH_X11_ALPHA OFF)
  563. set(WITH_GHOST_XDND OFF)
  564. set(WITH_INPUT_IME OFF)
  565. endif()
  566. if(WITH_CPU_SSE)
  567. TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
  568. else()
  569. message(STATUS "SSE and SSE2 optimizations are DISABLED!")
  570. set(COMPILER_SSE_FLAG)
  571. set(COMPILER_SSE2_FLAG)
  572. endif()
  573. if(WITH_BUILDINFO)
  574. find_package(Git)
  575. if(NOT GIT_FOUND)
  576. message(WARNING "Git was not found, disabling WITH_BUILDINFO")
  577. set(WITH_BUILDINFO OFF)
  578. endif()
  579. endif()
  580. TEST_SHARED_PTR_SUPPORT()
  581. TEST_UNORDERED_MAP_SUPPORT()
  582. if(WITH_AUDASPACE)
  583. if(WITH_SYSTEM_AUDASPACE)
  584. set(AUDASPACE_DEFINITIONS
  585. -DWITH_AUDASPACE
  586. -DWITH_SYSTEM_AUDASPACE
  587. "-DAUD_DEVICE_H=<AUD_Device.h>"
  588. "-DAUD_SPECIAL_H=<AUD_Special.h>"
  589. "-DAUD_SOUND_H=<AUD_Sound.h>"
  590. "-DAUD_HANDLE_H=<AUD_Handle.h>"
  591. "-DAUD_SEQUENCE_H=<AUD_Sequence.h>"
  592. "-DAUD_TYPES_H=<AUD_Types.h>"
  593. "-DAUD_PYTHON_H=<python/PyAPI.h>"
  594. )
  595. else()
  596. set(AUDASPACE_C_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/intern/audaspace/intern")
  597. set(AUDASPACE_PY_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/intern/audaspace/intern")
  598. set(AUDASPACE_DEFINITIONS
  599. -DWITH_AUDASPACE
  600. "-DAUD_DEVICE_H=<AUD_C-API.h>"
  601. "-DAUD_SPECIAL_H=<AUD_C-API.h>"
  602. "-DAUD_SOUND_H=<AUD_C-API.h>"
  603. "-DAUD_HANDLE_H=<AUD_C-API.h>"
  604. "-DAUD_SEQUENCE_H=<AUD_C-API.h>"
  605. "-DAUD_TYPES_H=<AUD_Space.h>"
  606. )
  607. endif()
  608. endif()
  609. if(APPLE)
  610. apple_check_quicktime()
  611. endif()
  612. #-----------------------------------------------------------------------------
  613. # Check for valid directories
  614. # ... a partial checkout may cause this.
  615. #
  616. # note: we need to check for a known subdir in both cases.
  617. # since uninitialized git submodules will give blank dirs
  618. if(WITH_INTERNATIONAL)
  619. if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale/languages")
  620. message(WARNING
  621. "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
  622. "This is a 'git submodule', which are known not to work with bridges to other version "
  623. "control systems, disabling 'WITH_INTERNATIONAL'."
  624. )
  625. set(WITH_INTERNATIONAL OFF)
  626. endif()
  627. endif()
  628. if(WITH_PYTHON)
  629. if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons/modules")
  630. message(WARNING
  631. "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
  632. "This is a 'git submodule', which are known not to work with bridges to other version "
  633. "control systems: * CONTINUING WITHOUT ADDONS *"
  634. )
  635. endif()
  636. endif()
  637. #-----------------------------------------------------------------------------
  638. # Initialize un-cached vars, avoid unused warning
  639. # linux only, not cached
  640. set(WITH_BINRELOC OFF)
  641. # MACOSX only, set to avoid uninitialized
  642. set(EXETYPE "")
  643. # C/C++ flags
  644. set(PLATFORM_CFLAGS)
  645. # these are added to later on.
  646. set(C_WARNINGS)
  647. set(CXX_WARNINGS)
  648. # for gcc -Wno-blah-blah
  649. set(CC_REMOVE_STRICT_FLAGS)
  650. # libraries to link the binary with passed to target_link_libraries()
  651. # known as LLIBS to scons
  652. set(PLATFORM_LINKLIBS "")
  653. # Added to linker flags in setup_liblinks
  654. # - CMAKE_EXE_LINKER_FLAGS
  655. # - CMAKE_EXE_LINKER_FLAGS_DEBUG
  656. set(PLATFORM_LINKFLAGS "")
  657. set(PLATFORM_LINKFLAGS_DEBUG "")
  658. #-----------------------------------------------------------------------------
  659. #Platform specifics
  660. if(WITH_X11)
  661. find_package(X11 REQUIRED)
  662. find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
  663. mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
  664. list(APPEND PLATFORM_LINKLIBS ${X11_X11_LIB})
  665. if(WITH_X11_XINPUT)
  666. if(X11_Xinput_LIB)
  667. list(APPEND PLATFORM_LINKLIBS ${X11_Xinput_LIB})
  668. else()
  669. set(WITH_X11_XINPUT OFF)
  670. endif()
  671. endif()
  672. if(WITH_X11_XF86VMODE)
  673. # XXX, why dont cmake make this available?
  674. find_library(X11_Xxf86vmode_LIB Xxf86vm ${X11_LIB_SEARCH_PATH})
  675. mark_as_advanced(X11_Xxf86vmode_LIB)
  676. if(X11_Xxf86vmode_LIB)
  677. list(APPEND PLATFORM_LINKLIBS ${X11_Xxf86vmode_LIB})
  678. else()
  679. set(WITH_X11_XF86VMODE OFF)
  680. endif()
  681. endif()
  682. if(WITH_X11_XFIXES)
  683. if(X11_Xfixes_LIB)
  684. list(APPEND PLATFORM_LINKLIBS ${X11_Xfixes_LIB})
  685. else()
  686. set(WITH_X11_XFIXES OFF)
  687. endif()
  688. endif()
  689. if(WITH_X11_ALPHA)
  690. find_library(X11_Xrender_LIB Xrender ${X11_LIB_SEARCH_PATH})
  691. mark_as_advanced(X11_Xrender_LIB)
  692. if(X11_Xrender_LIB)
  693. list(APPEND PLATFORM_LINKLIBS ${X11_Xrender_LIB})
  694. else()
  695. set(WITH_X11_ALPHA OFF)
  696. endif()
  697. endif()
  698. endif()
  699. # ----------------------------------------------------------------------------
  700. # Main Platform Checks
  701. #
  702. # - UNIX
  703. # - WIN32
  704. # - APPLE
  705. if(UNIX AND NOT APPLE)
  706. include(platform_unix)
  707. elseif(WIN32)
  708. include(platform_win32)
  709. elseif(APPLE)
  710. include(platform_apple)
  711. endif()
  712. #-----------------------------------------------------------------------------
  713. # Common.
  714. if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
  715. message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
  716. endif()
  717. if(WITH_CYCLES)
  718. if(NOT WITH_OPENIMAGEIO)
  719. message(FATAL_ERROR
  720. "Cycles requires WITH_OPENIMAGEIO, the library may not have been found. "
  721. "Configure OIIO or disable WITH_CYCLES"
  722. )
  723. endif()
  724. if(NOT WITH_BOOST)
  725. message(FATAL_ERROR
  726. "Cycles requires WITH_BOOST, the library may not have been found. "
  727. "Configure BOOST or disable WITH_CYCLES"
  728. )
  729. endif()
  730. if(WITH_CYCLES_OSL)
  731. if(NOT WITH_LLVM)
  732. message(FATAL_ERROR
  733. "Cycles OSL requires WITH_LLVM, the library may not have been found. "
  734. "Configure LLVM or disable WITH_CYCLES_OSL"
  735. )
  736. endif()
  737. endif()
  738. endif()
  739. if(WITH_INTERNATIONAL)
  740. if(NOT WITH_BOOST)
  741. message(FATAL_ERROR
  742. "Internationalization requires WITH_BOOST, the library may not have been found. "
  743. "Configure BOOST or disable WITH_INTERNATIONAL"
  744. )
  745. endif()
  746. endif()
  747. # See TEST_SSE_SUPPORT() for how this is defined.
  748. # Do it globally, SSE2 is required for quite some time now.
  749. # Doing it now allows to use SSE/SSE2 in inline headers.
  750. if(SUPPORT_SSE_BUILD)
  751. set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
  752. add_definitions(-D__SSE__ -D__MMX__)
  753. endif()
  754. if(SUPPORT_SSE2_BUILD)
  755. set(PLATFORM_CFLAGS " ${PLATFORM_CFLAGS} ${COMPILER_SSE2_FLAG}")
  756. add_definitions(-D__SSE2__)
  757. if(NOT SUPPORT_SSE_BUILD) # dont double up
  758. add_definitions(-D__MMX__)
  759. endif()
  760. endif()
  761. # set the endian define
  762. if(MSVC)
  763. # for some reason this fails on msvc
  764. add_definitions(-D__LITTLE_ENDIAN__)
  765. # OSX-Note: as we do cross-compiling with specific set architecture,
  766. # endianess-detection and auto-setting is counterproductive
  767. # so we just set endianess according CMAKE_OSX_ARCHITECTURES
  768. elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
  769. add_definitions(-D__LITTLE_ENDIAN__)
  770. elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)
  771. add_definitions(-D__BIG_ENDIAN__)
  772. else()
  773. include(TestBigEndian)
  774. test_big_endian(_SYSTEM_BIG_ENDIAN)
  775. if(_SYSTEM_BIG_ENDIAN)
  776. add_definitions(-D__BIG_ENDIAN__)
  777. else()
  778. add_definitions(-D__LITTLE_ENDIAN__)
  779. endif()
  780. unset(_SYSTEM_BIG_ENDIAN)
  781. endif()
  782. if(WITH_IMAGE_OPENJPEG)
  783. if(WITH_SYSTEM_OPENJPEG)
  784. # dealt with above
  785. set(OPENJPEG_DEFINES "")
  786. else()
  787. set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
  788. set(OPENJPEG_DEFINES "-DOPJ_STATIC")
  789. endif()
  790. # Special handling of Windows platform where openjpeg is always static.
  791. if(WIN32)
  792. set(OPENJPEG_DEFINES "-DOPJ_STATIC")
  793. endif()
  794. endif()
  795. if(NOT WITH_SYSTEM_EIGEN3)
  796. set(EIGEN3_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/Eigen3)
  797. endif()
  798. #-----------------------------------------------------------------------------
  799. # Configure OpenGL.
  800. find_package(OpenGL)
  801. blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
  802. if(WITH_GLU)
  803. list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_glu_LIBRARY}")
  804. list(APPEND GL_DEFINITIONS -DWITH_GLU)
  805. endif()
  806. if(WITH_SYSTEM_GLES)
  807. find_package_wrapper(OpenGLES)
  808. endif()
  809. if(WITH_GL_PROFILE_COMPAT OR WITH_GL_PROFILE_CORE)
  810. list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_gl_LIBRARY}")
  811. elseif(WITH_GL_PROFILE_ES20)
  812. if(WITH_SYSTEM_GLES)
  813. if(NOT OPENGLES_LIBRARY)
  814. message(FATAL_ERROR
  815. "Unable to find OpenGL ES libraries. "
  816. "Install them or disable WITH_SYSTEM_GLES."
  817. )
  818. endif()
  819. list(APPEND BLENDER_GL_LIBRARIES OPENGLES_LIBRARY)
  820. else()
  821. set(OPENGLES_LIBRARY "" CACHE FILEPATH "OpenGL ES 2.0 library file")
  822. mark_as_advanced(OPENGLES_LIBRARY)
  823. list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}")
  824. if(NOT OPENGLES_LIBRARY)
  825. message(FATAL_ERROR
  826. "To compile WITH_GL_EGL you need to set OPENGLES_LIBRARY "
  827. "to the file path of an OpenGL ES 2.0 library."
  828. )
  829. endif()
  830. endif()
  831. if(WIN32)
  832. # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
  833. set(OPENGLES_DLL "" CACHE FILEPATH "OpenGL ES 2.0 redistributable DLL file")
  834. mark_as_advanced(OPENGLES_DLL)
  835. if(NOT OPENGLES_DLL)
  836. message(FATAL_ERROR
  837. "To compile WITH_GL_PROFILE_ES20 you need to set OPENGLES_DLL to the file "
  838. "path of an OpenGL ES 2.0 runtime dynamic link library (DLL)."
  839. )
  840. endif()
  841. if(WITH_GL_ANGLE)
  842. list(APPEND GL_DEFINITIONS -DWITH_ANGLE)
  843. set(D3DCOMPILER_DLL "" CACHE FILEPATH "Direct3D Compiler redistributable DLL file (needed by ANGLE)")
  844. get_filename_component(D3DCOMPILER_FILENAME "${D3DCOMPILER_DLL}" NAME)
  845. list(APPEND GL_DEFINITIONS "-DD3DCOMPILER=\"\\\"${D3DCOMPILER_FILENAME}\\\"\"")
  846. mark_as_advanced(D3DCOMPILER_DLL)
  847. if(D3DCOMPILER_DLL STREQUAL "")
  848. message(FATAL_ERROR
  849. "To compile WITH_GL_ANGLE you need to set D3DCOMPILER_DLL to the file "
  850. "path of a copy of the DirectX redistributable DLL file: D3DCompiler_46.dll"
  851. )
  852. endif()
  853. endif()
  854. endif()
  855. endif()
  856. if(WITH_GL_EGL)
  857. list(APPEND GL_DEFINITIONS -DWITH_GL_EGL)
  858. if(WITH_SYSTEM_GLES)
  859. if(NOT OPENGLES_EGL_LIBRARY)
  860. message(FATAL_ERROR
  861. "Unable to find OpenGL ES libraries. "
  862. "Install them or disable WITH_SYSTEM_GLES."
  863. )
  864. endif()
  865. list(APPEND BLENDER_GL_LIBRARIES OPENGLES_EGL_LIBRARY)
  866. else()
  867. set(OPENGLES_EGL_LIBRARY "" CACHE FILEPATH "EGL library file")
  868. mark_as_advanced(OPENGLES_EGL_LIBRARY)
  869. list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}" "${OPENGLES_EGL_LIBRARY}")
  870. if(NOT OPENGLES_EGL_LIBRARY)
  871. message(FATAL_ERROR
  872. "To compile WITH_GL_EGL you need to set OPENGLES_EGL_LIBRARY "
  873. "to the file path of an EGL library."
  874. )
  875. endif()
  876. endif()
  877. if(WIN32)
  878. # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
  879. set(OPENGLES_EGL_DLL "" CACHE FILEPATH "EGL redistributable DLL file")
  880. mark_as_advanced(OPENGLES_EGL_DLL)
  881. if(NOT OPENGLES_EGL_DLL)
  882. message(FATAL_ERROR
  883. "To compile WITH_GL_EGL you need to set OPENGLES_EGL_DLL "
  884. "to the file path of an EGL runtime dynamic link library (DLL)."
  885. )
  886. endif()
  887. endif()
  888. endif()
  889. if(WITH_GL_PROFILE_COMPAT)
  890. list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_COMPAT)
  891. endif()
  892. if(WITH_GL_PROFILE_CORE)
  893. list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_CORE)
  894. endif()
  895. if(WITH_GL_PROFILE_ES20)
  896. list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_ES20)
  897. endif()
  898. if(WITH_GL_EGL)
  899. list(APPEND GL_DEFINITIONS -DWITH_EGL)
  900. endif()
  901. #-----------------------------------------------------------------------------
  902. # Configure OpenMP.
  903. if(WITH_OPENMP)
  904. find_package(OpenMP)
  905. if(OPENMP_FOUND)
  906. if(NOT WITH_OPENMP_STATIC)
  907. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
  908. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
  909. else()
  910. # Typically avoid adding flags as defines but we can't
  911. # pass OpenMP flags to the linker for static builds, meaning
  912. # we can't add any OpenMP related flags to CFLAGS variables
  913. # since they're passed to the linker as well.
  914. add_definitions("${OpenMP_C_FLAGS}")
  915. find_library_static(OpenMP_LIBRARIES gomp ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES})
  916. endif()
  917. else()
  918. set(WITH_OPENMP OFF)
  919. endif()
  920. mark_as_advanced(
  921. OpenMP_C_FLAGS
  922. OpenMP_CXX_FLAGS
  923. )
  924. endif()
  925. #-----------------------------------------------------------------------------
  926. # Configure GLEW
  927. if(WITH_GLEW_MX)
  928. list(APPEND GL_DEFINITIONS -DWITH_GLEW_MX)
  929. endif()
  930. if(WITH_SYSTEM_GLEW)
  931. find_package(GLEW)
  932. # Note: There is an assumption here that the system GLEW is not a static library.
  933. if(NOT GLEW_FOUND)
  934. message(FATAL_ERROR "GLEW is required to build Blender. Install it or disable WITH_SYSTEM_GLEW.")
  935. endif()
  936. if(WITH_GLEW_MX)
  937. set(BLENDER_GLEW_LIBRARIES ${GLEW_MX_LIBRARY})
  938. else()
  939. set(BLENDER_GLEW_LIBRARIES ${GLEW_LIBRARY})
  940. endif()
  941. else()
  942. if(WITH_GLEW_ES)
  943. set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew-es/include")
  944. list(APPEND GL_DEFINITIONS -DGLEW_STATIC -DWITH_GLEW_ES)
  945. # These definitions remove APIs from glew.h, making GLEW smaller, and catching unguarded API usage
  946. if(NOT WITH_GL_PROFILE_ES20)
  947. # No ES functions are needed
  948. list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
  949. elseif(NOT (WITH_GL_PROFILE_CORE OR WITH_GL_PROFILE_COMPAT))
  950. # ES is enabled, but the other functions are all disabled
  951. list(APPEND GL_DEFINITIONS -DGLEW_ES_ONLY)
  952. endif()
  953. if(WITH_GL_PROFILE_ES20)
  954. if(WITH_GL_EGL)
  955. list(APPEND GL_DEFINITIONS -DGLEW_USE_LIB_ES20)
  956. endif()
  957. # ToDo: This is an experiment to eliminate ES 1 symbols,
  958. # GLEW doesn't really properly provide this level of control
  959. # (for example, without modification it eliminates too many symbols)
  960. # so there are lots of modifications to GLEW to make this work,
  961. # and no attempt to make it work beyond Blender at this point.
  962. list(APPEND GL_DEFINITIONS -DGL_ES_VERSION_1_0=0 -DGL_ES_VERSION_CL_1_1=0 -DGL_ES_VERSION_CM_1_1=0)
  963. endif()
  964. if(WITH_GL_EGL)
  965. list(APPEND GL_DEFINITIONS -DGLEW_INC_EGL)
  966. endif()
  967. set(BLENDER_GLEW_LIBRARIES extern_glew_es bf_intern_glew_mx)
  968. else()
  969. set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
  970. list(APPEND GL_DEFINITIONS -DGLEW_STATIC)
  971. # This won't affect the non-experimental glew library,
  972. # but is used for conditional compilation elsewhere.
  973. list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
  974. set(BLENDER_GLEW_LIBRARIES extern_glew)
  975. endif()
  976. endif()
  977. if(NOT WITH_GLU)
  978. list(APPEND GL_DEFINITIONS -DGLEW_NO_GLU)
  979. endif()
  980. #-----------------------------------------------------------------------------
  981. # Configure Bullet
  982. if(WITH_BULLET AND WITH_SYSTEM_BULLET)
  983. find_package(Bullet)
  984. if(NOT BULLET_FOUND)
  985. set(WITH_BULLET OFF)
  986. endif()
  987. else()
  988. set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
  989. # set(BULLET_LIBRARIES "")
  990. endif()
  991. #-----------------------------------------------------------------------------
  992. # Configure Python.
  993. if(WITH_PYTHON_MODULE)
  994. add_definitions(-DPy_ENABLE_SHARED)
  995. endif()
  996. #-----------------------------------------------------------------------------
  997. # Configure GLog/GFlags
  998. if(WITH_LIBMV OR WITH_GTESTS OR (WITH_CYCLES AND WITH_CYCLES_LOGGING))
  999. if(WITH_SYSTEM_GFLAGS)
  1000. find_package(Gflags)
  1001. if(NOT GFLAGS_FOUND)
  1002. message(FATAL_ERROR "System wide Gflags is requested but was not found")
  1003. endif()
  1004. # FindGflags does not define this, and we are not even sure what to use here.
  1005. set(GFLAGS_DEFINES)
  1006. else()
  1007. set(GFLAGS_DEFINES
  1008. -DGFLAGS_DLL_DEFINE_FLAG=
  1009. -DGFLAGS_DLL_DECLARE_FLAG=
  1010. -DGFLAGS_DLL_DECL=
  1011. )
  1012. set(GFLAGS_NAMESPACE "gflags")
  1013. set(GFLAGS_LIBRARIES extern_gflags)
  1014. set(GFLAGS_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/extern/gflags/src")
  1015. endif()
  1016. if(WITH_SYSTEM_GLOG)
  1017. find_package(Glog)
  1018. if(NOT GLOG_FOUND)
  1019. message(FATAL_ERROR "System wide Glog is requested but was not found")
  1020. endif()
  1021. # FindGlog does not define this, and we are not even sure what to use here.
  1022. set(GLOG_DEFINES)
  1023. else()
  1024. set(GLOG_DEFINES
  1025. -DGOOGLE_GLOG_DLL_DECL=
  1026. )
  1027. set(GLOG_LIBRARIES extern_glog)
  1028. if(WIN32)
  1029. set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/glog/src/windows)
  1030. else()
  1031. set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/glog/src)
  1032. endif()
  1033. endif()
  1034. endif()
  1035. #-----------------------------------------------------------------------------
  1036. # Configure Ceres
  1037. if(WITH_LIBMV)
  1038. set(CERES_DEFINES)
  1039. if(WITH_CXX11)
  1040. # nothing to be done
  1041. elseif(SHARED_PTR_FOUND)
  1042. if(SHARED_PTR_TR1_MEMORY_HEADER)
  1043. list(APPEND CERES_DEFINES -DCERES_TR1_MEMORY_HEADER)
  1044. endif()
  1045. if(SHARED_PTR_TR1_NAMESPACE)
  1046. list(APPEND CERES_DEFINES -DCERES_TR1_SHARED_PTR)
  1047. endif()
  1048. else()
  1049. message(FATAL_ERROR "Ceres: Unable to find shared_ptr.")
  1050. endif()
  1051. if(WITH_CXX11)
  1052. list(APPEND CERES_DEFINES -DCERES_STD_UNORDERED_MAP)
  1053. elseif(HAVE_STD_UNORDERED_MAP_HEADER)
  1054. if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
  1055. list(APPEND CERES_DEFINES -DCERES_STD_UNORDERED_MAP)
  1056. else()
  1057. if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
  1058. list(APPEND CERES_DEFINES -DCERES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
  1059. else()
  1060. list(APPEND CERES_DEFINES -DCERES_NO_UNORDERED_MAP)
  1061. message(STATUS "Ceres: Replacing unordered_map/set with map/set (warning: slower!)")
  1062. endif()
  1063. endif()
  1064. else()
  1065. if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
  1066. list(APPEND CERES_DEFINES -DCERES_TR1_UNORDERED_MAP)
  1067. else()
  1068. list(APPEND CERES_DEFINES -DCERES_NO_UNORDERED_MAP)
  1069. message(STATUS "Ceres: Replacing unordered_map/set with map/set (warning: slower!)")
  1070. endif()
  1071. endif()
  1072. endif()
  1073. #-----------------------------------------------------------------------------
  1074. # Extra compile flags
  1075. if(CMAKE_COMPILER_IS_GNUCC)
  1076. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
  1077. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
  1078. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
  1079. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE -Werror=return-type)
  1080. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_VLA -Werror=vla)
  1081. # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
  1082. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES -Wstrict-prototypes)
  1083. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
  1084. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
  1085. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
  1086. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
  1087. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
  1088. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
  1089. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
  1090. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
  1091. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self) # needs -Wuninitialized
  1092. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull) # C only
  1093. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
  1094. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
  1095. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_TYPE_LIMITS -Wtype-limits)
  1096. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_FORMAT_SIGN -Wformat-signedness)
  1097. # gcc 4.2 gives annoying warnings on every file with this
  1098. if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
  1099. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
  1100. endif()
  1101. # versions before gcc4.6 give many BLI_math warnings
  1102. if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
  1103. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS -Wredundant-decls)
  1104. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
  1105. endif()
  1106. # versions before gcc4.8 include global name-space.
  1107. if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.8")
  1108. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_SHADOW -Wshadow)
  1109. endif()
  1110. # disable because it gives warnings for printf() & friends.
  1111. # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
  1112. if(NOT APPLE)
  1113. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
  1114. endif()
  1115. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
  1116. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
  1117. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
  1118. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
  1119. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self) # needs -Wuninitialized
  1120. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
  1121. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
  1122. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
  1123. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_RETURN_TYPE -Werror=return-type)
  1124. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
  1125. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
  1126. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
  1127. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_POINTER_ARITH -Wpointer-arith)
  1128. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_PARAMETER -Wunused-parameter)
  1129. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_WRITE_STRINGS -Wwrite-strings)
  1130. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
  1131. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_FORMAT_SIGN -Wformat-signedness)
  1132. # gcc 4.2 gives annoying warnings on every file with this
  1133. if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
  1134. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
  1135. endif()
  1136. # causes too many warnings
  1137. if(NOT APPLE)
  1138. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
  1139. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
  1140. endif()
  1141. # Use 'ATTR_FALLTHROUGH' macro to suppress.
  1142. if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "7.0"))
  1143. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_IMPLICIT_FALLTHROUGH -Wimplicit-fallthrough=5)
  1144. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_IMPLICIT_FALLTHROUGH -Wimplicit-fallthrough=5)
  1145. endif()
  1146. # flags to undo strict flags
  1147. ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
  1148. ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
  1149. if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "7.0"))
  1150. ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_IMPLICIT_FALLTHROUGH -Wno-implicit-fallthrough)
  1151. endif()
  1152. if(NOT APPLE)
  1153. ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
  1154. endif()
  1155. elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
  1156. if(APPLE AND WITH_OPENMP) # we need the Intel omp lib linked here to not fail all tests due presence of -fopenmp !
  1157. set(CMAKE_REQUIRED_FLAGS "-L${LIBDIR}/openmp/lib -liomp5") # these are only used for the checks
  1158. endif()
  1159. # strange, clang complains these are not supported, but then yses them.
  1160. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
  1161. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
  1162. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE -Werror=return-type)
  1163. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
  1164. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
  1165. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
  1166. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES -Wstrict-prototypes)
  1167. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
  1168. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
  1169. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
  1170. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
  1171. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
  1172. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
  1173. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_OVERLOADED_VIRTUAL -Wno-overloaded-virtual) # we get a lot of these, if its a problem a dev needs to look into it.
  1174. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
  1175. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
  1176. # gives too many unfixable warnings
  1177. # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS -Wunused-macros)
  1178. # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS -Wunused-macros)
  1179. # flags to undo strict flags
  1180. ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
  1181. ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
  1182. ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations)
  1183. ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INCOMPAT_PTR_DISCARD_QUAL -Wno-incompatible-pointer-types-discards-qualifiers)
  1184. ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function)
  1185. ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast)
  1186. ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes)
  1187. ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum)
  1188. ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNDEF -Wno-undef)
  1189. ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn)
  1190. ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field)
  1191. ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing)
  1192. ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor)
  1193. ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
  1194. ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_REORDER -Wno-reorder)
  1195. elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
  1196. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
  1197. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
  1198. ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
  1199. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
  1200. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
  1201. ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
  1202. # disable numbered, false positives
  1203. set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
  1204. set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
  1205. elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
  1206. # most msvc warnings are C & C++
  1207. set(_WARNINGS
  1208. # warning level:
  1209. "/W3"
  1210. "/w34062" # switch statement contains 'default' but no 'case' labels
  1211. # disable:
  1212. "/wd4018" # signed/unsigned mismatch
  1213. "/wd4146" # unary minus operator applied to unsigned type, result still unsigned
  1214. "/wd4065" # switch statement contains 'default' but no 'case' labels
  1215. "/wd4127" # conditional expression is constant
  1216. "/wd4181" # qualifier applied to reference type; ignored
  1217. "/wd4200" # zero-sized array in struct/union
  1218. "/wd4244" # conversion from 'type1' to 'type2', possible loss of data
  1219. "/wd4267" # conversion from 'size_t' to 'type', possible loss of data
  1220. "/wd4305" # truncation from 'type1' to 'type2'
  1221. "/wd4800" # forcing value to bool 'true' or 'false'
  1222. # errors:
  1223. "/we4013" # 'function' undefined; assuming extern returning int
  1224. "/we4431" # missing type specifier - int assumed
  1225. )
  1226. string(REPLACE ";" " " _WARNINGS "${_WARNINGS}")
  1227. set(C_WARNINGS "${_WARNINGS}")
  1228. set(CXX_WARNINGS "${_WARNINGS}")
  1229. unset(_WARNINGS)
  1230. endif()
  1231. # ensure python header is found since detection can fail, this could happen
  1232. # with _any_ library but since we used a fixed python version this tends to
  1233. # be most problematic.
  1234. if(WITH_PYTHON)
  1235. if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
  1236. message(FATAL_ERROR
  1237. "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
  1238. "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
  1239. "to a valid python include path. Containing "
  1240. "Python.h for python version \"${PYTHON_VERSION}\""
  1241. )
  1242. endif()
  1243. if(WIN32 OR APPLE)
  1244. # pass, we have this in an archive to extract
  1245. elseif(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
  1246. find_python_package(numpy)
  1247. endif()
  1248. if(WIN32 OR APPLE)
  1249. # pass, we have this in lib/python/site-packages
  1250. elseif(WITH_PYTHON_INSTALL_REQUESTS)
  1251. find_python_package(requests)
  1252. endif()
  1253. endif()
  1254. if(WITH_CXX11)
  1255. if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
  1256. # TODO(sergey): Do we want c++11 or gnu-c++11 here?
  1257. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  1258. elseif(MSVC)
  1259. # Nothing special is needed, C++11 features are available by default.
  1260. else()
  1261. message(FATAL_ERROR "Compiler ${CMAKE_C_COMPILER_ID} is not supported for C++11 build yet")
  1262. endif()
  1263. else()
  1264. # GCC-6 switched to C++11 by default, which would break linking with existing libraries
  1265. # by default. So we explicitly disable C++11 for a new GCC so no linking issues happens.
  1266. if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "6.0"))
  1267. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++98")
  1268. # We also disable any of C++11 ABI from usage, so we wouldn't even try to
  1269. # link to stuff from std::__cxx11 namespace.
  1270. add_definitions("-D_GLIBCXX_USE_CXX11_ABI=0")
  1271. endif()
  1272. endif()
  1273. # Visual Studio has all standards it supports available by default
  1274. if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "Intel")
  1275. # Use C99 + GNU extensions, works with GCC, Clang, ICC
  1276. if(WITH_C11)
  1277. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
  1278. else()
  1279. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
  1280. endif()
  1281. endif()
  1282. # Include warnings first, so its possible to disable them with user defined flags
  1283. # eg: -Wno-uninitialized
  1284. set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
  1285. set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
  1286. # defined above, platform specific but shared names
  1287. mark_as_advanced(
  1288. CYCLES_OSL
  1289. OSL_LIB_EXEC
  1290. OSL_COMPILER
  1291. OSL_LIB_COMP
  1292. OSL_LIB_QUERY
  1293. OSL_INCLUDE_DIR
  1294. )
  1295. mark_as_advanced(
  1296. LLVM_CONFIG
  1297. LLVM_ROOT_DIR
  1298. LLVM_LIBRARY
  1299. LLVM_VERSION
  1300. )
  1301. #-------------------------------------------------------------------------------
  1302. # Global Defines
  1303. # better not set includes here but this debugging option is off by default.
  1304. if(WITH_CXX_GUARDEDALLOC)
  1305. include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
  1306. add_definitions(-DWITH_CXX_GUARDEDALLOC)
  1307. endif()
  1308. if(WITH_ASSERT_ABORT)
  1309. add_definitions(-DWITH_ASSERT_ABORT)
  1310. endif()
  1311. # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
  1312. # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
  1313. #-----------------------------------------------------------------------------
  1314. # Libraries
  1315. if(WITH_GTESTS)
  1316. include(GTestTesting)
  1317. endif()
  1318. if(WITH_BLENDER OR WITH_PLAYER)
  1319. add_subdirectory(intern)
  1320. add_subdirectory(extern)
  1321. # source after intern and extern to gather all
  1322. # internal and external library information first, for test linking
  1323. add_subdirectory(source)
  1324. elseif(WITH_CYCLES_STANDALONE)
  1325. add_subdirectory(intern/cycles)
  1326. add_subdirectory(extern/clew)
  1327. if(WITH_CUDA_DYNLOAD)
  1328. add_subdirectory(extern/cuew)
  1329. endif()
  1330. if(NOT WITH_SYSTEM_GLEW)
  1331. add_subdirectory(extern/glew)
  1332. endif()
  1333. endif()
  1334. #-----------------------------------------------------------------------------
  1335. # Blender Application
  1336. if(WITH_BLENDER)
  1337. add_subdirectory(source/creator)
  1338. endif()
  1339. #-----------------------------------------------------------------------------
  1340. # Blender Player
  1341. if(WITH_PLAYER)
  1342. add_subdirectory(source/blenderplayer)
  1343. endif()
  1344. #-----------------------------------------------------------------------------
  1345. # Testing
  1346. add_subdirectory(tests)
  1347. #-----------------------------------------------------------------------------
  1348. # CPack for generating packages
  1349. include(build_files/cmake/packaging.cmake)
  1350. #-----------------------------------------------------------------------------
  1351. # Use dynamic loading for OpenMP
  1352. if(WITH_BLENDER)
  1353. openmp_delayload(blender)
  1354. endif(WITH_BLENDER)
  1355. if(WITH_PLAYER)
  1356. openmp_delayload(blenderplayer)
  1357. endif(WITH_PLAYER)
  1358. #-----------------------------------------------------------------------------
  1359. # Print Final Configuration
  1360. if(FIRST_RUN)
  1361. set(_config_msg "\nBlender Configuration\n=====================")
  1362. function(info_cfg_option
  1363. _setting
  1364. )
  1365. set(_msg " - ${_setting}")
  1366. string(LENGTH "${_msg}" _len)
  1367. while("32" GREATER "${_len}")
  1368. set(_msg "${_msg} ")
  1369. math(EXPR _len "${_len} + 1")
  1370. endwhile()
  1371. set(_config_msg "${_config_msg}\n${_msg}${${_setting}}" PARENT_SCOPE)
  1372. endfunction()
  1373. function(info_cfg_text
  1374. _text
  1375. )
  1376. set(_config_msg "${_config_msg}\n\n ${_text}" PARENT_SCOPE)
  1377. endfunction()
  1378. message(STATUS "C Compiler: \"${CMAKE_C_COMPILER_ID}\"")
  1379. message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
  1380. info_cfg_text("Build Options:")
  1381. info_cfg_option(WITH_GAMEENGINE)
  1382. info_cfg_option(WITH_PLAYER)
  1383. info_cfg_option(WITH_BULLET)
  1384. info_cfg_option(WITH_IK_SOLVER)
  1385. info_cfg_option(WITH_IK_ITASC)
  1386. info_cfg_option(WITH_OPENCOLLADA)
  1387. info_cfg_option(WITH_FFTW3)
  1388. info_cfg_option(WITH_INTERNATIONAL)
  1389. info_cfg_option(WITH_INPUT_NDOF)
  1390. info_cfg_option(WITH_CYCLES)
  1391. info_cfg_option(WITH_FREESTYLE)
  1392. info_cfg_option(WITH_OPENCOLORIO)
  1393. info_cfg_option(WITH_OPENVDB)
  1394. info_cfg_option(WITH_ALEMBIC)
  1395. info_cfg_text("Compiler Options:")
  1396. info_cfg_option(WITH_BUILDINFO)
  1397. info_cfg_option(WITH_OPENMP)
  1398. info_cfg_option(WITH_RAYOPTIMIZATION)
  1399. info_cfg_text("System Options:")
  1400. info_cfg_option(WITH_INSTALL_PORTABLE)
  1401. info_cfg_option(WITH_X11_ALPHA)
  1402. info_cfg_option(WITH_X11_XF86VMODE)
  1403. info_cfg_option(WITH_X11_XFIXES)
  1404. info_cfg_option(WITH_X11_XINPUT)
  1405. info_cfg_option(WITH_MEM_JEMALLOC)
  1406. info_cfg_option(WITH_MEM_VALGRIND)
  1407. info_cfg_option(WITH_SYSTEM_GLEW)
  1408. info_cfg_option(WITH_SYSTEM_OPENJPEG)
  1409. info_cfg_text("Image Formats:")
  1410. info_cfg_option(WITH_OPENIMAGEIO)
  1411. info_cfg_option(WITH_IMAGE_CINEON)
  1412. info_cfg_option(WITH_IMAGE_DDS)
  1413. info_cfg_option(WITH_IMAGE_HDR)
  1414. info_cfg_option(WITH_IMAGE_OPENEXR)
  1415. info_cfg_option(WITH_IMAGE_OPENJPEG)
  1416. info_cfg_option(WITH_IMAGE_TIFF)
  1417. info_cfg_text("Audio:")
  1418. info_cfg_option(WITH_OPENAL)
  1419. info_cfg_option(WITH_SDL)
  1420. info_cfg_option(WITH_SDL_DYNLOAD)
  1421. info_cfg_option(WITH_JACK)
  1422. info_cfg_option(WITH_JACK_DYNLOAD)
  1423. info_cfg_option(WITH_CODEC_AVI)
  1424. info_cfg_option(WITH_CODEC_FFMPEG)
  1425. info_cfg_option(WITH_CODEC_SNDFILE)
  1426. info_cfg_text("Compression:")
  1427. info_cfg_option(WITH_LZMA)
  1428. info_cfg_option(WITH_LZO)
  1429. info_cfg_text("Python:")
  1430. info_cfg_option(WITH_PYTHON_INSTALL)
  1431. info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
  1432. info_cfg_option(WITH_PYTHON_MODULE)
  1433. info_cfg_option(WITH_PYTHON_SAFETY)
  1434. if(APPLE)
  1435. info_cfg_option(WITH_PYTHON_FRAMEWORK)
  1436. endif()
  1437. info_cfg_text("Modifiers:")
  1438. info_cfg_option(WITH_MOD_BOOLEAN)
  1439. info_cfg_option(WITH_MOD_REMESH)
  1440. info_cfg_option(WITH_MOD_FLUID)
  1441. info_cfg_option(WITH_MOD_OCEANSIM)
  1442. info_cfg_text("OpenGL:")
  1443. info_cfg_option(WITH_GLEW_ES)
  1444. info_cfg_option(WITH_GLU)
  1445. info_cfg_option(WITH_GL_EGL)
  1446. info_cfg_option(WITH_GL_PROFILE_COMPAT)
  1447. info_cfg_option(WITH_GL_PROFILE_CORE)
  1448. info_cfg_option(WITH_GL_PROFILE_ES20)
  1449. if(WIN32)
  1450. info_cfg_option(WITH_GL_ANGLE)
  1451. endif()
  1452. info_cfg_text("")
  1453. message("${_config_msg}")
  1454. endif()
  1455. if(0)
  1456. print_all_vars()
  1457. endif()