From a8e30024c1268fbfaebdb35603bbc43a3ee36c2c Mon Sep 17 00:00:00 2001 From: Jamie Snape Date: Mon, 26 Feb 2018 18:03:19 -0500 Subject: [PATCH] Add CPack configuration for building Debian packages, etc. --- CMakeLists.txt | 66 +++++++++++++++++++++++++++ tools/install/install.py.in | 19 ++++++-- tools/install/libdrake/VERSION.TXT.in | 1 + 3 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 tools/install/libdrake/VERSION.TXT.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 74f0d0033ddd..9c80680e9778 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,6 +126,28 @@ ExternalProject_Add(drake_cxx_python USES_TERMINAL_INSTALL 1 ) +set(GIT_REVISION HEAD) + +find_package(Git) + +if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") + execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD + RESULT_VARIABLE GIT_REV_PARSE_RESULT_VARIABLE + OUTPUT_VARIABLE GIT_REV_PARSE_OUTPUT_VARIABLE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + if(GIT_REV_PARSE_RESULT_VARIABLE EQUAL 0) + set(GIT_REVISION "${GIT_REV_PARSE_OUTPUT_VARIABLE}") + endif() +endif() + +string(TIMESTAMP BUILD_TIMESTAMP "%Y%m%d%H%M%S") + +configure_file(tools/install/libdrake/VERSION.TXT.in VERSION.TXT @ONLY) + +install(FILES "${PROJECT_BINARY_DIR}/VERSION.TXT" DESTINATION share/doc/drake) + list(APPEND CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}") if(WITH_MATLAB) @@ -145,3 +167,47 @@ if(WITH_MATLAB) BUILD_ALWAYS 1 ) endif() + +set(CPACK_GENERATOR TGZ) +set(CPACK_INSTALLED_DIRECTORIES "${CMAKE_INSTALL_PREFIX}" .) +set(CPACK_PACKAGE_CONTACT RobotLocomotion) +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY + "Planning, control, and analysis toolbox for nonlinear dynamical systems" +) +set(CPACK_PACKAGE_VENDOR RobotLocomotion) +set(CPACK_PACKAGE_VERSION_MAJOR 0) +set(CPACK_PACKAGE_VERSION_MINOR 0) +set(CPACK_PACKAGE_VERSION_PATCH 0) +set(CPACK_PACKAGE_CHECKSUM SHA256) +set(CPACK_SET_DESTDIR ON) +set(CPACK_SOURCE_GENERATOR "") + +if(APPLE) + set(CPACK_SYSTEM_NAME mac) +else() + string(TOLOWER "${CMAKE_SYSTEM_NAME}" CPACK_SYSTEM_NAME) + + list(APPEND CPACK_GENERATOR DEB) + + set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) + set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION ON) + set(CPACK_DEBIAN_PACKAGE_HOMEPAGE http://drake.mit.edu/) + set(CPACK_DEBIAN_PACKAGE_RELEASE 1) + set(CPACK_DEBIAN_PACKAGE_SECTION contrib/devel) + + file(STRINGS setup/ubuntu/16.04/binary_distribution/packages.txt + CPACK_DEBIAN_PACKAGE_DEPENDS + ) + string(REGEX REPLACE "([a-z0-9\\-]+)=([a-z0-9\\-\\.~]+)" "\\1 (= \\2)" + CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" + ) + string(REPLACE ";" ", " CPACK_DEBIAN_PACKAGE_DEPENDS + "${CPACK_DEBIAN_PACKAGE_DEPENDS}" + ) +endif() + +set(CPACK_PACKAGE_FILE_NAME + "${PROJECT_NAME}-${BUILD_TIMESTAMP}-${CPACK_SYSTEM_NAME}" +) + +include(CPack) diff --git a/tools/install/install.py.in b/tools/install/install.py.in index b69e6b44e94b..ad730383c9d4 100644 --- a/tools/install/install.py.in +++ b/tools/install/install.py.in @@ -79,13 +79,13 @@ def install(src, dst): dst_full = os.path.join(prefix, dst) # Install file, if not up to date. if needs_install(src, dst): - print("[Installing] {}".format(dst)) + print("-- Installing: {}".format(dst_full)) if os.path.exists(dst_full): os.remove(dst_full) shutil.copy2(src, dst_full) installed = True else: - print("[Up to date] {}".format(dst)) + print("-- Up-to-date: {}".format(dst_full)) re_result = re.match(dylib_match, dst) if re_result is not None: # It is a library basename = os.path.basename(re_result.group(0)) @@ -255,9 +255,11 @@ def create_java_launcher(filename, classpath, jvm_flags, main_class): if list_only: print(filename) return - print("[Generating] {}".format(filename)) - # Make sure install directory exists. + filename = os.path.join(prefix, filename) + print("-- Generating: {}".format(filename)) + + # Make sure install directory exists. filepath = os.path.dirname(filename) if not os.path.exists(filepath): os.makedirs(filepath) @@ -304,6 +306,12 @@ def main(args): prefix = args.prefix list_only = args.list + # Transform install prefix if DESTDIR is set. + # https://www.gnu.org/prep/standards/html_node/DESTDIR.html + destdir = os.environ.get('DESTDIR') + if destdir: + prefix = destdir + prefix + # Because Bazel executes us in a strange working directory and not the # working directory of the user's shell, enforce that the install # location is an absolute path so that the user is not surprised. @@ -313,6 +321,9 @@ def main(args): .format(prefix)) sys.exit(1) + # Match the output of the CMake install step. + print("Install the project...") + # Execute the install actions. <> diff --git a/tools/install/libdrake/VERSION.TXT.in b/tools/install/libdrake/VERSION.TXT.in new file mode 100644 index 000000000000..f9bf6709cd23 --- /dev/null +++ b/tools/install/libdrake/VERSION.TXT.in @@ -0,0 +1 @@ +@BUILD_TIMESTAMP@ @GIT_REVISION@