|
| 1 | +# |
| 2 | +# Copyright 2019 Kai Pastor |
| 3 | +# |
| 4 | +# This file is part of OpenOrienteering. |
| 5 | +# |
| 6 | +# OpenOrienteering is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# OpenOrienteering is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with OpenOrienteering. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +cmake_minimum_required(VERSION 3.3 FATAL_ERROR) |
| 20 | + |
| 21 | + |
| 22 | +# Sets CMAKE_CROSSCOMPILING and variables which describe the target system. |
| 23 | +macro(HANDLE_CROSSCOMPILING) |
| 24 | + set(CMAKE_CROSSCOMPILING @CMAKE_CROSSCOMPILING@) |
| 25 | + # These variables must describe the target system |
| 26 | + set(ANDROID @ANDROID@) |
| 27 | + set(APPLE @APPLE@) |
| 28 | + set(MINGW @MINGW@) |
| 29 | + set(UNIX @UNIX@) |
| 30 | + set(WIN32 @WIN32@) |
| 31 | +endmacro() |
| 32 | + |
| 33 | + |
| 34 | +function(LICENSING_HELPER_COLLECT_RUNTIME var) |
| 35 | + handle_crosscompiling() |
| 36 | + if(MINGW) |
| 37 | + set(pattern "$ENV{DESTDIR}${CMAKE_INSTALL_FULL_BINDIR}/*.dll") |
| 38 | + else() |
| 39 | + set(pattern pattern-NOTFOUND) |
| 40 | + endif() |
| 41 | + file(GLOB runtime "${pattern}") |
| 42 | + set(${var} "${runtime}" PARENT_SCOPE) |
| 43 | +endfunction() |
| 44 | + |
| 45 | + |
| 46 | +function(LICENSING_HELPER_COLLECT_COPYRIGHT var) |
| 47 | + handle_crosscompiling() |
| 48 | + foreach(file ${ARGN}) |
| 49 | + get_filename_component(orig_name "${file}" NAME) |
| 50 | + if(MINGW) |
| 51 | + string(REGEX REPLACE "-*[0-9]*\\.dll$" "" name "${orig_name}") |
| 52 | + else() |
| 53 | + set(name orig_name) |
| 54 | + endif() |
| 55 | + # Direct match |
| 56 | + file(GLOB licensing_files "${LICENSING_COPYRIGHT_DIR}/${name}-*.txt") |
| 57 | + if(NOT licensing_files) |
| 58 | + # Match without lib prefix |
| 59 | + string(REGEX REPLACE "^lib" "" short_name "${name}") |
| 60 | + file(GLOB licensing_files "${LICENSING_COPYRIGHT_DIR}/${short_name}-*.txt") |
| 61 | + endif() |
| 62 | + if(NOT licensing_files) |
| 63 | + # Explicit replacements (MinGW) |
| 64 | + string(REGEX REPLACE "libgcc_.*" "gcc-libs" name "${name}") |
| 65 | + string(REGEX REPLACE "libpng.*" "libpng1.6" name "${name}") |
| 66 | + string(REGEX REPLACE "libstdc\\+\\+.*" "gnustl" name "${name}") |
| 67 | + string(REGEX REPLACE "libwinpthread" "winpthreads" name "${name}") |
| 68 | + string(REGEX REPLACE "libz$" "zlib" name "${name}") |
| 69 | + string(REGEX REPLACE "Qt5Widgets|Qt5Gui|Qt5Core.*" "qtbase" name "${name}") |
| 70 | + file(GLOB licensing_files "${LICENSING_COPYRIGHT_DIR}/${name}-*.txt") |
| 71 | + endif() |
| 72 | + list(LENGTH licensing_files matches) |
| 73 | + if(matches EQUAL 1) |
| 74 | + list(APPEND ${var} "${licensing_files}") |
| 75 | + elseif(matches GREATER 1 OR NOT name IN_LIST LICENSING_OPTIONAL_ITEMS) |
| 76 | + message(SEND_ERROR " .. ${orig_name}: ${matches} matching licensing files found\n${licensing_files}") |
| 77 | + else() |
| 78 | + message(STATUS " .. ${orig_name}: no matching license files found (ignored)") |
| 79 | + endif() |
| 80 | + endforeach() |
| 81 | + list(REMOVE_DUPLICATES ${var}) |
| 82 | + set(${var} "${${var}}" PARENT_SCOPE) |
| 83 | +endfunction() |
| 84 | + |
| 85 | + |
| 86 | +function(LICENSING_HELPER_DEPLOY_COPYRIGHT app) |
| 87 | + set(licensing_dir "$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DOCDIR}/licensing") |
| 88 | + file(INSTALL ${ARGN} DESTINATION "${licensing_dir}") |
| 89 | +endfunction() |
| 90 | + |
| 91 | + |
| 92 | +function(LICENSING_HELPER_COLLECT_COMMON var) |
| 93 | + file(GLOB common_licenses "${LICENSING_COMMON_DIR}/*.txt") |
| 94 | + foreach(file ${common_licenses}) |
| 95 | + get_filename_component(filename "${file}" NAME) |
| 96 | + string(REPLACE ".txt" "" license "${filename}") |
| 97 | + string(REPLACE "." "[.]" license_pattern "${license}") |
| 98 | + foreach(copyright_file ${ARGN}) |
| 99 | + file(STRINGS "${copyright_file}" copyright REGEX "License: ") |
| 100 | + if(copyright MATCHES "([( ])${license_pattern}(.0|)([+]|-or-later|)([ );]|$)") |
| 101 | + list(APPEND ${var} "${file}") |
| 102 | + break() |
| 103 | + endif() |
| 104 | + endforeach() |
| 105 | + endforeach() |
| 106 | + list(REMOVE_DUPLICATES ${var}) |
| 107 | + set(${var} "${${var}}" PARENT_SCOPE) |
| 108 | +endfunction() |
| 109 | + |
| 110 | + |
| 111 | +function(LICENSING_HELPER_DEPLOY_COMMON app) |
| 112 | + set(common_dir "$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DOCDIR}/licensing/common-licenses") |
| 113 | + file(INSTALL ${ARGN} DESTINATION "${common_dir}") |
| 114 | +endfunction() |
| 115 | + |
| 116 | + |
| 117 | +function(LICENSING_HELPER_DEDUP_COMMON app) |
| 118 | + file(GLOB common_files "$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DOCDIR}/licensing/common-licenses/*") |
| 119 | + foreach(filename ${ARGN}) |
| 120 | + set(file "$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DOCDIR}/${filename}") |
| 121 | + if(NOT EXISTS "${file}") |
| 122 | + message(FATAL_ERROR "No such file: ${filename} (${file})") |
| 123 | + endif() |
| 124 | + foreach(common_file ${common_files}) |
| 125 | + execute_process( |
| 126 | + COMMAND ${CMAKE_COMMAND} -E compare_files "${file}" "${common_file}" |
| 127 | + OUTPUT_QUIET |
| 128 | + ERROR_QUIET |
| 129 | + RESULT_VARIABLE compare_result |
| 130 | + ) |
| 131 | + if(compare_result EQUAL 0) |
| 132 | + file(REMOVE "${file}") |
| 133 | + break() |
| 134 | + endif() |
| 135 | + endforeach() |
| 136 | + endforeach() |
| 137 | +endfunction() |
| 138 | + |
| 139 | + |
| 140 | +set(BUNDLE_EXECUTABLE "@BUNDLE_EXECUTABLE@") |
| 141 | +set(BUNDLE_COPYRIGHT "@BUNDLE_COPYRIGHT@") |
| 142 | + |
| 143 | +set(LICENSING_OPTIONAL_ITEMS "@LICENSING_OPTIONAL_ITEMS@") |
| 144 | +set(LICENSING_COPYRIGHT_DIR "@LICENSING_COPYRIGHT_DIR@") |
| 145 | +set(LICENSING_COMMON_DIR "@LICENSING_COMMON_DIR@") |
| 146 | + |
| 147 | +set(CMAKE_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@") |
| 148 | +set(CMAKE_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@") |
| 149 | +set(CMAKE_INSTALL_DOCDIR "@CMAKE_INSTALL_DOCDIR@") |
| 150 | +include(GNUInstallDirs) |
| 151 | + |
| 152 | +set(runtime ) |
| 153 | +set(files ) |
| 154 | +set(common ) |
| 155 | +licensing_helper_collect_runtime(runtime) |
| 156 | +licensing_helper_collect_copyright(files ${runtime}) |
| 157 | +licensing_helper_deploy_copyright("${BUNDLE_EXECUTABLE}" ${files}) |
| 158 | +licensing_helper_collect_common(common ${files}) |
| 159 | +licensing_helper_deploy_common("${BUNDLE_EXECUTABLE}" ${common}) |
| 160 | +licensing_helper_dedup_common("${BUNDLE_EXECUTABLE}" ${BUNDLE_COPYRIGHT}) |
0 commit comments