root/OpenSceneGraph/trunk/CMakeModules/OsgCPack.cmake @ 9528

Revision 9528, 6.3 kB (checked in by robert, 6 years ago)

From Mattias Helsing, "got some feedback from J-S on the packaging so I have changed the
name of the top folder in each package to OpenSceneGraph-x.y.z

Noone else has had an opinion on whether compiler and it's version
should be part of the package filename on their platform/setup so I'll
leave it as is. That is - No action is taken for compilers other than
msvc but one can easily add this information to the cmake cache
regardless of platform.
"

Line 
1# This script sets up packaging targets for each "COMPONENT" as specified in INSTALL commands
2#
3# for each component a CPackConfig-<component>.cmake is generated in the build tree
4# and a target is added to call cpack for it (e.g. package_openscenegaph
5# A target for generating a package with everything that gets INSTALLED is generated (package_openscenegraph-all)
6# A target for making all of the abaove packages is generated (package_ALL)
7#
8# package filenames are created on the form <package>-<platform>-<arch>[-<compiler>]-<build_type>[-static].tar.gz
9# ...where compiler optionally set using a cmake gui (OSG_CPACK_COMPILER). This script tries to guess compiler version for msvc generators
10# ...build_type matches CMAKE_BUILD_TYPE for all generators but the msvc ones
11
12# resolve architecture. The reason i "change" i686 to i386 is that debian packages
13# require i386 so this is for the future
14IF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
15    SET(SYSTEM_ARCH "i386")
16ELSE("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
17    SET(SYSTEM_ARCH ${CMAKE_SYSTEM_PROCESSOR})
18ENDIF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
19
20# set a default system name - use CMake setting (Linux|Windows|...)
21SET(SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
22#message(STATUS "CMAKE_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}")
23#message(STATUS "CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}")
24
25# for msvc the SYSTEM_NAME is set win32/64 instead of "Windows"
26IF(MSVC)
27    IF(CMAKE_CL_64)
28        SET(SYSTEM_NAME "win64")
29    ELSE(CMAKE_CL_64)
30        SET(SYSTEM_NAME "win32")
31    ENDIF(CMAKE_CL_64)
32ENDIF(MSVC)
33# Guess the compiler (is this desired for other platforms than windows?)
34IF(NOT DEFINED OSG_CPACK_COMPILER)
35    INCLUDE(OsgDetermineCompiler)
36ENDIF(NOT DEFINED OSG_CPACK_COMPILER)
37
38# expose the compiler setting to the user
39SET(OSG_CPACK_COMPILER "${OSG_COMPILER}" CACHE STRING "This ia short string (vc90, vc80sp1, gcc-4.3, ...) describing your compiler. The string is used for creating package filenames")
40
41IF(OSG_CPACK_COMPILER)
42  SET(OSG_CPACK_SYSTEM_SPEC_STRING ${SYSTEM_NAME}-${SYSTEM_ARCH}-${OSG_CPACK_COMPILER})
43ELSE(OSG_CPACK_COMPILER)
44  SET(OSG_CPACK_SYSTEM_SPEC_STRING ${SYSTEM_NAME}-${SYSTEM_ARCH})
45ENDIF(OSG_CPACK_COMPILER)
46
47
48## variables that apply to all packages
49SET(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${OPENSCENEGRAPH_VERSION}")
50
51# these goes for all platforms. Setting these stops the CPack.cmake script from generating options about other package compression formats (.z .tz, etc.)
52SET(CPACK_GENERATOR "TGZ")
53SET(CPACK_SOURCE_GENERATOR "TGZ")
54
55
56# for ms visual studio we use it's internally defined variable to get the configuration (debug,release, ...)
57IF(MSVC_IDE)
58    SET(OSG_CPACK_CONFIGURATION "$(OutDir)")
59    SET(PACKAGE_TARGET_PREFIX "Package ")
60ELSE(MSVC_IDE)
61    # on un*x an empty CMAKE_BUILD_TYPE means release
62    IF(CMAKE_BUILD_TYPE)
63        SET(OSG_CPACK_CONFIGURATION ${CMAKE_BUILD_TYPE})
64    ELSE(CMAKE_BUILD_TYPE)
65        SET(OSG_CPACK_CONFIGURATION "Release")
66    ENDIF(CMAKE_BUILD_TYPE)
67    SET(PACKAGE_TARGET_PREFIX "package_")
68ENDIF(MSVC_IDE)
69
70# Get all defined components
71GET_CMAKE_PROPERTY(CPACK_COMPONENTS_ALL COMPONENTS)
72IF(NOT CPACK_COMPONENTS_ALL)
73  # cmake 2.6.0 don't supply the COMPONENTS property.
74  # I set it manually to be the packages that can always be packaged
75  MESSAGE("When building packages please consider using cmake version 2.6.1 or above")
76  SET(CPACK_COMPONENTS_ALL libopenscenegraph libopenthreads openscenegraph libopenscenegraph-dev libopenthreads-dev)
77ENDIF(NOT CPACK_COMPONENTS_ALL)
78
79# Create a target that will be used to generate all packages defined below
80SET(PACKAGE_ALL_TARGETNAME "${PACKAGE_TARGET_PREFIX}ALL")
81ADD_CUSTOM_TARGET(${PACKAGE_ALL_TARGETNAME})
82
83MACRO(GENERATE_PACKAGING_TARGET package_name)
84    SET(CPACK_PACKAGE_NAME ${package_name})
85
86    # the doc packages don't need a system-arch specification
87    IF(${package} MATCHES -doc)
88        SET(OSG_PACKAGE_FILE_NAME ${package_name}-${OPENSCENEGRAPH_VERSION})
89    ELSE(${package} MATCHES -doc)
90        SET(OSG_PACKAGE_FILE_NAME ${package_name}-${OPENSCENEGRAPH_VERSION}-${OSG_CPACK_SYSTEM_SPEC_STRING}-${OSG_CPACK_CONFIGURATION})
91        IF(NOT DYNAMIC_OPENSCENEGRAPH)
92            SET(OSG_PACKAGE_FILE_NAME ${OSG_PACKAGE_FILE_NAME}-static)
93        ENDIF(NOT DYNAMIC_OPENSCENEGRAPH)
94    ENDIF(${package} MATCHES -doc)
95
96    CONFIGURE_FILE("${OpenSceneGraph_SOURCE_DIR}/CMakeModules/OsgCPackConfig.cmake.in" "${OpenSceneGraph_BINARY_DIR}/CPackConfig-${package_name}.cmake" IMMEDIATE)
97
98    SET(PACKAGE_TARGETNAME "${PACKAGE_TARGET_PREFIX}${package_name}")
99
100    # This is naive and will probably need fixing eventually
101    IF(MSVC)
102        SET(MOVE_COMMAND "move")
103    ELSE(MSVC)
104        SET(MOVE_COMMAND "mv")
105    ENDIF(MSVC)
106   
107    # Create a target that creates the current package
108    # and rename the package to give it proper filename
109    ADD_CUSTOM_TARGET(${PACKAGE_TARGETNAME})
110    ADD_CUSTOM_COMMAND(TARGET ${PACKAGE_TARGETNAME}
111        COMMAND ${CMAKE_CPACK_COMMAND} -C ${OSG_CPACK_CONFIGURATION} --config ${OpenSceneGraph_BINARY_DIR}/CPackConfig-${package_name}.cmake
112        COMMAND "${MOVE_COMMAND}" "${CPACK_PACKAGE_FILE_NAME}.tar.gz" "${OSG_PACKAGE_FILE_NAME}.tar.gz"
113        COMMAND ${CMAKE_COMMAND} -E echo "renamed ${CPACK_PACKAGE_FILE_NAME}.tar.gz -> ${OSG_PACKAGE_FILE_NAME}.tar.gz"
114        COMMENT "Run CPack packaging for ${package_name}..."
115    )
116    # Add the exact same custom command to the all package generating target.
117    # I can't use add_dependencies to do this because it would allow parallell building of packages so am going brute here
118    ADD_CUSTOM_COMMAND(TARGET ${PACKAGE_ALL_TARGETNAME}
119        COMMAND ${CMAKE_CPACK_COMMAND} -C ${OSG_CPACK_CONFIGURATION} --config ${OpenSceneGraph_BINARY_DIR}/CPackConfig-${package_name}.cmake
120        COMMAND "${MOVE_COMMAND}" "${CPACK_PACKAGE_FILE_NAME}.tar.gz" "${OSG_PACKAGE_FILE_NAME}.tar.gz"
121        COMMAND ${CMAKE_COMMAND} -E echo "renamed ${CPACK_PACKAGE_FILE_NAME}.tar.gz -> ${OSG_PACKAGE_FILE_NAME}.tar.gz"
122    )
123ENDMACRO(GENERATE_PACKAGING_TARGET)
124
125# Create configs and targets for a package including all components
126SET(OSG_CPACK_COMPONENT ALL)
127GENERATE_PACKAGING_TARGET(openscenegraph-all)
128
129# Create configs and targets for each component
130FOREACH(package ${CPACK_COMPONENTS_ALL})
131    SET(OSG_CPACK_COMPONENT ${package})
132    GENERATE_PACKAGING_TARGET(${package})
133ENDFOREACH(package ${CPACK_COMPONENTS_ALL})
Note: See TracBrowser for help on using the browser.