Cycles: svn merge -r41225:41232 ^/trunk/blender
[blender.git] / CMakeLists.txt
1 # -*- mode: cmake; indent-tabs-mode: t; -*-
2 # ***** BEGIN GPL LICENSE BLOCK *****
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18 # The Original Code is Copyright (C) 2006, Blender Foundation
19 # All rights reserved.
20 #
21 # The Original Code is: all of this file.
22 #
23 # Contributor(s): Jacques Beaurain.
24 #
25 # ***** END GPL LICENSE BLOCK *****
26
27 #-----------------------------------------------------------------------------
28 # We don't allow in-source builds. This causes no end of troubles because
29 # all out-of-source builds will use the CMakeCache.txt file there and even
30 # build the libs and objects in it.
31
32 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
33         if(NOT DEFINED WITH_IN_SOURCE_BUILD)
34                 message(FATAL_ERROR
35                         "CMake generation for blender is not allowed within the source directory!"
36                         "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
37                         "\n "
38                         "\n rm CMakeCache.txt"
39                         "\n cd .."
40                         "\n mkdir cmake-make"
41                         "\n cd cmake-make"
42                         "\n cmake ../blender"
43                         "\n "
44                         "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
45                 )
46         endif()
47 endif()
48
49 cmake_minimum_required(VERSION 2.8)
50
51 if(NOT EXECUTABLE_OUTPUT_PATH)
52         set(FIRST_RUN "TRUE")
53 endif()
54
55 # this starts out unset
56 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
57
58 # avoid having empty buildtype
59 set(CMAKE_BUILD_TYPE_INIT "Release")
60
61 # quiet output for Makefiles, 'make -s' helps too
62 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
63
64 #-----------------------------------------------------------------------------
65 # Set policy
66
67 # see "cmake --help-policy CMP0003"
68 # So library linking is more sane
69 cmake_policy(SET CMP0003 NEW)
70
71 # So BUILDINFO and BLENDERPATH strings are automatically quoted
72 cmake_policy(SET CMP0005 NEW)
73
74 # So syntax problems are errors
75 cmake_policy(SET CMP0010 NEW)
76
77 # Input directories must have CMakeLists.txt
78 cmake_policy(SET CMP0014 NEW)
79
80 #-----------------------------------------------------------------------------
81 # Load some macros.
82 include(build_files/cmake/macros.cmake)
83
84
85 #-----------------------------------------------------------------------------
86 # Initialize project.
87
88 blender_project_hack_pre()
89
90 project(Blender)
91
92 blender_project_hack_post()
93
94 enable_testing()
95
96 #-----------------------------------------------------------------------------
97 # Redirect output files
98
99 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE )
100 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE )
101 set(INCLUDE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/include CACHE INTERNAL "" FORCE )
102
103 #-----------------------------------------------------------------------------
104 # Set default config options
105
106 get_blender_version()
107
108
109 # Blender internal features
110 option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
111 mark_as_advanced(WITH_BLENDER)
112
113 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
114
115 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
116 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default (recommend to leave off)" OFF)
117 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
118 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distrobutions see this as a security issue, rather than have them patch it, make a build option.
119
120 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)
121 option(WITH_PYTHON_MODULE "Enable building as a python module (experemental, only enable for development)" OFF)
122 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ON)
123 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
124 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" OFF)
125 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
126 option(WITH_GAMEENGINE    "Enable Game Engine" ON)
127 option(WITH_PLAYER        "Build Player" OFF)
128
129 # GHOST Windowing Library Options
130 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
131 mark_as_advanced(WITH_GHOST_DEBUG)
132
133 option(WITH_GHOST_SDL    "Enable building blender against SDL for windowing rather then the native APIs" OFF)
134 mark_as_advanced(WITH_GHOST_SDL)
135
136 # Misc...
137 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
138 mark_as_advanced(WITH_HEADLESS)
139
140 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
141 mark_as_advanced(WITH_AUDASPACE)
142
143
144 # (unix defaults to OpenMP On)
145 if(UNIX AND NOT APPLE)
146         option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
147 else()
148         option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" OFF)
149 endif()
150
151 if(UNIX AND NOT APPLE)
152         option(WITH_X11_XINPUT "Enable X11 Xinput (tablet support)"     ON)
153         option(WITH_BUILTIN_GLEW "Use GLEW OpenGL wrapper library bundled with blender" ON)
154 else()
155         # not an option for other OS's
156         set(WITH_BUILTIN_GLEW ON)
157 endif()
158
159 # Modifiers
160 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
161 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
162 option(WITH_MOD_DECIMATE        "Enable Decimate Modifier" ON)
163 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
164 option(WITH_MOD_CLOTH_ELTOPO    "Enable Experemental cloth solver" OFF)
165 mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
166
167 # Image format support
168 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
169 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
170 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
171 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
172 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
173 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
174 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" OFF)
175 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
176
177 # Audio/Video format support
178 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" OFF)
179 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
180 if(APPLE OR (WIN32 AND NOT UNIX))
181         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" OFF)
182 endif()
183
184 # 3D format support
185 # disable opencollada on non-apple unix because opencollada has no package for debian
186 option(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org)"       OFF)
187
188 # Sound output
189 option(WITH_SDL           "Enable SDL for sound and joystick support" ON)
190 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
191 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" OFF)
192
193 # Compression
194 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
195 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
196
197 # Misc
198 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
199 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
200 if(UNIX AND NOT APPLE)
201         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
202 endif()
203 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
204
205 # Cycles
206 option(WITH_CYCLES                      "Enable Cycles Render Engine" ON)
207 OPTION(WITH_CYCLES_OSL          "Build with Open Shading Language support" OFF)
208 OPTION(WITH_CYCLES_CUDA         "Build with CUDA binaries" OFF)
209 OPTION(WITH_CYCLES_BLENDER      "Build Blender Python extension" ON)
210 OPTION(WITH_CYCLES_PARTIO       "Build with Partio point cloud support (unfinished)" OFF)
211 OPTION(WITH_CYCLES_NETWORK      "Build with network rendering support (unfinished)" OFF)
212 OPTION(WITH_CYCLES_TEST         "Build cycles test application" OFF)
213
214 # disable for now, but plan to support on all platforms eventually
215 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
216 mark_as_advanced(WITH_MEM_JEMALLOC)
217
218 # Debug
219 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
220 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
221
222 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
223 mark_as_advanced(WITH_ASSERT_ABORT)
224
225
226 if(APPLE)
227         if(NOT CMAKE_OSX_ARCHITECTURES)
228                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
229                 "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
230                 FORCE)
231         endif()
232         if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
233                 set(CMAKE_OSX_DEPLOYMENT_TARGET 10.5 CACHE STRING
234                 "Choose the minimum OSX version required: 10.4 or 10.5"
235                 FORCE)
236         endif()
237         option(WITH_COCOA         "Use Cocoa framework instead of deprecated Carbon" ON)
238         option(USE_QTKIT          "Use QtKit instead of Carbon quicktime (needed for having partial quicktime for 64bit)" OFF)
239         option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
240 endif()
241
242 #-----------------------------------------------------------------------------
243 # Check for conflicting/unsupported configurations
244
245 if(NOT WITH_BLENDER AND NOT WITH_PLAYER)
246         message(FATAL_ERROR "At least one of WITH_BLENDER or WITH_PLAYER must be enabled, nothing to do!")
247 endif()
248
249 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
250         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
251 endif()
252
253 if(NOT WITH_AUDASPACE AND (WITH_OPENAL OR WITH_SDL OR WITH_JACK))
254         message(FATAL_ERROR "WITH_OPENAL/WITH_SDL/WITH_JACK/WITH_CODEC_FFMPEG require WITH_AUDASPACE")
255 endif()
256
257 if(NOT WITH_SDL AND WITH_GHOST_SDL)
258         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL to be ON")
259 endif()
260
261 if(NOT WITH_IMAGE_OPENJPEG AND WITH_IMAGE_REDCODE)
262         message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG")
263 endif()
264
265 # python module, needs some different options
266 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
267         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
268 endif()
269
270 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
271         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
272 endif()
273
274 if(WITH_CODEC_QUICKTIME AND MINGW)
275         message(FATAL_ERROR "MINGW requires WITH_CODEC_QUICKTIME to be OFF "
276                                                 "because it is currently unsupported, remove this "
277                                                 "line if youre a developer who wants to add support.")
278 endif()
279
280 # may as well build python module without a UI
281 if(WITH_PYTHON_MODULE)
282         set(WITH_HEADLESS ON)
283 endif()
284
285 # auto enable openimageio and boost for cycles
286 if(WITH_CYCLES)
287         set(WITH_OPENIMAGEIO ON)
288         set(WITH_BOOST ON)
289 endif()
290
291 if(WITH_OPENIMAGEIO)
292         set(WITH_BOOST ON)
293 endif()
294
295 TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
296
297 # don't store paths to libs for portable distrobution
298 if(WITH_INSTALL_PORTABLE)
299         set(CMAKE_SKIP_BUILD_RPATH TRUE)
300 endif()
301
302 #-----------------------------------------------------------------------------
303 # Initialize un-cached vars, avoid unused warning
304
305 # linux only, not cached
306 set(WITH_BINRELOC OFF)
307
308 # MAXOSX only, set to avoid uninitialized
309 set(EXETYPE "")
310
311 # C/C++ flags
312 set(PLATFORM_CFLAGS)
313
314 # these are added to later on.
315 set(C_WARNINGS)
316 set(CXX_WARNINGS)
317
318 # libraries to link the binary with passed to target_link_libraries()
319 # known as LLIBS to scons
320 set(PLATFORM_LINKLIBS "")
321
322 # Added to linker flags in setup_liblinks
323 # - CMAKE_EXE_LINKER_FLAGS
324 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
325 set(PLATFORM_LINKFLAGS "")
326 set(PLATFORM_LINKFLAGS_DEBUG "")
327
328
329 # disabled for now, not supported
330 # option(WITH_WEBPLUGIN     "Enable Web Plugin (Unix only)" OFF)
331
332 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
333 # On Unix:
334 #   cmake ../blender \
335 #         -D PYTHON_VERSION=3.2 \
336 #         -D PYTHON_INCLUDE_DIR=/opt/py32/include/python3.2d \
337 #         -D PYTHON_LIBRARY=/opt/py32/lib/libpython3.2d.so
338 #
339 # On Macs:
340 #   cmake ../blender \
341 #         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2 \
342 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/config \
343 #         -G Xcode
344 #
345 # When changing any of this remember to update the notes in doc/build_systems/cmake.txt
346
347 #-----------------------------------------------------------------------------
348 #Platform specifics
349
350 if(UNIX AND NOT APPLE)
351
352         # needed for ubuntu 11.04
353         if(EXISTS "/usr/lib/x86_64-linux-gnu")
354                 set(CMAKE_LIBRARY_PATH "/usr/lib/x86_64-linux-gnu;${CMAKE_LIBRARY_PATH}")
355         endif()
356
357         find_package(JPEG REQUIRED)
358         find_package(PNG REQUIRED)
359         find_package(ZLIB REQUIRED)
360         find_package(Freetype REQUIRED)
361
362         if(WITH_PYTHON)
363                 # No way to set py32. remove for now.
364                 # find_package(PythonLibs)
365
366                 # Use our own instead, since wothout py is such a rare case,
367                 # require this package
368                 find_package(PythonLibsUnix REQUIRED)
369         endif()
370
371
372         if(WITH_IMAGE_OPENEXR)
373                 find_package(OpenEXR)  # our own module
374                 if(NOT OPENEXR_FOUND)
375                         set(WITH_IMAGE_OPENEXR OFF)
376                 endif()
377         endif()
378
379         if(WITH_IMAGE_OPENJPEG)
380                 find_package(OpenJPEG)
381                 if(NOT OPENJPEG_FOUND)
382                         set(WITH_IMAGE_OPENJPEG OFF)
383                 endif()
384         endif()
385
386         if(WITH_IMAGE_TIFF)
387                 find_package(TIFF)
388                 if(NOT TIFF_FOUND)
389                         set(WITH_IMAGE_TIFF OFF)
390                 endif()
391         endif()
392
393         # Audio IO
394         if(WITH_OPENAL)
395                 find_package(OpenAL)
396                 if(NOT OPENAL_FOUND)
397                         set(WITH_OPENAL OFF)
398                 endif()
399         endif()
400
401         if(WITH_SDL)
402                 find_package(SDL)
403                 mark_as_advanced(
404                         SDLMAIN_LIBRARY
405                         SDL_INCLUDE_DIR
406                         SDL_LIBRARY
407                         SDL_LIBRARY_TEMP
408                 )
409                 # unset(SDLMAIN_LIBRARY CACHE)
410                 if(NOT SDL_FOUND)
411                         set(WITH_SDL OFF)
412                 endif()
413         endif()
414
415         if(WITH_JACK)
416                 find_package(Jack)
417                 if(NOT JACK_FOUND)
418                         set(WITH_JACK OFF)
419                 endif()
420         endif()
421
422         # Codecs
423         if(WITH_CODEC_SNDFILE)
424                 find_package(SndFile)
425                 if(NOT SNDFILE_FOUND)
426                         set(WITH_CODEC_SNDFILE OFF)
427                 endif()
428         endif()
429
430         if(WITH_CODEC_FFMPEG)
431                 set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
432                 mark_as_advanced(FFMPEG)
433                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
434                 set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
435                 mark_as_advanced(FFMPEG_LIBRARIES)
436                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
437                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
438         endif()
439
440         if(WITH_INTERNATIONAL)
441                 find_library(INTL_LIBRARY
442                         NAMES intl
443                         PATHS
444                         /sw/lib
445                 )
446
447                 find_library(ICONV_LIBRARY
448                         NAMES iconv
449                         PATHS
450                         /sw/lib
451                 )
452                 mark_as_advanced(
453                         ICONV_LIBRARY
454                         INTL_LIBRARY
455                 )
456
457                 if(INTL_LIBRARY AND ICONV_LIBRARY)
458                         set(GETTEXT_LIBRARIES ${INTL_LIBRARY} ${ICONV_LIBRARY})
459                 endif()
460         endif()
461
462         if(WITH_FFTW3)
463                 find_package(Fftw3)
464                 if(NOT FFTW3_FOUND)
465                         set(WITH_FFTW3 OFF)
466                 endif()
467         endif()
468
469         if(WITH_OPENCOLLADA)
470                 find_package(OpenCOLLADA)
471                 if(OPENCOLLADA_FOUND)
472                         find_package(XML2)
473                         find_package(PCRE)
474                 else()
475                         set(WITH_OPENCOLLADA OFF)
476                 endif()
477         endif()
478
479         if(WITH_MEM_JEMALLOC)
480                 find_package(JeMalloc)
481                 if(NOT JEMALLOC_FOUND)
482                         set(WITH_MEM_JEMALLOC OFF)
483                 endif()
484         endif()
485
486         if (WITH_INPUT_NDOF)
487                 find_package(Spacenav)
488                 if(NOT SPACENAV_FOUND)
489                         set(WITH_INPUT_NDOF OFF)
490                 endif()
491
492                 # use generic names within blenders buildsystem.
493                 if(SPACENAV_FOUND)
494                         set(NDOF_INCLUDE_DIRS ${SPACENAV_INCLUDE_DIRS})
495                         set(NDOF_LIBRARIES ${SPACENAV_LIBRARIES})
496                 endif()
497         endif()
498
499         if(WITH_BOOST)
500                 if(CYCLES_BOOST)
501                         set(BOOST ${CYCLES_BOOST} CACHE PATH "Boost Directory")
502                         unset(CYCLES_BOOST CACHE)
503                 else()
504                         set(BOOST "/usr" CACHE PATH "Boost Directory")
505                 endif()
506
507                 if(NOT BOOST_CUSTOM)
508                         set(BOOST_ROOT ${BOOST})
509                         set(Boost_USE_MULTITHREADED ON)
510                         find_package(Boost 1.34 REQUIRED COMPONENTS filesystem regex system thread)
511                 endif()
512
513                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
514                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
515                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
516                 set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
517         endif()
518
519         if(WITH_OPENIMAGEIO)
520
521                 # temp, update
522                 if(CYCLES_OIIO)
523                         set(OPENIMAGEIO ${CYCLES_OIIO})
524                         unset(CYCLES_OIIO CACHE)
525                 endif()
526
527                 set(OPENIMAGEIO_ROOT_DIR ${OPENIMAGEIO})
528                 find_package(OpenImageIO REQUIRED)
529
530                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
531                 set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
532                 set(OPENIMAGEIO_DEFINITIONS)
533
534                 if(NOT OPENIMAGEIO_FOUND)
535                         set(WITH_OPENIMAGEIO OFF)
536                 endif()
537
538         endif()
539
540         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
541         set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread -lstdc++")
542
543         if((NOT WITH_HEADLESS) AND (NOT WITH_GHOST_SDL))
544                 find_package(X11 REQUIRED)
545                 find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
546                 mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
547
548                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_X11_LIB}")
549
550                 if(WITH_X11_XINPUT)
551                         set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xinput_LIB}")
552                 endif()
553         endif()
554
555         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
556                 if(NOT WITH_PYTHON_MODULE)
557                         # BSD's dont use libdl.so
558                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -ldl")
559                         # binreloc is linux only
560                         set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
561                         set(WITH_BINRELOC ON)
562                 endif()
563         endif()
564
565         set(PLATFORM_LINKFLAGS "-pthread")
566
567         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE")
568         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE")
569
570         # GNU Compiler
571         if(CMAKE_COMPILER_IS_GNUCC)
572                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
573         # CLang is the same as GCC for now.
574         elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
575                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
576         # Intel C++ Compiler
577         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
578                 # think these next two are broken
579                 find_program(XIAR xiar)
580                 if(XIAR)
581                         set(CMAKE_AR "${XIAR}")
582                 endif()
583                 mark_as_advanced(XIAR)
584
585                 find_program(XILD xild)
586                 if(XILD)
587                         set(CMAKE_LINKER "${XILD}")
588                 endif()
589                 mark_as_advanced(XILD)
590
591                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
592                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
593
594                 # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
595                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
596                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
597         endif()
598
599 elseif(WIN32)
600
601         # this file is included anyway when building under Windows with cl.exe
602         #  include(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake)
603
604         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows)
605
606         # Setup 64bit and 64bit windows systems
607         if(CMAKE_CL_64)
608                 message("64 bit compiler detected.")
609                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64)
610         endif()
611
612         add_definitions(-DWIN32)
613
614         if(WITH_INTERNATIONAL)
615                 set(ICONV ${LIBDIR}/iconv)
616                 set(ICONV_INCLUDE_DIRS ${ICONV}/include)
617                 set(ICONV_LIBRARIES iconv)
618                 set(ICONV_LIBPATH ${ICONV}/lib)
619         endif()
620
621         set(PNG "${LIBDIR}/png")
622         set(PNG_INCLUDE_DIR "${PNG}/include")
623         set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
624
625         set(JPEG "${LIBDIR}/jpeg")
626         set(JPEG_INCLUDE_DIR "${JPEG}/include")
627         set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
628
629         set(WINTAB_INC ${LIBDIR}/wintab/include)
630
631         if(WITH_OPENAL)
632                 set(OPENAL ${LIBDIR}/openal)
633                 set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
634                 set(OPENAL_LIBRARY wrap_oal)
635                 set(OPENAL_LIBPATH ${OPENAL}/lib)
636         endif()
637
638         if(WITH_CODEC_SNDFILE)
639                 set(SNDFILE ${LIBDIR}/sndfile)
640                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
641                 set(SNDFILE_LIBRARIES libsndfile-1)
642                 set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
643         endif()
644
645         if(WITH_SDL)
646                 set(SDL ${LIBDIR}/sdl)
647                 set(SDL_INCLUDE_DIR ${SDL}/include)
648                 set(SDL_LIBRARY SDL)
649                 set(SDL_LIBPATH ${SDL}/lib)
650         endif()
651
652         if(WITH_CODEC_QUICKTIME)
653                 set(QUICKTIME ${LIBDIR}/QTDevWin)
654                 set(QUICKTIME_INCLUDE_DIRS ${QUICKTIME}/CIncludes)
655                 set(QUICKTIME_LIBRARIES qtmlClient)
656                 set(QUICKTIME_LIBPATH ${QUICKTIME}/Libraries)
657         endif()
658
659         if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
660                 add_definitions(-D__SSE__ -D__MMX__)
661         endif()
662
663         if(MSVC)
664                 if(CMAKE_CL_64)
665                         set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid)
666                 else()
667                         set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid)
668                 endif()
669
670                 add_definitions(/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_CONSOLE /D_LIB)
671
672                 set(CMAKE_CXX_FLAGS "/nologo /J /W0 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013" CACHE STRING "MSVC MT C++ flags " FORCE)
673                 set(CMAKE_C_FLAGS   "/nologo /J /W0 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013 /EHsc" CACHE STRING "MSVC MT C++ flags " FORCE)
674
675                 if(CMAKE_CL_64)
676                         set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
677                 else()
678                         set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
679                 endif()
680                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
681                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
682                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
683                 if(CMAKE_CL_64)
684                         set(CMAKE_C_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
685                 else()
686                         set(CMAKE_C_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
687                 endif()
688                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
689                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
690                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
691
692                 if(WITH_INTERNATIONAL)
693                         set(GETTEXT ${LIBDIR}/gettext)
694                         set(GETTEXT_INCLUDE_DIRS ${GETTEXT}/include)
695                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
696                         set(GETTEXT_LIBRARIES gnu_gettext)
697                 endif()
698
699                 if(CMAKE_CL_64)
700                         set(PNG_LIBRARIES libpng)
701                 else()
702                         set(PNG_LIBRARIES libpng_st)
703                 endif()
704                 set(JPEG_LIBRARIES libjpeg)
705
706                 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
707                 if(CMAKE_CL_64)
708                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz.lib)
709                 else()
710                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/zlib.lib)
711                 endif()
712
713                 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
714                 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
715
716                 set(FREETYPE ${LIBDIR}/freetype)
717                 set(FREETYPE_INCLUDE_DIRS
718                         ${LIBDIR}/freetype/include
719                         ${LIBDIR}/freetype/include/freetype2
720                 )
721                 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
722
723                 if(WITH_FFTW3)
724                         set(FFTW3 ${LIBDIR}/fftw3)
725                         set(FFTW3_LIBRARIES libfftw)
726                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
727                         set(FFTW3_LIBPATH ${FFTW3}/lib)
728                 endif()
729
730                 if(WITH_OPENCOLLADA)
731
732                         set(OPENCOLLADA_INCLUDE_DIRS
733                                 ${LIBDIR}/opencollada/include/COLLADAStreamWriter/include
734                                 ${LIBDIR}/opencollada/include/COLLADABaseUtils/include
735                                 ${LIBDIR}/opencollada/include/COLLADAFramework/include
736                                 ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader/include
737                                 ${LIBDIR}/opencollada/include/GeneratedSaxParser/include
738                         )
739
740                         set(OPENCOLLADA_LIBRARIES
741                                 ${LIBDIR}/opencollada/lib/OpenCOLLADASaxFrameworkLoader.lib
742                                 ${LIBDIR}/opencollada/lib/OpenCOLLADAFramework.lib
743                                 ${LIBDIR}/opencollada/lib/OpenCOLLADABaseUtils.lib
744                                 ${LIBDIR}/opencollada/lib/OpenCOLLADAStreamWriter.lib
745                                 ${LIBDIR}/opencollada/lib/MathMLSolver.lib
746                                 ${LIBDIR}/opencollada/lib/GeneratedSaxParser.lib
747                                 ${LIBDIR}/opencollada/lib/xml2.lib
748                                 ${LIBDIR}/opencollada/lib/buffer.lib
749                                 ${LIBDIR}/opencollada/lib/ftoa.lib
750                                 ${LIBDIR}/opencollada/lib/UTF.lib
751                         )
752                         set(PCRE_LIBRARIES
753                                 ${LIBDIR}/opencollada/lib/pcre.lib
754                         )
755                 endif()
756
757                 if(WITH_CODEC_FFMPEG)
758                         set(FFMPEG_INCLUDE_DIRS
759                                 ${LIBDIR}/ffmpeg/include
760                                 ${LIBDIR}/ffmpeg/include/msvc
761                         )
762                         set(FFMPEG_LIBRARIES
763                                 ${LIBDIR}/ffmpeg/lib/avcodec-53.lib
764                                 ${LIBDIR}/ffmpeg/lib/avformat-53.lib
765                                 ${LIBDIR}/ffmpeg/lib/avdevice-53.lib
766                                 ${LIBDIR}/ffmpeg/lib/avutil-51.lib
767                                 ${LIBDIR}/ffmpeg/lib/swscale-2.lib
768                         )
769                 endif()
770
771                 if(WITH_IMAGE_OPENEXR)
772                         if(MSVC90)
773                                 set(MSVC_LIB _vs2008)
774                                 set(MSVC_INC)
775                         elseif(MSVC10)
776                                 set(MSVC_LIB _vs2010)
777                                 set(MSVC_INC _vs2010)
778                         else()
779                                 set(MSVC_LIB msvc)
780                                 set(MSVC_INC)
781                         endif()
782                         set(OPENEXR ${LIBDIR}/openexr)
783                         set(OPENEXR_LIBPATH ${OPENEXR}/lib${MSVC_LIB})
784                         set(OPENEXR_LIBRARIES
785                                 ${OPENEXR_LIBPATH}/Iex.lib
786                                 ${OPENEXR_LIBPATH}/Half.lib
787                                 ${OPENEXR_LIBPATH}/IlmImf.lib
788                                 ${OPENEXR_LIBPATH}/Imath.lib
789                                 ${OPENEXR_LIBPATH}/IlmThread.lib
790                         )
791                         set(OPENEXR_INCUDE ${OPENEXR}/include${MSVC_INC})
792                         set(OPENEXR_INCLUDE_DIRS
793                                 ${OPENEXR_INCUDE}
794                                 ${OPENEXR_INCUDE}/IlmImf
795                                 ${OPENEXR_INCUDE}/Iex
796                                 ${OPENEXR_INCUDE}/Imath
797                         )
798                         unset(OPENEXR_INCUDE)
799                         unset(OPENEXR_LIBPATH)
800                 endif()
801
802                 if(WITH_IMAGE_TIFF)
803                         set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
804                         set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
805                 endif()
806
807                 if(WITH_JACK)
808                         set(JACK_INCLUDE_DIRS
809                                 ${LIBDIR}/jack/include/jack
810                                 ${LIBDIR}/jack/include
811                         )
812                         set(JACK_LIBRARIES ${LIBDIR}/jack/lib/libjack.lib)
813                 endif()
814
815                 if(WITH_PYTHON)
816                         # normally cached but not since we include them with blender
817                         set(PYTHON_VERSION 3.2) # CACHE STRING)
818                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}") # CACHE PATH)
819                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python32.lib") #CACHE FILEPATH)
820
821                         # uncached vars
822                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
823                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
824                 endif()
825
826                 if(WITH_BOOST)
827                         set(BOOST ${LIBDIR}/boost)
828                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
829                         if(CMAKE_CL_64)
830                                 set(BOOST_POSTFIX "vc90-mt-s-1_45.lib")
831                                 set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_45.lib")
832                         else()
833                                 set(BOOST_POSTFIX "vc90-mt-s-1_46_1.lib")
834                                 set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_46_1.lib")
835                         endif()
836                         set(BOOST_LIBRARIES
837                                 optimized libboost_date_time-${BOOST_POSTFIX} libboost_filesystem-${BOOST_POSTFIX}
838                                 libboost_regex-${BOOST_POSTFIX} libboost_system-${BOOST_POSTFIX} libboost_thread-${BOOST_POSTFIX}
839                                 debug libboost_date_time-${BOOST_DEBUG_POSTFIX} libboost_filesystem-${BOOST_DEBUG_POSTFIX}
840                                 libboost_regex-${BOOST_DEBUG_POSTFIX} libboost_system-${BOOST_DEBUG_POSTFIX} libboost_thread-${BOOST_DEBUG_POSTFIX})
841                         set(BOOST_LIBPATH ${BOOST}/lib)
842                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
843                 endif()
844                         
845                 if(WITH_OPENIMAGEIO)
846                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
847                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
848                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
849                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
850                         set(OPENIMAGEIO_DEFINITIONS)
851                 endif()
852
853                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
854
855                 # MSVC only, Mingw doesnt need
856                 if(CMAKE_CL_64)
857                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
858                 else()
859                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
860                 endif()
861
862                 set(PLATFORM_LINKFLAGS_DEBUG "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
863
864         else()
865                 # keep GCC specific stuff here
866                 if(CMAKE_COMPILER_IS_GNUCC)
867                         set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32")
868                         set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
869
870                         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
871                 endif()
872
873                 add_definitions(-DFREE_WINDOWS)
874
875                 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
876                 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
877
878                 if(WITH_INTERNATIONAL)
879                         set(GETTEXT ${LIBDIR}/gcc/gettext)
880                         set(GETTEXT_INCLUDE_DIRS ${GETTEXT}/include)
881                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
882                         set(GETTEXT_LIBRARIES intl)
883                 endif()
884
885                 set(JPEG_LIBRARIES libjpeg)
886                 set(PNG_LIBRARIES png)
887
888                 set(ZLIB ${LIBDIR}/zlib)
889                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
890                 set(ZLIB_LIBPATH ${ZLIB}/lib)
891                 set(ZLIB_LIBRARIES z)
892
893                 set(PTHREADS ${LIBDIR}/pthreads)
894                 set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
895                 set(PTHREADS_LIBPATH ${PTHREADS}/lib)
896                 set(PTHREADS_LIBRARIES pthreadGC2)
897
898                 set(FREETYPE ${LIBDIR}/gcc/freetype)
899                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
900                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
901                 set(FREETYPE_LIBRARY freetype)
902
903                 if(WITH_FFTW3)
904                         set(FFTW3 ${LIBDIR}/gcc/fftw3)
905                         set(FFTW3_LIBRARIES fftw3)
906                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
907                         set(FFTW3_LIBPATH ${FFTW3}/lib)
908                 endif()
909
910                 if(WITH_OPENCOLLADA)
911                         set(OPENCOLLADA ${LIBDIR}/gcc/opencollada)
912                         set(OPENCOLLADA_INCLUDE_DIRS
913                                 ${LIBDIR}/gcc/opencollada/include/COLLADAStreamWriter/include
914                                 ${LIBDIR}/gcc/opencollada/include/COLLADABaseUtils/include
915                                 ${LIBDIR}/gcc/opencollada/include/COLLADAFramework/include
916                                 ${LIBDIR}/gcc/opencollada/include/COLLADASaxFrameworkLoader/include
917                                 ${LIBDIR}/gcc/opencollada/include/GeneratedSaxParser/include
918                         )
919                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib ${OPENCOLLADA}/lib)
920                         set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver expat pcre buffer ftoa)
921                         set(PCRE_LIBRARIES pcre)
922                 endif()
923
924                 if(WITH_CODEC_FFMPEG)
925                         set(FFMPEG ${LIBDIR}/ffmpeg)
926                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include ${FFMPEG}/include)
927                         set(FFMPEG_LIBRARIES avcodec-53 avformat-53 avdevice-53 avutil-51 swscale-2)
928                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
929                 endif()
930
931                 if(WITH_IMAGE_OPENEXR)
932                         set(OPENEXR ${LIBDIR}/gcc/openexr)
933                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
934                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
935                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
936                 endif()
937
938                 if(WITH_IMAGE_TIFF)
939                         set(TIFF ${LIBDIR}/gcc/tiff)
940                         set(TIFF_LIBRARY tiff)
941                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
942                         set(TIFF_LIBPATH ${TIFF}/lib)
943                 endif()
944
945                 if(WITH_JACK)
946                         set(JACK ${LIBDIR}/jack)
947                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
948                         set(JACK_LIBRARIES jack)
949                         set(JACK_LIBPATH ${JACK}/lib)
950
951                         # TODO, gives linking errors, force off
952                         set(WITH_JACK OFF)
953                 endif()
954
955                 if(WITH_PYTHON)
956                         # normally cached but not since we include them with blender
957                         set(PYTHON_VERSION 3.2) #  CACHE STRING)
958                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
959                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python32mw.lib")  # CACHE FILEPATH)
960
961                         # uncached vars
962                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
963                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
964                 endif()
965
966                 if(WITH_BOOST)
967                         set(BOOST ${LIBDIR}/boost)
968                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
969                         set(BOOST_POSTFIX "vc90-mt-s-1_46_1")
970                         set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_46_1")
971                         set(BOOST_LIBRARIES
972                                 optimized libboost_date_time-${BOOST_POSTFIX} libboost_filesystem-${BOOST_POSTFIX}
973                                 libboost_regex-${BOOST_POSTFIX} libboost_system-${BOOST_POSTFIX} libboost_thread-${BOOST_POSTFIX}
974                                 debug libboost_date_time-${BOOST_DEBUG_POSTFIX} libboost_filesystem-${BOOST_DEBUG_POSTFIX}
975                                 libboost_regex-${BOOST_DEBUG_POSTFIX} libboost_system-${BOOST_DEBUG_POSTFIX} libboost_thread-${BOOST_DEBUG_POSTFIX})
976                         set(BOOST_LIBPATH ${BOOST}/lib)
977                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
978                 endif()
979                         
980                 if(WITH_OPENIMAGEIO)
981                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
982                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
983                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
984                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
985                         set(OPENIMAGEIO_DEFINITIONS)
986                 endif()
987
988                 set(PLATFORM_LINKFLAGS "--stack,2097152")
989
990         endif()
991
992         # used in many places so include globally, like OpenGL
993         blender_include_dirs("${PTHREADS_INCLUDE_DIRS}")
994
995 elseif(APPLE)
996
997         if (${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5")
998                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE)
999         endif()
1000
1001         if(WITH_LIBS10.5)
1002                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
1003         else()
1004                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1005                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
1006                 else()
1007                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
1008                 endif()
1009         endif()
1010
1011
1012         if(WITH_OPENAL)
1013                 find_package(OpenAL)
1014                 if(OPENAL_FOUND)
1015                         set(WITH_OPENAL ON)
1016                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
1017                 else()
1018                         set(WITH_OPENAL OFF)
1019                 endif()
1020         endif()
1021
1022         if(WITH_JACK)
1023                 set(JACK /usr)
1024                 set(JACK_INCLUDE_DIRS ${JACK}/include/jack)
1025                 set(JACK_LIBRARIES jack)
1026                 set(JACK_LIBPATH ${JACK}/lib)
1027         endif()
1028
1029         if(WITH_CODEC_SNDFILE)
1030                 set(SNDFILE ${LIBDIR}/sndfile)
1031                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1032                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
1033                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
1034         endif()
1035
1036         if(WITH_PYTHON)
1037                 # we use precompiled libraries for py 3.2 and up by default
1038
1039                 # normally cached but not since we include them with blender
1040                 set(PYTHON_VERSION 3.2)
1041                 set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")
1042                 # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
1043                 set(PYTHON_LIBRARY python${PYTHON_VERSION})
1044                 set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
1045                 # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
1046
1047                 # uncached vars
1048                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1049                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1050         endif()
1051
1052         if(WITH_INTERNATIONAL)
1053                 set(GETTEXT ${LIBDIR}/gettext)
1054                 set(GETTEXT_INCLUDE_DIRS "${GETTEXT}/include")
1055                 set(GETTEXT_LIBRARIES intl iconv)
1056                 set(GETTEXT_LIBPATH ${GETTEXT}/lib)
1057         endif()
1058
1059         if(WITH_FFTW3)
1060                 set(FFTW3 ${LIBDIR}/fftw3)
1061                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1062                 set(FFTW3_LIBRARIES fftw3)
1063                 set(FFTW3_LIBPATH ${FFTW3}/lib)
1064         endif()
1065
1066         set(PNG_LIBRARIES png)
1067         set(JPEG_LIBRARIES jpeg)
1068
1069         set(ZLIB /usr)
1070         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
1071         set(ZLIB_LIBRARIES z bz2)
1072
1073         set(FREETYPE ${LIBDIR}/freetype)
1074         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1075         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1076         set(FREETYPE_LIBRARY freetype)
1077
1078         if(WITH_IMAGE_OPENEXR)
1079                 set(OPENEXR ${LIBDIR}/openexr)
1080                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1081                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
1082                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1083         endif()
1084
1085         if(WITH_CODEC_FFMPEG)
1086                 set(FFMPEG ${LIBDIR}/ffmpeg)
1087                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1088                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
1089                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1090                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
1091         endif()
1092
1093         find_library(SYSTEMSTUBS_LIBRARY
1094                 NAMES
1095                 SystemStubs
1096                 PATHS
1097         )
1098         mark_as_advanced(SYSTEMSTUBS_LIBRARY)
1099         if(SYSTEMSTUBS_LIBRARY)
1100                 set(PLATFORM_LINKLIBS stdc++ SystemStubs)
1101         else()
1102                 set(PLATFORM_LINKLIBS stdc++)
1103         endif()
1104
1105         if(WITH_COCOA)
1106                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -DGHOST_COCOA")
1107                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
1108                 if(USE_QTKIT)
1109                         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DUSE_QTKIT")
1110                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
1111                         if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1112                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1113                                 #libSDL still needs 32bit carbon quicktime
1114                         endif()
1115                 elseif(WITH_CODEC_QUICKTIME)
1116                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1117                 endif()
1118
1119                 # XXX - SOME MAC DEV PLEASE TEST WITH THE SDK INSTALLED!
1120                 # ALSO SHOULD BE MOVED INTO OWN MODULE WHEN FUNCTIONAL
1121                 if(WITH_INPUT_NDOF)
1122                         # This thread it *should* work and check the framework - campbell
1123                         # http://www.cmake.org/pipermail/cmake/2005-December/007740.html
1124                         find_library(3D_CONNEXION_CLIENT_LIBRARY
1125                                 NAMES 3DconnexionClient
1126                         )
1127                         if(NOT 3D_CONNEXION_CLIENT_LIBRARY)
1128                                 set(WITH_INPUT_NDOF OFF)
1129                         endif()
1130
1131                         if(WITH_INPUT_NDOF)
1132                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -weak_framework 3DconnexionClient")
1133                         endif()
1134                 endif()
1135
1136         else()
1137                 set(PLATFORM_CFLAGS "-pipe -funsigned-char")
1138                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Carbon -framework AGL -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework QuickTime")
1139                 set(WITH_INPUT_NDOF OFF)  # unsupported
1140         endif()
1141
1142         if(WITH_OPENCOLLADA)
1143                 set(OPENCOLLADA ${LIBDIR}/opencollada)
1144
1145                 set(OPENCOLLADA_INCLUDE_DIRS
1146                         ${LIBDIR}/opencollada/include/COLLADAStreamWriter
1147                         ${LIBDIR}/opencollada/include/COLLADABaseUtils
1148                         ${LIBDIR}/opencollada/include/COLLADAFramework
1149                         ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
1150                         ${LIBDIR}/opencollada/include/GeneratedSaxParser
1151                 )
1152
1153                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
1154                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa" )
1155                 #pcre is bundled with openCollada
1156                 #set(PCRE ${LIBDIR}/pcre)
1157                 #set(PCRE_LIBPATH ${PCRE}/lib)
1158                 set(PCRE_LIBRARIES pcre)
1159                 #libxml2 is used
1160                 #set(EXPAT ${LIBDIR}/expat)
1161                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
1162                 set(EXPAT_LIB)
1163         endif()
1164
1165         if(WITH_SDL)
1166                 set(SDL ${LIBDIR}/sdl)
1167                 set(SDL_INCLUDE_DIR ${SDL}/include)
1168                 set(SDL_LIBRARY SDL)
1169                 set(SDL_LIBPATH ${SDL}/lib)
1170         endif()
1171
1172         set(PNG "${LIBDIR}/png")
1173         set(PNG_INCLUDE_DIR "${PNG}/include")
1174         set(PNG_LIBPATH ${PNG}/lib)
1175
1176         set(JPEG "${LIBDIR}/jpeg")
1177         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1178         set(JPEG_LIBPATH ${JPEG}/lib)
1179
1180         if(WITH_IMAGE_TIFF)
1181                 set(TIFF ${LIBDIR}/tiff)
1182                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1183                 set(TIFF_LIBRARY tiff)
1184                 set(TIFF_LIBPATH ${TIFF}/lib)
1185         endif()
1186
1187         if (WITH_INPUT_NDOF)
1188                 # linker needs "-weak_framework 3DconnexionClient"
1189         endif()
1190
1191         if(WITH_BOOST)
1192                 set(BOOST ${LIBDIR}/boost)
1193                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1194                 set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt)
1195                 set(BOOST_LIBPATH ${BOOST}/lib)
1196                 set(BOOST_DEFINITIONS)
1197         endif()
1198
1199         if(WITH_OPENIMAGEIO)
1200                 set(OPENIMAGEIO ${LIBDIR}/openimageio)
1201                 set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1202                 set(OPENIMAGEIO_LIBRARIES OpenImageIO ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
1203                 set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib ${JPEG_LIBPATH} ${PNG_LIBPATH} ${TIFF_LIBPATH} ${OPENEXR_LIBPATH} ${ZLIB_LIBPATH})
1204                 set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
1205         endif()
1206
1207         set(EXETYPE MACOSX_BUNDLE)
1208
1209         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
1210         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
1211         if(CMAKE_OSX_ARCHITECTURES MATCHES "i386")
1212                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
1213                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
1214         elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
1215                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1216                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1217         else()
1218                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1219                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1220         endif()
1221 endif()
1222
1223 #-----------------------------------------------------------------------------
1224 # Common.
1225
1226 if(APPLE OR WIN32)
1227         if(NOT EXISTS "${LIBDIR}/")
1228                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
1229         endif()
1230 endif()
1231
1232 # See TEST_SSE_SUPPORT() for how this is defined.
1233
1234 if(WITH_RAYOPTIMIZATION)
1235         if(SUPPORT_SSE_BUILD)
1236                 set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
1237                 add_definitions(-D__SSE__ -D__MMX__)
1238         endif()
1239         if(SUPPORT_SSE2_BUILD)
1240                 set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
1241                 add_definitions(-D__SSE2__)
1242                 if(NOT SUPPORT_SSE_BUILD) # dont double up
1243                         add_definitions(-D__MMX__)
1244                 endif()
1245         endif()
1246 endif()
1247
1248
1249 # set the endian define
1250 if(MSVC)
1251         # for some reason this fails on msvc
1252         add_definitions(-D__LITTLE_ENDIAN__)
1253 else()
1254         include(TestBigEndian)
1255         test_big_endian(_SYSTEM_BIG_ENDIAN)
1256         if(_SYSTEM_BIG_ENDIAN)
1257                 add_definitions(-D__BIG_ENDIAN__)
1258         else()
1259                 add_definitions(-D__LITTLE_ENDIAN__)
1260         endif()
1261         unset(_SYSTEM_BIG_ENDIAN)
1262 endif()
1263
1264
1265 if(WITH_IMAGE_OPENJPEG)
1266         if(UNIX AND NOT APPLE)
1267                 # dealt with above
1268         else()
1269                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
1270         endif()
1271 endif()
1272
1273 if(WITH_IMAGE_REDCODE)
1274         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
1275         set(REDCODE_INC ${REDCODE})
1276 endif()
1277
1278 #-----------------------------------------------------------------------------
1279 # Blender WebPlugin
1280
1281 if(WITH_WEBPLUGIN)
1282         set(GECKO_DIR "${CMAKE_SOURCE_DIR}/../gecko-sdk/" CACHE PATH "Gecko SDK path")
1283         set(WEBPLUGIN_SANDBOX_MODE "apparmor" CACHE STRING "WEB Plugin sandbox mode, can be apparmor, privsep, none")
1284
1285         set(WITH_PLAYER ON)
1286 endif()
1287
1288
1289 #-----------------------------------------------------------------------------
1290 # Configure OpenGL.
1291 find_package(OpenGL)
1292 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
1293 # unset(OPENGL_LIBRARIES CACHE) # not compat with older cmake
1294 # unset(OPENGL_xmesa_INCLUDE_DIR CACHE) # not compat with older cmake
1295
1296 #-----------------------------------------------------------------------------
1297 # Configure OpenMP.
1298 if(WITH_OPENMP)
1299         find_package(OpenMP)
1300         if(OPENMP_FOUND)
1301                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
1302                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
1303
1304                 if(APPLE AND ${CMAKE_GENERATOR} MATCHES "Xcode")
1305                         set(CMAKE_XCODE_ATTRIBUTE_ENABLE_OPENMP_SUPPORT "YES")
1306                 endif()
1307         else()
1308                 set(WITH_OPENMP OFF)
1309         endif()
1310
1311         mark_as_advanced(
1312                 OpenMP_C_FLAGS
1313                 OpenMP_CXX_FLAGS
1314         )
1315 endif()
1316
1317 #-----------------------------------------------------------------------------
1318 # Configure GLEW
1319
1320 if(WITH_BUILTIN_GLEW)
1321         # set(GLEW_LIBRARY "")  # unused
1322         set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1323 else()
1324         find_package(GLEW)
1325
1326         if(NOT GLEW_FOUND)
1327                 message(FATAL_ERROR "GLEW is required to build blender, install it or use WITH_BUILTIN_GLEW")
1328         endif()
1329
1330         mark_as_advanced(
1331                 GLEW_LIBRARY
1332                 GLEW_INCLUDE_PATH
1333         )
1334 endif()
1335
1336 #-----------------------------------------------------------------------------
1337 # Configure Python.
1338
1339 if(WITH_PYTHON_MODULE)
1340         add_definitions(-DPy_ENABLE_SHARED)
1341 endif()
1342
1343 #-----------------------------------------------------------------------------
1344 # Extra compile flags
1345
1346 if((NOT WIN32) AND (NOT MSVC))
1347         # used for internal debug checks
1348         set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
1349         set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
1350
1351         # assert() checks for this.
1352         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
1353         set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -DNDEBUG")
1354         set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DNDEBUG")
1355
1356         set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
1357         set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
1358         set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DNDEBUG")
1359 endif()
1360
1361 if(CMAKE_COMPILER_IS_GNUCC)
1362
1363         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1364         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1365         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
1366         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1367         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE -Werror=return-type)
1368         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1369         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES -Wstrict-prototypes)
1370         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1371         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1372         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1373         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1374         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1375
1376         # # this causes too many warnings, disable
1377         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEFINED -Wundef)
1378
1379         # disable because it gives warnings for printf() & friends.
1380         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1381         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1382
1383         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1384         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1385         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1386
1387         # # this causes too many warnings, disable
1388         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEFINED -Wundef)
1389
1390 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1391
1392         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1393         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1394         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1395
1396         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1397         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1398         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1399
1400         # disable numbered, false positives
1401         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
1402         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
1403
1404 endif()
1405
1406 # MSVC2010 fails to links C++ libs right
1407 if(MSVC10)
1408         if(WITH_IMAGE_OPENEXR)
1409                 message(WARNING "MSVC 2010 does not support OpenEXR, disabling WITH_IMAGE_OPENEXR. To enable support use Use MSVC 2008")
1410                 set(WITH_IMAGE_OPENEXR OFF)
1411         endif()
1412         if(WITH_OPENCOLLADA)
1413                 message(WARNING "MSVC 2010 does not support OpenCollada, disabling WITH_OPENCOLLADA. To enable support use Use MSVC 2008")
1414                 set(WITH_OPENCOLLADA OFF)
1415         endif()
1416 endif()
1417
1418 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1419         if(WITH_IK_ITASC OR WITH_MOD_FLUID)
1420                 message(WARNING "Using Clang as CXX compiler: disabling WITH_IK_ITASC and WITH_MOD_FLUID, these features will be missing.")
1421                 set(WITH_IK_ITASC OFF)
1422                 set(WITH_MOD_FLUID OFF)
1423         endif()
1424 endif()
1425
1426
1427 # ensure python header is found since detection can fail, this could happen
1428 # with _any_ library but since we used a fixed python version this tends to
1429 # be most problematic.
1430 if(WITH_PYTHON)
1431         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
1432                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
1433                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
1434                                                         "to a valid python include path. Containing "
1435                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
1436         endif()
1437 endif()
1438
1439
1440 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS} ${C_WARNINGS}")
1441 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ${CXX_WARNINGS}")
1442
1443 #-------------------------------------------------------------------------------
1444 # Global Defines
1445
1446 # better not set includes here but this debugging option is off by default.
1447 if(WITH_CXX_GUARDEDALLOC)
1448         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
1449 endif()
1450
1451 if(WITH_ASSERT_ABORT)
1452         add_definitions(-DWITH_ASSERT_ABORT)
1453 endif()
1454
1455 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
1456 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
1457
1458 #-----------------------------------------------------------------------------
1459 # Libraries
1460
1461 add_subdirectory(source)
1462 add_subdirectory(intern)
1463 add_subdirectory(extern)
1464
1465
1466 #-----------------------------------------------------------------------------
1467 # Blender Application
1468 if(WITH_BLENDER)
1469         add_subdirectory(source/creator)
1470 endif()
1471
1472
1473 #-----------------------------------------------------------------------------
1474 # Blender Player
1475 if(WITH_PLAYER)
1476         add_subdirectory(source/blenderplayer)
1477 endif()
1478
1479 #-----------------------------------------------------------------------------
1480 # CPack for generating packages
1481 include(build_files/cmake/packaging.cmake)
1482
1483
1484 #-----------------------------------------------------------------------------
1485 # Print Final Configuration
1486
1487 if(FIRST_RUN)
1488         set(_config_msg "\n* Blender Configuration *")
1489         macro(info_cfg_option
1490                 _setting)
1491                 set(_msg "   * ${_setting}")
1492                 string(LENGTH "${_msg}" _len)
1493                 while("28" GREATER "${_len}")
1494                         set(_msg "${_msg} ")
1495                          math(EXPR _len "${_len} + 1")
1496                 endwhile()
1497
1498                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
1499         endmacro()
1500
1501         macro(info_cfg_text
1502                 _text)
1503                 set(_config_msg "${_config_msg}\n\n  ${_text}")
1504
1505
1506         endmacro()
1507
1508         info_cfg_text("Build Options:")
1509         info_cfg_option(WITH_GAMEENGINE)
1510         info_cfg_option(WITH_PLAYER)
1511         info_cfg_option(WITH_BULLET)
1512         info_cfg_option(WITH_IK_ITASC)
1513         info_cfg_option(WITH_OPENCOLLADA)
1514         info_cfg_option(WITH_FFTW3)
1515         info_cfg_option(WITH_INTERNATIONAL)
1516         info_cfg_option(WITH_INPUT_NDOF)
1517
1518         info_cfg_text("Compiler Options:")
1519         info_cfg_option(WITH_BUILDINFO)
1520         info_cfg_option(WITH_OPENMP)
1521         info_cfg_option(WITH_RAYOPTIMIZATION)
1522
1523         info_cfg_text("System Options:")
1524         info_cfg_option(WITH_INSTALL_PORTABLE)
1525         info_cfg_option(WITH_X11_XINPUT)
1526         info_cfg_option(WITH_BUILTIN_GLEW)
1527
1528         info_cfg_text("Image Formats:")
1529         info_cfg_option(WITH_IMAGE_CINEON)
1530         info_cfg_option(WITH_IMAGE_DDS)
1531         info_cfg_option(WITH_IMAGE_HDR)
1532         info_cfg_option(WITH_IMAGE_OPENEXR)
1533         info_cfg_option(WITH_IMAGE_OPENJPEG)
1534         info_cfg_option(WITH_IMAGE_REDCODE)
1535         info_cfg_option(WITH_IMAGE_TIFF)
1536         info_cfg_option(WITH_OPENIMAGEIO)
1537
1538         info_cfg_text("Audio:")
1539         info_cfg_option(WITH_OPENAL)
1540         info_cfg_option(WITH_SDL)
1541         info_cfg_option(WITH_JACK)
1542         info_cfg_option(WITH_CODEC_FFMPEG)
1543         info_cfg_option(WITH_CODEC_SNDFILE)
1544
1545         info_cfg_text("Compression:")
1546         info_cfg_option(WITH_LZMA)
1547         info_cfg_option(WITH_LZO)
1548
1549         info_cfg_text("Python:")
1550         info_cfg_option(WITH_PYTHON_INSTALL)
1551         info_cfg_option(WITH_PYTHON_MODULE)
1552         info_cfg_option(WITH_PYTHON_SAFETY)
1553
1554         info_cfg_text("Modifiers:")
1555         info_cfg_option(WITH_MOD_BOOLEAN)
1556         info_cfg_option(WITH_MOD_DECIMATE)
1557         info_cfg_option(WITH_MOD_FLUID)
1558
1559         info_cfg_text("")
1560
1561         message("${_config_msg}")
1562 endif()