Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

installers #59

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

PROJECT(GitWrap)
set( PROJECT_MAINTAINER "Nils Fenner" )
set( PROJECT_CONTACT "Nils Fenner (My personal key) <[email protected]>" )
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)

FIND_PACKAGE(RAD-Tools REQUIRED)
Expand Down Expand Up @@ -42,3 +44,75 @@ RAD_ADD_DOXYGEN_TARGET(
${MGV_GITWRAP_SOURCE_DIR}
EXCLUDE ${MGV_GITWRAP_SOURCE_DIR}/libgit2
)


#== Packaging ==

# To Create a package go into the build directory
# and run one of the following commands:
#
# - On Mac OSX run: cpack -G "DragNDrop"
# - On Windows run: cpack -G "NSIS"
# - On Linux, you have the following options:
# 1. To create a DEB package, run "make package"
# 2. To upload the PPA for Ubuntu, enable the "PreparePPA" flag
# and (after building) run "make dput" to upload the PPA.
# Make sure, the "devscripts" package installed.
# 3. (NOT IMPLEMENTED YET) -- To create an RPM package run: cpack -G "RPM"
#
# This will create the package from the "CpackConfig.cmake" file.
#
# You may want to use other package generators like e.g. RPM.
# To do so, just change the attribute after the "-G" parameter


# == Environment ==
if(NOT CPACK_SYSTEM_NAME)
set(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_PROCESSOR}")
if(CPACK_SYSTEM_NAME STREQUAL "x86_64")
set(CPACK_SYSTEM_NAME "amd64")
endif()
endif()

# == CPack generstor ==
IF( APPLE )
SET( CPACK_BINARY_DRAGNDROP ON )
ELSEIF( LINUX )
SET( CPACK_GENERATOR TGZ TBZ2 DEB RPM )
SET( CPACK_SOURCE_GENERATOR TGZ TBZ2 )
ELSEIF( WIN32 )
SET( CPACK_BINARY_WIX ON )
ENDIF()

# == Basic information ==
SET( CPACK_PACKAGE_NAME "libGitWrap" )
SET( CPACK_PACKAGE_VERSION "0.1.0" )
SET( CPACK_PACAGE_VENDOR "http://macgitver.info" )
SET( CPACK_PACKAGE_CONTACT "${PROJECT_CONTACT}" )
SET( CPACK_PACKAGE_DESCRIPTION_SUMMARY "Qt API for libgit2." )
SET( CPACK_PACKAGE_DESCRIPTION "The GitWrap library wraps the libgit2 library for Qt applications." )
#SET( CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/DESCRIPTION" )


# == DEB package config ==
SET( CPACK_DEBIAN_PACKAGE_MAINTAINER "${PROJECT_MAINTAINER}" )
SET( CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CPACK_SYSTEM_NAME}" )
SET( CPACK_DEBIAN_PACKAGE_SECTION "devel" )
SET( CPACK_DEBIAN_PACKAGE_PRIORITY "optional" )
#SET( CPACK_DEBIAN_PACKAGE_DEPENDS "libgit2 (>=0.21.1)" )
set( CPACK_DEBIAN_BUILD_DEPENDS debhelper cmake )

# == RPM package config ==
#SET( CPACK_RPM_PACKAGE_REQUIRES "" )
## == Source package config ==


include( CPack )

if( ${PreparePPA} )
# TODO: This should be asked from the distro
set( UBUNTU_NAME "trusty" )
set( DPUT_HOST "ppa:nilsfenner/macgitver-dev" )

include( cmake/UploadPPA.cmake )
endif()
183 changes: 183 additions & 0 deletions cmake/UploadPPA.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
##
# Copyright (c) 2010 Daniel Pfeifer <[email protected]>
#
# UploadPPA.cmake is free software. It comes without any warranty,
# to the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details. */
##

find_program(DEBUILD_EXECUTABLE debuild)
find_program(DPUT_EXECUTABLE dput)

if(NOT DEBUILD_EXECUTABLE OR NOT DPUT_EXECUTABLE)
return()
endif(NOT DEBUILD_EXECUTABLE OR NOT DPUT_EXECUTABLE)

