[chrome-gnome-shell] cmake: improve build script. Allow to explicitly disable dist target. Add status messages.



commit c8cbc2ee9af0eefd67c15a45b6249335a3f67a2d
Author: Yuri Konotopov <ykonotopov gmail com>
Date:   Sun Mar 13 10:44:08 2016 +0300

    cmake: improve build script.
    Allow to explicitly disable dist target.
    Add status messages.

 CMakeLists.txt |  124 ++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 72 insertions(+), 52 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 32c34c4..f856a88 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,9 +13,10 @@ set(ARCHIVE_FULL_NAME ${ARCHIVE_NAME}.tar.xz)
 set(ARCHIVE_DEB_NAME ${CMAKE_PROJECT_NAME}_${PROJECT_VERSION}.orig.tar.xz)
 set(DEB_DIR ${CMAKE_CURRENT_BINARY_DIR}/deb)
 
-option(BUILD_EXTENSION "Build extension zip package"   TRUE)
-option(BUILD_CONNECTOR "Build native messaging host"   TRUE)
-option(BUILD_DEB       "Build debian package"          FALSE)
+option(BUILD_EXTENSION         "Build extension zip package"   TRUE)
+option(BUILD_CONNECTOR         "Build native messaging host"   TRUE)
+option(BUILD_SOURCE_PACKAGE    "Build source package"          FALSE)
+option(BUILD_DEB               "Build debian package"          FALSE)
 
 if(NOT DEFINED(EXTENSION_ID))
        set(EXTENSION_ID "gphhapmejobijbbhgpjhcjognlahblep")
@@ -29,6 +30,18 @@ if(NOT DEFINED(DEBIAN_DISTRO))
        set(DEBIAN_DISTRO "trusty")
 endif(NOT DEFINED(DEBIAN_DISTRO))
 
+macro(find_program_ex program message_type)
+       string(TOUPPER ${program} _PROGRAM_UPPER)
+
+       find_program(${_PROGRAM_UPPER}_EXECUTABLE ${program})
+
+       if(${_PROGRAM_UPPER}_EXECUTABLE)
+               message(STATUS "Found ${program}: ${${_PROGRAM_UPPER}_EXECUTABLE}")
+               set(${_PROGRAM_UPPER}_FOUND TRUE)
+       else(${_PROGRAM_UPPER}_EXECUTABLE)
+               message(${message_type} "Could NOT find ${program}.")
+       endif(${_PROGRAM_UPPER}_EXECUTABLE)
+endmacro(find_program_ex)
 
 include(GNUInstallDirs)
 
@@ -36,14 +49,20 @@ if(NOT BUILD_EXTENSION AND NOT BUILD_CONNECTOR)
        message(FATAL_ERROR "No build options selected")
 endif(NOT BUILD_EXTENSION AND NOT BUILD_CONNECTOR)
 
+if(BUILD_DEB AND NOT BUILD_SOURCE_PACKAGE)
+       message(STATUS "Building of debian package enabled. Turning on building source package.")
+       set(BUILD_SOURCE_PACKAGE TRUE)
+endif(BUILD_DEB AND NOT BUILD_SOURCE_PACKAGE)
+
+if(BUILD_SOURCE_PACKAGE AND NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/)
+       message(FATAL_ERROR "Unable to build source package outside of git repository.")
+endif(BUILD_SOURCE_PACKAGE AND NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/)
+
 if(BUILD_EXTENSION)
-       find_program(7ZIP 7z)
-       if(NOT 7ZIP)
-               message(FATAL_ERROR "7-zip not found.")
-       endif(NOT 7ZIP)
+       find_program_ex(7z FATAL_ERROR)
 
        add_custom_target(extension ALL
-               COMMAND "${7ZIP}" a -tzip "${CMAKE_BINARY_DIR}/extension.zip" ./
+               COMMAND "${7Z_EXECUTABLE}" a -tzip "${CMAKE_BINARY_DIR}/extension.zip" ./
                WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/extension/")
 endif(BUILD_EXTENSION)
 
@@ -58,49 +77,50 @@ if(BUILD_CONNECTOR)
        install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/connector/external_extension.json" DESTINATION 
"/usr/share/chromium/extensions/" RENAME "${EXTENSION_ID}.json")
 endif(BUILD_CONNECTOR)
 
