CMake package_archive target to create a .zip/.tar.bz2 package on mac/unix,
[blender.git] / build_files / cmake / packaging.cmake
1 set(PROJECT_DESCRIPTION  "Blender is a very fast and versatile 3D modeller/renderer.")
2 set(PROJECT_COPYRIGHT    "Copyright (C) 2001-2011 Blender Foundation")
3 set(PROJECT_CONTACT      "foundation@blender.org")
4 set(PROJECT_VENDOR       "Blender Foundation")
5 set(ORG_WEBSITE          "www.blender.org")
6
7 set(MAJOR_VERSION ${BLENDER_VERSION_MAJOR})
8 set(MINOR_VERSION ${BLENDER_VERSION_MINOR})
9 set(PATCH_VERSION ${BLENDER_VERSION_CHAR_INDEX})
10
11 set(CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
12 set(CPACK_PACKAGE_DESCRIPTION ${PROJECT_DESCRIPTION})
13 set(CPACK_PACKAGE_VENDOR ${PROJECT_VENDOR})
14 set(CPACK_PACKAGE_CONTACT ${PROJECT_CONTACT})
15 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
16 set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
17 SET(CPACK_PACKAGE_VERSION_MAJOR "${MAJOR_VERSION}")
18 SET(CPACK_PACKAGE_VERSION_MINOR "${MINOR_VERSION}")
19 SET(CPACK_PACKAGE_VERSION_PATCH "${PATCH_VERSION}")
20
21
22 # Get the build revision, note that this can get out-of-sync, so for packaging run cmake first.
23 include(FindSubversion)
24 set(MY_WC_REVISION "unknown")
25 if(EXISTS ${CMAKE_SOURCE_DIR}/.svn/)
26         if(Subversion_FOUND)
27                 Subversion_WC_INFO(${CMAKE_SOURCE_DIR} MY)
28         endif()
29 endif()
30 set(BUILD_REV ${MY_WC_REVISION})
31
32
33 # Force Package Name
34 set(CPACK_PACKAGE_FILE_NAME ${PROJECT_NAME}-${BLENDER_VERSION}-r${BUILD_REV}-${CPACK_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR})
35
36 if(CMAKE_SYSTEM_NAME MATCHES "Linux")
37         # RPM packages
38         include(build_files/cmake/RpmBuild.cmake)
39         if(RPMBUILD_FOUND AND NOT WIN32)
40                 set(CPACK_GENERATOR "RPM")
41                 set(CPACK_SET_DESTDIR TRUE)
42                 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_DESCRIPTION}")
43                 set(CPACK_RPM_PACKAGE_LICENSE "GPLv2")
44                 set(CPACK_RPM_PACKAGE_GROUP "Amusements/Graphics")
45         endif()
46 endif()
47
48 # Mac Bundle
49 if(APPLE)
50         set(CPACK_GENERATOR "DragNDrop")
51
52         # Libraries are bundled directly
53         set(CPACK_COMPONENT_LIBRARIES_HIDDEN TRUE)
54 endif()
55
56 set(CPACK_PACKAGE_EXECUTABLES "blender")
57 include(CPack)
58
59 # Target for build_archive.py script, to automatically pass along
60 # version, revision, platform, build directory
61 macro(add_package_archive packagename extension)
62         set(build_archive python ${CMAKE_SOURCE_DIR}/build_files/package_spec/build_archive.py)
63         set(package_output ${CMAKE_BINARY_DIR}/release/${packagename}.${extension})
64
65         add_custom_target(package_archive DEPENDS ${package_output})
66
67         add_custom_command(
68                 OUTPUT ${package_output}
69                 COMMAND ${build_archive} ${packagename} ${extension} bin release
70                 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
71 endmacro()
72
73 if(APPLE)
74         add_package_archive(
75                 "blender-${BLENDER_VERSION}-r${BUILD_REV}-OSX-${CMAKE_OSX_ARCHITECTURES}"
76                 "zip")
77 elseif(UNIX)
78         # platform name could be tweaked, to include glibc, and ensure processor is correct (i386 vs i686)
79         string(TOLOWER ${CMAKE_SYSTEM_NAME} PACKAGE_SYSTEM_NAME)
80
81         add_package_archive(
82                 "blender-${BLENDER_VERSION}-r${BUILD_REV}-${PACKAGE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}"
83                 "tar.bz2")
84 endif()
85