# DEBIAN/control
# debian policy enforce lower case for package name
# Package: (mandatory)
IF(NOT CPACK_DEBIAN_PACKAGE_NAME)
STRING(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME)
ENDIF(NOT CPACK_DEBIAN_PACKAGE_NAME)

# Section: (recommended)
IF(NOT CPACK_DEBIAN_PACKAGE_SECTION)
SET(CPACK_DEBIAN_PACKAGE_SECTION "devel")
ENDIF(NOT CPACK_DEBIAN_PACKAGE_SECTION)

# Priority: (recommended)
IF(NOT CPACK_DEBIAN_PACKAGE_PRIORITY)
SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
ENDIF(NOT CPACK_DEBIAN_PACKAGE_PRIORITY)

file(STRINGS ${CPACK_PACKAGE_DESCRIPTION_FILE} DESC_LINES)
foreach(LINE ${DESC_LINES})
set(DEB_LONG_DESCRIPTION "${DEB_LONG_DESCRIPTION} ${LINE}\n")
endforeach(LINE ${DESC_LINES})

file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/Debian)
set(DEBIAN_SOURCE_DIR ${CMAKE_BINARY_DIR}/Debian/${CPACK_DEBIAN_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-source)
execute_process(COMMAND ${CMAKE_COMMAND} -E
copy_directory ${CMAKE_SOURCE_DIR} ${DEBIAN_SOURCE_DIR}
)
execute_process(COMMAND ${CMAKE_COMMAND} -E
remove_directory ${DEBIAN_SOURCE_DIR}/.git
)

file(MAKE_DIRECTORY ${DEBIAN_SOURCE_DIR}/debian)

##############################################################################
# debian/control
set(DEBIAN_CONTROL ${DEBIAN_SOURCE_DIR}/debian/control)
file(WRITE ${DEBIAN_CONTROL}
"Source: ${CPACK_DEBIAN_PACKAGE_NAME}\n"
"Section: ${CPACK_DEBIAN_PACKAGE_SECTION}\n"
"Priority: ${CPACK_DEBIAN_PACKAGE_PRIORITY}\n"
"Maintainer: ${CPACK_PACKAGE_CONTACT}\n"
"Build-Depends: "
)

foreach(DEP ${CPACK_DEBIAN_BUILD_DEPENDS})
file(APPEND ${DEBIAN_CONTROL} "${DEP}, ")
endforeach(DEP ${CPACK_DEBIAN_BUILD_DEPENDS})

file(APPEND ${DEBIAN_CONTROL} "cmake\n"
"Standards-Version: 3.9.5\n"
"Homepage: ${CPACK_PACKAGE_VENDOR}\n"
"\n"
"Package: ${CPACK_DEBIAN_PACKAGE_NAME}\n"
"Architecture: any\n"
"Depends: ${CPACK_DEBIAN_PACKAGE_DEPENDS}\n"
"Description: ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}\n"
"${DEB_LONG_DESCRIPTION}"
)

foreach(COMPONENT ${CPACK_COMPONENTS_ALL})
string(TOUPPER ${COMPONENT} UPPER_COMPONENT)
set(DEPENDS "${CPACK_DEBIAN_PACKAGE_NAME}")
foreach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_DEPENDS})
set(DEPENDS "${DEPENDS}, ${CPACK_DEBIAN_PACKAGE_NAME}-${DEP}")
endforeach(DEP ${CPACK_COMPONENT_${UPPER_COMPONENT}_DEPENDS})
file(APPEND ${DEBIAN_CONTROL} "\n"
"Package: ${CPACK_DEBIAN_PACKAGE_NAME}-${COMPONENT}\n"
"Architecture: any\n"
"Depends: ${DEPENDS}\n"
"Description: ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}"
": ${CPACK_COMPONENT_${UPPER_COMPONENT}_DISPLAY_NAME}\n"
"${DEB_LONG_DESCRIPTION}"
" .\n"
" ${CPACK_COMPONENT_${UPPER_COMPONENT}_DESCRIPTION}\n"
)
endforeach(COMPONENT ${CPACK_COMPONENTS_ALL})

