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