Skip to content

Commit 71492e7

Browse files
committed
Packaging: Add 3rd-party copyright deployment
1 parent 5923974 commit 71492e7

File tree

4 files changed

+226
-0
lines changed

4 files changed

+226
-0
lines changed

ci/openorienteering-cupcalculator-ci.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ set(CupCalculator_CI_SOURCE_DIR "NOTFOUND" CACHE STRING
3434
set(CupCalculator_CI_ENABLE_COVERAGE "OFF" CACHE BOOL
3535
"CupCalculator (CI): Enable test coverage analysis"
3636
)
37+
set(CupCalculator_CI_LICENSING_OPTIONAL_ITEMS "" CACHE STRING
38+
"CupCalculator (CI): List of items which may be deployed even when licensing documentation is absent"
39+
)
3740

3841

3942
add_custom_target(openorienteering-cupcalculator-ci-source)
@@ -47,12 +50,15 @@ superbuild_package(
4750

4851
USING
4952
CupCalculator_CI_ENABLE_COVERAGE
53+
CupCalculator_CI_LICENSING_OPTIONAL_ITEMS
5054
BUILD [[
5155
CMAKE_ARGS
5256
"-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
5357
"-UCMAKE_STAGING_PREFIX"
5458
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
59+
"-ULICENSING_OPTIONAL_ITEMS" # unset here, updated via CMAKE_CACHE_ARGS
5560
CMAKE_CACHE_ARGS
61+
"-DLICENSING_OPTIONAL_ITEMS:STRING=@CupCalculator_CI_LICENSING_OPTIONAL_ITEMS@"
5662
$<$<BOOL:@WIN32@>:
5763
"-DCMAKE_INSTALL_BINDIR:STRING=."
5864
"-DCMAKE_INSTALL_DATAROOTDIR:STRING=."

cmake/licensing_helper.cmake

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
20+
# Setup a licensing helper script to be run at install time.
21+
22+
find_file(LICENSING_COPYRIGHT_DIR
23+
NAMES copyright
24+
PATH_SUFFIXES share/doc
25+
DOC "Path to directory with 3rd-party component copyright files."
26+
)
27+
28+
find_file(LICENSING_COMMON_DIR
29+
NAMES common-licenses
30+
PATHS "${LICENSING_COPYRIGHT_DIR}"
31+
NO_DEFAULT_PATH
32+
DOC "Path to directory with common license files."
33+
)
34+
35+
set(LICENSING_OPTIONAL_ITEMS "" CACHE STRING
36+
"List of items which may be deployed even when licensing documentation is absent"
37+
)
38+
39+
40+
# Deploy 3rd-party copyright, terms etc.
41+
# The app name can be followed by the filenames of its explicit license texts as
42+
# installed to the documenation directory. They will be checked for duplicates
43+
# in the common license text. If an identical file is found there, the named
44+
# file is removed.
45+
46+
function(LICENSING_HELPER_POSTPROCESS app)
47+
if(NOT LICENSING_COPYRIGHT_DIR OR NOT LICENSING_COMMON_DIR)
48+
message(STATUS "LICENSING_COPYRIGHT_DIR: ${LICENSING_COPYRIGHT_DIR}")
49+
message(STATUS "LICENSING_COMMON_DIR: ${LICENSING_COMMON_DIR}")
50+
message(FATAL_ERROR "Both LICENSING_COPYRIGHT_DIR and LICENSING_COMMON_DIR must be set")
51+
endif()
52+
53+
set(BUNDLE_EXECUTABLE "${app}")
54+
set(BUNDLE_COPYRIGHT "${ARGN}")
55+
set(script_name "licensing_helper_${app}.cmake")
56+
configure_file("${PROJECT_SOURCE_DIR}/cmake/licensing_helper_install.cmake.in" "${script_name}" @ONLY)
57+
install(CODE "include(\"${CMAKE_CURRENT_BINARY_DIR}/${script_name}\")")
58+
endfunction()
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
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})

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ find_package(Qt5Widgets REQUIRED)
2121
find_package(Qt5Test REQUIRED)
2222

2323
include("bundle_helper")
24+
include("licensing_helper")
2425

2526
set(CMAKE_AUTOMOC ON)
2627

@@ -66,6 +67,7 @@ install(TARGETS CupCalculator
6667
)
6768
if(MAKE_BUNDLE)
6869
bundle_helper_postprocess(CupCalculator Qt5Widgets Qt5Gui)
70+
licensing_helper_postprocess(CupCalculator COPYING.txt)
6971
endif()
7072

7173
add_executable(CupCalculatorTest test.cpp)

0 commit comments

Comments
 (0)