##############################################################################
# debian/copyright
set(DEBIAN_COPYRIGHT ${DEBIAN_SOURCE_DIR}/debian/copyright)
execute_process(COMMAND ${CMAKE_COMMAND} -E
copy ${CPACK_RESOURCE_FILE_LICENSE} ${DEBIAN_COPYRIGHT}
)

##############################################################################
# debian/rules
set(DEBIAN_RULES ${DEBIAN_SOURCE_DIR}/debian/rules)
file(WRITE ${DEBIAN_RULES}
"#!/usr/bin/make -f\n"
"\n"
"BUILDDIR = build_dir\n"
"\n"
"build:\n"
" mkdir $(BUILDDIR)\n"
" cd $(BUILDDIR); cmake ..\n"
" make -C $(BUILDDIR) preinstall\n"
" touch build\n"
"\n"
"binary: binary-indep binary-arch\n"
"\n"
"binary-indep: build\n"
"\n"
"binary-arch: build\n"
" cd $(BUILDDIR); cmake -DCOMPONENT=Unspecified -DCMAKE_INSTALL_PREFIX=../debian/tmp/usr -P cmake_install.cmake\n"
" mkdir debian/tmp/DEBIAN\n"
" dpkg-gencontrol -p${CPACK_DEBIAN_PACKAGE_NAME}\n"
" dpkg --build debian/tmp ..\n"
)

foreach(COMPONENT ${CPACK_COMPONENTS_ALL})
set(PATH debian/tmp_${COMPONENT})
set(PACKAGE ${CPACK_DEBIAN_PACKAGE_NAME}-${COMPONENT})
file(APPEND ${DEBIAN_RULES}
" cd $(BUILDDIR); cmake -DCOMPONENT=${COMPONENT} -DCMAKE_INSTALL_PREFIX=../${PATH}/usr -P cmake_install.cmake\n"
" mkdir ${PATH}/DEBIAN\n"
" dpkg-gencontrol -p${PACKAGE} -P${PATH}\n"
" dpkg --build ${PATH} ..\n"
)
endforeach(COMPONENT ${CPACK_COMPONENTS_ALL})

file(APPEND ${DEBIAN_RULES}
"\n"
"clean:\n"
" rm -f build\n"
" rm -rf $(BUILDDIR)\n"
"\n"
".PHONY: binary binary-arch binary-indep clean\n"
)

execute_process(COMMAND chmod +x ${DEBIAN_RULES})

##############################################################################
# debian/compat
file(WRITE ${DEBIAN_SOURCE_DIR}/debian/compat "7")

##############################################################################
# debian/source/format
file(WRITE ${DEBIAN_SOURCE_DIR}/debian/source/format "3.0 (native)")

##############################################################################
# debian/changelog
set(DEBIAN_CHANGELOG ${DEBIAN_SOURCE_DIR}/debian/changelog)
execute_process(COMMAND date -R OUTPUT_VARIABLE DATE_TIME)
file(WRITE ${DEBIAN_CHANGELOG}
"${CPACK_DEBIAN_PACKAGE_NAME} (${CPACK_PACKAGE_VERSION}) ${UBUNTU_NAME}; urgency=low\n\n"
" * Package built with CMake\n\n"
" -- ${CPACK_PACKAGE_CONTACT} ${DATE_TIME}"
)

##############################################################################
# debuild -S
set(DEB_SOURCE_CHANGES
${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_source.changes
)

add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/Debian/${DEB_SOURCE_CHANGES}
COMMAND ${DEBUILD_EXECUTABLE} -S
WORKING_DIRECTORY ${DEBIAN_SOURCE_DIR}
)

##############################################################################
# dput ppa:your-lp-id/ppa <source.changes>
add_custom_target(dput ${DPUT_EXECUTABLE} ${DPUT_HOST} ${DEB_SOURCE_CHANGES}
DEPENDS ${CMAKE_BINARY_DIR}/Debian/${DEB_SOURCE_CHANGES}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Debian
)