Automatically generate blender.1 man page during build process
[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         install(
391                 CODE
392                 "
393                 execute_process(COMMAND
394                                 ${CMAKE_SOURCE_DIR}/doc/manpage/blender.1.py
395                                 ${TARGETDIR}/blender
396                                 ${TARGETDIR}/blender.1)
397                 "
398         )
399
400         # there are a few differences between portable and system install
401         if(WITH_INSTALL_PORTABLE)
402                 install(
403                         FILES
404                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/blender.desktop
405                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/scalable/apps/blender.svg
406                         DESTINATION ${TARGETDIR}
407                 )
408
409                 install(
410                         PROGRAMS
411                         ${CMAKE_SOURCE_DIR}/release/bin/blender-thumbnailer.py
412                         DESTINATION ${TARGETDIR}
413                 )
414
415                 install(
416                         FILES ${BLENDER_TEXT_FILES}
417                         DESTINATION ${TARGETDIR}
418                 )
419
420         else()
421                 # main blender binary
422                 if(WITH_PYTHON_MODULE)
423                         install(
424                                 TARGETS blender
425                                 LIBRARY
426                                 DESTINATION ${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages
427                         )
428                 else()
429                         install(
430                                 PROGRAMS ${TARGETDIR}/blender
431                                 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
432                         )
433                 endif()
434
435
436                 if(WITH_GAMEENGINE AND WITH_PLAYER)
437                         install(
438                                 PROGRAMS ${TARGETDIR}/blenderplayer
439                                 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
440                         )
441                 endif()
442
443                 # misc files
444                 install(
445                         FILES ${CMAKE_SOURCE_DIR}/release/freedesktop/blender.desktop
446                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications
447                 )
448                 install(
449                         DIRECTORY
450                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/16x16
451                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/22x22
452                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/24x24
453                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/32x32
454                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/48x48
455                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/256x256
456                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor
457                         PATTERN "*.svg" EXCLUDE
458                 )
459                 install(
460                         FILES ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/scalable/apps/blender.svg
461                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps
462                 )
463                 install(
464                         PROGRAMS ${CMAKE_SOURCE_DIR}/release/bin/blender-thumbnailer.py
465                         DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
466                 )
467                 install(
468                         FILES ${TARGETDIR}/blender.1
469                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1
470                 )
471                 install(
472                         FILES ${BLENDER_TEXT_FILES}
473                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/blender
474                 )
475         endif()
476
477         if(WITH_PYTHON)
478                 if(WITH_PYTHON_INSTALL)
479                         # on some platforms (like openSUSE) Python is linked
480                         # to be used from lib64 folder.
481                         # determine this from Python's libraries path
482                         #
483                         # ugh, its possible 'lib64' is just a symlink to 'lib' which causes incorrect use of 'lib64'
484                         get_filename_component(_pypath_real ${PYTHON_LIBPATH} REALPATH)
485                         if(${_pypath_real} MATCHES "lib64$")
486                                 set(_target_LIB "lib64")
487                         else()
488                                 set(_target_LIB "lib")
489                         endif()
490                         unset(_pypath_real)
491
492                         # Copy the systems python into the install directory
493                         # Scons copy in tools/Blender.py
494                         # install(CODE "message(\"copying a subset of the systems python...\")")
495                         install(
496                                 DIRECTORY ${PYTHON_LIBPATH}/python${PYTHON_VERSION}
497                                 DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}
498                                 PATTERN ".svn" EXCLUDE
499                                 PATTERN "__pycache__" EXCLUDE               # * any cache *
500                                 PATTERN "distutils" EXCLUDE                 # ./distutils
501                                 PATTERN "lib2to3" EXCLUDE                   # ./lib2to3
502                                 PATTERN "config" EXCLUDE                    # ./config
503                                 PATTERN "config-*" EXCLUDE                  # ./config-*
504                                 PATTERN "site-packages/*" EXCLUDE           # ./site-packages/*
505                                 PATTERN "tkinter" EXCLUDE                   # ./tkinter
506                                 PATTERN "lib-dynload/_tkinter.*" EXCLUDE    # ./lib-dynload/_tkinter.co
507                                 PATTERN "idlelib" EXCLUDE                   # ./idlelib
508                                 PATTERN "test" EXCLUDE                      # ./test
509                                 PATTERN "turtledemo" EXCLUDE                # ./turtledemo
510                                 PATTERN "turtle.py" EXCLUDE                                     # ./turtle.py
511                         )
512
513                         # # doesnt work, todo
514                         # install(CODE "execute_process(COMMAND find ${TARGETDIR}/${BLENDER_VERSION}/python/lib/ -name '*.so' -exec strip -s {} '\;')")
515                         
516                         if(WITH_PYTHON_INSTALL_NUMPY)
517                                 install(
518                                         DIRECTORY ${PYTHON_NUMPY_PATH}/numpy
519                                         DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}/python${PYTHON_VERSION}/site-packages
520                                         PATTERN ".svn" EXCLUDE
521                                         PATTERN "__pycache__" EXCLUDE           # * any cache *
522                                         PATTERN "*.pyc" EXCLUDE                 # * any cache *
523                                         PATTERN "*.pyo" EXCLUDE                 # * any cache *
524                                         PATTERN "distutils" EXCLUDE             # ./distutils
525                                         PATTERN "oldnumeric" EXCLUDE            # ./oldnumeric
526                                         PATTERN "doc" EXCLUDE                   # ./doc
527                                         PATTERN "tests" EXCLUDE                 # ./tests
528                                         PATTERN "f2py" EXCLUDE                  # ./f2py - fortran/python interface code, not fun for blender devs.
529                                         PATTERN "include" EXCLUDE               # include dirs all over, we wont use NumPy/CAPI
530                                         PATTERN "*.h" EXCLUDE                   # some includes are not in include dirs
531                                         PATTERN "*.a" EXCLUDE                   # ./core/lib/libnpymath.a - for linking, we dont need.
532                                 )
533                         endif()
534
535                         # Copy requests, we need to generalize site-packages
536                         if(WITH_PYTHON_INSTALL_REQUESTS)
537                                 install(
538                                         DIRECTORY ${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/requests
539                                         DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}/python${PYTHON_VERSION}/site-packages
540                                         PATTERN ".svn" EXCLUDE
541                                         PATTERN "__pycache__" EXCLUDE           # * any cache *
542                                         PATTERN "*.pyc" EXCLUDE                 # * any cache *
543                                         PATTERN "*.pyo" EXCLUDE                 # * any cache *
544                                         PATTERN "cacert.pem" EXCLUDE            # for now we don't deal with security
545                                 )
546                         endif()
547                         unset(_target_LIB)
548                         
549                 endif()
550         endif()
551 elseif(WIN32)
552
553         install(
554                 FILES ${BLENDER_TEXT_FILES}
555                 DESTINATION ${TARGETDIR}
556         )
557
558         if(WITH_PYTHON)
559                 string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
560
561                 install(
562                         FILES ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}.dll
563                         DESTINATION ${TARGETDIR}
564                         CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel
565                 )
566
567                 install(
568                         FILES ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}_d.dll
569                         DESTINATION ${TARGETDIR}
570                         CONFIGURATIONS Debug
571                 )
572
573                 if(WITH_PYTHON_INSTALL)
574                         # note, as far as python is concerned 'RelWithDebInfo' is not debug since its without debug flags.
575
576                         # create the directory in multiple steps, so it actually gets created when it doesn't exist yet
577                         install(
578                                 CODE
579                                 "
580                                 message(\"creating ${TARGETDIR_VER}/python/lib\")
581                                 file(MAKE_DIRECTORY \"${TARGETDIR_VER}/python\")
582                                 file(MAKE_DIRECTORY \"${TARGETDIR_VER}/python/lib\")
583                                 message(\"done creating dir\")
584                                 "
585                         )
586
587                         install(
588                                 CODE
589                                 "
590                                 if(\"\${CMAKE_INSTALL_CONFIG_NAME}\" STREQUAL \"Debug\")
591                                         execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir \"${TARGETDIR_VER}/python/lib\"
592                                                 \"${CMAKE_COMMAND}\" -E tar xzfv \"${LIBDIR}/release/python${_PYTHON_VERSION_NO_DOTS}_d.tar.gz\")
593                                 else()
594                                         execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir \"${TARGETDIR_VER}/python/lib\"
595                                                 \"${CMAKE_COMMAND}\" -E tar xzfv \"${LIBDIR}/release/python${_PYTHON_VERSION_NO_DOTS}.tar.gz\")
596                                 endif()
597                                 "
598                         )
599
600                         if(WITH_PYTHON_INSTALL_NUMPY)
601                                 install(
602                                         CODE
603                                         "
604                                         execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir \"${TARGETDIR_VER}/python/lib/site-packages\"
605                                                 \"${CMAKE_COMMAND}\" -E tar xzfv \"${LIBDIR}/release/python${_PYTHON_VERSION_NO_DOTS}_numpy_1.8.tar.gz\")
606                                         "
607                                 )
608                         endif()
609
610                         # release/site-packages
611                         install(
612                                 CODE
613                                 "
614                                 execute_process(COMMAND \"${CMAKE_COMMAND}\" -E copy_directory
615                                         ${LIBDIR}/release/site-packages
616                                         \"${TARGETDIR_VER}/python/lib/site-packages\")
617                                 "
618                         )
619
620
621                         # doesnt work, todo
622                         # install(CODE "execute_process(COMMAND find ${TARGETDIR}/${BLENDER_VERSION}/python/lib/ -name '*.so' -exec strip -s {} '\;')")
623                 endif()
624
625                 unset(_PYTHON_VERSION_NO_DOTS)
626         endif()
627
628         if(MSVC)
629                 install(
630                         FILES ${LIBDIR}/pthreads/lib/pthreadVC2.dll
631                         DESTINATION ${TARGETDIR}
632                 )
633         else()
634                 #MinGW64 comes with own version. For portable builds it will probaly have to be copied to work
635                 if(NOT WITH_MINGW64)
636                         install(
637                                 FILES ${LIBDIR}/pthreads/lib/pthreadGC2.dll
638                                 DESTINATION ${TARGETDIR}
639                         )
640                 elseif(WITH_MINGW64)
641                         install(
642                                 FILES 
643                                         ${LIBDIR}/binaries/libgcc_s_sjlj-1.dll
644                                         ${LIBDIR}/binaries/libwinpthread-1.dll
645                                         ${LIBDIR}/binaries/libstdc++-6.dll
646                                 DESTINATION ${TARGETDIR}
647                         )
648                         
649                         if(WITH_OPENMP)
650                                 install(
651                                         FILES 
652                                         ${LIBDIR}/binaries/libgomp-1.dll
653                                         DESTINATION ${TARGETDIR}
654                                 )
655                         endif()
656                 endif()
657         endif()
658
659         if(WITH_CODEC_FFMPEG)
660                 if(WITH_MINGW64)
661                         install(
662                                 FILES
663                                         ${LIBDIR}/ffmpeg/lib/avcodec-53.dll
664                                         ${LIBDIR}/ffmpeg/lib/avformat-53.dll
665                                         ${LIBDIR}/ffmpeg/lib/avdevice-53.dll
666                                         ${LIBDIR}/ffmpeg/lib/avutil-51.dll
667                                         ${LIBDIR}/ffmpeg/lib/swscale-2.dll
668                                         ${LIBDIR}/ffmpeg/lib/swresample-0.dll
669                                         ${LIBDIR}/ffmpeg/lib/xvidcore.dll
670                                 DESTINATION ${TARGETDIR}
671                         )
672                 else()
673                         install(
674                                 FILES
675                                         ${LIBDIR}/ffmpeg/lib/avcodec-55.dll
676                                         ${LIBDIR}/ffmpeg/lib/avformat-55.dll
677                                         ${LIBDIR}/ffmpeg/lib/avdevice-55.dll
678                                         ${LIBDIR}/ffmpeg/lib/avutil-52.dll
679                                         ${LIBDIR}/ffmpeg/lib/swscale-2.dll
680                                 DESTINATION ${TARGETDIR}
681                         )
682                 endif()
683         endif()
684
685         if(WITH_CODEC_SNDFILE)
686                 install(
687                         FILES ${LIBDIR}/sndfile/lib/libsndfile-1.dll
688                         DESTINATION ${TARGETDIR}
689                 )
690         endif()
691
692         if(WITH_OPENAL)
693                 install(
694                         FILES
695                                 ${LIBDIR}/openal/lib/OpenAL32.dll
696                                 ${LIBDIR}/openal/lib/wrap_oal.dll
697                         DESTINATION ${TARGETDIR}
698                 )
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                 # copy site-packages files
820                 install_dir(
821                         ${LIBDIR}/release/site-packages
822                         ${CMAKE_CURRENT_BINARY_DIR}/python/lib/python${PYTHON_VERSION}/site-packages
823                 )
824
825         endif()
826         
827         # install blenderplayer bundle - copy of blender.app above. re-using macros et al
828         # note we are using OSX Bundle as base and copying Blender dummy bundle on top of it
829         if(WITH_GAMEENGINE AND WITH_PLAYER)
830                 set(OSX_APP_PLAYER_SOURCEDIR ${CMAKE_SOURCE_DIR}/release/darwin/blenderplayer.app)
831                 set(PLAYER_SOURCEINFO ${OSX_APP_PLAYER_SOURCEDIR}/Contents/Info.plist)
832                 set(PLAYER_TARGETDIR_VER ${TARGETDIR}/blenderplayer.app/Contents/MacOS/${BLENDER_VERSION})
833
834
835                 # important to make a clean  install each time else old scripts get loaded.
836                 install(
837                         CODE
838                         "file(REMOVE_RECURSE ${PLAYER_TARGETDIR_VER})"
839                 )
840
841                 install(
842                         FILES ${OSX_APP_PLAYER_SOURCEDIR}/Contents/PkgInfo
843                         DESTINATION ${TARGETDIR}/blenderplayer.app/Contents
844                 )
845
846                 install_dir(
847                         ${OSX_APP_PLAYER_SOURCEDIR}/Contents/Resources
848                         \${TARGETDIR}/blenderplayer.app/Contents/
849                 )
850
851                 # python
852                 if(WITH_PYTHON AND NOT WITH_PYTHON_FRAMEWORK)
853                         add_custom_command(
854                                 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python
855                                 COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/python/
856                                 COMMAND mkdir ${CMAKE_CURRENT_BINARY_DIR}/python/
857                                 COMMAND unzip -q ${LIBDIR}/release/${PYTHON_ZIP} -d ${CMAKE_CURRENT_BINARY_DIR}/python/
858                                 DEPENDS ${LIBDIR}/release/${PYTHON_ZIP})
859
860                         # copy extracted python files
861                         install_dir(
862                                 ${CMAKE_CURRENT_BINARY_DIR}/python
863                                 \${PLAYER_TARGETDIR_VER}
864                         )
865                 endif()
866
867         endif()
868
869 endif()
870
871 # -----------------------------------------------------------------------------
872 # Generic Install, for all targets
873
874
875
876 # install more files specified elsewhere
877 delayed_do_install(${TARGETDIR_VER})
878
879 unset(BLENDER_TEXT_FILES)
880
881
882 # -----------------------------------------------------------------------------
883 # Setup link libs
884
885 add_dependencies(blender makesdna)
886
887 get_property(BLENDER_LINK_LIBS GLOBAL PROPERTY BLENDER_LINK_LIBS)
888
889 list(APPEND BLENDER_LINK_LIBS
890         bf_windowmanager
891         bf_render
892 )
893
894 if(WITH_MOD_FLUID)
895         list(APPEND BLENDER_LINK_LIBS bf_intern_elbeem)
896 endif()
897
898 if(WITH_CYCLES)
899         list(APPEND BLENDER_LINK_LIBS
900                 cycles_render
901                 cycles_bvh
902                 cycles_device
903                 cycles_kernel
904                 cycles_util
905                 cycles_subd)
906         if(WITH_CYCLES_OSL)
907                 list(APPEND BLENDER_LINK_LIBS cycles_kernel_osl)
908         endif()
909 endif()
910
911 #if(UNIX)
912         # Sort libraries
913         set(BLENDER_SORTED_LIBS
914                 bf_windowmanager
915
916                 bf_editor_space_api
917                 bf_editor_space_action
918                 bf_editor_space_buttons
919                 bf_editor_space_console
920                 bf_editor_space_file
921                 bf_editor_space_graph
922                 bf_editor_space_image
923                 bf_editor_space_info
924                 bf_editor_space_logic
925                 bf_editor_space_nla
926                 bf_editor_space_node
927                 bf_editor_space_outliner
928                 bf_editor_space_script
929                 bf_editor_space_sequencer
930                 bf_editor_space_text
931                 bf_editor_space_time
932                 bf_editor_space_userpref
933                 bf_editor_space_view3d
934                 bf_editor_space_clip
935
936                 bf_editor_transform
937                 bf_editor_util
938                 bf_editor_uvedit
939                 bf_editor_curve
940                 bf_editor_gpencil
941                 bf_editor_interface
942                 bf_editor_mesh
943                 bf_editor_metaball
944                 bf_editor_object
945                 bf_editor_armature
946                 bf_editor_physics
947                 bf_editor_render
948                 bf_editor_screen
949                 bf_editor_sculpt_paint
950                 bf_editor_sound
951                 bf_editor_animation
952                 bf_editor_datafiles
953                 bf_editor_mask
954                 bf_editor_io
955
956                 bf_render
957                 bf_python
958                 bf_python_ext
959                 bf_python_mathutils
960                 bf_python_bmesh
961                 bf_freestyle
962                 bf_ikplugin
963                 bf_modifiers
964                 bf_bmesh
965                 bf_blenkernel
966                 bf_nodes
967                 bf_gpu
968                 bf_blenloader
969                 bf_imbuf
970                 bf_blenlib
971                 bf_intern_ghost
972                 bf_intern_string
973                 bf_avi
974                 bf_imbuf_cineon
975                 bf_imbuf_openexr
976                 bf_imbuf_openimageio
977                 bf_imbuf_dds
978                 bf_collada
979                 bf_intern_elbeem
980                 bf_intern_memutil
981                 bf_intern_guardedalloc
982                 bf_intern_ctr
983                 bf_intern_utfconv
984                 ge_blen_routines
985                 ge_converter
986                 ge_phys_dummy
987                 ge_phys_bullet
988                 bf_intern_smoke
989                 extern_minilzo
990                 extern_lzma
991                 extern_colamd
992                 ge_logic_ketsji
993                 extern_recastnavigation
994                 ge_logic
995                 ge_rasterizer
996                 ge_oglrasterizer
997                 ge_logic_expressions
998                 ge_scenegraph
999                 ge_logic_network
1000                 ge_logic_ngnetwork
1001                 ge_logic_loopbacknetwork
1002                 bf_intern_moto
1003                 extern_openjpeg
1004                 extern_redcode
1005                 ge_videotex
1006                 bf_rna
1007                 bf_dna
1008                 bf_blenfont
1009                 bf_intern_audaspace
1010                 bf_intern_mikktspace
1011                 bf_intern_dualcon
1012                 bf_intern_cycles
1013                 cycles_render
1014                 cycles_bvh
1015                 cycles_device
1016                 cycles_kernel
1017                 cycles_util
1018                 cycles_subd
1019                 bf_intern_raskter
1020                 bf_intern_opencolorio
1021                 extern_rangetree
1022                 extern_wcwidth
1023                 extern_libmv
1024         )
1025
1026         if(WITH_COMPOSITOR)
1027                 # added for opencl compositor
1028                 list_insert_before(BLENDER_SORTED_LIBS "bf_blenkernel" "bf_compositor")
1029                 list_insert_after(BLENDER_SORTED_LIBS "bf_compositor" "bf_intern_opencl")
1030         endif()
1031
1032         if(WITH_LIBMV)
1033                 list(APPEND BLENDER_SORTED_LIBS extern_ceres)
1034         endif()
1035
1036         if(WITH_MOD_CLOTH_ELTOPO)
1037                 list(APPEND BLENDER_SORTED_LIBS extern_eltopo)
1038         endif()
1039
1040         if(NOT WITH_SYSTEM_GLEW)
1041                 list(APPEND BLENDER_SORTED_LIBS extern_glew)
1042         endif()
1043
1044         if(WITH_BINRELOC)
1045                 list(APPEND BLENDER_SORTED_LIBS extern_binreloc)
1046         endif()
1047
1048         if(WITH_CXX_GUARDEDALLOC)
1049                 list(APPEND BLENDER_SORTED_LIBS bf_intern_guardedalloc_cpp)
1050         endif()
1051
1052         if(WITH_IK_SOLVER)
1053                 list_insert_after(BLENDER_SORTED_LIBS "bf_intern_elbeem" "bf_intern_iksolver")
1054         endif()
1055
1056         if(WITH_IK_ITASC)
1057                 list(APPEND BLENDER_SORTED_LIBS bf_intern_itasc)
1058         endif()
1059
1060         if(WITH_CODEC_QUICKTIME)
1061                 list(APPEND BLENDER_SORTED_LIBS bf_quicktime)
1062         endif()
1063
1064         if(WITH_INPUT_NDOF)
1065                 list(APPEND BLENDER_SORTED_LIBS bf_intern_ghostndof3dconnexion)
1066         endif()
1067         
1068         if(WITH_MOD_BOOLEAN)
1069                 list(APPEND BLENDER_SORTED_LIBS extern_carve)
1070         endif()
1071
1072         if(WITH_GHOST_XDND)
1073                 list(APPEND BLENDER_SORTED_LIBS extern_xdnd)
1074         endif()
1075
1076         if(WITH_CYCLES_OSL)
1077                 list_insert_after(BLENDER_SORTED_LIBS "cycles_kernel" "cycles_kernel_osl")
1078         endif()
1079
1080         if(WITH_INTERNATIONAL)
1081                 list(APPEND BLENDER_SORTED_LIBS bf_intern_locale)
1082         endif()
1083
1084         if(WITH_OPENNL)
1085                 list_insert_after(BLENDER_SORTED_LIBS "bf_render" "bf_intern_opennl")
1086         endif()
1087
1088         if(WITH_BULLET)
1089                 list_insert_after(BLENDER_SORTED_LIBS "bf_blenkernel" "bf_intern_rigidbody")
1090         endif()
1091
1092         if(WITH_BULLET AND NOT WITH_SYSTEM_BULLET)
1093                 list_insert_after(BLENDER_SORTED_LIBS "ge_logic_ngnetwork" "extern_bullet")
1094         endif()
1095
1096         foreach(SORTLIB ${BLENDER_SORTED_LIBS})
1097                 set(REMLIB ${SORTLIB})
1098                 foreach(SEARCHLIB ${BLENDER_LINK_LIBS})
1099                         if(${SEARCHLIB} STREQUAL ${SORTLIB})
1100                                 set(REMLIB "")
1101                         endif()
1102                 endforeach()
1103                 if(REMLIB)
1104                         # message(STATUS "Removing library ${REMLIB} from blender linking because: not configured")
1105                         list(APPEND REM_MSG ${REMLIB})
1106                         list(REMOVE_ITEM BLENDER_SORTED_LIBS ${REMLIB})
1107                 endif()
1108         endforeach()
1109         if(REM_MSG)
1110                 list(SORT REM_MSG)
1111                 message(STATUS "Blender Skipping: (${REM_MSG})")
1112         endif()
1113         target_link_libraries(blender ${BLENDER_SORTED_LIBS})
1114
1115         unset(SEARCHLIB)
1116         unset(SORTLIB)
1117         unset(REMLIB)
1118         unset(REM_MSG)
1119
1120 #else()
1121 #       target_link_libraries(blender ${BLENDER_LINK_LIBS})
1122 #endif()
1123
1124 setup_liblinks(blender)