-find_program(XZ xz)
-if(XZ)
-       # http://agateau.com/2009/cmake-and-make-dist-the-simple-version/
-       add_custom_target(dist
-               COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD | ${XZ} -z > 
${CMAKE_BINARY_DIR}/${ARCHIVE_FULL_NAME}
-               WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
-else(XZ)
+if(BUILD_SOURCE_PACKAGE)
+       set(MESSAGE_NO_DIST "Unable to generate dist target. Dependencies missing.")
+
+       find_program_ex(xz WARNING)
+       find_package(Git)
+
+       if(GIT_FOUND AND XZ_FOUND)
+               # http://agateau.com/2009/cmake-and-make-dist-the-simple-version/
+               add_custom_target(dist
+                       COMMAND ${GIT_EXECUTABLE} archive --prefix=${ARCHIVE_NAME}/ HEAD | ${XZ_EXECUTABLE} 
-z > ${CMAKE_BINARY_DIR}/${ARCHIVE_FULL_NAME}
+                       WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
+       else(GIT_FOUND AND XZ_FOUND)
+               if(BUILD_DEB)
+                       message(FATAL_ERROR ${MESSAGE_NO_DIST})
+               else(BUILD_DEB)
+                       message(WARNING ${MESSAGE_NO_DIST})
+               endif(BUILD_DEB)
+       endif(GIT_FOUND AND XZ_FOUND)
+
        if(BUILD_DEB)
-               message(FATAL_ERROR "XZ utils not found.")
-       else(BUILD_DEB)
-               message(WARNING "XZ utils not found. Dist target will not be generated.")
+               find_program_ex(debuild FATAL_ERROR)
+               find_program_ex(tar FATAL_ERROR)
+
+               if(GPG_KEY)
+                       message(STATUS "Using GPG key ${GPG_KEY}")
+                       set(DEBUILD_KEY "-k${GPG_KEY}")
+               else(GPG_KEY)
+                       message(STATUS "GPG_KEY not set. Using default GPG key")
+               endif(GPG_KEY)
+
+               configure_file("${CMAKE_CURRENT_SOURCE_DIR}/contrib/ubuntu/changelog"
+                               "${CMAKE_BINARY_DIR}/debian_changelog")
+
+               add_custom_target(deb_prepare
+                       DEPENDS dist
+                       COMMAND ${CMAKE_COMMAND} -E make_directory "${DEB_DIR}/${ARCHIVE_NAME}"
+                       COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${ARCHIVE_FULL_NAME}" 
"${DEB_DIR}/${ARCHIVE_DEB_NAME}"
+                       COMMAND ${TAR_EXECUTABLE} -xvf "${DEB_DIR}/${ARCHIVE_DEB_NAME}" -C 
"${DEB_DIR}/${ARCHIVE_NAME}" --strip-components=1)
+
+               add_custom_target(deb ALL
+                       DEPENDS deb_prepare
+                       COMMAND ${CMAKE_COMMAND} -E copy_directory 
"${CMAKE_CURRENT_SOURCE_DIR}/contrib/ubuntu" "${DEB_DIR}/${ARCHIVE_NAME}/debian"
+                       COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/debian_changelog" 
"${DEB_DIR}/${ARCHIVE_NAME}/debian/changelog"
+                       COMMAND ${DEBUILD_EXECUTABLE} -S ${DEBUILD_KEY}
+                       WORKING_DIRECTORY ${DEB_DIR}/${ARCHIVE_NAME})
        endif(BUILD_DEB)
-endif(XZ)
-
-if(BUILD_DEB)
-       find_program(DEBUILD debuild)
-       find_program(TAR tar)
-
-       if(NOT DEBUILD)
-               message(FATAL_ERROR "Debuild not found.")
-       endif(NOT DEBUILD)
-
-       if(NOT TAR)
-               message(FATAL_ERROR "Tar not found.")
-       endif(NOT TAR)
-
-       if(GPG_KEY)
-               set(DEBUILD_KEY "-k${GPG_KEY}")
-       endif(GPG_KEY)
-
-       configure_file("${CMAKE_CURRENT_SOURCE_DIR}/contrib/ubuntu/changelog"
-                       "${CMAKE_BINARY_DIR}/debian_changelog")
-
-       add_custom_target(deb_prepare
-               DEPENDS dist
-               COMMAND ${CMAKE_COMMAND} -E make_directory "${DEB_DIR}/${ARCHIVE_NAME}"
-               COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${ARCHIVE_FULL_NAME}" 
"${DEB_DIR}/${ARCHIVE_DEB_NAME}"
-               COMMAND ${TAR} -xvf "${DEB_DIR}/${ARCHIVE_DEB_NAME}" -C "${DEB_DIR}/${ARCHIVE_NAME}" 
--strip-components=1)
-
-       add_custom_target(deb ALL
-               DEPENDS deb_prepare
-               COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/contrib/ubuntu" 
"${DEB_DIR}/${ARCHIVE_NAME}/debian"
-               COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/debian_changelog" 
"${DEB_DIR}/${ARCHIVE_NAME}/debian/changelog"
-               COMMAND ${DEBUILD} -S ${DEBUILD_KEY}
-               WORKING_DIRECTORY ${DEB_DIR}/${ARCHIVE_NAME})
-endif(BUILD_DEB)
+endif(BUILD_SOURCE_PACKAGE)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]