Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame^] | 1 | # Ceres Solver - A fast non-linear least squares minimizer |
| 2 | # Copyright 2015 Google Inc. All rights reserved. |
| 3 | # http://ceres-solver.org/ |
| 4 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are met: |
| 7 | # |
| 8 | # * Redistributions of source code must retain the above copyright notice, |
| 9 | # this list of conditions and the following disclaimer. |
| 10 | # * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | # this list of conditions and the following disclaimer in the documentation |
| 12 | # and/or other materials provided with the distribution. |
| 13 | # * Neither the name of Google Inc. nor the names of its contributors may be |
| 14 | # used to endorse or promote products derived from this software without |
| 15 | # specific prior written permission. |
| 16 | # |
| 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 21 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 25 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 | # POSSIBILITY OF SUCH DAMAGE. |
| 28 | # |
| 29 | # Authors: keir@google.com (Keir Mierle) |
| 30 | # alexs.mac@gmail.com (Alex Stewart) |
| 31 | |
| 32 | # Set up the git hook to make Gerrit Change-Id: lines in commit messages. |
| 33 | function(ADD_GERRIT_COMMIT_HOOK SOURCE_DIR BINARY_DIR) |
| 34 | if (NOT (EXISTS ${SOURCE_DIR} AND IS_DIRECTORY ${SOURCE_DIR})) |
| 35 | message(FATAL_ERROR "Specified SOURCE_DIR: ${SOURCE_DIR} does not exist, " |
| 36 | "or is not a directory, cannot add Gerrit commit hook.") |
| 37 | endif() |
| 38 | if (NOT (EXISTS ${BINARY_DIR} AND IS_DIRECTORY ${BINARY_DIR})) |
| 39 | message(FATAL_ERROR "Specified BINARY_DIR: ${BINARY_DIR} does not exist, " |
| 40 | "or is not a directory, cannot add Gerrit commit hook.") |
| 41 | endif() |
| 42 | unset (LOCAL_GIT_DIRECTORY) |
| 43 | if (EXISTS ${SOURCE_DIR}/.git) |
| 44 | if (IS_DIRECTORY ${SOURCE_DIR}/.git) |
| 45 | # .git directory can be found on Unix based system, or on Windows with |
| 46 | # Git Bash (shipped with msysgit). |
| 47 | set (LOCAL_GIT_DIRECTORY ${SOURCE_DIR}/.git) |
| 48 | else(IS_DIRECTORY ${SOURCE_DIR}/.git) |
| 49 | # .git is a file, this means Ceres is a git submodule of another project |
| 50 | # and our .git file contains the path to the git directory which manages |
| 51 | # Ceres, so we should add the gerrit hook there. |
| 52 | file(READ ${SOURCE_DIR}/.git GIT_SUBMODULE_FILE_CONTENTS) |
| 53 | # Strip any trailing newline characters, s/t we get a valid path. |
| 54 | string(REGEX REPLACE "gitdir:[ ]*([^$].*)[\n].*" "${SOURCE_DIR}/\\1" |
| 55 | GIT_SUBMODULE_GIT_DIRECTORY_PATH "${GIT_SUBMODULE_FILE_CONTENTS}") |
| 56 | get_filename_component(GIT_SUBMODULE_GIT_DIRECTORY_PATH |
| 57 | "${GIT_SUBMODULE_GIT_DIRECTORY_PATH}" ABSOLUTE) |
| 58 | if (EXISTS ${GIT_SUBMODULE_GIT_DIRECTORY_PATH} |
| 59 | AND IS_DIRECTORY ${GIT_SUBMODULE_GIT_DIRECTORY_PATH}) |
| 60 | set(LOCAL_GIT_DIRECTORY "${GIT_SUBMODULE_GIT_DIRECTORY_PATH}") |
| 61 | endif() |
| 62 | endif() |
| 63 | else (EXISTS ${SOURCE_DIR}/.git) |
| 64 | # TODO(keir) Add proper Windows support. |
| 65 | endif (EXISTS ${SOURCE_DIR}/.git) |
| 66 | |
| 67 | if (EXISTS ${LOCAL_GIT_DIRECTORY}) |
| 68 | if (NOT EXISTS ${LOCAL_GIT_DIRECTORY}/hooks/commit-msg) |
| 69 | message(STATUS "Detected Ceres being used as a git submodule, adding " |
| 70 | "commit hook for Gerrit to: ${LOCAL_GIT_DIRECTORY}") |
| 71 | # Download the hook only if it is not already present. |
| 72 | file(DOWNLOAD https://ceres-solver-review.googlesource.com/tools/hooks/commit-msg |
| 73 | ${BINARY_DIR}/commit-msg) |
| 74 | |
| 75 | # Make the downloaded file executable, since it is not by default. |
| 76 | file(COPY ${BINARY_DIR}/commit-msg |
| 77 | DESTINATION ${LOCAL_GIT_DIRECTORY}/hooks/ |
| 78 | FILE_PERMISSIONS |
| 79 | OWNER_READ OWNER_WRITE OWNER_EXECUTE |
| 80 | GROUP_READ GROUP_WRITE GROUP_EXECUTE |
| 81 | WORLD_READ WORLD_EXECUTE) |
| 82 | endif (NOT EXISTS ${LOCAL_GIT_DIRECTORY}/hooks/commit-msg) |
| 83 | endif (EXISTS ${LOCAL_GIT_DIRECTORY}) |
| 84 | endfunction() |