Build system support for numpy on ms-windows
[blender.git] / source / creator / 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 setup_libdirs()
27
28 blender_include_dirs(
29         ../../intern/guardedalloc
30         ../blender/blenlib
31         ../blender/blenkernel
32         ../blender/blenloader
33         ../blender/editors/include
34         ../blender/makesrna
35         ../blender/imbuf
36         ../blender/render/extern/include
37         ../blender/makesdna
38         ../blender/gpu
39         ../blender/windowmanager
40 )
41
42 if(WIN32)
43         blender_include_dirs(../../intern/utfconv)
44 endif()
45
46 if(WITH_LIBMV)
47         blender_include_dirs(../../extern/libmv)
48         add_definitions(-DWITH_LIBMV)
49 endif()
50
51 if(WITH_CODEC_FFMPEG)
52         add_definitions(-DWITH_FFMPEG)
53 endif()
54
55 if(WITH_PYTHON)
56         blender_include_dirs(../blender/python)
57         add_definitions(-DWITH_PYTHON)
58
59         if(WITH_PYTHON_SECURITY)
60                 add_definitions(-DWITH_PYTHON_SECURITY)
61         endif()
62 endif()
63
64 if(WITH_HEADLESS)
65         add_definitions(-DWITH_HEADLESS)
66 endif()
67
68 if(WITH_GAMEENGINE)
69         blender_include_dirs(../gameengine/BlenderRoutines)
70
71         add_definitions(-DWITH_GAMEENGINE)
72 endif()
73
74 if(WITH_SDL)
75         add_definitions(-DWITH_SDL)
76 endif()
77
78 if(WITH_BINRELOC)
79         add_definitions(-DWITH_BINRELOC)
80         blender_include_dirs(${BINRELOC_INCLUDE_DIRS})
81 endif()
82
83 if(WITH_FREESTYLE)
84         add_definitions(-DWITH_FREESTYLE)
85         blender_include_dirs(../blender/freestyle)
86 endif()
87
88 # Setup the exe sources and buildinfo
89 set(SRC
90         creator.c
91 )
92
93 # MSVC 2010 gives linking errors with the manifest
94 if(WIN32 AND NOT UNIX)
95         string(SUBSTRING ${BLENDER_VERSION} 0 1 bver1)
96         string(SUBSTRING ${BLENDER_VERSION} 2 1 bver2)
97         string(SUBSTRING ${BLENDER_VERSION} 3 1 bver3)
98         if(MINGW)
99                 add_definitions(
100                         -DWINDRES
101                         -DBLEN_VER_RC_STR_M=${BLENDER_VERSION}
102                         -DBLEN_VER_RC_1=${bver1}
103                         -DBLEN_VER_RC_2=${bver2}
104                         -DBLEN_VER_RC_3=${bver3}
105                         -DBLEN_VER_RC_4=0
106                 )
107         else()
108                 add_definitions(
109                         -DBLEN_VER_RC_STR=${BLENDER_VERSION}
110                         -DBLEN_VER_RC_1=${bver1}
111                         -DBLEN_VER_RC_2=${bver2}
112                         -DBLEN_VER_RC_3=${bver3}
113                         -DBLEN_VER_RC_4=0
114                 )
115         endif()
116
117
118         list(APPEND SRC
119                 ../icons/winblender.rc
120         )
121 endif()
122
123 if(WITH_BUILDINFO)
124         add_definitions(-DWITH_BUILDINFO)
125         # --------------------------------------------------------------------------
126         # These defines could all be moved into the header below
127         string(REPLACE " " "\ " BUILDINFO_CFLAGS "${CMAKE_C_FLAGS}")
128         string(REPLACE " " "\ " BUILDINFO_CXXFLAGS "${CMAKE_CXX_FLAGS}")
129         string(REPLACE " " "\ " BUILDINFO_LINKFLAGS "${PLATFORM_LINKFLAGS}")
130         add_definitions(
131                 # # define in header now, else these get out of date on rebuilds.
132                 # -DBUILD_DATE="${BUILD_DATE}"
133                 # -DBUILD_TIME="${BUILD_TIME}"
134                 # -DBUILD_COMMIT_TIMESTAMP="${BUILD_COMMIT_TIMESTAMP}"
135                 # -DBUILD_COMMIT_TIME="${BUILD_COMMIT_TIME}"
136                 # -DBUILD_COMMIT_DATE="${BUILD_COMMIT_DATE}"
137                 # -DBUILD_HASH="${BUILD_HASH}"
138                 # -DBUILD_BRANCH="${BUILD_BRANCH}"
139                 -DWITH_BUILDINFO_HEADER # alternative to lines above
140                 -DBUILD_PLATFORM="${CMAKE_SYSTEM_NAME}"
141                 -DBUILD_TYPE="${CMAKE_BUILD_TYPE}"
142                 -DBUILD_CFLAGS="${BUILDINFO_CFLAGS}"
143                 -DBUILD_CXXFLAGS="${BUILDINFO_CXXFLAGS}"
144                 -DBUILD_LINKFLAGS="${BUILDINFO_LINKFLAGS}"
145                 -DBUILD_SYSTEM="CMake"
146         )
147
148         # --------------------------------------------------------------------------
149         # write header for values that change each build
150         # note, generaed file is in build dir's source/creator
151         #       except when used as an include path.
152
153         # include the output directory, where the buildinfo.h file is generated
154         include_directories(${CMAKE_BINARY_DIR}/source/creator)
155
156         # a custom target that is always built
157         add_custom_target(buildinfo ALL
158                 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/buildinfo.h)
159
160         # creates svnheader.h using cmake script
161         add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/buildinfo.h
162                 COMMAND ${CMAKE_COMMAND}
163                 -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
164                 -P ${CMAKE_SOURCE_DIR}/build_files/cmake/buildinfo.cmake)
165
166         # buildinfo.h is a generated file
167         set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/buildinfo.h
168                 PROPERTIES GENERATED TRUE
169                 HEADER_FILE_ONLY TRUE)
170
171         # add deps below, after adding blender
172         # -------------- done with header values.
173
174         list(APPEND SRC
175                 buildinfo.c
176         )
177 endif()
178
179 # message(STATUS "Configuring blender")
180 if(WITH_PYTHON_MODULE)
181         add_definitions(-DWITH_PYTHON_MODULE)
182
183         # creates ./bin/bpy.so which can be imported as a python module.
184         #
185         # note that 'SHARED' works on Linux and Windows,
186         # but not OSX which _must_ be 'MODULE'
187         add_library(blender MODULE ${SRC})
188         set_target_properties(
189                 blender
190                 PROPERTIES
191                         PREFIX ""
192                         OUTPUT_NAME bpy
193                         LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
194                         RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin  # only needed on windows
195         )
196
197         if(APPLE)
198                 set_target_properties(
199                         blender
200                         PROPERTIES
201                                 LINK_FLAGS_RELEASE "${PLATFORM_LINKFLAGS}"
202                                 LINK_FLAGS_DEBUG "${PLATFORM_LINKFLAGS_DEBUG}"
203                 )
204         endif()
205
206         if(WIN32)
207                 # python modules use this
208                 set_target_properties(
209                         blender
210                         PROPERTIES
211                         SUFFIX ".pyd"
212                 )
213         endif()
214
215 else()
216         add_executable(blender ${EXETYPE} ${SRC})
217 endif()
218
219 if(WITH_BUILDINFO)
220         # explicitly say that the executable depends on the buildinfo
221         add_dependencies(blender buildinfo)
222 endif()
223
224 # Post build steps for bundling/packaging.
225
226
227 if(MSVC_IDE)
228         # ${CMAKE_CFG_INTDIR} should replace \${BUILD_TYPE} when using add_command
229         set(TARGETDIR ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE})
230 elseif(APPLE)
231         set(TARGETDIR ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE})
232 else()
233         set(TARGETDIR ${EXECUTABLE_OUTPUT_PATH})
234 endif()
235
236 set(BLENDER_TEXT_FILES
237         ${CMAKE_SOURCE_DIR}/release/text/GPL-license.txt
238         ${CMAKE_SOURCE_DIR}/release/text/Python-license.txt
239         ${CMAKE_SOURCE_DIR}/release/text/copyright.txt
240         ${CMAKE_SOURCE_DIR}/release/text/readme.html
241         ${CMAKE_SOURCE_DIR}/release/datafiles/LICENSE-bfont.ttf.txt
242 )
243
244 if(WITH_INTERNATIONAL)
245         list(APPEND BLENDER_TEXT_FILES
246                 ${CMAKE_SOURCE_DIR}/release/datafiles/LICENSE-droidsans.ttf.txt
247                 ${CMAKE_SOURCE_DIR}/release/datafiles/LICENSE-bmonofont-i18n.ttf.txt
248         )
249 endif()
250
251
252 # -----------------------------------------------------------------------------
253 # Platform Specific Var: TARGETDIR_VER
254
255 if(UNIX AND NOT APPLE)
256         if(WITH_INSTALL_PORTABLE)
257                 set(TARGETDIR_VER ${TARGETDIR}/${BLENDER_VERSION})
258         else()
259                 if(WITH_PYTHON_MODULE)
260                         set(TARGETDIR_VER ${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/${BLENDER_VERSION})
261                 else()
262                         set(TARGETDIR_VER ${CMAKE_INSTALL_PREFIX}/share/blender/${BLENDER_VERSION})
263                 endif()
264         endif()
265
266 elseif(WIN32)
267         set(TARGETDIR_VER ${TARGETDIR}/${BLENDER_VERSION})
268
269 elseif(APPLE)
270         if(WITH_PYTHON_MODULE)
271                 set(TARGETDIR_VER ${TARGETDIR}/${BLENDER_VERSION})
272         else()
273                 set(TARGETDIR_VER ${TARGETDIR}/blender.app/Contents/MacOS/${BLENDER_VERSION})
274         endif()
275
276 endif()
277
278
279 # -----------------------------------------------------------------------------
280 # Install Targets (Generic, All Platforms)
281
282
283 # important to make a clean  install each time, else old scripts get loaded.
284 install(
285         CODE
286         "file(REMOVE_RECURSE ${TARGETDIR_VER})"
287 )
288
289 if(WITH_PYTHON)
290         # install(CODE "message(\"copying blender scripts...\")")
291         
292         # exclude addons_contrib if release
293         if("${BLENDER_VERSION_CYCLE}" STREQUAL "release")
294                 set(ADDON_EXCLUDE_CONDITIONAL "addons_contrib/*")
295         else()
296                 set(ADDON_EXCLUDE_CONDITIONAL "_addons_contrib/*")  # dummy, wont do anything
297         endif()
298
299         # do not install freestyle dir if disabled
300         if(NOT WITH_FREESTYLE)
301                 set(FREESTYLE_EXCLUDE_CONDITIONAL "freestyle/*")
302         else()
303                 set(FREESTYLE_EXCLUDE_CONDITIONAL "_freestyle/*")  # dummy, wont do anything
304         endif()
305
306         install(
307                 DIRECTORY ${CMAKE_SOURCE_DIR}/release/scripts
308                 DESTINATION ${TARGETDIR_VER}
309                 PATTERN ".git" EXCLUDE
310                 PATTERN "__pycache__" EXCLUDE
311                 PATTERN "${ADDON_EXCLUDE_CONDITIONAL}" EXCLUDE
312                 PATTERN "${FREESTYLE_EXCLUDE_CONDITIONAL}" EXCLUDE
313         )
314         
315         unset(ADDON_EXCLUDE_CONDITIONAL)
316         unset(FREESTYLE_EXCLUDE_CONDITIONAL)
317 endif()
318
319 # localization
320 if(WITH_INTERNATIONAL)
321         install(
322                 DIRECTORY
323                         ${CMAKE_SOURCE_DIR}/release/datafiles/fonts
324                 DESTINATION ${TARGETDIR_VER}/datafiles
325         )
326
327         set(_locale_dir "${CMAKE_SOURCE_DIR}/release/datafiles/locale")
328         set(_locale_target_dir ${TARGETDIR_VER}/datafiles/locale)
329
330         file(GLOB _po_files "${_locale_dir}/po/*.po")
331         foreach(_po_file ${_po_files})
332                 msgfmt_simple(${_po_file} _all_mo_files)
333         endforeach()
334
335         # Create a custom target which will compile all po to mo
336         add_custom_target(
337                 locales
338                 DEPENDS ${_all_mo_files})
339
340         add_dependencies(blender locales)
341
342         # Generate INSTALL rules
343         install(
344                 FILES ${_locale_dir}/languages
345                 DESTINATION ${_locale_target_dir}
346         )
347
348         foreach(_mo_file ${_all_mo_files})
349                 get_filename_component(_locale_name ${_mo_file} NAME_WE)
350                 install(
351                         FILES ${_mo_file}
352                         DESTINATION ${_locale_target_dir}/${_locale_name}/LC_MESSAGES
353                         RENAME blender.mo
354                 )
355                 unset(_locale_name)
356         endforeach()
357
358         unset(_all_mo_files)
359         unset(_po_files)
360         unset(_po_file)
361         unset(_mo_file)
362         unset(_locale_target_dir)
363
364         unset(_locale_dir)
365 endif()
366
367 # color management
368 if(WITH_OPENCOLORIO)
369         install(
370                 DIRECTORY ${CMAKE_SOURCE_DIR}/release/datafiles/colormanagement
371                 DESTINATION ${TARGETDIR_VER}/datafiles
372         )
373 endif()
374
375 # helpful tip when using make
376 if("${CMAKE_GENERATOR}" MATCHES ".*Makefiles.*")
377         # message after building.
378         add_custom_command(
379                 TARGET blender POST_BUILD MAIN_DEPENDENCY blender
380                 COMMAND ${CMAKE_COMMAND} -E echo 'now run: \"make install\" to copy runtime files and scripts to ${TARGETDIR_VER}'
381         )
382 endif()
383
384
385 # -----------------------------------------------------------------------------
386 # Install Targets (Platform Specific)
387
388 if(UNIX AND NOT APPLE)
389
390         # there are a few differences between portable and system install
391         if(WITH_INSTALL_PORTABLE)
392                 install(
393                         FILES
394                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/blender.desktop
395                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/scalable/apps/blender.svg
396                                 ${CMAKE_SOURCE_DIR}/doc/manpage/blender.1
397                         DESTINATION ${TARGETDIR}
398                 )
399
400                 install(
401                         PROGRAMS
402                         ${CMAKE_SOURCE_DIR}/release/bin/blender-thumbnailer.py
403                         DESTINATION ${TARGETDIR}
404                 )
405
406                 install(
407                         FILES ${BLENDER_TEXT_FILES}
408                         DESTINATION ${TARGETDIR}
409                 )
410
411         else()
412                 # main blender binary
413                 if(WITH_PYTHON_MODULE)
414                         install(
415                                 TARGETS blender
416                                 LIBRARY
417                                 DESTINATION ${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages
418                         )
419                 else()
420                         install(
421                                 PROGRAMS ${TARGETDIR}/blender
422                                 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
423                         )
424                 endif()
425
426
427                 if(WITH_GAMEENGINE AND WITH_PLAYER)
428                         install(
429                                 PROGRAMS ${TARGETDIR}/blenderplayer
430                                 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
431                         )
432                 endif()
433
434                 # misc files
435                 install(
436                         FILES ${CMAKE_SOURCE_DIR}/release/freedesktop/blender.desktop
437                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications
438                 )
439                 install(
440                         DIRECTORY
441                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/16x16
442                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/22x22
443                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/24x24
444                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/32x32
445                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/48x48
446                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/256x256
447                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor
448                         PATTERN "*.svg" EXCLUDE
449                 )
450                 install(
451                         FILES ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/scalable/apps/blender.svg
452                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps
453                 )
454                 install(
455                         PROGRAMS ${CMAKE_SOURCE_DIR}/release/bin/blender-thumbnailer.py
456                         DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
457                 )
458                 install(
459                         FILES ${CMAKE_SOURCE_DIR}/doc/manpage/blender.1
460                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1
461                 )
462                 install(
463                         FILES ${BLENDER_TEXT_FILES}
464                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/blender
465                 )
466         endif()
467
468         if(WITH_PYTHON)
469                 if(WITH_PYTHON_INSTALL)
470                         # on some platforms (like openSUSE) Python is linked
471                         # to be used from lib64 folder.
472                         # determine this from Python's libraries path
473                         #
474                         # ugh, its possible 'lib64' is just a symlink to 'lib' which causes incorrect use of 'lib64'
475                         get_filename_component(_pypath_real ${PYTHON_LIBPATH} REALPATH)
476                         if(${_pypath_real} MATCHES "lib64$")
477                                 set(_target_LIB "lib64")
478                         else()
479                                 set(_target_LIB "lib")
480                         endif()
481                         unset(_pypath_real)
482
483                         # Copy the systems python into the install directory
484                         # Scons copy in tools/Blender.py
485                         # install(CODE "message(\"copying a subset of the systems python...\")")
486                         install(
487                                 DIRECTORY ${PYTHON_LIBPATH}/python${PYTHON_VERSION}
488                                 DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}
489                                 PATTERN ".svn" EXCLUDE
490                                 PATTERN "__pycache__" EXCLUDE               # * any cache *
491                                 PATTERN "distutils" EXCLUDE                 # ./distutils
492                                 PATTERN "lib2to3" EXCLUDE                   # ./lib2to3
493                                 PATTERN "config" EXCLUDE                    # ./config
494                                 PATTERN "config-*" EXCLUDE                  # ./config-*
495                                 PATTERN "site-packages/*" EXCLUDE           # ./site-packages/*
496                                 PATTERN "tkinter" EXCLUDE                   # ./tkinter
497                                 PATTERN "lib-dynload/_tkinter.*" EXCLUDE    # ./lib-dynload/_tkinter.co
498                                 PATTERN "idlelib" EXCLUDE                   # ./idlelib
499                                 PATTERN "test" EXCLUDE                      # ./test
500                                 PATTERN "turtledemo" EXCLUDE                # ./turtledemo
501                                 PATTERN "turtle.py" EXCLUDE                                     # ./turtle.py
502                         )
503
504                         # # doesnt work, todo
505                         # install(CODE "execute_process(COMMAND find ${TARGETDIR}/${BLENDER_VERSION}/python/lib/ -name '*.so' -exec strip -s {} '\;')")
506                         
507                         if(WITH_PYTHON_INSTALL_NUMPY)
508                                 install(
509                                         DIRECTORY ${PYTHON_NUMPY_PATH}/numpy
510                                         DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}/python${PYTHON_VERSION}/site-packages
511                                         PATTERN ".svn" EXCLUDE
512                                         PATTERN "__pycache__" EXCLUDE           # * any cache *
513                                         PATTERN "*.pyc" EXCLUDE                 # * any cache *
514                                         PATTERN "*.pyo" EXCLUDE                 # * any cache *
515                                         PATTERN "distutils" EXCLUDE             # ./distutils
516                                         PATTERN "oldnumeric" EXCLUDE            # ./oldnumeric
517                                         PATTERN "doc" EXCLUDE                   # ./doc
518                                         PATTERN "tests" EXCLUDE                 # ./tests
519                                         PATTERN "f2py" EXCLUDE                  # ./f2py - fortran/python interface code, not fun for blender devs.
520                                         PATTERN "include" EXCLUDE               # include dirs all over, we wont use NumPy/CAPI
521                                         PATTERN "*.h" EXCLUDE                   # some includes are not in include dirs
522                                         PATTERN "*.a" EXCLUDE                   # ./core/lib/libnpymath.a - for linking, we dont need.
523                                 )
524                         endif()
525                         
526                         unset(_target_LIB)
527                         
528                 endif()
529         endif()
530 elseif(WIN32)
531
532         install(
533                 FILES ${BLENDER_TEXT_FILES}
534                 DESTINATION ${TARGETDIR}
535         )
536
537         if(WITH_PYTHON)
538                 string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
539
540                 install(
541                         FILES ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}.dll
542                         DESTINATION ${TARGETDIR}
543                         CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel
544                 )
545
546                 install(
547                         FILES ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}_d.dll
548                         DESTINATION ${TARGETDIR}
549                         CONFIGURATIONS Debug
550                 )
551
552                 if(WITH_PYTHON_INSTALL)
553                         # note, as far as python is concerned 'RelWithDebInfo' is not debug since its without debug flags.
554
555                         # create the directory in multiple steps, so it actually gets created when it doesn't exist yet
556                         install(
557                                 CODE
558                                 "
559                                 message(\"creating ${TARGETDIR_VER}/python/lib\")
560                                 file(MAKE_DIRECTORY \"${TARGETDIR_VER}/python\")
561                                 file(MAKE_DIRECTORY \"${TARGETDIR_VER}/python/lib\")
562                                 message(\"done creating dir\")
563                                 "
564                         )
565
566                         install(
567                                 CODE
568                                 "
569                                 if(\"\${CMAKE_INSTALL_CONFIG_NAME}\" STREQUAL \"Debug\")
570                                         execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir \"${TARGETDIR_VER}/python/lib\"
571                                                 \"${CMAKE_COMMAND}\" -E tar xzfv \"${LIBDIR}/release/python${_PYTHON_VERSION_NO_DOTS}_d.tar.gz\")
572                                 else()
573                                         execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir \"${TARGETDIR_VER}/python/lib\"
574                                                 \"${CMAKE_COMMAND}\" -E tar xzfv \"${LIBDIR}/release/python${_PYTHON_VERSION_NO_DOTS}.tar.gz\")
575                                 endif()
576                                 "
577                         )
578
579                         if(WITH_PYTHON_INSTALL_NUMPY)
580                                 install(
581                                         CODE
582                                         "
583                                         execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir \"${TARGETDIR_VER}/python/lib/site-packages\"
584                                                 \"${CMAKE_COMMAND}\" -E tar xzfv \"${LIBDIR}/release/python${_PYTHON_VERSION_NO_DOTS}_numpy_1.8.tar.gz\")
585                                         "
586                                 )
587                         endif()
588
589                         # doesnt work, todo
590                         # install(CODE "execute_process(COMMAND find ${TARGETDIR}/${BLENDER_VERSION}/python/lib/ -name '*.so' -exec strip -s {} '\;')")
591                 endif()
592
593                 unset(_PYTHON_VERSION_NO_DOTS)
594         endif()
595
596         if(MSVC)
597                 install(
598                         FILES ${LIBDIR}/pthreads/lib/pthreadVC2.dll
599                         DESTINATION ${TARGETDIR}
600                 )
601         else()
602                 #MinGW64 comes with own version. For portable builds it will probaly have to be copied to work
603                 if(NOT WITH_MINGW64)
604                         install(
605                                 FILES ${LIBDIR}/pthreads/lib/pthreadGC2.dll
606                                 DESTINATION ${TARGETDIR}
607                         )
608                 elseif(WITH_MINGW64)
609                         install(
610                                 FILES 
611                                         ${LIBDIR}/binaries/libgcc_s_sjlj-1.dll
612                                         ${LIBDIR}/binaries/libwinpthread-1.dll
613                                         ${LIBDIR}/binaries/libstdc++-6.dll
614                                 DESTINATION ${TARGETDIR}
615                         )
616                         
617                         if(WITH_OPENMP)
618                                 install(
619                                         FILES 
620                                         ${LIBDIR}/binaries/libgomp-1.dll
621                                         DESTINATION ${TARGETDIR}
622                                 )
623                         endif()
624                 endif()
625         endif()
626
627         if(WITH_CODEC_FFMPEG)
628                 if(MSVC11)
629                         install(
630                                 FILES
631                                         ${LIBDIR}/ffmpeg/lib/avcodec-54.dll
632                                         ${LIBDIR}/ffmpeg/lib/avformat-54.dll
633                                         ${LIBDIR}/ffmpeg/lib/avdevice-54.dll
634                                         ${LIBDIR}/ffmpeg/lib/avutil-52.dll
635                                         ${LIBDIR}/ffmpeg/lib/avfilter-3.dll
636                                         ${LIBDIR}/ffmpeg/lib/swresample-0.dll
637                                         ${LIBDIR}/ffmpeg/lib/swscale-2.dll
638                                 DESTINATION ${TARGETDIR}
639                         )
640                 else()
641                         install(
642                                 FILES
643                                         ${LIBDIR}/ffmpeg/lib/avcodec-53.dll
644                                         ${LIBDIR}/ffmpeg/lib/avformat-53.dll
645                                         ${LIBDIR}/ffmpeg/lib/avdevice-53.dll
646                                         ${LIBDIR}/ffmpeg/lib/avutil-51.dll
647                                         ${LIBDIR}/ffmpeg/lib/swscale-2.dll
648                                 DESTINATION ${TARGETDIR}
649                         )
650                 endif()
651                 if(WITH_MINGW64)
652                 install(
653                         FILES
654                                 ${LIBDIR}/ffmpeg/lib/swresample-0.dll
655                                 ${LIBDIR}/ffmpeg/lib/xvidcore.dll
656                         DESTINATION ${TARGETDIR}
657                 )
658                 endif()
659         endif()
660
661         if(WITH_CODEC_SNDFILE)
662                 install(
663                         FILES ${LIBDIR}/sndfile/lib/libsndfile-1.dll
664                         DESTINATION ${TARGETDIR}
665                 )
666         endif()
667
668         if(WITH_OPENAL)
669                 if(MSVC11)
670                         install(
671                                 FILES
672                                         ${LIBDIR}/openal/lib/OpenAL32.dll
673                                 DESTINATION ${TARGETDIR}
674                         )
675                 else()
676                         install(
677                                 FILES
678                                         ${LIBDIR}/openal/lib/OpenAL32.dll
679                                         ${LIBDIR}/openal/lib/wrap_oal.dll
680                                 DESTINATION ${TARGETDIR}
681                         )
682                 endif()
683         endif()
684
685 #       if(WITH_JACK AND MSVC11)
686 #               if(CMAKE_CL_64)
687 #                       install(
688 #                               FILES
689 #                                       ${LIBDIR}/jack/lib/libjack64.dll
690 #                               DESTINATION ${TARGETDIR}
691 #                       )
692 #               else()
693 #                       install(
694 #                               FILES
695 #                                       ${LIBDIR}/jack/lib/libjack.dll
696 #                               DESTINATION ${TARGETDIR}
697 #                       )
698 #               endif()
699 #       endif()
700
701         if(WITH_SDL)
702                 if(NOT CMAKE_CL_64)
703                         install(
704                                 FILES ${LIBDIR}/sdl/lib/SDL.dll
705                                 DESTINATION ${TARGETDIR}
706                         )
707                 endif()
708         endif()
709
710         if(NOT CMAKE_CL_64)
711                 install(
712                         FILES ${LIBDIR}/thumbhandler/lib/BlendThumb.dll
713                         DESTINATION ${TARGETDIR}
714                 )
715         endif()
716                 
717         install( # x86 builds can run on x64 Windows, so this is required at all times
718                 FILES ${LIBDIR}/thumbhandler/lib/BlendThumb64.dll
719                 DESTINATION ${TARGETDIR}
720         )
721
722         if(WITH_OPENCOLORIO)
723                 set(OCIOBIN ${LIBDIR}/opencolorio/bin)
724                 if(NOT MINGW)
725                         install(
726                                 FILES
727                                         ${OCIOBIN}/OpenColorIO.dll
728                                 DESTINATION ${TARGETDIR}
729                         )
730                 else()
731                         install(
732                                 FILES
733                                         ${OCIOBIN}/libOpenColorIO.dll
734                                 DESTINATION ${TARGETDIR}
735                         )
736                 endif()
737         endif()
738
739 elseif(APPLE)
740
741         # handy install macro to exclude files, we use \$ escape for the "to"
742         # argument when calling so ${BUILD_TYPE} does not get expanded
743         macro(install_dir from to)
744                 install(
745                         DIRECTORY ${from}
746                         DESTINATION ${to}
747                         PATTERN ".git" EXCLUDE
748                         PATTERN ".svn" EXCLUDE
749                         PATTERN "*.pyc" EXCLUDE
750                         PATTERN "*.pyo" EXCLUDE
751                         PATTERN "*.orig" EXCLUDE
752                         PATTERN "*.rej" EXCLUDE
753                         PATTERN "__pycache__" EXCLUDE
754                         PATTERN "__MACOSX" EXCLUDE
755                         PATTERN ".DS_Store" EXCLUDE
756                 )
757         endmacro()
758
759         set(OSX_APP_SOURCEDIR ${CMAKE_SOURCE_DIR}/release/darwin/blender.app)
760
761         # setup Info.plist
762         execute_process(COMMAND date "+%Y-%m-%d" OUTPUT_VARIABLE BLENDER_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
763
764         set_target_properties(blender PROPERTIES
765                 MACOSX_BUNDLE_INFO_PLIST ${OSX_APP_SOURCEDIR}/Contents/Info.plist
766                 MACOSX_BUNDLE_SHORT_VERSION_STRING ${BLENDER_VERSION}
767                 MACOSX_BUNDLE_LONG_VERSION_STRING "${BLENDER_VERSION} ${BLENDER_DATE}")
768
769
770         # install release and app files
771         install(
772                 FILES ${BLENDER_TEXT_FILES}
773                 DESTINATION ${TARGETDIR}
774         )
775
776         install(
777                 FILES ${OSX_APP_SOURCEDIR}/Contents/PkgInfo
778                 DESTINATION ${TARGETDIR}/blender.app/Contents
779         )
780
781         install_dir(
782                 ${OSX_APP_SOURCEDIR}/Contents/Resources
783                 \${TARGETDIR}/blender.app/Contents/
784         )
785
786         if(WITH_OPENMP AND CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS '3.4')
787                 install(
788                         FILES ${LIBDIR}/openmp/lib/libiomp5.dylib
789                         DESTINATION ${TARGETDIR}/blender.app/Contents/MacOS
790                 )
791         endif()
792
793         # python
794         if(WITH_PYTHON AND NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
795                 # the python zip is first extract as part of the build process,
796                 # and then later installed as part of make install. this is much
797                 # quicker, and means we can easily exclude files on copy
798                 # Not needed for PYTHON_MODULE or WEB_PLUGIN due uses  Pyhon framework
799                 add_custom_target(
800                         extractpyzip
801                         DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python)
802
803                 set(PYTHON_ZIP "python_${CMAKE_OSX_ARCHITECTURES}.zip")
804
805                 add_custom_command(
806                         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python
807                         COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/python/
808                         COMMAND mkdir ${CMAKE_CURRENT_BINARY_DIR}/python/
809                         COMMAND unzip -q ${LIBDIR}/release/${PYTHON_ZIP} -d ${CMAKE_CURRENT_BINARY_DIR}/python/
810                         DEPENDS ${LIBDIR}/release/${PYTHON_ZIP})
811
812                 add_dependencies(blender extractpyzip)
813
814                 # copy extracted python files
815                 install_dir(
816                         ${CMAKE_CURRENT_BINARY_DIR}/python
817                         \${TARGETDIR_VER}
818                 )
819
820         endif()
821         
822         # install blenderplayer bundle - copy of blender.app above. re-using macros et al
823         # note we are using OSX Bundle as base and copying Blender dummy bundle on top of it
824         if(WITH_GAMEENGINE AND WITH_PLAYER)
825                 set(OSX_APP_PLAYER_SOURCEDIR ${CMAKE_SOURCE_DIR}/release/darwin/blenderplayer.app)
826                 set(PLAYER_SOURCEINFO ${OSX_APP_PLAYER_SOURCEDIR}/Contents/Info.plist)
827                 set(PLAYER_TARGETDIR_VER ${TARGETDIR}/blenderplayer.app/Contents/MacOS/${BLENDER_VERSION})
828
829
830                 # important to make a clean  install each time else old scripts get loaded.
831                 install(
832                         CODE
833                         "file(REMOVE_RECURSE ${PLAYER_TARGETDIR_VER})"
834                 )
835
836                 install(
837                         FILES ${OSX_APP_PLAYER_SOURCEDIR}/Contents/PkgInfo
838                         DESTINATION ${TARGETDIR}/blenderplayer.app/Contents
839                 )
840
841                 install_dir(
842                         ${OSX_APP_PLAYER_SOURCEDIR}/Contents/Resources
843                         \${TARGETDIR}/blenderplayer.app/Contents/
844                 )
845
846                 # python
847                 if(WITH_PYTHON AND NOT WITH_PYTHON_FRAMEWORK)
848                         add_custom_command(
849                                 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python
850                                 COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/python/
851                                 COMMAND mkdir ${CMAKE_CURRENT_BINARY_DIR}/python/
852                                 COMMAND unzip -q ${LIBDIR}/release/${PYTHON_ZIP} -d ${CMAKE_CURRENT_BINARY_DIR}/python/
853                                 DEPENDS ${LIBDIR}/release/${PYTHON_ZIP})
854
855                         # copy extracted python files
856                         install_dir(
857                                 ${CMAKE_CURRENT_BINARY_DIR}/python
858                                 \${PLAYER_TARGETDIR_VER}
859                         )
860                 endif()
861
862         endif()
863
864 endif()
865
866 # -----------------------------------------------------------------------------
867 # Generic Install, for all targets
868
869
870
871 # install more files specified elsewhere
872 delayed_do_install(${TARGETDIR_VER})
873
874 unset(BLENDER_TEXT_FILES)
875
876
877 # -----------------------------------------------------------------------------
878 # Setup link libs
879
880 add_dependencies(blender makesdna)
881
882 get_property(BLENDER_LINK_LIBS GLOBAL PROPERTY BLENDER_LINK_LIBS)
883
884 list(APPEND BLENDER_LINK_LIBS
885         bf_windowmanager
886         bf_render
887 )
888
889 if(WITH_MOD_FLUID)
890         list(APPEND BLENDER_LINK_LIBS bf_intern_elbeem)
891 endif()
892
893 if(WITH_CYCLES)
894         list(APPEND BLENDER_LINK_LIBS
895                 cycles_render
896                 cycles_bvh
897                 cycles_device
898                 cycles_kernel
899                 cycles_util
900                 cycles_subd)
901         if(WITH_CYCLES_OSL)
902                 list(APPEND BLENDER_LINK_LIBS cycles_kernel_osl)
903         endif()
904 endif()
905
906 #if(UNIX)
907         # Sort libraries
908         set(BLENDER_SORTED_LIBS
909                 bf_windowmanager
910
911                 bf_editor_space_api
912                 bf_editor_space_action
913                 bf_editor_space_buttons
914                 bf_editor_space_console
915                 bf_editor_space_file
916                 bf_editor_space_graph
917                 bf_editor_space_image
918                 bf_editor_space_info
919                 bf_editor_space_logic
920                 bf_editor_space_nla
921                 bf_editor_space_node
922                 bf_editor_space_outliner
923                 bf_editor_space_script
924                 bf_editor_space_sequencer
925                 bf_editor_space_time
926                 bf_editor_space_userpref
927                 bf_editor_space_view3d
928                 bf_editor_space_clip
929
930                 bf_editor_text
931                 bf_editor_transform
932                 bf_editor_util
933                 bf_editor_uvedit
934                 bf_editor_curve
935                 bf_editor_gpencil
936                 bf_editor_interface
937                 bf_editor_mesh
938                 bf_editor_metaball
939                 bf_editor_object
940                 bf_editor_armature
941                 bf_editor_physics
942                 bf_editor_render
943                 bf_editor_screen
944                 bf_editor_sculpt_paint
945                 bf_editor_sound
946                 bf_editor_animation
947                 bf_editor_datafiles
948                 bf_editor_mask
949                 bf_editor_io
950
951                 bf_render
952                 bf_python
953                 bf_python_ext
954                 bf_python_mathutils
955                 bf_python_bmesh
956                 bf_freestyle
957                 bf_ikplugin
958                 bf_modifiers
959                 bf_bmesh
960                 bf_blenkernel
961                 bf_nodes
962                 bf_gpu
963                 bf_blenloader
964                 bf_imbuf
965                 bf_blenlib
966                 bf_intern_ghost
967                 bf_intern_string
968                 bf_avi
969                 bf_imbuf_cineon
970                 bf_imbuf_openexr
971                 bf_imbuf_openimageio
972                 bf_imbuf_dds
973                 bf_collada
974                 bf_intern_elbeem
975                 bf_intern_memutil
976                 bf_intern_guardedalloc
977                 bf_intern_ctr
978                 bf_intern_utfconv
979                 ge_blen_routines
980                 ge_converter
981                 ge_phys_dummy
982                 ge_phys_bullet
983                 bf_intern_smoke
984                 extern_minilzo
985                 extern_lzma
986                 extern_colamd
987                 ge_logic_ketsji
988                 extern_recastnavigation
989                 ge_logic
990                 ge_rasterizer
991                 ge_oglrasterizer
992                 ge_logic_expressions
993                 ge_scenegraph
994                 ge_logic_network
995                 ge_logic_ngnetwork
996                 ge_logic_loopbacknetwork
997                 bf_intern_moto
998                 extern_openjpeg
999                 extern_redcode
1000                 ge_videotex
1001                 bf_rna
1002                 bf_dna
1003                 bf_blenfont
1004                 bf_intern_audaspace
1005                 bf_intern_mikktspace
1006                 bf_intern_dualcon
1007                 bf_intern_cycles
1008                 cycles_render
1009                 cycles_bvh
1010                 cycles_device
1011                 cycles_kernel
1012                 cycles_util
1013                 cycles_subd
1014                 bf_intern_raskter
1015                 bf_intern_opencolorio
1016                 extern_rangetree
1017                 extern_wcwidth
1018                 extern_libmv
1019         )
1020
1021         if(WITH_COMPOSITOR)
1022                 # added for opencl compositor
1023                 list_insert_before(BLENDER_SORTED_LIBS "bf_blenkernel" "bf_compositor")
1024                 list_insert_after(BLENDER_SORTED_LIBS "bf_compositor" "bf_intern_opencl")
1025         endif()
1026
1027         if(WITH_LIBMV)
1028                 list(APPEND BLENDER_SORTED_LIBS extern_ceres)
1029         endif()
1030
1031         if(WITH_MOD_CLOTH_ELTOPO)
1032                 list(APPEND BLENDER_SORTED_LIBS extern_eltopo)
1033         endif()
1034
1035         if(NOT WITH_SYSTEM_GLEW)
1036                 list(APPEND BLENDER_SORTED_LIBS extern_glew)
1037         endif()
1038
1039         if(WITH_BINRELOC)
1040                 list(APPEND BLENDER_SORTED_LIBS extern_binreloc)
1041         endif()
1042
1043         if(WITH_CXX_GUARDEDALLOC)
1044                 list(APPEND BLENDER_SORTED_LIBS bf_intern_guardedalloc_cpp)
1045         endif()
1046
1047         if(WITH_IK_SOLVER)
1048                 list_insert_after(BLENDER_SORTED_LIBS "bf_intern_elbeem" "bf_intern_iksolver")
1049         endif()
1050
1051         if(WITH_IK_ITASC)
1052                 list(APPEND BLENDER_SORTED_LIBS bf_intern_itasc)
1053         endif()
1054
1055         if(WITH_CODEC_QUICKTIME)
1056                 list(APPEND BLENDER_SORTED_LIBS bf_quicktime)
1057         endif()
1058
1059         if(WITH_INPUT_NDOF)
1060                 list(APPEND BLENDER_SORTED_LIBS bf_intern_ghostndof3dconnexion)
1061         endif()
1062         
1063         if(WITH_MOD_BOOLEAN)
1064                 list(APPEND BLENDER_SORTED_LIBS extern_carve)
1065         endif()
1066
1067         if(WITH_GHOST_XDND)
1068                 list(APPEND BLENDER_SORTED_LIBS extern_xdnd)
1069         endif()
1070
1071         if(WITH_CYCLES_OSL)
1072                 list_insert_after(BLENDER_SORTED_LIBS "cycles_kernel" "cycles_kernel_osl")
1073         endif()
1074
1075         if(WITH_INTERNATIONAL)
1076                 list(APPEND BLENDER_SORTED_LIBS bf_intern_locale)
1077         endif()
1078
1079         if(WITH_OPENNL)
1080                 list_insert_after(BLENDER_SORTED_LIBS "bf_render" "bf_intern_opennl")
1081         endif()
1082
1083         if(WITH_BULLET)
1084                 list_insert_after(BLENDER_SORTED_LIBS "bf_blenkernel" "bf_intern_rigidbody")
1085         endif()
1086
1087         if(WITH_BULLET AND NOT WITH_SYSTEM_BULLET)
1088                 list_insert_after(BLENDER_SORTED_LIBS "ge_logic_ngnetwork" "extern_bullet")
1089         endif()
1090
1091         foreach(SORTLIB ${BLENDER_SORTED_LIBS})
1092                 set(REMLIB ${SORTLIB})
1093                 foreach(SEARCHLIB ${BLENDER_LINK_LIBS})
1094                         if(${SEARCHLIB} STREQUAL ${SORTLIB})
1095                                 set(REMLIB "")
1096                         endif()
1097                 endforeach()
1098                 if(REMLIB)
1099                         # message(STATUS "Removing library ${REMLIB} from blender linking because: not configured")
1100                         list(APPEND REM_MSG ${REMLIB})
1101                         list(REMOVE_ITEM BLENDER_SORTED_LIBS ${REMLIB})
1102                 endif()
1103         endforeach()
1104         if(REM_MSG)
1105                 list(SORT REM_MSG)
1106                 message(STATUS "Blender Skipping: (${REM_MSG})")
1107         endif()
1108         target_link_libraries(blender ${BLENDER_SORTED_LIBS})
1109
1110         unset(SEARCHLIB)
1111         unset(SORTLIB)
1112         unset(REMLIB)
1113         unset(REM_MSG)
1114
1115 #else()
1116 #       target_link_libraries(blender ${BLENDER_LINK_LIBS})
1117 #endif()
1118
1119 setup_liblinks(blender)