Cmake windows/msvc minor cleanup
[blender.git] / CMakeLists.txt
1 # ***** BEGIN GPL LICENSE BLOCK *****
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # The Original Code is Copyright (C) 2006, Blender Foundation
18 # All rights reserved.
19 #
20 # The Original Code is: all of this file.
21 #
22 # Contributor(s): Jacques Beaurain.
23 #
24 # ***** END GPL LICENSE BLOCK *****
25
26 #-----------------------------------------------------------------------------
27 # We don't allow in-source builds. This causes no end of troubles because
28 # all out-of-source builds will use the CMakeCache.txt file there and even
29 # build the libs and objects in it.
30
31 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
32         if(NOT DEFINED WITH_IN_SOURCE_BUILD)
33                 message(FATAL_ERROR
34                         "CMake generation for blender is not allowed within the source directory!"
35                         "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
36                         "\n "
37                         "\n rm CMakeCache.txt"
38                         "\n cd .."
39                         "\n mkdir cmake-make"
40                         "\n cd cmake-make"
41                         "\n cmake ../blender"
42                         "\n "
43                         "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
44                 )
45         endif()
46 endif()
47
48 cmake_minimum_required(VERSION 2.8)
49
50 if(NOT (${CMAKE_VERSION} VERSION_LESS 3.0))
51         # keep until CMake-3.0 is min requirement
52         cmake_policy(SET CMP0043 OLD)
53 endif()
54
55 if(NOT EXECUTABLE_OUTPUT_PATH)
56         set(FIRST_RUN "TRUE")
57 endif()
58
59 # this starts out unset
60 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
61
62 # avoid having empty buildtype
63 set(CMAKE_BUILD_TYPE_INIT "Release")
64
65 # quiet output for Makefiles, 'make -s' helps too
66 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
67
68 # global compile definitions since add_definitions() adds for all.
69 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG           DEBUG _DEBUG)
70 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE         NDEBUG)
71 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL      NDEBUG)
72 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO  NDEBUG)
73
74
75 #-----------------------------------------------------------------------------
76 # Set policy
77
78 # see "cmake --help-policy CMP0003"
79 # So library linking is more sane
80 cmake_policy(SET CMP0003 NEW)
81
82 # So BUILDINFO and BLENDERPATH strings are automatically quoted
83 cmake_policy(SET CMP0005 NEW)
84
85 # So syntax problems are errors
86 cmake_policy(SET CMP0010 NEW)
87
88 # Input directories must have CMakeLists.txt
89 cmake_policy(SET CMP0014 NEW)
90
91 #-----------------------------------------------------------------------------
92 # Load some macros.
93 include(build_files/cmake/macros.cmake)
94
95
96 #-----------------------------------------------------------------------------
97 # Initialize project.
98
99 blender_project_hack_pre()
100
101 project(Blender)
102
103 blender_project_hack_post()
104
105 enable_testing()
106
107 #-----------------------------------------------------------------------------
108 # Redirect output files
109
110 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE)
111 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE)
112 set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests CACHE INTERNAL "" FORCE)
113
114 #-----------------------------------------------------------------------------
115 # Set default config options
116
117 get_blender_version()
118
119
120 #-----------------------------------------------------------------------------
121 # Platform Specific Defaults
122
123 # list of var-names
124 set(_init_vars)
125
126 # initialize to ON
127 macro(option_defaults_init)
128         foreach(_var ${ARGV})
129                 set(${_var} ON)
130                 list(APPEND _init_vars "${_var}")
131         endforeach()
132         unset(_INC)
133 endmacro()
134
135 # remove from namespace
136 macro(option_defaults_clear)
137         foreach(_var ${_init_vars})
138                 unset(${_var})
139         endforeach()
140         unset(_var)
141         unset(_init_vars)
142 endmacro()
143
144
145 # values to initialize WITH_****
146 option_defaults_init(
147         _init_BUILDINFO
148         _init_CODEC_FFMPEG
149         _init_CYCLES_OSL
150         _init_IMAGE_OPENEXR
151         _init_IMAGE_REDCODE
152         _init_INPUT_NDOF
153         _init_JACK
154         _init_LIBMV_SCHUR_SPECIALIZATION
155         _init_OPENCOLLADA
156         _init_OPENCOLORIO
157         _init_SDL
158         _init_FFTW3
159         _init_GAMEENGINE
160 )
161
162 # customize...
163 if(UNIX AND NOT APPLE)
164         # some of these libraries are problematic on Linux
165         # disable less important dependencies by default
166         set(_init_BUILDINFO                      OFF)
167         set(_init_CODEC_FFMPEG                   OFF)
168         set(_init_CYCLES_OSL                     OFF)
169         set(_init_IMAGE_OPENEXR                  OFF)
170         set(_init_IMAGE_REDCODE                  OFF)
171         set(_init_INPUT_NDOF                     OFF)
172         set(_init_JACK                           OFF)
173         set(_init_LIBMV_SCHUR_SPECIALIZATION     OFF)
174         set(_init_OPENCOLLADA                    OFF)
175         set(_init_OPENCOLORIO                    OFF)
176         set(_init_SDL                            OFF)
177         set(_init_FFTW3                          OFF)
178         set(_init_GAMEENGINE                     OFF)
179 endif()
180
181 # Blender internal features
182 option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
183 mark_as_advanced(WITH_BLENDER)
184
185 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
186
187 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
188 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default" ON) 
189 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
190 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distributions see this as a security issue, rather than have them patch it, make a build option.
191 set(WITH_PYTHON_SECURITY ON CACHE BOOL "ON" FORCE) # temp force on. 
192
193 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)
194 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)" OFF)
195 if(APPLE)
196         option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
197 endif()
198
199 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ${_init_BUILDINFO})
200 if(${CMAKE_VERSION} VERSION_LESS 2.8.8)
201         # add_library OBJECT arg unsupported
202         set(WITH_BUILDINFO OFF)
203 endif()
204
205 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
206 option(WITH_IK_SOLVER     "Enable Legacy IK solver (only disable for development)" ON)
207 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" ${_init_FFTW3})
208 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
209 option(WITH_SYSTEM_BULLET "Use the systems bullet library (currently unsupported due to missing features in upstream!)" )
210 mark_as_advanced(WITH_SYSTEM_BULLET)
211 option(WITH_GAMEENGINE    "Enable Game Engine" ${_init_GAMEENGINE})
212 option(WITH_PLAYER        "Build Player" OFF)
213 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ${_init_OPENCOLORIO})
214 option(WITH_COMPOSITOR    "Enable the tile based nodal compositor" ON)
215
216 # GHOST Windowing Library Options
217 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
218 mark_as_advanced(WITH_GHOST_DEBUG)
219
220 option(WITH_GHOST_SDL    "Enable building blender against SDL for windowing rather then the native APIs" OFF)
221 mark_as_advanced(WITH_GHOST_SDL)
222
223 if(WITH_X11)
224         option(WITH_GHOST_XDND    "Enable drag'n'drop support on X11 using XDND protocol" ON)
225 endif()
226
227 # Misc...
228 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
229 mark_as_advanced(WITH_HEADLESS)
230
231 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
232 mark_as_advanced(WITH_AUDASPACE)
233
234 option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
235
236 if(UNIX AND NOT APPLE)
237         set(WITH_X11 ON)
238 endif()
239
240 if(WITH_X11)
241         option(WITH_X11_XINPUT    "Enable X11 Xinput (tablet support and unicode input)"  ON)
242         option(WITH_X11_XF86VMODE "Enable X11 video mode switching"                       ON)
243 endif()
244
245 if(UNIX AND NOT APPLE)
246         option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" ON)
247         option(WITH_SYSTEM_GLES "Use OpenGL ES library provided by the operating system"           ON)
248 else()
249         # not an option for other OS's
250         set(WITH_SYSTEM_GLEW OFF)
251         set(WITH_SYSTEM_GLES OFF)
252 endif()
253
254
255 # (unix defaults to System OpenJPEG On)
256 option(WITH_SYSTEM_OPENJPEG "Use the operating systems OpenJPEG library" OFF)
257
258
259 # Modifiers
260 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
261 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
262 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
263 option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
264 # option(WITH_MOD_CLOTH_ELTOPO    "Enable Experimental cloth solver" OFF)  # this is now only available in a branch
265 # mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
266 option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
267
268 # Image format support
269 option(WITH_OPENIMAGEIO         "Enable OpenImageIO Support (http://www.openimageio.org)" ON)
270 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ${_init_IMAGE_OPENEXR})
271 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
272 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
273 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
274 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
275 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
276 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" ${_init_IMAGE_REDCODE})
277 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
278
279 # Audio/Video format support
280 option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
281 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" ${_init_CODEC_FFMPEG})
282 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
283
284 if(APPLE)
285         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" ON)
286 endif()
287
288 # 3D format support
289 # Disable opencollada when we don't have precompiled libs
290 option(WITH_OPENCOLLADA   "Enable OpenCollada Support (http://www.opencollada.org)" ${_init_OPENCOLLADA})
291
292 # Sound output
293 option(WITH_SDL           "Enable SDL for sound and joystick support" ${_init_SDL})
294 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
295 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" ${_init_JACK})
296 if(UNIX AND NOT APPLE)
297         option(WITH_JACK_DYNLOAD  "Enable runtime dynamic Jack libraries loading" OFF)
298 endif()
299
300 # Compression
301 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
302 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
303
304 # Camera/motion tracking
305 option(WITH_LIBMV         "Enable libmv structure from motion library" ON)
306 option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." ${_init_LIBMV_SCHUR_SPECIALIZATION})
307 mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
308
309 # Freestyle
310 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
311
312 # Misc
313 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ${_init_INPUT_NDOF})
314 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
315 option(WITH_OPENNL        "Enable use of Open Numerical Library" ON)
316 if(UNIX AND NOT APPLE)
317         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
318         option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
319         if(WITH_STATIC_LIBS)
320                 option(WITH_BOOST_ICU "Boost uses ICU library (required for linking with static Boost built with libicu)." OFF)
321                 mark_as_advanced(WITH_BOOST_ICU)
322         endif()
323 endif()
324 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
325 option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
326 set(PYTHON_NUMPY_PATH            "" CACHE PATH "Path to python site-packages or dist-packages containing 'numpy' module")
327 mark_as_advanced(PYTHON_NUMPY_PATH)
328 option(WITH_CPU_SSE              "Enable SIMD instruction if they're detected on the host machine" ON)
329 mark_as_advanced(WITH_CPU_SSE)
330
331 if(UNIX AND NOT APPLE)
332         option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
333         set(PYTHON_REQUESTS_PATH "" CACHE PATH "Path to python site-packages or dist-packages containing 'requests' module")
334         mark_as_advanced(PYTHON_REQUESTS_PATH)
335 endif()
336
337 # Cycles
338 option(WITH_CYCLES                                      "Enable cycles Render Engine" ON)
339 option(WITH_CYCLES_STANDALONE           "Build cycles standalone application" OFF)
340 option(WITH_CYCLES_STANDALONE_GUI       "Build cycles standalone with GUI" OFF)
341 option(WITH_CYCLES_OSL                          "Build Cycles with OSL support" ${_init_CYCLES_OSL})
342 option(WITH_CYCLES_CUDA_BINARIES        "Build cycles CUDA binaries" OFF)
343 set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 sm_35 sm_50 CACHE STRING "CUDA architectures to build binaries for")
344 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
345 unset(PLATFORM_DEFAULT)
346 option(WITH_CYCLES_LOGGING      "Build cycles with logging support" OFF)
347 option(WITH_CYCLES_DEBUG        "Build cycles with with extra debug capabilties" OFF)
348 mark_as_advanced(WITH_CYCLES_LOGGING)
349 mark_as_advanced(WITH_CYCLES_DEBUG)
350
351 # LLVM
352 option(WITH_LLVM                                        "Use LLVM" OFF)
353 if(APPLE)
354         option(LLVM_STATIC                                      "Link with LLVM static libraries" ON) # we prefer static llvm build on Apple, dyn build possible though
355 else()
356         option(LLVM_STATIC                                      "Link with LLVM static libraries" OFF)
357 endif()
358 mark_as_advanced(LLVM_STATIC)
359
360 # disable for now, but plan to support on all platforms eventually
361 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
362 mark_as_advanced(WITH_MEM_JEMALLOC)
363
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
368 # Debug
369 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
370 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
371
372 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
373 mark_as_advanced(WITH_ASSERT_ABORT)
374
375 option(WITH_BOOST                                       "Enable features depending on boost" ON)
376
377 # Unit testsing
378 option(WITH_GTESTS "Enable GTest unit testing" OFF)
379
380
381 # Documentation
382 if(UNIX AND NOT APPLE)
383         option(WITH_DOC_MANPAGE "Create a manual page (Unix manpage)" OFF)
384 endif()
385
386
387 # OpenGL
388
389 option(WITH_GLEW_MX             "Support multiple GLEW contexts (experimental)"                                                                     OFF )
390 option(WITH_GLEW_ES             "Switches to experimental copy of GLEW that has support for OpenGL ES. (temporary option for development purposes)" OFF)
391 option(WITH_GL_EGL              "Use the EGL OpenGL system library instead of the platform specific OpenGL system library (CGL, glX, or WGL)"       OFF)
392 option(WITH_GL_PROFILE_COMPAT   "Support using the OpenGL 'compatibility' profile. (deprecated)"                                                    ON )
393 option(WITH_GL_PROFILE_CORE     "Support using the OpenGL 3.2+ 'core' profile."                                                                     OFF)
394 option(WITH_GL_PROFILE_ES20     "Support using OpenGL ES 2.0. (thru either EGL or the AGL/WGL/XGL 'es20' profile)"                                  OFF)
395
396 mark_as_advanced(
397         WITH_GLEW_MX
398         WITH_GLEW_ES
399         WITH_GL_EGL
400         WITH_GL_PROFILE_COMPAT
401         WITH_GL_PROFILE_CORE
402         WITH_GL_PROFILE_ES20
403 )
404
405 if(WITH_GL_PROFILE_COMPAT)
406         set(WITH_GLU ON)
407 else()
408         set(WITH_GLU OFF)
409 endif()
410
411 if(WIN32)
412         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)
413         mark_as_advanced(WITH_GL_ANGLE)
414 endif()
415
416 if(WITH_GLEW_ES AND WITH_SYSTEM_GLEW)
417         message(WARNING Ignoring WITH_SYSTEM_GLEW and using WITH_GLEW_ES)
418         set(WITH_SYSTEM_GLEW OFF)
419 endif()
420
421 if(MSVC)
422         getDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
423         set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
424 endif()
425
426 # avoid using again
427 option_defaults_clear()
428
429 # end option(...)
430
431
432
433 # By default we want to install to the directory we are compiling our executables
434 # unless specified otherwise, which we currently do not allow
435 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
436         if(MSVC)
437                 set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
438         elseif(APPLE)
439                 set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
440         else()
441                 if(WITH_INSTALL_PORTABLE)
442                         set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH} CACHE PATH "default install path" FORCE)
443                 endif()
444         endif()
445 endif()
446
447
448
449 # Apple
450
451 if(APPLE)
452         if(${CMAKE_VERSION} VERSION_LESS 3.0) # else breaks setting CMP0043 policy
453                 cmake_minimum_required(VERSION 2.8.8)
454                 cmake_policy(VERSION 2.8.8)
455         endif()
456
457         if(NOT CMAKE_OSX_ARCHITECTURES)
458                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
459                 "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
460                 FORCE)
461         endif()
462         
463         execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version
464         if(${MAC_SYS} MATCHES 14)
465                 set(OSX_SYSTEM 10.10)
466                 # throw an error here, older cmake cannot handle 2 digit subversion!
467                 cmake_minimum_required(VERSION 3.0.0)
468         elseif(${MAC_SYS} MATCHES 13)
469                 set(OSX_SYSTEM 10.9)
470         elseif(${MAC_SYS} MATCHES 12)
471                 set(OSX_SYSTEM 10.8)
472         elseif(${MAC_SYS} MATCHES 11)
473                 set(OSX_SYSTEM 10.7)
474         elseif(${MAC_SYS} MATCHES 10)
475                 set(OSX_SYSTEM 10.6)
476         elseif(${MAC_SYS} MATCHES 9)
477                 set(OSX_SYSTEM 10.5)
478         else()
479                 set(OSX_SYSTEM unsupported)
480         endif()
481         message(STATUS "Detected system-version: " ${OSX_SYSTEM})
482         
483         # workaround for incorrect cmake xcode lookup for developer previews - XCODE_VERSION does not take xcode-select path into accout
484         # but would always look into /Applications/Xcode.app while dev versions are named Xcode<version>-DP<preview_number>
485         execute_process(COMMAND xcode-select --print-path  OUTPUT_VARIABLE XCODE_CHECK OUTPUT_STRIP_TRAILING_WHITESPACE)
486         string(REPLACE "/Contents/Developer" "" XCODE_BUNDLE ${XCODE_CHECK}) # truncate to bundlepath in any case
487         message(STATUS "Xcode-bundle : " ${XCODE_BUNDLE})
488         
489         if(${CMAKE_GENERATOR} MATCHES "Xcode")
490         
491                 if(${XCODE_VERSION} VERSION_GREATER 4.2) # earlier xcode has no bundled developer dir, no sense in getting xcode path from
492                         string(SUBSTRING "${XCODE_CHECK}" 14 6 DP_NAME) # reduce to XCode name without dp extension
493                         if(${DP_NAME} MATCHES Xcode5)
494                                 set(XCODE_VERSION 5)
495                         endif()
496                 endif()
497
498                 ##### cmake incompatibility with xcode  4.3 and higher #####
499                 if(${XCODE_VERSION} MATCHES '') # cmake fails due looking for xcode in the wrong path, thus will be empty var
500                         message(FATAL_ERROR "Xcode 4.3 and higher must be used with cmake 2.8-8 or higher")
501                 endif()
502                 ### end cmake incompatibility with xcode 4.3 and higher ###
503                 
504                 if(${XCODE_VERSION} VERSION_EQUAL 4 OR ${XCODE_VERSION} VERSION_GREATER 4 AND ${XCODE_VERSION} VERSION_LESS 4.3)
505                         # Xcode 4 defaults to the Apple LLVM Compiler.
506                         # Override the default compiler selection because Blender only compiles with gcc up to xcode 4.2
507                         set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42")
508                         message(STATUS "Setting compiler to: " ${CMAKE_XCODE_ATTRIBUTE_GCC_VERSION})
509                 endif()
510         else() # unix makefile generator does not fill XCODE_VERSION var, so we get it with a command
511                 execute_process(COMMAND xcodebuild -version OUTPUT_VARIABLE XCODE_VERS_BUILD_NR)
512                 string(SUBSTRING "${XCODE_VERS_BUILD_NR}" 6 3 XCODE_VERSION) # truncate away build-nr
513                 unset(XCODE_VERS_BUILD_NR)
514         endif()
515         
516         message(STATUS "Detected Xcode-version: " ${XCODE_VERSION})
517
518         if(${XCODE_VERSION} VERSION_LESS 4.3)
519                 set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE)  # use guaranteed existing sdk
520         else()
521                 # note: xcode-select path could be ambigous, cause /Applications/Xcode.app/Contents/Developer or /Applications/Xcode.app would be allowed
522                 # so i use a selfcomposed bundlepath here  
523                 set(OSX_SYSROOT_PREFIX ${XCODE_BUNDLE}/Contents/Developer/Platforms/MacOSX.platform)
524                 message(STATUS "OSX_SYSROOT_PREFIX: " ${OSX_SYSROOT_PREFIX})
525                 set(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk) # use guaranteed existing sdk
526                 set(CMAKE_OSX_SYSROOT ${OSX_SYSROOT_PREFIX}/${OSX_DEVELOPER_PREFIX} CACHE PATH "" FORCE)
527                 if(${CMAKE_GENERATOR} MATCHES "Xcode")
528                         set(CMAKE_XCODE_ATTRIBUTE_SDKROOT macosx${OSX_SYSTEM}) # to silence sdk not found warning, just overrides CMAKE_OSX_SYSROOT
529                 endif()
530         endif()
531
532         if(OSX_SYSTEM MATCHES 10.9)
533                 set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT}) # make sure syslibs and headers are looked up in sdk ( expecially for 10.9 openGL atm. )
534         endif()
535
536         if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
537                 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.6" CACHE STRING "" FORCE) # 10.6 is our min. target, if you use higher sdk, weak linking happens
538         endif()
539         
540         if(NOT ${CMAKE_GENERATOR} MATCHES "Xcode")
541                 # force CMAKE_OSX_DEPLOYMENT_TARGET for makefiles, will not work else ( cmake bug ? )
542                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
543                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
544                 add_definitions("-DMACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
545         endif()
546
547         option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
548 endif()
549
550
551 #-----------------------------------------------------------------------------
552 # Check for conflicting/unsupported configurations
553
554 if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_STANDALONE)
555         message(FATAL_ERROR "At least one of WITH_BLENDER or WITH_PLAYER or WITH_CYCLES_STANDALONE must be enabled, nothing to do!")
556 endif()
557
558 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
559         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
560 endif()
561
562 if(NOT WITH_AUDASPACE)
563         if(WITH_OPENAL)
564                 message(FATAL_ERROR "WITH_OPENAL requires WITH_AUDASPACE")
565         endif()
566         if(WITH_JACK)
567                 message(FATAL_ERROR "WITH_JACK requires WITH_AUDASPACE")
568         endif()
569         if(WITH_GAMEENGINE)
570                 message(FATAL_ERROR "WITH_GAMEENGINE requires WITH_AUDASPACE")
571         endif()
572 endif()
573
574 if(NOT WITH_SDL AND WITH_GHOST_SDL)
575         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
576 endif()
577
578 if(WITH_IMAGE_REDCODE AND ((NOT WITH_IMAGE_OPENJPEG) OR (NOT WITH_CODEC_FFMPEG)))
579         message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG and WITH_CODEC_FFMPEG")
580 endif()
581
582 # python module, needs some different options
583 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
584         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
585 endif()
586
587 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
588         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
589 endif()
590
591
592 # may as well build python module without a UI
593 if(WITH_PYTHON_MODULE)
594         set(WITH_HEADLESS ON)
595 endif()
596
597 if(NOT WITH_PYTHON)
598         set(WITH_CYCLES OFF)
599 endif()
600
601 # enable boost for cycles, audaspace or i18n
602 # otherwise if the user disabled
603 if(NOT WITH_BOOST)
604         # Explicitly disabled. so disable all deps.
605         macro(set_and_warn
606                 _setting _val)
607                 if(${${_setting}})
608                         message(STATUS "'WITH_BOOST' is disabled: forceing 'set(${_setting} ${_val})'")
609                 endif()
610                 set(${_setting} ${_val})
611         endmacro()
612
613         set_and_warn(WITH_CYCLES         OFF)
614         set_and_warn(WITH_AUDASPACE      OFF)
615         set_and_warn(WITH_INTERNATIONAL  OFF)
616
617         set_and_warn(WITH_OPENAL         OFF)  # depends on AUDASPACE
618         set_and_warn(WITH_GAMEENGINE     OFF)  # depends on AUDASPACE
619 elseif(WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_AUDASPACE OR WITH_INTERNATIONAL)
620         # Keep enabled
621 else()
622         # Enabled but we don't need it
623         set(WITH_BOOST OFF)
624 endif()
625
626 # auto enable openimageio for cycles
627 if(WITH_CYCLES)
628         set(WITH_OPENIMAGEIO ON)
629 endif()
630
631 # auto enable openimageio linking dependencies
632 if(WITH_OPENIMAGEIO)
633         set(WITH_IMAGE_OPENEXR ON)
634         set(WITH_IMAGE_TIFF ON)
635 endif()
636
637 # auto enable llvm for cycles_osl
638 if(WITH_CYCLES_OSL)
639         set(WITH_LLVM ON CACHE BOOL "" FORCE)
640 endif()
641
642 # don't store paths to libs for portable distribution
643 if(WITH_INSTALL_PORTABLE)
644         set(CMAKE_SKIP_BUILD_RPATH TRUE)
645 endif()
646
647 if(WITH_GHOST_SDL OR WITH_HEADLESS)
648         set(WITH_X11           OFF)
649         set(WITH_X11_XINPUT    OFF)
650         set(WITH_X11_XF86VMODE OFF)
651         set(WITH_GHOST_XDND    OFF)
652 endif()
653
654 if(WITH_CPU_SSE)
655         TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
656 else()
657         message(STATUS "SSE and SSE2 optimizations are DISABLED!")
658         set(COMPILER_SSE_FLAG)
659         set(COMPILER_SSE2_FLAG)
660 endif()
661
662 TEST_STDBOOL_SUPPORT()
663 if(HAVE_STDBOOL_H)
664         add_definitions(-DHAVE_STDBOOL_H)
665 endif()
666
667 #-----------------------------------------------------------------------------
668 # Check for valid directories
669 # ... a partial checkout may cause this.
670 #
671 # note: we need to check for a known subdir in both cases.
672 #       since uninitialized git submodules will give blank dirs
673
674 if(WITH_INTERNATIONAL)
675         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale/languages")
676                 message(WARNING "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
677                                                 "This is a 'git submodule', which are known not to work with bridges to other version "
678                                                 "control systems, disabling 'WITH_INTERNATIONAL'.")
679                 set(WITH_INTERNATIONAL OFF)
680         endif()
681 endif()
682
683 if(WITH_PYTHON)
684         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons/modules")
685                 message(WARNING "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
686                                                 "This is a 'git submodule', which are known not to work with bridges to other version "
687                                                 "control systems: * CONTINUING WITHOUT ADDONS *")
688         endif()
689 endif()
690
691 #-----------------------------------------------------------------------------
692 # Initialize un-cached vars, avoid unused warning
693
694 # linux only, not cached
695 set(WITH_BINRELOC OFF)
696
697 # MAXOSX only, set to avoid uninitialized
698 set(EXETYPE "")
699
700 # C/C++ flags
701 set(PLATFORM_CFLAGS)
702
703 # these are added to later on.
704 set(C_WARNINGS)
705 set(CXX_WARNINGS)
706
707 # for gcc -Wno-blah-blah
708 set(CC_REMOVE_STRICT_FLAGS)
709
710 # libraries to link the binary with passed to target_link_libraries()
711 # known as LLIBS to scons
712 set(PLATFORM_LINKLIBS "")
713
714 # Added to linker flags in setup_liblinks
715 # - CMAKE_EXE_LINKER_FLAGS
716 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
717 set(PLATFORM_LINKFLAGS "")
718 set(PLATFORM_LINKFLAGS_DEBUG "")
719
720
721 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
722 # On Unix:
723 #   cmake ../blender \
724 #         -D PYTHON_VERSION=3.4 \
725 #         -D PYTHON_INCLUDE_DIR=/opt/py34/include/python3.4d \
726 #         -D PYTHON_LIBRARY=/opt/py34/lib/libpython3.4d.so
727 #
728 # On Macs:
729 #   cmake ../blender \
730 #         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4 \
731 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/config \
732 #         -G Xcode
733 #
734 # When changing any of this remember to update the notes in doc/build_systems/cmake.txt
735
736 #-----------------------------------------------------------------------------
737 #Platform specifics
738
739 if(WITH_X11)
740         find_package(X11 REQUIRED)
741
742         find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
743         mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
744
745         list(APPEND PLATFORM_LINKLIBS ${X11_X11_LIB})
746
747         if(WITH_X11_XINPUT)
748                 if(X11_Xinput_LIB)
749                         list(APPEND PLATFORM_LINKLIBS ${X11_Xinput_LIB})
750                 else()
751                         set(WITH_X11_XINPUT OFF)
752                 endif()
753         endif()
754
755         if(WITH_X11_XF86VMODE)
756                 # XXX, why dont cmake make this available?
757                 find_library(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
758                 mark_as_advanced(X11_Xxf86vmode_LIB)
759                 if(X11_Xxf86vmode_LIB)
760                         list(APPEND PLATFORM_LINKLIBS ${X11_Xxf86vmode_LIB})
761                 else()
762                         set(WITH_X11_XF86VMODE OFF)
763                 endif()
764         endif()
765
766 endif()
767
768 if(UNIX AND NOT APPLE)
769         macro(find_package_wrapper)
770                 string(TOUPPER ${ARGV0} _NAME_UPPER)
771                 if(WITH_STATIC_LIBS)
772                         set(_cmake_find_library_suffixes_back ${CMAKE_FIND_LIBRARY_SUFFIXES})
773                         set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
774                 endif()
775                 find_package(${ARGV})
776                 if(WITH_STATIC_LIBS)
777                         set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
778                         unset(_cmake_find_library_suffixes_back)
779                 endif()
780         endmacro()
781
782         find_package_wrapper(JPEG REQUIRED)
783         find_package_wrapper(PNG REQUIRED)
784         find_package_wrapper(ZLIB REQUIRED)
785         find_package_wrapper(Freetype REQUIRED)
786
787         if(WITH_PYTHON)
788                 # No way to set py34. remove for now.
789                 # find_package(PythonLibs)
790
791                 # Use our own instead, since wothout py is such a rare case,
792                 # require this package
793                 # XXX Linking errors with debian static python :/
794 #               find_package_wrapper(PythonLibsUnix REQUIRED)
795                 find_package(PythonLibsUnix REQUIRED)
796         endif()
797
798         if(WITH_IMAGE_OPENEXR)
799                 find_package_wrapper(OpenEXR)  # our own module
800                 if(NOT OPENEXR_FOUND)
801                         set(WITH_IMAGE_OPENEXR OFF)
802                 endif()
803         endif()
804
805         if(WITH_IMAGE_OPENJPEG)
806                 find_package_wrapper(OpenJPEG)
807                 if(NOT OPENJPEG_FOUND)
808                         set(WITH_IMAGE_OPENJPEG OFF)
809                 endif()
810         endif()
811
812         if(WITH_IMAGE_TIFF)
813                 # XXX Linking errors with debian static tiff :/
814 #               find_package_wrapper(TIFF)
815                 find_package(TIFF)
816                 if(NOT TIFF_FOUND)
817                         set(WITH_IMAGE_TIFF OFF)
818                 endif()
819         endif()
820
821         # Audio IO
822         if(WITH_OPENAL)
823                 find_package_wrapper(OpenAL)
824                 if(NOT OPENAL_FOUND)
825                         set(WITH_OPENAL OFF)
826                 endif()
827         endif()
828
829         if(WITH_SDL)
830                 find_package_wrapper(SDL)
831                 mark_as_advanced(
832                         SDLMAIN_LIBRARY
833                         SDL_INCLUDE_DIR
834                         SDL_LIBRARY
835                         SDL_LIBRARY_TEMP
836                 )
837                 # unset(SDLMAIN_LIBRARY CACHE)
838                 if(NOT SDL_FOUND)
839                         set(WITH_SDL OFF)
840                 endif()
841         endif()
842
843         if(WITH_JACK)
844                 find_package_wrapper(Jack)
845                 if(NOT JACK_FOUND)
846                         set(WITH_JACK OFF)
847                 endif()
848         endif()
849
850         # Codecs
851         if(WITH_CODEC_SNDFILE)
852                 find_package_wrapper(SndFile)
853                 if(NOT SNDFILE_FOUND)
854                         set(WITH_CODEC_SNDFILE OFF)
855                 endif()
856         endif()
857
858         if(WITH_CODEC_FFMPEG)
859                 set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
860                 set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
861
862                 mark_as_advanced(FFMPEG)
863
864                 # lame, but until we have proper find module for ffmpeg
865                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
866                 if(EXISTS "${FFMPEG}/include/ffmpeg/")
867                         list(APPEND FFMPEG_INCLUDE_DIRS "${FFMPEG}/include/ffmpeg")
868                 endif()
869                 # end lameness
870
871                 mark_as_advanced(FFMPEG_LIBRARIES)
872                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
873         endif()
874
875         if(WITH_FFTW3)
876                 find_package_wrapper(Fftw3)
877                 if(NOT FFTW3_FOUND)
878                         set(WITH_FFTW3 OFF)
879                 endif()
880         endif()
881
882         if(WITH_OPENCOLLADA)
883                 find_package_wrapper(OpenCOLLADA)
884                 if(OPENCOLLADA_FOUND)
885                         find_package_wrapper(XML2)
886                         find_package_wrapper(PCRE)
887                 else()
888                         set(WITH_OPENCOLLADA OFF)
889                 endif()
890         endif()
891
892         if(WITH_MEM_JEMALLOC)
893                 find_package_wrapper(JeMalloc)
894                 if(NOT JEMALLOC_FOUND)
895                         set(WITH_MEM_JEMALLOC OFF)
896                 endif()
897         endif()
898
899         if(WITH_INPUT_NDOF)
900                 find_package_wrapper(Spacenav)
901                 if(NOT SPACENAV_FOUND)
902                         set(WITH_INPUT_NDOF OFF)
903                 endif()
904
905                 # use generic names within blenders buildsystem.
906                 if(SPACENAV_FOUND)
907                         set(NDOF_INCLUDE_DIRS ${SPACENAV_INCLUDE_DIRS})
908                         set(NDOF_LIBRARIES ${SPACENAV_LIBRARIES})
909                 endif()
910         endif()
911
912         if(WITH_BOOST)
913                 # uses in build instructions to override include and library variables
914                 if(NOT BOOST_CUSTOM)
915                         if(WITH_STATIC_LIBS)
916                                 set(Boost_USE_STATIC_LIBS ON)
917                         endif()
918                         set(Boost_USE_MULTITHREADED ON)
919                         set(__boost_packages filesystem regex system thread date_time)
920                         if(WITH_INTERNATIONAL)
921                                 list(APPEND __boost_packages locale)
922                         endif()
923                         if(WITH_CYCLES_NETWORK)
924                                 list(APPEND __boost_packages serialization)
925                         endif()
926                         find_package(Boost 1.48 COMPONENTS ${__boost_packages})
927                         if(NOT Boost_FOUND)
928                                 # try to find non-multithreaded if -mt not found, this flag
929                                 # doesn't matter for us, it has nothing to do with thread
930                                 # safety, but keep it to not disturb build setups
931                                 set(Boost_USE_MULTITHREADED OFF)
932                                 find_package(Boost 1.48 COMPONENTS ${__boost_packages})
933                         endif()
934                         unset(__boost_packages)
935                         if(Boost_USE_STATIC_LIBS AND WITH_BOOST_ICU)
936                                 find_package(IcuLinux)
937                         endif()
938                         mark_as_advanced(Boost_DIR)  # why doesnt boost do this?
939                 endif()
940
941                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
942                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
943                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
944                 set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
945         endif()
946
947         if(WITH_OPENIMAGEIO)
948                 find_package_wrapper(OpenImageIO)
949
950                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
951                 set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
952                 set(OPENIMAGEIO_DEFINITIONS "")
953
954                 if(WITH_IMAGE_TIFF)
955                         list(APPEND OPENIMAGEIO_LIBRARIES "${TIFF_LIBRARY}")
956                 endif()
957                 if(WITH_IMAGE_OPENEXR)
958                         list(APPEND OPENIMAGEIO_LIBRARIES "${OPENEXR_LIBRARIES}")
959                 endif()
960
961                 if(NOT OPENIMAGEIO_FOUND)
962                         set(WITH_OPENIMAGEIO OFF)
963                         message(STATUS "OpenImageIO not found, disabling WITH_CYCLES")
964                 endif()
965         endif()
966
967         if(WITH_OPENCOLORIO)
968                 find_package_wrapper(OpenColorIO)
969
970                 set(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBRARIES})
971                 set(OPENCOLORIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
972                 set(OPENCOLORIO_DEFINITIONS)
973
974                 if(NOT OPENCOLORIO_FOUND)
975                         set(WITH_OPENCOLORIO OFF)
976                         message(STATUS "OpenColorIO not found")
977                 endif()
978         endif()
979
980         # XXX Maybe most of this section should go into an llvm module?
981         if(WITH_LLVM)
982                 # Set llvm version if not specified
983                 if(NOT LLVM_VERSION)
984                         set(LLVM_VERSION "3.0")
985                 endif()
986
987                 if(LLVM_DIRECTORY)
988                         find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION} HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
989                         if(NOT LLVM_CONFIG)
990                                 find_program(LLVM_CONFIG llvm-config HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
991                         endif()
992                 else()
993                         find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION})
994                         if(NOT LLVM_CONFIG)
995                                 find_program(LLVM_CONFIG llvm-config)
996                         endif()
997                 endif()
998
999                 if(NOT DEFINED LLVM_VERSION)
1000                         execute_process(COMMAND ${LLVM_CONFIG} --version
1001                                                         OUTPUT_VARIABLE LLVM_VERSION
1002                                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
1003                         set(LLVM_VERSION ${LLVM_VERSION} CACHE STRING "Version of LLVM to use")
1004                 endif()
1005                 if(NOT DEFINED LLVM_DIRECTORY)
1006                         execute_process(COMMAND ${LLVM_CONFIG} --prefix
1007                                                         OUTPUT_VARIABLE LLVM_DIRECTORY
1008                                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
1009                         set(LLVM_DIRECTORY ${LLVM_DIRECTORY} CACHE PATH "Path to the LLVM installation")
1010                 endif()
1011                 if(NOT DEFINED LLVM_LIBPATH)
1012                         execute_process(COMMAND ${LLVM_CONFIG} --libdir
1013                                                         OUTPUT_VARIABLE LLVM_LIBPATH
1014                                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
1015                         set(LLVM_LIBPATH ${LLVM_LIBPATH} CACHE PATH "Path to the LLVM library path")
1016                         mark_as_advanced(LLVM_LIBPATH)
1017                 endif()
1018
1019                 if(LLVM_STATIC)
1020                         find_library(LLVM_LIBRARY
1021                                      NAMES LLVMAnalysis # first of a whole bunch of libs to get
1022                                      PATHS ${LLVM_LIBPATH})
1023                 else()
1024                         find_library(LLVM_LIBRARY
1025                                      NAMES LLVM-${LLVM_VERSION}
1026                                      PATHS ${LLVM_LIBPATH})
1027                 endif()
1028
1029
1030                 if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIBPATH)
1031                         if(LLVM_STATIC)
1032                                 # if static LLVM libraries were requested, use llvm-config to generate
1033                                 # the list of what libraries we need, and substitute that in the right
1034                                 # way for LLVM_LIBRARY.
1035                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
1036                                                 OUTPUT_VARIABLE LLVM_LIBRARY
1037                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1038                                 string(REPLACE " " ";" LLVM_LIBRARY "${LLVM_LIBRARY}")
1039                         endif()
1040                 else()
1041                         message(FATAL_ERROR "LLVM not found.")
1042                 endif()
1043
1044                 # Fix for conflict with Mesa llvmpipe
1045                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,--version-script=${CMAKE_SOURCE_DIR}/source/creator/blender.map")
1046         endif()
1047
1048         if(WITH_CYCLES_OSL)
1049                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
1050         
1051                 message(STATUS "CYCLES_OSL = ${CYCLES_OSL}")
1052         
1053                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1054                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1055                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1056                 # Note: --whole-archive is needed to force loading of all symbols in liboslexec,
1057                 # otherwise LLVM is missing the osl_allocate_closure_component function
1058                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -Wl,--whole-archive ${OSL_LIB_EXEC} -Wl,--no-whole-archive ${OSL_LIB_QUERY})
1059                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1060                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1061         
1062                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
1063                         set(OSL_FOUND TRUE)
1064                         message(STATUS "OSL includes = ${OSL_INCLUDES}")
1065                         message(STATUS "OSL library = ${OSL_LIBRARIES}")
1066                         message(STATUS "OSL compiler = ${OSL_COMPILER}")
1067                 else()
1068                         message(STATUS "OSL not found")
1069                 endif()
1070         endif()
1071
1072         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
1073         list(APPEND PLATFORM_LINKLIBS -lutil -lc -lm -lpthread)
1074
1075         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
1076                 if(NOT WITH_PYTHON_MODULE)
1077                         # binreloc is linux only
1078                         set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
1079                         set(WITH_BINRELOC ON)
1080                 endif()
1081         endif()
1082
1083         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -pthread")
1084         if(CMAKE_DL_LIBS)
1085                 list(APPEND PLATFORM_LINKLIBS ${CMAKE_DL_LIBS})
1086         endif()
1087
1088         # lfs on glibc, all compilers should use
1089         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
1090
1091         # GNU Compiler
1092         if(CMAKE_COMPILER_IS_GNUCC)
1093                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
1094         # CLang is the same as GCC for now.
1095         elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
1096                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
1097         # Solaris CC
1098         elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro")
1099                 set(PLATFORM_CFLAGS "-pipe -features=extensions -fPIC -D__FUNCTION__=__func__")
1100                 
1101         # Intel C++ Compiler
1102         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1103                 # think these next two are broken
1104                 find_program(XIAR xiar)
1105                 if(XIAR)
1106                         set(CMAKE_AR "${XIAR}")
1107                 endif()
1108                 mark_as_advanced(XIAR)
1109
1110                 find_program(XILD xild)
1111                 if(XILD)
1112                         set(CMAKE_LINKER "${XILD}")
1113                 endif()
1114                 mark_as_advanced(XILD)
1115
1116                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
1117                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
1118
1119                 # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
1120                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
1121                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
1122         endif()
1123
1124 elseif(WIN32)
1125
1126         add_definitions(-DWIN32)
1127
1128         if(MSVC)
1129
1130                 # needed for some MSVC installations
1131                 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
1132                 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
1133                 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
1134
1135                 list(APPEND PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid psapi)
1136
1137                 add_definitions(
1138                         -D_CRT_NONSTDC_NO_DEPRECATE
1139                         -D_CRT_SECURE_NO_DEPRECATE
1140                         -D_SCL_SECURE_NO_DEPRECATE
1141                         -D_CONSOLE
1142                         -D_LIB
1143                 )
1144
1145                 # MSVC11 needs _ALLOW_KEYWORD_MACROS to build
1146                 add_definitions(-D_ALLOW_KEYWORD_MACROS)
1147
1148                 if(CMAKE_CL_64)
1149                         # We want to support Vista level ABI for x64
1150                         add_definitions(-D_WIN32_WINNT=0x600)
1151                 endif()
1152
1153                 # Make cmake find the msvc redistributables
1154                 set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
1155                 include(InstallRequiredSystemLibraries)
1156
1157                 set(CMAKE_CXX_FLAGS "/nologo /J /Gd /EHsc /MP" CACHE STRING "MSVC MT C++ flags " FORCE)
1158                 set(CMAKE_C_FLAGS   "/nologo /J /Gd /MP"       CACHE STRING "MSVC MT C++ flags " FORCE)
1159
1160                 if(CMAKE_CL_64)
1161                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /RTC1 /MTd /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1162                 else()
1163                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /RTC1 /MTd /ZI /MP" CACHE STRING "MSVC MT flags " FORCE)
1164                 endif()
1165                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1166                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1167                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1168                 if(CMAKE_CL_64)
1169                         set(CMAKE_C_FLAGS_DEBUG "/Od /RTC1 /MTd /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1170                 else()
1171                         set(CMAKE_C_FLAGS_DEBUG "/Od /RTC1 /MTd /ZI /MP" CACHE STRING "MSVC MT flags " FORCE)
1172                 endif()
1173                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1174                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1175                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1176
1177
1178                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
1179
1180                 # MSVC only, Mingw doesnt need
1181                 if(CMAKE_CL_64)
1182                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
1183                 else()
1184                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
1185                 endif()
1186
1187                 set(PLATFORM_LINKFLAGS_DEBUG "/IGNORE:4099 /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
1188
1189                 if(NOT DEFINED LIBDIR)
1190                         # Setup 64bit and 64bit windows systems
1191                         if(CMAKE_CL_64)
1192                                 message(STATUS "64 bit compiler detected.")
1193                                 set(LIBDIR_BASE ${CMAKE_SOURCE_DIR}/../lib/win64)
1194                         else()
1195                                 message(STATUS "32 bit compiler detected.")
1196                                 set(LIBDIR_BASE ${CMAKE_SOURCE_DIR}/../lib/windows)
1197                         endif()
1198                         if(MSVC12)
1199                                 message(STATUS "Visual C++ 2013 detected.")
1200                                 set(LIBDIR ${LIBDIR_BASE}_vc12)
1201                         else()
1202                                 set(LIBDIR ${LIBDIR_BASE})
1203                         endif()
1204                 else()
1205                         message(STATUS using LIBDIR  ${LIBDIR})
1206                 endif()
1207
1208                 # Add each of our libraries to our cmake_prefix_path so find_package() could work
1209                 file(GLOB children RELATIVE ${LIBDIR} ${LIBDIR}/*)
1210                 foreach(child ${children})
1211                 if(IS_DIRECTORY ${LIBDIR}/${child})
1212                         list(APPEND CMAKE_PREFIX_PATH  ${LIBDIR}/${child})
1213                 endif()
1214                 endforeach()
1215
1216                 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
1217                 set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz_st.lib)
1218                 set(ZLIB_INCLUDE_DIR ${LIBDIR}/zlib/include)
1219                 set(ZLIB_LIBRARY ${LIBDIR}/zlib/lib/libz_st.lib)
1220                 set(ZLIB_DIR ${LIBDIR}/zlib)
1221                 #find_package(zlib) # we want to find before finding things that depend on it like png
1222
1223
1224                 find_package(png)
1225                 if(NOT PNG_FOUND)
1226                         set(PNG_PNG_INCLUDE_DIR ${LIBDIR}/png/include)
1227                         message(WARNING "Using HARDCODED libpng locations")
1228                         set(PNG_LIBRARIES libpng)
1229                         set(PNG "${LIBDIR}/png")
1230                         set(PNG_INCLUDE_DIRS "${PNG}/include")
1231                         set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1232                 endif()
1233
1234                 if(MSVC)
1235                         set(JPEG_NAMES ${JPEG_NAMES} libjpeg)
1236                 endif()
1237                 find_package(jpeg REQUIRED)
1238
1239                 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
1240                 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
1241
1242                 set(FREETYPE ${LIBDIR}/freetype)
1243                 set(FREETYPE_INCLUDE_DIRS
1244                         ${LIBDIR}/freetype/include
1245                         ${LIBDIR}/freetype/include/freetype2
1246                 )
1247                 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
1248                 find_package(freetype REQUIRED)
1249
1250                 if(WITH_FFTW3)
1251                         set(FFTW3 ${LIBDIR}/fftw3)
1252                         set(FFTW3_LIBRARIES libfftw)
1253                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1254                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1255                 endif()
1256
1257                 if(WITH_OPENCOLLADA)
1258                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1259
1260                         set(OPENCOLLADA_INCLUDE_DIRS
1261                                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
1262                                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
1263                                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
1264                                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
1265                                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
1266                         )
1267
1268                         set(OPENCOLLADA_LIBRARIES
1269                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader.lib
1270                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework.lib
1271                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils.lib
1272                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter.lib
1273                                 ${OPENCOLLADA}/lib/opencollada/MathMLSolver.lib
1274                                 ${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser.lib
1275                                 ${OPENCOLLADA}/lib/opencollada/xml.lib
1276                                 ${OPENCOLLADA}/lib/opencollada/buffer.lib
1277                                 ${OPENCOLLADA}/lib/opencollada/ftoa.lib
1278                         )
1279
1280                         if(NOT WITH_LLVM)
1281                                 list(APPEND OPENCOLLADA_LIBRARIES ${OPENCOLLADA}/lib/opencollada/UTF.lib)
1282                         endif()
1283
1284                         set(PCRE_LIBRARIES
1285                                 ${OPENCOLLADA}/lib/opencollada/pcre.lib
1286                         )
1287                 endif()
1288
1289                 if(WITH_CODEC_FFMPEG)
1290                         set(FFMPEG_INCLUDE_DIRS
1291                                 ${LIBDIR}/ffmpeg/include
1292                                 ${LIBDIR}/ffmpeg/include/msvc
1293                         )
1294                         find_package(FFMPEG)
1295                         if(NOT FFMPEG_FOUND)
1296                                 message(WARNING "Using HARDCODED ffmpeg locations")
1297                                 set(FFMPEG_LIBRARY_VERSION 55)
1298                                 set(FFMPEG_LIBRARY_VERSION_AVU 52)
1299                                 set(FFMPEG_LIBRARIES
1300                                         ${LIBDIR}/ffmpeg/lib/avcodec-${FFMPEG_LIBRARY_VERSION}.lib
1301                                         ${LIBDIR}/ffmpeg/lib/avformat-${FFMPEG_LIBRARY_VERSION}.lib
1302                                         ${LIBDIR}/ffmpeg/lib/avdevice-${FFMPEG_LIBRARY_VERSION}.lib
1303                                         ${LIBDIR}/ffmpeg/lib/avutil-${FFMPEG_LIBRARY_VERSION_AVU}.lib
1304                                         ${LIBDIR}/ffmpeg/lib/swscale-2.lib
1305                                         )
1306                         endif()
1307                 endif()
1308
1309                 if(WITH_IMAGE_OPENEXR)
1310                         set(OPENEXR_ROOT_DIR ${LIBDIR}/openexr)
1311                         set(OPENEXR_VERSION "2.1")
1312                         find_package(OPENEXR REQUIRED)
1313                         if(NOT OPENEXR_FOUND)
1314                         message(WARNING "Using HARDCODED OpenEXR locations")
1315                         set(OPENEXR ${LIBDIR}/openexr)
1316                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1317                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1318                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1319                         if(MSVC12)
1320                                 set(OPENEXR_LIBRARIES
1321                                         ${OPENEXR_LIBPATH}/Iex-2_1.lib
1322                                         ${OPENEXR_LIBPATH}/Half.lib
1323                                         ${OPENEXR_LIBPATH}/IlmImf-2_1.lib
1324                                         ${OPENEXR_LIBPATH}/Imath-2_1.lib
1325                                         ${OPENEXR_LIBPATH}/IlmThread-2_1.lib
1326                                 )
1327                         else()
1328                                 set(OPENEXR_LIBRARIES
1329                                         ${OPENEXR_LIBPATH}/Iex.lib
1330                                         ${OPENEXR_LIBPATH}/Half.lib
1331                                         ${OPENEXR_LIBPATH}/IlmImf.lib
1332                                         ${OPENEXR_LIBPATH}/Imath.lib
1333                                         ${OPENEXR_LIBPATH}/IlmThread.lib
1334                                 )
1335                         endif()
1336                         endif(NOT OPENEXR_FOUND)
1337                 endif()
1338
1339                 if(WITH_IMAGE_TIFF)
1340                 # Try to find tiff first then complain and set static and maybe wrong paths
1341                 find_package(TIFF)
1342                 if(NOT TIFF_FOUND)
1343                         message(WARNING "Using HARDCODED libtiff locations")
1344                         set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
1345                         set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
1346                 endif()
1347                 endif()
1348
1349                 if(WITH_JACK)
1350                         set(JACK_INCLUDE_DIRS
1351                                 ${LIBDIR}/jack/include/jack
1352                                 ${LIBDIR}/jack/include
1353                         )
1354                         set(JACK_LIBRARIES optimized ${LIBDIR}/jack/lib/libjack.lib debug ${LIBDIR}/jack/lib/libjack_d.lib)
1355                 endif()
1356
1357                 if(WITH_PYTHON)
1358                         set(PYTHON_VERSION 3.4) # CACHE STRING)
1359
1360                         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
1361                         # Use shared libs for vc2008 and vc2010 until we actually have vc2010 libs
1362                         set(PYTHON_LIBRARY ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}.lib)
1363                         unset(_PYTHON_VERSION_NO_DOTS)
1364
1365                         # Shared includes for both vc2008 and vc2010
1366                         set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/include/python${PYTHON_VERSION})
1367
1368                         # uncached vars
1369                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1370                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1371                 endif()
1372
1373                 if(WITH_BOOST)
1374                         if(WITH_CYCLES_OSL)
1375                                 set(boost_extra_libs wave)
1376                         endif(WITH_CYCLES_OSL)
1377                         if(WITH_INTERNATIONAL)
1378                                 list(APPEND boost_extra_libs locale)
1379                         endif(WITH_INTERNATIONAL)
1380                         set(Boost_USE_STATIC_RUNTIME ON) # prefix lib
1381                         set(Boost_USE_MULTITHREADED ON) # suffix -mt
1382                         set(Boost_USE_STATIC_LIBS ON) # suffix -s
1383                         find_package(Boost COMPONENTS date_time filesystem thread regex system ${boost_extra_libs})
1384                         if(NOT Boost_FOUND)
1385                                 message(WARNING "USING HARDCODED boost locations")
1386                                 set(BOOST ${LIBDIR}/boost)
1387                                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1388                                 if(MSVC12)
1389                                         set(BOOST_LIBPATH ${BOOST}/lib)
1390                                         set(BOOST_POSTFIX "vc120-mt-s-1_55.lib")
1391                                         set(BOOST_DEBUG_POSTFIX "vc120-mt-sgd-1_55.lib")
1392                                 else()
1393                                         set(BOOST_LIBPATH ${BOOST}/lib)
1394                                         set(BOOST_POSTFIX "vc90-mt-s-1_49.lib")
1395                                         set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_49.lib")
1396                                 endif()
1397                                 set(BOOST_LIBRARIES
1398                                         optimized libboost_date_time-${BOOST_POSTFIX} optimized libboost_filesystem-${BOOST_POSTFIX}
1399                                         optimized libboost_regex-${BOOST_POSTFIX}
1400                                         optimized libboost_system-${BOOST_POSTFIX} optimized libboost_thread-${BOOST_POSTFIX}
1401                                         debug libboost_date_time-${BOOST_DEBUG_POSTFIX} debug libboost_filesystem-${BOOST_DEBUG_POSTFIX}
1402                                         debug libboost_regex-${BOOST_DEBUG_POSTFIX}
1403                                         debug libboost_system-${BOOST_DEBUG_POSTFIX} debug libboost_thread-${BOOST_DEBUG_POSTFIX})
1404                                 if(WITH_CYCLES_OSL)
1405                                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1406                                                 optimized libboost_wave-${BOOST_POSTFIX}
1407                                                 debug libboost_wave-${BOOST_DEBUG_POSTFIX})
1408                                 endif()
1409                                 if(WITH_INTERNATIONAL)
1410                                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1411                                                 optimized libboost_locale-${BOOST_POSTFIX}
1412                                                 debug libboost_locale-${BOOST_DEBUG_POSTFIX})
1413                                 endif()
1414                         else() # we found boost using find_package
1415                                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
1416                                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
1417                                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
1418                         endif()
1419                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
1420                 endif()
1421                         
1422                 if(WITH_OPENIMAGEIO)
1423                         find_package(OpenImageIO)
1424                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1425                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1426                         set(OIIO_OPTIMIZED optimized OpenImageIO optimized OpenImageIO_Util)
1427                         set(OIIO_DEBUG debug OpenImageIO_d debug OpenImageIO_Util_d)
1428                         set(OPENIMAGEIO_LIBRARIES ${OIIO_OPTIMIZED} ${OIIO_DEBUG})
1429                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1430                         set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0")
1431                 endif()
1432
1433                 if(WITH_LLVM)
1434                         set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1435                         file(GLOB LLVM_LIBRARY_OPTIMIZED ${LLVM_DIRECTORY}/lib/*.lib)
1436
1437                         if(EXISTS ${LLVM_DIRECTORY}/debug/lib)
1438                                 foreach(LLVM_OPTIMIZED_LIB ${LLVM_LIBRARY_OPTIMIZED})
1439                                         get_filename_component(LIBNAME ${LLVM_OPTIMIZED_LIB} ABSOLUTE)
1440                                         list(APPEND LLVM_LIBS optimized ${LIBNAME})
1441                                 endforeach(LLVM_OPTIMIZED_LIB)
1442                         
1443                                 file(GLOB LLVM_LIBRARY_DEBUG ${LLVM_DIRECTORY}/debug/lib/*.lib)
1444
1445                                 foreach(LLVM_DEBUG_LIB ${LLVM_LIBRARY_DEBUG})
1446                                         get_filename_component(LIBNAME ${LLVM_DEBUG_LIB} ABSOLUTE)
1447                                         list(APPEND LLVM_LIBS debug ${LIBNAME})
1448                                 endforeach(LLVM_DEBUG_LIB)
1449
1450                                 set(LLVM_LIBRARY ${LLVM_LIBS})
1451                         else()
1452                                 message(WARNING "LLVM debug libs not present on this system. Using release libs for debug builds.")
1453                                 set(LLVM_LIBRARY ${LLVM_LIBRARY_OPTIMIZED})
1454                         endif()
1455                         
1456                 endif()
1457         
1458                 if(WITH_OPENCOLORIO)
1459                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1460                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1461                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1462                         set(OPENCOLORIO_LIBPATH ${LIBDIR}/opencolorio/lib)
1463                         set(OPENCOLORIO_DEFINITIONS)
1464                 endif()
1465                 
1466
1467                 if(WITH_MOD_CLOTH_ELTOPO)
1468                         set(LAPACK ${LIBDIR}/lapack)
1469                         # set(LAPACK_INCLUDE_DIR ${LAPACK}/include)
1470                         set(LAPACK_LIBPATH ${LAPACK}/lib)
1471                         set(LAPACK_LIBRARIES
1472                                 ${LIBDIR}/lapack/lib/libf2c.lib
1473                                 ${LIBDIR}/lapack/lib/clapack_nowrap.lib
1474                                 ${LIBDIR}/lapack/lib/BLAS_nowrap.lib
1475                         )
1476                 endif()
1477
1478                 # used in many places so include globally, like OpenGL
1479                 blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
1480
1481         elseif(CMAKE_COMPILER_IS_GNUCC)
1482                 # keep GCC specific stuff here
1483                 include(CheckCSourceCompiles)
1484                 # Setup 64bit and 64bit windows systems
1485                 CHECK_C_SOURCE_COMPILES("
1486                         #ifndef __MINGW64__
1487                         #error
1488                         #endif
1489                         int main(void) { return 0; }
1490                         " 
1491                         WITH_MINGW64)
1492                 
1493                 if(WITH_MINGW64)
1494                         message(STATUS "Compiling for 64 bit with MinGW-w64.")
1495                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
1496                 else()
1497                         message(STATUS "Compiling for 32 bit with MinGW-w32.")
1498                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
1499                         
1500                         if(WITH_RAYOPTIMIZATION)
1501                                 message(WARNING "MinGW-w32 is known to be unstable with 'WITH_RAYOPTIMIZATION' option enabled.")
1502                         endif()
1503                 endif()
1504                 
1505                 list(APPEND PLATFORM_LINKLIBS -lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi)
1506                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
1507
1508                 if(WITH_MINGW64)
1509                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
1510                         list(APPEND PLATFORM_LINKLIBS -lpthread)
1511                         
1512                         add_definitions(-DFREE_WINDOWS64 -DMS_WIN64)
1513                 endif()
1514
1515                 add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
1516
1517                 add_definitions(-DFREE_WINDOWS)
1518
1519                 set(PNG "${LIBDIR}/png")
1520                 set(PNG_INCLUDE_DIRS "${PNG}/include")
1521                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1522
1523                 if(WITH_MINGW64)
1524                         set(JPEG_LIBRARIES jpeg)
1525                 else()
1526                         set(JPEG_LIBRARIES libjpeg)
1527                 endif()
1528                 set(PNG_LIBRARIES png)
1529
1530                 set(ZLIB ${LIBDIR}/zlib)
1531                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
1532                 set(ZLIB_LIBPATH ${ZLIB}/lib)
1533                 set(ZLIB_LIBRARIES z)
1534
1535                 set(JPEG "${LIBDIR}/jpeg")
1536                 set(JPEG_INCLUDE_DIR "${JPEG}/include")
1537                 set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
1538                 
1539                 # comes with own pthread library
1540                 if(NOT WITH_MINGW64)
1541                         set(PTHREADS ${LIBDIR}/pthreads)
1542                         #set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
1543                         set(PTHREADS_LIBPATH ${PTHREADS}/lib)
1544                         set(PTHREADS_LIBRARIES pthreadGC2)
1545                 endif()
1546                 
1547                 set(FREETYPE ${LIBDIR}/freetype)
1548                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1549                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1550                 set(FREETYPE_LIBRARY freetype)
1551
1552                 if(WITH_FFTW3)
1553                         set(FFTW3 ${LIBDIR}/fftw3)
1554                         set(FFTW3_LIBRARIES fftw3)
1555                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1556                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1557                 endif()
1558
1559                 if(WITH_OPENCOLLADA)
1560                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1561                         set(OPENCOLLADA_INCLUDE_DIRS
1562                                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
1563                                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
1564                                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
1565                                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
1566                                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
1567                         )
1568                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib/opencollada)
1569                         set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver buffer ftoa xml)
1570                         set(PCRE_LIBRARIES pcre)
1571                 endif()
1572
1573                 if(WITH_CODEC_FFMPEG)
1574                         set(FFMPEG ${LIBDIR}/ffmpeg)
1575                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1576                         if(WITH_MINGW64)
1577                                 set(FFMPEG_LIBRARIES avcodec.dll avformat.dll avdevice.dll avutil.dll swscale.dll swresample.dll)
1578                         else()
1579                                 set(FFMPEG_LIBRARIES avcodec-55 avformat-55 avdevice-55 avutil-52 swscale-2)
1580                         endif()
1581                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1582                 endif()
1583
1584                 if(WITH_IMAGE_OPENEXR)
1585                         set(OPENEXR ${LIBDIR}/openexr)
1586                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1587                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1588                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
1589                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1590                 endif()
1591
1592                 if(WITH_IMAGE_TIFF)
1593                         set(TIFF ${LIBDIR}/tiff)
1594                         set(TIFF_LIBRARY tiff)
1595                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
1596                         set(TIFF_LIBPATH ${TIFF}/lib)
1597                 endif()
1598
1599                 if(WITH_JACK)
1600                         set(JACK ${LIBDIR}/jack)
1601                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
1602                         set(JACK_LIBRARIES jack)
1603                         set(JACK_LIBPATH ${JACK}/lib)
1604
1605                         # TODO, gives linking errors, force off
1606                         set(WITH_JACK OFF)
1607                 endif()
1608
1609                 if(WITH_PYTHON)
1610                         # normally cached but not since we include them with blender
1611                         set(PYTHON_VERSION 3.4) #  CACHE STRING)
1612                         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
1613                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
1614                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}mw.lib")  # CACHE FILEPATH)
1615                         unset(_PYTHON_VERSION_NO_DOTS)
1616
1617                         # uncached vars
1618                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1619                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1620                 endif()
1621
1622                 if(WITH_BOOST)
1623                         set(BOOST ${LIBDIR}/boost)
1624                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1625                         if(WITH_MINGW64)
1626                                 set(BOOST_POSTFIX "mgw47-mt-s-1_49")
1627                                 set(BOOST_DEBUG_POSTFIX "mgw47-mt-sd-1_49")
1628                         else()
1629                                 set(BOOST_POSTFIX "mgw46-mt-s-1_49")
1630                                 set(BOOST_DEBUG_POSTFIX "mgw46-mt-sd-1_49")
1631                         endif()
1632                         set(BOOST_LIBRARIES
1633                                 optimized boost_date_time-${BOOST_POSTFIX} boost_filesystem-${BOOST_POSTFIX}
1634                                 boost_regex-${BOOST_POSTFIX}
1635                                 boost_system-${BOOST_POSTFIX} boost_thread-${BOOST_POSTFIX}
1636                                 debug boost_date_time-${BOOST_DEBUG_POSTFIX} boost_filesystem-${BOOST_DEBUG_POSTFIX}
1637                                 boost_regex-${BOOST_DEBUG_POSTFIX}
1638                                 boost_system-${BOOST_DEBUG_POSTFIX} boost_thread-${BOOST_DEBUG_POSTFIX})
1639                         if(WITH_INTERNATIONAL)
1640                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1641                                         optimized boost_locale-${BOOST_POSTFIX}
1642                                         debug boost_locale-${BOOST_DEBUG_POSTFIX}) 
1643                         endif()
1644                         if(WITH_CYCLES_OSL)
1645                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1646                                         optimized boost_wave-${BOOST_POSTFIX}
1647                                         debug boost_wave-${BOOST_DEBUG_POSTFIX}) 
1648                         endif()
1649                         set(BOOST_LIBPATH ${BOOST}/lib)
1650                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB -DBOOST_THREAD_USE_LIB ")
1651                 endif()
1652                         
1653                 if(WITH_OPENIMAGEIO)
1654                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1655                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1656                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
1657                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1658                         set(OPENIMAGEIO_DEFINITIONS "")
1659                 endif()
1660                 
1661                 if(WITH_LLVM)
1662                         set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1663                         set(LLVM_LIBPATH ${LLVM_DIRECTORY}/lib)
1664                         # Explicitly set llvm lib order.
1665                         #---- WARNING ON GCC ORDER OF LIBS IS IMPORTANT, DO NOT CHANGE! ---------
1666                         set(LLVM_LIBRARY LLVMSelectionDAG LLVMCodeGen LLVMScalarOpts LLVMAnalysis LLVMArchive
1667                                 LLVMAsmParser LLVMAsmPrinter
1668                                 LLVMBitReader LLVMBitWriter
1669                                 LLVMDebugInfo LLVMExecutionEngine
1670                                 LLVMInstCombine LLVMInstrumentation
1671                                 LLVMInterpreter LLVMJIT
1672                                 LLVMLinker LLVMMC
1673                                 LLVMMCDisassembler LLVMMCJIT
1674                                 LLVMMCParser LLVMObject
1675                                 LLVMRuntimeDyld 
1676                                 LLVMSupport
1677                                 LLVMTableGen LLVMTarget
1678                                 LLVMTransformUtils LLVMVectorize
1679                                 LLVMX86AsmParser LLVMX86AsmPrinter
1680                                 LLVMX86CodeGen LLVMX86Desc
1681                                 LLVMX86Disassembler LLVMX86Info
1682                                 LLVMX86Utils LLVMipa
1683                                 LLVMipo LLVMCore)
1684                         # imagehelp is needed by LLVM 3.1 on MinGW, check lib\Support\Windows\Signals.inc
1685                         list(APPEND PLATFORM_LINKLIBS -limagehlp)
1686                 endif()
1687                 
1688                 if(WITH_OPENCOLORIO)
1689                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1690                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1691                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1692                         set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1693                         set(OPENCOLORIO_DEFINITIONS)
1694                 endif()
1695
1696                 set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
1697
1698                 ## DISABLE - causes linking errors 
1699                 ## for re-distribution, so users dont need mingw installed
1700                 # set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-libgcc -static-libstdc++")
1701
1702         endif()
1703         
1704         # Things common to both mingw and MSVC  should go here
1705
1706         set(WINTAB_INC ${LIBDIR}/wintab/include)
1707
1708         if(WITH_OPENAL)
1709                 set(OPENAL ${LIBDIR}/openal)
1710                 set(OPENALDIR ${LIBDIR}/openal)
1711                 set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
1712                 if(MSVC12)
1713                         set(OPENAL_LIBRARY openal32)
1714                 else()
1715                         set(OPENAL_LIBRARY wrap_oal)
1716                 endif()
1717                 set(OPENAL_LIBPATH ${OPENAL}/lib)
1718         endif()
1719
1720         if(WITH_CODEC_SNDFILE)
1721                 set(SNDFILE ${LIBDIR}/sndfile)
1722                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1723                 set(SNDFILE_LIBRARIES libsndfile-1)
1724                 set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
1725         endif()
1726
1727         if(WITH_SDL)
1728                 set(SDL ${LIBDIR}/sdl)
1729                 set(SDL_INCLUDE_DIR ${SDL}/include)
1730                 set(SDL_LIBRARY SDL2)
1731                 set(SDL_LIBPATH ${SDL}/lib)
1732         endif()
1733
1734         if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
1735                 add_definitions(-D__SSE__ -D__MMX__)
1736         endif()
1737
1738         if(WITH_CYCLES_OSL)
1739                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
1740         
1741                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1742                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1743                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1744                 find_library(OSL_LIB_EXEC_DEBUG NAMES oslexec_d PATHS ${CYCLES_OSL}/lib)
1745                 find_library(OSL_LIB_COMP_DEBUG NAMES oslcomp_d PATHS ${CYCLES_OSL}/lib)
1746                 find_library(OSL_LIB_QUERY_DEBUG NAMES oslquery_d PATHS ${CYCLES_OSL}/lib)
1747                 list(APPEND OSL_LIBRARIES optimized ${OSL_LIB_COMP} optimized ${OSL_LIB_EXEC} optimized ${OSL_LIB_QUERY} debug ${OSL_LIB_EXEC_DEBUG} debug ${OSL_LIB_COMP_DEBUG} debug ${OSL_LIB_QUERY_DEBUG})
1748                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1749                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1750         
1751                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
1752                         set(OSL_FOUND TRUE)
1753                 else()
1754                         message(STATUS "OSL not found")
1755                 endif()
1756         endif()
1757
1758 elseif(APPLE)
1759
1760         if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} STRGREATER "10.5")
1761                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE) # valid also for 10.6/7/8/9
1762         endif()
1763
1764         if(WITH_LIBS10.5)
1765                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
1766         else()
1767                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1768                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
1769                 else()
1770                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
1771                 endif()
1772         endif()
1773
1774
1775         if(WITH_OPENAL)
1776                 find_package(OpenAL)
1777                 if(OPENAL_FOUND)
1778                         set(WITH_OPENAL ON)
1779                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
1780                 else()
1781                         set(WITH_OPENAL OFF)
1782                 endif()
1783         endif()
1784
1785         if(WITH_JACK)
1786                 find_library(JACK_FRAMEWORK
1787                         NAMES jackmp
1788                 )
1789                 set(JACK_INCLUDE_DIRS ${JACK_FRAMEWORK}/headers)
1790                 if(NOT JACK_FRAMEWORK)
1791                         set(WITH_JACK OFF)
1792                 endif()
1793         endif()
1794
1795         if(WITH_CODEC_SNDFILE)
1796                 set(SNDFILE ${LIBDIR}/sndfile)
1797                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1798                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
1799                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
1800         endif()
1801
1802         if(WITH_PYTHON)
1803                 # we use precompiled libraries for py 3.4 and up by default
1804                 set(PYTHON_VERSION 3.4)
1805                 if(NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
1806                         # normally cached but not since we include them with blender
1807                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}m")
1808                         # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
1809                         set(PYTHON_LIBRARY python${PYTHON_VERSION}m)
1810                         set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
1811                         # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
1812                 else()
1813                         # module must be compiled against Python framework
1814                         set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
1815                         set(PYTHON_BINARY "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
1816                         #set(PYTHON_LIBRARY python${PYTHON_VERSION})
1817                         set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-${PYTHON_VERSION}m")
1818                         #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python")  # won't  build with this enabled
1819                 endif()
1820                 
1821                 # uncached vars
1822                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1823                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1824         endif()
1825
1826         if(WITH_FFTW3)
1827                 set(FFTW3 ${LIBDIR}/fftw3)
1828                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1829                 set(FFTW3_LIBRARIES fftw3)
1830                 set(FFTW3_LIBPATH ${FFTW3}/lib)
1831         endif()
1832
1833         set(PNG_LIBRARIES png)
1834         set(JPEG_LIBRARIES jpeg)
1835
1836         set(ZLIB /usr)
1837         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
1838         set(ZLIB_LIBRARIES z bz2)
1839
1840         set(FREETYPE ${LIBDIR}/freetype)
1841         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1842         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1843         set(FREETYPE_LIBRARY freetype)
1844
1845         if(WITH_IMAGE_OPENEXR)
1846                 set(OPENEXR ${LIBDIR}/openexr)
1847                 set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1848                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1849                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
1850                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1851         endif()
1852
1853         if(WITH_CODEC_FFMPEG)
1854                 set(FFMPEG ${LIBDIR}/ffmpeg)
1855                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1856                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
1857                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1858         endif()
1859
1860         find_library(SYSTEMSTUBS_LIBRARY
1861                 NAMES
1862                 SystemStubs
1863                 PATHS
1864         )
1865         mark_as_advanced(SYSTEMSTUBS_LIBRARY)
1866         if(SYSTEMSTUBS_LIBRARY)
1867                 list(APPEND PLATFORM_LINKLIBS stdc++ SystemStubs)
1868         else()
1869                 list(APPEND PLATFORM_LINKLIBS stdc++)
1870         endif()
1871
1872         set(PLATFORM_CFLAGS "-pipe -funsigned-char")
1873         set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
1874         if(WITH_CODEC_QUICKTIME)
1875                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
1876                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1877                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1878                         # libSDL still needs 32bit carbon quicktime
1879                 endif()
1880         endif()
1881
1882         # XXX - SOME MAC DEV PLEASE TEST WITH THE SDK INSTALLED!
1883         # ALSO SHOULD BE MOVED INTO OWN MODULE WHEN FUNCTIONAL
1884         if(WITH_INPUT_NDOF)
1885                 # This thread it *should* work and check the framework - campbell
1886                 # http://www.cmake.org/pipermail/cmake/2005-December/007740.html
1887                 find_library(3DCONNEXION_CLIENT_FRAMEWORK
1888                         NAMES 3DconnexionClient
1889                 )
1890                 if(NOT 3DCONNEXION_CLIENT_FRAMEWORK)
1891                         set(WITH_INPUT_NDOF OFF)
1892                 endif()
1893
1894                 if(WITH_INPUT_NDOF)
1895                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework 3DconnexionClient")
1896                         set(NDOF_INCLUDE_DIRS /Library/Frameworks/3DconnexionClient.framework/Headers )
1897                 endif()
1898         endif()
1899
1900         if(WITH_JACK)
1901                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework jackmp")
1902         endif()
1903         
1904         if(WITH_PYTHON_MODULE OR WITH_PYTHON_FRAMEWORK)
1905                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/Python")# force cmake to link right framework
1906         endif()
1907         
1908         if(WITH_OPENCOLLADA)
1909                 set(OPENCOLLADA ${LIBDIR}/opencollada)
1910
1911                 set(OPENCOLLADA_INCLUDE_DIRS
1912                         ${LIBDIR}/opencollada/include/COLLADAStreamWriter
1913                         ${LIBDIR}/opencollada/include/COLLADABaseUtils
1914                         ${LIBDIR}/opencollada/include/COLLADAFramework
1915                         ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
1916                         ${LIBDIR}/opencollada/include/GeneratedSaxParser
1917                 )
1918
1919                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
1920                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lxml2 -lbuffer -lftoa")
1921                 # Use UTF functions from collada if LLVM is not enabled
1922                 if(NOT WITH_LLVM)
1923                         set(OPENCOLLADA_LIBRARIES "${OPENCOLLADA_LIBRARIES} -lUTF")
1924                 endif()
1925                 # pcre is bundled with openCollada
1926                 #set(PCRE ${LIBDIR}/pcre)
1927                 #set(PCRE_LIBPATH ${PCRE}/lib)
1928                 set(PCRE_LIBRARIES pcre)
1929                 #libxml2 is used
1930                 #set(EXPAT ${LIBDIR}/expat)
1931                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
1932                 set(EXPAT_LIB)
1933         endif()
1934
1935         if(WITH_SDL)
1936                 set(SDL ${LIBDIR}/sdl)
1937                 set(SDL_INCLUDE_DIR ${SDL}/include)
1938                 set(SDL_LIBRARY SDL)
1939                 set(SDL_LIBPATH ${SDL}/lib)
1940         endif()
1941
1942         set(PNG "${LIBDIR}/png")
1943         set(PNG_INCLUDE_DIRS "${PNG}/include")
1944         set(PNG_LIBPATH ${PNG}/lib)
1945
1946         set(JPEG "${LIBDIR}/jpeg")
1947         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1948         set(JPEG_LIBPATH ${JPEG}/lib)
1949
1950         if(WITH_IMAGE_TIFF)
1951                 set(TIFF ${LIBDIR}/tiff)
1952                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1953                 set(TIFF_LIBRARY tiff)
1954                 set(TIFF_LIBPATH ${TIFF}/lib)
1955         endif()
1956
1957         if(WITH_INPUT_NDOF)
1958                 # linker needs "-weak_framework 3DconnexionClient"
1959         endif()
1960
1961         if(WITH_BOOST)
1962                 set(BOOST ${LIBDIR}/boost)
1963                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1964                 set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt boost_wave-mt)
1965                 if(WITH_INTERNATIONAL)
1966                         list(APPEND BOOST_LIBRARIES boost_locale-mt)
1967                 endif()
1968                 if(WITH_CYCLES_NETWORK)
1969                         list(APPEND BOOST_LIBRARIES boost_serialization-mt)
1970                 endif()
1971                 set(BOOST_LIBPATH ${BOOST}/lib)
1972                 set(BOOST_DEFINITIONS)
1973         endif()
1974         
1975         if(WITH_INTERNATIONAL OR WITH_CODEC_FFMPEG)
1976                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -liconv") # boost_locale and ffmpeg needs it !
1977         endif()
1978
1979         if(WITH_OPENIMAGEIO)
1980                 set(OPENIMAGEIO ${LIBDIR}/openimageio)
1981                 set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1982                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO}/lib/libOpenImageIO.a ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
1983                 set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib ${JPEG_LIBPATH} ${PNG_LIBPATH} ${TIFF_LIBPATH} ${OPENEXR_LIBPATH} ${ZLIB_LIBPATH})
1984                 set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
1985                 add_definitions(-DOIIO_STATIC_BUILD)
1986         endif()
1987
1988         if(WITH_OPENCOLORIO)
1989                 set(OPENCOLORIO ${LIBDIR}/opencolorio)
1990                 set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1991                 set(OPENCOLORIO_LIBRARIES OpenColorIO tinyxml yaml-cpp)
1992                 set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1993                 set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
1994         endif()
1995
1996         if(WITH_LLVM)
1997                 set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1998                 set(LLVM_VERSION "3.4" CACHE STRING     "Version of LLVM to use")
1999                 if(EXISTS "${LLVM_DIRECTORY}/bin/llvm-config")
2000                         set(LLVM_CONFIG "${LLVM_DIRECTORY}/bin/llvm-config")
2001                 else()
2002                         set(LLVM_CONFIG llvm-config)
2003                 endif()
2004                 execute_process(COMMAND ${LLVM_CONFIG} --version
2005                                 OUTPUT_VARIABLE LLVM_VERSION
2006                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
2007                 execute_process(COMMAND ${LLVM_CONFIG} --prefix
2008                                 OUTPUT_VARIABLE LLVM_DIRECTORY
2009                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
2010                 execute_process(COMMAND ${LLVM_CONFIG} --libdir
2011                                 OUTPUT_VARIABLE LLVM_LIBPATH
2012                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
2013                 find_library(LLVM_LIBRARY
2014                              NAMES LLVMAnalysis # first of a whole bunch of libs to get
2015                              PATHS ${LLVM_LIBPATH})
2016
2017                 if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIBPATH)
2018                         if(LLVM_STATIC)
2019                                 # if static LLVM libraries were requested, use llvm-config to generate
2020                                 # the list of what libraries we need, and substitute that in the right
2021                                 # way for LLVM_LIBRARY.
2022                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
2023                                                 OUTPUT_VARIABLE LLVM_LIBRARY
2024                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
2025                                 string(REPLACE " " ";" LLVM_LIBRARY ${LLVM_LIBRARY})
2026                         else()
2027                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -lLLVM-3.4")
2028                         endif()
2029                 else()
2030                         message(FATAL_ERROR "LLVM not found.")
2031                 endif()
2032         endif()
2033
2034         if(WITH_CYCLES_OSL)
2035                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
2036         
2037                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
2038                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
2039                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
2040                 # WARNING! depends on correct order of OSL libs linking
2041                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -force_load ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
2042                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
2043                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
2044         
2045                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
2046                         set(OSL_FOUND TRUE)
2047                 else()
2048                         message(STATUS "OSL not found")
2049                 endif()
2050         endif()
2051         
2052         if(WITH_OPENMP)
2053                 execute_process(COMMAND ${CMAKE_C_COMPILER} --version OUTPUT_VARIABLE COMPILER_VENDOR)
2054                 string(SUBSTRING "${COMPILER_VENDOR}" 0 5 VENDOR_NAME) # truncate output
2055                 if(${VENDOR_NAME} MATCHES "Apple") # Apple does not support OpenMP reliable with gcc and not with clang
2056                         set(WITH_OPENMP OFF)
2057                 else() # vanilla gcc or clang_omp support OpenMP
2058                         message(STATUS "Using special OpenMP enabled compiler !") # letting find_package(OpenMP) module work for gcc
2059                         if(CMAKE_C_COMPILER_ID MATCHES "Clang") # clang-omp in darwin libs
2060                                 set(OPENMP_FOUND ON)
2061                                 set(OpenMP_C_FLAGS "-fopenmp" CACHE STRING "C compiler flags for OpenMP parallization" FORCE)
2062                                 set(OpenMP_CXX_FLAGS "-fopenmp" CACHE STRING "C++ compiler flags for OpenMP parallization" FORCE)
2063                                 include_directories(${LIBDIR}/openmp/include)
2064                                 link_directories(${LIBDIR}/openmp/lib)
2065                                 # This is a workaround for our helperbinaries ( datatoc, masgfmt, ... ),
2066                                 # They are linked also to omp lib, so we need it in builddir for runtime exexcution, TODO: remove all unneeded dependencies from these
2067                                 execute_process(COMMAND ditto -arch ${CMAKE_OSX_ARCHITECTURES} ${LIBDIR}/openmp/lib/libiomp5.dylib ${CMAKE_BINARY_DIR}/bin/libiomp5.dylib) # for intermediate binaries, lib id @loader_path
2068                         endif()
2069                 endif()
2070         endif()
2071
2072         set(EXETYPE MACOSX_BUNDLE)
2073
2074         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
2075         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
2076         if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" OR CMAKE_OSX_ARCHITECTURES MATCHES "i386")
2077                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -msse -msse2 -msse3 -mssse3")
2078                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic  -msse -msse2 -msse3 -mssse3")
2079                 if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
2080                         set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
2081                         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
2082                 endif()
2083         else()
2084                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
2085                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
2086         endif()
2087
2088         if(${XCODE_VERSION} VERSION_EQUAL 5 OR ${XCODE_VERSION} VERSION_GREATER 5)
2089                 # Xcode 5 is always using CLANG, which has too low template depth of 128 for libmv
2090                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=1024")
2091         endif()
2092         # Get rid of eventually clashes, we export some symbols explicite as local
2093         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Xlinker -unexported_symbols_list -Xlinker ${CMAKE_SOURCE_DIR}/source/creator/osx_locals.map")
2094 endif()
2095
2096 #-----------------------------------------------------------------------------
2097 # Common.
2098
2099 if(APPLE OR WIN32)
2100         if(NOT EXISTS "${LIBDIR}/")
2101                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
2102         endif()
2103 endif()
2104
2105 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
2106         message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
2107 endif()
2108
2109 if(WITH_CYCLES)
2110         if(NOT WITH_OPENIMAGEIO)
2111                 message(FATAL_ERROR "Cycles requires WITH_OPENIMAGEIO, the library may not have been found. Configure OIIO or disable WITH_CYCLES")
2112         endif()
2113         if(NOT WITH_BOOST)
2114                 message(FATAL_ERROR "Cycles requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_CYCLES")
2115         endif()
2116
2117         if(WITH_CYCLES_OSL)
2118                 if(NOT WITH_LLVM)
2119                         message(FATAL_ERROR "Cycles OSL requires WITH_LLVM, the library may not have been found. Configure LLVM or disable WITH_CYCLES_OSL")
2120                 endif()
2121         endif()
2122 endif()
2123
2124 if(WITH_INTERNATIONAL)
2125         if(NOT WITH_BOOST)
2126                 message(FATAL_ERROR "Internationalization requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_INTERNATIONAL")
2127         endif()
2128 endif()
2129
2130 # See TEST_SSE_SUPPORT() for how this is defined.
2131
2132 if(WITH_RAYOPTIMIZATION)
2133         if(SUPPORT_SSE_BUILD)
2134                 set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
2135                 add_definitions(-D__SSE__ -D__MMX__)
2136         endif()
2137         if(SUPPORT_SSE2_BUILD)
2138                 set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
2139                 add_definitions(-D__SSE2__)
2140                 if(NOT SUPPORT_SSE_BUILD) # dont double up
2141                         add_definitions(-D__MMX__)
2142                 endif()
2143         endif()
2144 endif()
2145
2146
2147 # set the endian define
2148 if(MSVC)
2149         # for some reason this fails on msvc
2150         add_definitions(-D__LITTLE_ENDIAN__)
2151         
2152 # OSX-Note: as we do crosscompiling with specific set architecture,
2153 # endianess-detection and autosetting is counterproductive
2154 # so we just set endianess according CMAKE_OSX_ARCHITECTURES
2155
2156 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
2157         add_definitions(-D__LITTLE_ENDIAN__)
2158 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)            
2159         add_definitions(-D__BIG_ENDIAN__)
2160         
2161 else()
2162         include(TestBigEndian)
2163         test_big_endian(_SYSTEM_BIG_ENDIAN)
2164         if(_SYSTEM_BIG_ENDIAN)
2165                 add_definitions(-D__BIG_ENDIAN__)
2166         else()
2167                 add_definitions(-D__LITTLE_ENDIAN__)
2168         endif()
2169         unset(_SYSTEM_BIG_ENDIAN)
2170 endif()
2171
2172
2173 if(WITH_IMAGE_OPENJPEG)
2174         if(WITH_SYSTEM_OPENJPEG)
2175                 # dealt with above
2176         else()
2177                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
2178                 add_definitions(-DOPJ_STATIC)
2179         endif()
2180 endif()
2181
2182 if(WITH_IMAGE_REDCODE)
2183         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
2184         set(REDCODE_INC ${REDCODE})
2185 endif()
2186
2187
2188 #-----------------------------------------------------------------------------
2189 # Configure OpenGL.
2190
2191 find_package(OpenGL)
2192 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
2193
2194 if(WITH_GLU)
2195         list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_glu_LIBRARY}")
2196         list(APPEND GL_DEFINITIONS -DWITH_GLU)
2197 endif()
2198
2199 if(WITH_SYSTEM_GLES)
2200         find_package_wrapper(OpenGLES)
2201 endif()
2202
2203 if(WITH_GL_PROFILE_COMPAT OR WITH_GL_PROFILE_CORE)
2204         list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_gl_LIBRARY}")
2205
2206 elseif(WITH_GL_PROFILE_ES20)
2207         if(WITH_SYSTEM_GLES)
2208                 if(NOT OPENGLES_LIBRARY)
2209                         message(FATAL_ERROR "Unable to find OpenGL ES libraries.  Install them or disable WITH_SYSTEM_GLES.")
2210                 endif()
2211
2212                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_LIBRARY)
2213
2214         else()
2215                 set(OPENGLES_LIBRARY "" CACHE FILEPATH "OpenGL ES 2.0 library file")
2216                 mark_as_advanced(OPENGLES_LIBRARY)
2217
2218                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}")
2219
2220                 if(NOT OPENGLES_LIBRARY)
2221                         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.")
2222                 endif()
2223
2224         endif()
2225
2226         if(WIN32)
2227                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
2228
2229                 set(OPENGLES_DLL "" CACHE FILEPATH "OpenGL ES 2.0 redistributable DLL file")
2230                 mark_as_advanced(OPENGLES_DLL)
2231
2232                 if(NOT OPENGLES_DLL)
2233                         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).")
2234                 endif()
2235
2236                 if(WITH_GL_ANGLE)
2237                         list(APPEND GL_DEFINITIONS -DWITH_ANGLE)
2238
2239                         set(D3DCOMPILER_DLL "" CACHE FILEPATH "Direct3D Compiler redistributable DLL file (needed by ANGLE)")
2240
2241                         get_filename_component(D3DCOMPILER_FILENAME "${D3DCOMPILER_DLL}" NAME)
2242                         list(APPEND GL_DEFINITIONS "-DD3DCOMPILER=\"\\\"${D3DCOMPILER_FILENAME}\\\"\"")
2243
2244                         mark_as_advanced(D3DCOMPILER_DLL)
2245
2246                         if(D3DCOMPILER_DLL STREQUAL "")
2247                                 message(FATAL_ERROR "To compile WITH_GL_ANGLE you need to set D3DCOMPILER_DLL to the file path of a copy of the DirectX redistributable DLL file: D3DCompiler_46.dll")
2248                         endif()
2249
2250                 endif()
2251
2252         endif()
2253
2254 endif()
2255
2256 if(WITH_GL_EGL)
2257         list(APPEND GL_DEFINITIONS -DWITH_GL_EGL)
2258
2259         if(WITH_SYSTEM_GLES)
2260                 if(NOT OPENGLES_EGL_LIBRARY)
2261                         message(FATAL_ERROR "Unable to find OpenGL ES libraries.  Install them or disable WITH_SYSTEM_GLES.")
2262                 endif()
2263
2264                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_EGL_LIBRARY)
2265
2266         else()
2267                 set(OPENGLES_EGL_LIBRARY "" CACHE FILEPATH "EGL library file")
2268                 mark_as_advanced(OPENGLES_EGL_LIBRARY)
2269
2270                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}" "${OPENGLES_EGL_LIBRARY}")
2271
2272                 if(NOT OPENGLES_EGL_LIBRARY)
2273                         message(FATAL_ERROR "To compile WITH_GL_EGL you need to set OPENGLES_EGL_LIBRARY to the file path of an EGL library.")
2274                 endif()
2275
2276         endif()
2277
2278         if(WIN32)
2279                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
2280
2281                 set(OPENGLES_EGL_DLL "" CACHE FILEPATH "EGL redistributable DLL file")
2282                 mark_as_advanced(OPENGLES_EGL_DLL)
2283
2284                 if(NOT OPENGLES_EGL_DLL)
2285                         message(FATAL_ERROR "To compile WITH_GL_EGL you need to set OPENGLES_EGL_DLL to the file path of an EGL runtime dynamic link library (DLL).")
2286                 endif()
2287
2288         endif()
2289
2290 endif()
2291
2292 if(WITH_GL_PROFILE_COMPAT)
2293         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_COMPAT)
2294 endif()
2295
2296 if(WITH_GL_PROFILE_CORE)
2297         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_CORE)
2298 endif()
2299
2300 if(WITH_GL_PROFILE_ES20)
2301         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_ES20)
2302 endif()
2303
2304 if(WITH_GL_EGL)
2305         list(APPEND GL_DEFINITIONS -DWITH_EGL)
2306 endif()
2307
2308 #-----------------------------------------------------------------------------
2309 # Configure OpenMP.
2310 if(WITH_OPENMP)
2311         find_package(OpenMP)
2312         if(OPENMP_FOUND)
2313                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
2314                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
2315         else()
2316                 set(WITH_OPENMP OFF)
2317         endif()
2318
2319         mark_as_advanced(
2320                 OpenMP_C_FLAGS
2321                 OpenMP_CXX_FLAGS
2322         )
2323 endif()
2324
2325 #-----------------------------------------------------------------------------
2326 # Configure GLEW
2327
2328 if(WITH_GLEW_MX)
2329         list(APPEND GL_DEFINITIONS -DWITH_GLEW_MX)
2330 endif()
2331
2332 if(WITH_SYSTEM_GLEW)
2333         find_package(GLEW)
2334
2335         # Note: There is an assumption here that the system GLEW is not a static library.
2336
2337         if(NOT GLEW_FOUND)
2338                 message(FATAL_ERROR "GLEW is required to build Blender. Install it or disable WITH_SYSTEM_GLEW.")
2339         endif()
2340
2341         if(WITH_GLEW_MX)
2342                 set(BLENDER_GLEW_LIBRARIES ${GLEW_MX_LIBRARY})
2343         else()
2344                 set(BLENDER_GLEW_LIBRARIES ${GLEW_LIBRARY})
2345         endif()
2346 else()
2347         if(WITH_GLEW_ES)
2348                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew-es/include")
2349
2350                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC -DWITH_GLEW_ES)
2351
2352                 # These definitions remove APIs from glew.h, making GLEW smaller, and catching unguarded API usage
2353                 if(NOT WITH_GL_PROFILE_ES20)
2354                         # No ES functions are needed
2355                         list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
2356                 elseif(NOT (WITH_GL_PROFILE_CORE OR WITH_GL_PROFILE_COMPAT))
2357                         # ES is enabled, but the other functions are all disabled
2358                         list(APPEND GL_DEFINITIONS -DGLEW_ES_ONLY)
2359                 endif()
2360
2361                 if(WITH_GL_PROFILE_ES20)
2362                         if(WITH_GL_EGL)
2363                                 list(APPEND GL_DEFINITIONS -DGLEW_USE_LIB_ES20)
2364                         endif()
2365
2366                         # ToDo: This is an experiment to eliminate ES 1 symbols,
2367                         # GLEW doesn't really properly provide this level of control
2368                         # (for example, without modification it eliminates too many symbols)
2369                         # so there are lots of modifications to GLEW to make this work,
2370                         # and no attempt to make it work beyond Blender at this point.
2371                         list(APPEND GL_DEFINITIONS -DGL_ES_VERSION_1_0=0 -DGL_ES_VERSION_CL_1_1=0 -DGL_ES_VERSION_CM_1_1=0)
2372                 endif()
2373
2374                 if(WITH_GL_EGL)
2375                         list(APPEND GL_DEFINITIONS -DGLEW_INC_EGL)
2376                 endif()
2377
2378                 set(BLENDER_GLEW_LIBRARIES extern_glew_es bf_intern_glew_mx)
2379
2380         else()
2381                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
2382
2383                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC)
2384
2385                 # This won't affect the non-experimental glew library, 
2386                 # but is used for conditional compilation elsewhere.
2387                 list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
2388
2389                 set(BLENDER_GLEW_LIBRARIES extern_glew)
2390
2391         endif()
2392
2393 endif()
2394
2395 if(NOT WITH_GLU)
2396         list(APPEND GL_DEFINITIONS -DGLEW_NO_GLU)
2397 endif()
2398
2399 #-----------------------------------------------------------------------------
2400 # Configure Bullet
2401
2402 if(WITH_BULLET AND WITH_SYSTEM_BULLET)
2403         find_package(Bullet)
2404         if(NOT BULLET_FOUND)
2405                 set(WITH_BULLET OFF)
2406         endif()
2407 else()
2408         set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
2409         # set(BULLET_LIBRARIES "")
2410 endif()
2411
2412 #-----------------------------------------------------------------------------
2413 # Configure Python.
2414
2415 if(WITH_PYTHON_MODULE)
2416         add_definitions(-DPy_ENABLE_SHARED)
2417 endif()
2418
2419 #-----------------------------------------------------------------------------
2420 # Extra compile flags
2421
2422 if(CMAKE_COMPILER_IS_GNUCC)
2423
2424         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2425         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
2426         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2427         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2428         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2429         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
2430         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
2431         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
2432         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2433         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2434         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2435         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
2436         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
2437         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
2438         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
2439         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
2440         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)  # C only
2441         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
2442         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
2443         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_TYPE_LIMITS -Wtype-limits)
2444
2445         # gcc 4.2 gives annoying warnings on every file with this
2446         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
2447                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
2448         endif()
2449
2450         # versions before gcc4.6 give many BLI_math warnings
2451         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
2452                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
2453                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
2454         endif()
2455
2456         # disable because it gives warnings for printf() & friends.
2457         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
2458
2459         if(NOT APPLE)
2460                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
2461         endif()
2462
2463         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2464         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2465         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2466         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
2467         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
2468         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
2469         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
2470         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
2471
2472         # gcc 4.2 gives annoying warnings on every file with this
2473         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
2474                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
2475         endif()
2476
2477         # causes too many warnings
2478         if(NOT APPLE)
2479                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
2480                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
2481         endif()
2482
2483         # flags to undo strict flags
2484         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
2485         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
2486
2487         if(NOT APPLE)
2488                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
2489         endif()
2490
2491 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
2492
2493         if(APPLE AND WITH_OPENMP) # we need the Intel omp lib linked here to not fail all tests due presence of -fopenmp !
2494                 set(CMAKE_REQUIRED_FLAGS "-L${LIBDIR}/openmp/lib -liomp5") # these are only used for the checks
2495         endif()
2496
2497         # strange, clang complains these are not supported, but then yses them.
2498         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2499         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2500         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2501         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2502         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2503         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2504         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2505         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
2506         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
2507         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
2508
2509         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2510         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2511         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
2512         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
2513         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.
2514         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
2515         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
2516
2517         # gives too many unfixable warnings
2518         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
2519         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
2520
2521         # flags to undo strict flags
2522         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
2523         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
2524
2525         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations)
2526         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INCOMPAT_PTR_DISCARD_QUAL -Wno-incompatible-pointer-types-discards-qualifiers)
2527         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function)
2528         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast)
2529         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes)
2530         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum)
2531         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNDEF -Wno-undef)
2532         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn)
2533
2534         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field)
2535         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing)
2536         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor)
2537         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
2538         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_REORDER -Wno-reorder)
2539
2540 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
2541
2542         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2543         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2544         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2545
2546         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2547         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2548         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2549
2550         # disable numbered, false positives
2551         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
2552         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
2553 elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
2554         # most msvc warnings are C & C++
2555         set(_WARNINGS
2556                 # warning level:
2557                 "/W3"
2558                 "/w34062"  # switch statement contains 'default' but no 'case' labels
2559                 # disable:
2560                 "/wd4018"  # signed/unsigned mismatch
2561                 "/wd4065"  # switch statement contains 'default' but no 'case' labels
2562                 "/wd4127"  # conditional expression is constant
2563                 "/wd4181"  # qualifier applied to reference type; ignored
2564                 "/wd4200"  # zero-sized array in struct/union
2565                 "/wd4244"  # conversion from 'type1' to 'type2', possible loss of data
2566                 "/wd4267"  # conversion from 'size_t' to 'type', possible loss of data
2567                 "/wd4305"  # truncation from 'type1' to 'type2'
2568                 "/wd4800"  # forcing value to bool 'true' or 'false'
2569                 # errors:
2570                 "/we4013"  # 'function' undefined; assuming extern returning int
2571                 "/we4431"  # missing type specifier - int assumed
2572         )
2573
2574         string(REPLACE ";" " " _WARNINGS "${_WARNINGS}")
2575         set(C_WARNINGS "${_WARNINGS}")
2576         set(CXX_WARNINGS "${_WARNINGS}")
2577         unset(_WARNINGS)
2578 endif()
2579
2580 # ensure python header is found since detection can fail, this could happen
2581 # with _any_ library but since we used a fixed python version this tends to
2582 # be most problematic.
2583 if(WITH_PYTHON)
2584         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
2585                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
2586                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
2587                                                         "to a valid python include path. Containing "
2588                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
2589         endif()
2590
2591         if(WIN32)
2592                 # pass, we have this in an archive to extract
2593         elseif(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
2594                 find_python_package(numpy)
2595         endif()
2596
2597         if(WIN32 OR APPLE)
2598                 # pass, we have this in lib/python/site-packages
2599         elseif(WITH_PYTHON_INSTALL_REQUESTS)
2600                 find_python_package(requests)
2601         endif()
2602 endif()
2603
2604 # Include warnings first, so its possible to disable them with user defined flags
2605 # eg: -Wno-uninitialized
2606 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
2607 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
2608
2609 # defined above, platform spesific but shared names
2610 mark_as_advanced(
2611         CYCLES_OSL
2612         OSL_LIB_EXEC
2613         OSL_COMPILER
2614         OSL_LIB_COMP
2615         OSL_LIB_QUERY
2616         OSL_INCLUDES
2617 )
2618
2619 mark_as_advanced(
2620         LLVM_CONFIG
2621         LLVM_DIRECTORY
2622         LLVM_LIBRARY
2623         LLVM_VERSION
2624 )
2625
2626 #-------------------------------------------------------------------------------
2627 # Global Defines
2628
2629 # better not set includes here but this debugging option is off by default.
2630 if(WITH_CXX_GUARDEDALLOC)
2631         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
2632         add_definitions(-DWITH_CXX_GUARDEDALLOC)
2633 endif()
2634
2635 if(WITH_ASSERT_ABORT)
2636         add_definitions(-DWITH_ASSERT_ABORT)
2637 endif()
2638
2639 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
2640 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
2641
2642 #-----------------------------------------------------------------------------
2643 # Libraries
2644
2645 if(WITH_GTESTS)
2646         include(GTestTesting)
2647 endif()
2648
2649 if(WITH_BLENDER OR WITH_PLAYER)
2650         add_subdirectory(intern)
2651         add_subdirectory(extern)
2652
2653         # source after intern and extern to gather all
2654         # internal and external library information first, for test linking
2655         add_subdirectory(source)
2656 elseif(WITH_CYCLES_STANDALONE)
2657         add_subdirectory(intern/cycles)
2658         add_subdirectory(extern/clew)
2659         add_subdirectory(extern/cuew)
2660         if(NOT WITH_SYSTEM_GLEW)
2661                 add_subdirectory(extern/glew)
2662         endif()
2663 endif()
2664
2665 #-----------------------------------------------------------------------------
2666 # Blender Application
2667 if(WITH_BLENDER)
2668         add_subdirectory(source/creator)
2669 endif()
2670
2671
2672 #-----------------------------------------------------------------------------
2673 # Blender Player
2674 if(WITH_PLAYER)
2675         add_subdirectory(source/blenderplayer)
2676 endif()
2677
2678
2679 #-----------------------------------------------------------------------------
2680 # Testing
2681 add_subdirectory(tests)
2682
2683
2684 #-----------------------------------------------------------------------------
2685 # CPack for generating packages
2686 include(build_files/cmake/packaging.cmake)
2687
2688
2689 #-----------------------------------------------------------------------------
2690 # Print Final Configuration
2691
2692 if(FIRST_RUN)
2693         set(_config_msg "\n* Blender Configuration *")
2694         macro(info_cfg_option
2695                 _setting)
2696                 set(_msg "   * ${_setting}")
2697                 string(LENGTH "${_msg}" _len)
2698                 while("32" GREATER "${_len}")
2699                         set(_msg "${_msg} ")
2700                          math(EXPR _len "${_len} + 1")
2701                 endwhile()
2702
2703                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
2704         endmacro()
2705
2706         macro(info_cfg_text
2707                 _text)
2708                 set(_config_msg "${_config_msg}\n\n  ${_text}")
2709
2710
2711         endmacro()
2712
2713         message(STATUS "C Compiler:   \"${CMAKE_C_COMPILER_ID}\"")
2714         message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
2715
2716         info_cfg_text("Build Options:")
2717         info_cfg_option(WITH_GAMEENGINE)
2718         info_cfg_option(WITH_PLAYER)
2719         info_cfg_option(WITH_BULLET)
2720         info_cfg_option(WITH_IK_SOLVER)
2721         info_cfg_option(WITH_IK_ITASC)
2722         info_cfg_option(WITH_OPENCOLLADA)
2723         info_cfg_option(WITH_FFTW3)
2724         info_cfg_option(WITH_INTERNATIONAL)
2725         info_cfg_option(WITH_INPUT_NDOF)
2726         info_cfg_option(WITH_CYCLES)
2727         info_cfg_option(WITH_FREESTYLE)
2728         info_cfg_option(WITH_OPENCOLORIO)
2729
2730         info_cfg_text("Compiler Options:")
2731         info_cfg_option(WITH_BUILDINFO)
2732         info_cfg_option(WITH_OPENMP)
2733         info_cfg_option(WITH_RAYOPTIMIZATION)
2734
2735         info_cfg_text("System Options:")
2736         info_cfg_option(WITH_INSTALL_PORTABLE)
2737         info_cfg_option(WITH_X11_XF86VMODE)
2738         info_cfg_option(WITH_X11_XINPUT)
2739         info_cfg_option(WITH_MEM_JEMALLOC)
2740         info_cfg_option(WITH_MEM_VALGRIND)
2741         info_cfg_option(WITH_SYSTEM_GLEW)
2742         info_cfg_option(WITH_SYSTEM_OPENJPEG)
2743
2744         info_cfg_text("Image Formats:")
2745         info_cfg_option(WITH_OPENIMAGEIO)
2746         info_cfg_option(WITH_IMAGE_CINEON)
2747         info_cfg_option(WITH_IMAGE_DDS)
2748         info_cfg_option(WITH_IMAGE_HDR)
2749         info_cfg_option(WITH_IMAGE_OPENEXR)
2750         info_cfg_option(WITH_IMAGE_OPENJPEG)
2751         info_cfg_option(WITH_IMAGE_REDCODE)
2752         info_cfg_option(WITH_IMAGE_TIFF)
2753
2754         info_cfg_text("Audio:")
2755         info_cfg_option(WITH_OPENAL)
2756         info_cfg_option(WITH_SDL)
2757         info_cfg_option(WITH_JACK)
2758         info_cfg_option(WITH_JACK_DYNLOAD)
2759         info_cfg_option(WITH_CODEC_AVI)
2760         info_cfg_option(WITH_CODEC_FFMPEG)
2761         info_cfg_option(WITH_CODEC_SNDFILE)
2762
2763         info_cfg_text("Compression:")
2764         info_cfg_option(WITH_LZMA)
2765         info_cfg_option(WITH_LZO)
2766
2767         info_cfg_text("Python:")
2768         info_cfg_option(WITH_PYTHON_INSTALL)
2769         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
2770         info_cfg_option(WITH_PYTHON_MODULE)
2771         info_cfg_option(WITH_PYTHON_SAFETY)
2772         if(APPLE)
2773                 info_cfg_option(WITH_PYTHON_FRAMEWORK)
2774         endif()
2775
2776         info_cfg_text("Modifiers:")
2777         info_cfg_option(WITH_MOD_BOOLEAN)
2778         info_cfg_option(WITH_MOD_REMESH)
2779         info_cfg_option(WITH_MOD_FLUID)
2780         info_cfg_option(WITH_MOD_OCEANSIM)
2781
2782         info_cfg_text("OpenGL:")
2783         info_cfg_option(WITH_GLEW_ES)
2784         info_cfg_option(WITH_GLU)
2785         info_cfg_option(WITH_GL_EGL)
2786         info_cfg_option(WITH_GL_PROFILE_COMPAT)
2787         info_cfg_option(WITH_GL_PROFILE_CORE)
2788         info_cfg_option(WITH_GL_PROFILE_ES20)
2789         if(WIN32)
2790                 info_cfg_option(WITH_GL_ANGLE)
2791         endif()
2792
2793         info_cfg_text("Other:")
2794         info_cfg_option(WITH_OPENNL)
2795
2796         # debug
2797         message(STATUS "HAVE_STDBOOL_H = ${HAVE_STDBOOL_H}")
2798
2799         info_cfg_text("")
2800
2801         message("${_config_msg}")
2802 endif()