root/OpenSceneGraph/branches/OpenSceneGraph-2.8/CMakeModules/OsgCPack.cmake @ 10009

Revision 10009, 6.2 kB (checked in by robert, 5 years ago)

From Mattias Helsing, "
* Use the CPack ZIP generator on windows (WIN32)
* Reformatted according to Philip Lowman's recent submissions"

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()
17    SET(SYSTEM_ARCH ${CMAKE_SYSTEM_PROCESSOR})
18ENDIF()
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()
30        SET(SYSTEM_NAME "win32")
31    ENDIF()
32ENDIF()
33# Guess the compiler (is this desired for other platforms than windows?)
34IF(NOT DEFINED OSG_CPACK_COMPILER)
35    INCLUDE(OsgDetermineCompiler)
36ENDIF()
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()
44  SET(OSG_CPACK_SYSTEM_SPEC_STRING ${SYSTEM_NAME}-${SYSTEM_ARCH})
45ENDIF()
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.)
52IF(WIN32)
53    SET(CPACK_GENERATOR "ZIP")
54ELSE()
55    SET(CPACK_GENERATOR "TGZ")
56ENDIF()
57SET(CPACK_SOURCE_GENERATOR "TGZ")
58
59
60# for ms visual studio we use it's internally defined variable to get the configuration (debug,release, ...)
61IF(MSVC_IDE)
62    SET(OSG_CPACK_CONFIGURATION "$(OutDir)")
63    SET(PACKAGE_TARGET_PREFIX "Package ")
64ELSE()
65    # on un*x an empty CMAKE_BUILD_TYPE means release
66    IF(CMAKE_BUILD_TYPE)
67        SET(OSG_CPACK_CONFIGURATION ${CMAKE_BUILD_TYPE})
68    ELSE()
69        SET(OSG_CPACK_CONFIGURATION "Release")
70    ENDIF()
71    SET(PACKAGE_TARGET_PREFIX "package_")
72ENDIF()
73
74# Get all defined components
75GET_CMAKE_PROPERTY(CPACK_COMPONENTS_ALL COMPONENTS)
76IF(NOT CPACK_COMPONENTS_ALL)
77  # cmake 2.6.0 don't supply the COMPONENTS property.
78  # I set it manually to be the packages that can always be packaged
79  MESSAGE("When building packages please consider using cmake version 2.6.1 or above")
80  SET(CPACK_COMPONENTS_ALL libopenscenegraph libopenthreads openscenegraph libopenscenegraph-dev libopenthreads-dev)
81ENDIF()
82
83# Create a target that will be used to generate all packages defined below
84SET(PACKAGE_ALL_TARGETNAME "${PACKAGE_TARGET_PREFIX}ALL")
85ADD_CUSTOM_TARGET(${PACKAGE_ALL_TARGETNAME})
86
87MACRO(GENERATE_PACKAGING_TARGET package_name)
88    SET(CPACK_PACKAGE_NAME ${package_name})
89
90    # the doc packages don't need a system-arch specification
91    IF(${package} MATCHES -doc)
92        SET(OSG_PACKAGE_FILE_NAME ${package_name}-${OPENSCENEGRAPH_VERSION})
93    ELSE()
94        SET(OSG_PACKAGE_FILE_NAME ${package_name}-${OPENSCENEGRAPH_VERSION}-${OSG_CPACK_SYSTEM_SPEC_STRING}-${OSG_CPACK_CONFIGURATION})
95        IF(NOT DYNAMIC_OPENSCENEGRAPH)
96            SET(OSG_PACKAGE_FILE_NAME ${OSG_PACKAGE_FILE_NAME}-static)
97        ENDIF()
98    ENDIF()
99
100    CONFIGURE_FILE("${OpenSceneGraph_SOURCE_DIR}/CMakeModules/OsgCPackConfig.cmake.in" "${OpenSceneGraph_BINARY_DIR}/CPackConfig-${package_name}.cmake" IMMEDIATE)
101
102    SET(PACKAGE_TARGETNAME "${PACKAGE_TARGET_PREFIX}${package_name}")
103
104    # This is naive and will probably need fixing eventually
105    IF(MSVC)
106        SET(MOVE_COMMAND "move")
107    ELSE()
108        SET(MOVE_COMMAND "mv")
109    ENDIF()
110
111    # Set in and out archive filenames. Windows = zip, others = tar.gz
112    IF(WIN32)
113        SET(ARCHIVE_EXT "zip")
114    ELSE()
115        SET(ARCHIVE_EXT "tar.gz")
116    ENDIF()
117   
118    # Create a target that creates the current package
119    # and rename the package to give it proper filename
120    ADD_CUSTOM_TARGET(${PACKAGE_TARGETNAME})
121    ADD_CUSTOM_COMMAND(TARGET ${PACKAGE_TARGETNAME}
122        COMMAND ${CMAKE_CPACK_COMMAND} -C ${OSG_CPACK_CONFIGURATION} --config ${OpenSceneGraph_BINARY_DIR}/CPackConfig-${package_name}.cmake
123        COMMAND "${MOVE_COMMAND}" "${CPACK_PACKAGE_FILE_NAME}.${ARCHIVE_EXT}" "${OSG_PACKAGE_FILE_NAME}.${ARCHIVE_EXT}"
124        COMMAND ${CMAKE_COMMAND} -E echo "renamed ${CPACK_PACKAGE_FILE_NAME}.${ARCHIVE_EXT} -> ${OSG_PACKAGE_FILE_NAME}.${ARCHIVE_EXT}"
125        COMMENT "Run CPack packaging for ${package_name}..."
126    )
127    # Add the exact same custom command to the all package generating target.
128    # I can't use add_dependencies to do this because it would allow parallell building of packages so am going brute here
129    ADD_CUSTOM_COMMAND(TARGET ${PACKAGE_ALL_TARGETNAME}
130        COMMAND ${CMAKE_CPACK_COMMAND} -C ${OSG_CPACK_CONFIGURATION} --config ${OpenSceneGraph_BINARY_DIR}/CPackConfig-${package_name}.cmake
131        COMMAND "${MOVE_COMMAND}" "${CPACK_PACKAGE_FILE_NAME}.${ARCHIVE_EXT}" "${OSG_PACKAGE_FILE_NAME}.${ARCHIVE_EXT}"
132        COMMAND ${CMAKE_COMMAND} -E echo "renamed ${CPACK_PACKAGE_FILE_NAME}.${ARCHIVE_EXT} -> ${OSG_PACKAGE_FILE_NAME}.${ARCHIVE_EXT}"
133    )
134ENDMACRO(GENERATE_PACKAGING_TARGET)
135
136# Create configs and targets for a package including all components
137SET(OSG_CPACK_COMPONENT ALL)
138GENERATE_PACKAGING_TARGET(openscenegraph-all)
139
140# Create configs and targets for each component
141FOREACH(package ${CPACK_COMPONENTS_ALL})
142    SET(OSG_CPACK_COMPONENT ${package})
143    GENERATE_PACKAGING_TARGET(${package})
144ENDFOREACH()
Note: See TracBrowser for help on using the browser.