Skip to content

Commit c879b89

Browse files
committed
cmake: Generate install_manifest.cmake if WITH_PACKAGES enabled.
The information from install_mainfest.cmake is used for generating the packages.
1 parent 72379df commit c879b89

File tree

2 files changed

+176
-0
lines changed

2 files changed

+176
-0
lines changed

packaging/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@
2727
# along with this program; if not, write to the Free Software Foundation, Inc.,
2828
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2929

30+
# ======================================================================
31+
# Install manifest
32+
# ======================================================================
33+
34+
# Generate and install install_manifest.cmake file which contains
35+
# information about install components and files in each component.
36+
# See the install_mainfest.cmake script in this directory.
37+
38+
add_custom_target(generate_manifest
39+
ALL
40+
COMMAND ${CMAKE_COMMAND}
41+
-D INSTALL_DIR=${CMAKE_INSTALL_PREFIX}
42+
-D BUILD_DIR=${PROJECT_BINARY_DIR}
43+
-P "${CMAKE_CURRENT_SOURCE_DIR}/install_manifest.cmake"
44+
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
45+
COMMENT "Generating install manifest"
46+
)
47+
48+
install(
49+
FILES "${PROJECT_BINARY_DIR}/install_manifest.cmake"
50+
DESTINATION .
51+
COMPONENT Auxiliary
52+
)
53+
3054

3155
# ======================================================================
3256
# Licenses for binary packages

packaging/install_manifest.cmake

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License, version 2.0, as
5+
# published by the Free Software Foundation.
6+
#
7+
# This program is also distributed with certain software (including
8+
# but not limited to OpenSSL) that is licensed under separate terms,
9+
# as designated in a particular file or component or in included license
10+
# documentation. The authors of MySQL hereby grant you an
11+
# additional permission to link the program and your derivative works
12+
# with the separately licensed software that they have included with
13+
# MySQL.
14+
#
15+
# Without limiting anything contained in the foregoing, this file,
16+
# which is part of MySQL Connector/C++, is also subject to the
17+
# Universal FOSS Exception, version 1.0, a copy of which can be found at
18+
# http://oss.oracle.com/licenses/universal-foss-exception.
19+
#
20+
# This program is distributed in the hope that it will be useful, but
21+
# WITHOUT ANY WARRANTY; without even the implied warranty of
22+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23+
# See the GNU General Public License, version 2.0, for more details.
24+
#
25+
# You should have received a copy of the GNU General Public License
26+
# along with this program; if not, write to the Free Software Foundation, Inc.,
27+
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28+
29+
#
30+
# This script collects information about install components and files
31+
# inside each components and writes it to install_mainfest.cmake file
32+
# in form of set() commands that set the following variables:
33+
#
34+
# - COMPONENTS -- list of install components
35+
# - FILES_${CCC} -- list of files in component CCC
36+
#
37+
# The information is collected from CPackConfig.cmake and cmake_install.cmake
38+
# files that are generated in project's build location. This location must
39+
# be give via BUILD_DIR variable.
40+
#
41+
# If INSTALL_DIR is defined and contains install_manifest.cmake, the
42+
# information collected here is merged with the information from
43+
# ${INSTALL_DIR}/install_manifest.cmake. This way information from several
44+
# builds can be merged together (easiest if all these builds install to
45+
# the same install location).
46+
#
47+
48+
# The output file
49+
50+
set(MANIFEST_FILE ${BUILD_DIR}/install_manifest.cmake)
51+
52+
# Check if requiret input files exist
53+
54+
if(NOT EXISTS "${BUILD_DIR}/CPackConfig.cmake")
55+
message(FATAL_ERROR "Could not find CPackConfig.cmake at: ${BUILD_DIR}")
56+
endif()
57+
58+
if(NOT EXISTS "${BUILD_DIR}/cmake_install.cmake")
59+
message(FATAL_ERROR "Could not find cmake_install.cmake at: ${BUILD_DIR}")
60+
endif()
61+
62+
# Read existing information to be extended (if present) and CPackConfig.cmake
63+
# to get list of install components. Update COMPONENTS basead on this.
64+
65+
include("${INSTALL_DIR}/install_manifest.cmake" OPTIONAL)
66+
include("${BUILD_DIR}/CPackConfig.cmake")
67+
68+
list(APPEND COMPONENTS ${CPACK_COMPONENTS_ALL})
69+
list(REMOVE_DUPLICATES COMPONENTS)
70+
71+
#
72+
# Now we will include cmake_install.cmake which uses file(INSTALL ...) commands
73+
# to install all files. We redefine file() command to extract file information
74+
# instead of copying it to the destination.
75+
#
76+
77+
function(file CMD)
78+
79+
# we only look at file(INSTALL ...) variant
80+
81+
if(NOT CMD STREQUAL "INSTALL")
82+
return()
83+
endif()
84+
85+
#
86+
# example file(INSTALL ...) invocation in cmake_install.cmake:
87+
#
88+
# file(INSTALL DESTINATION "..." TYPE STATIC_LIBRARY OPTIONAL FILES ...)
89+
#
90+
# we read destination location and remove all arguments up to the list of
91+
# files
92+
#
93+
94+
list(GET ARGN 1 DEST)
95+
list(REMOVE_AT ARGN 0 1 2 3 4)
96+
97+
# Because of things like OPTIONAL, which can be present or not, the first
98+
# item in ARGN can be the FILES keyword - remove it if this is the case.
99+
100+
list(GET ARGN 0 FIRST)
101+
if(FIRST STREQUAL "FILES")
102+
list(REMOVE_AT ARGN 0)
103+
endif()
104+
105+
# Now process the files and append them to FILES_CCC list
106+
107+
foreach(F ${ARGN})
108+
get_filename_component(FN ${F} NAME)
109+
#message("- adding (${CMAKE_INSTALL_COMPONENT}): ${DEST}/${FN}")
110+
list(APPEND FILES_${CMAKE_INSTALL_COMPONENT} "${DEST}/${FN}")
111+
endforeach()
112+
113+
list(REMOVE_DUPLICATES FILES_${CMAKE_INSTALL_COMPONENT})
114+
#message("-- files: ${FILES_${CMAKE_INSTALL_COMPONENT}}")
115+
set(FILES_${CMAKE_INSTALL_COMPONENT} ${FILES_${CMAKE_INSTALL_COMPONENT}} PARENT_SCOPE)
116+
117+
endfunction(file)
118+
119+
120+
#
121+
# Include cmake_install.cmake one time for each component, each time
122+
# setting CMAKE_INSTALL_COMPONENT to the component being processed. This
123+
# way only files from that component are processed inside cmake_install
124+
# script.
125+
#
126+
127+
set(CMAKE_INSTALL_CONFIG_NAME "Release")
128+
set(CMAKE_INSTALL_PREFIX ".")
129+
130+
foreach(COMP ${CPACK_COMPONENTS_ALL})
131+
set(CMAKE_INSTALL_COMPONENT ${COMP})
132+
#message("\nComponent: ${CMAKE_INSTALL_COMPONENT}")
133+
include(${BUILD_DIR}/cmake_install.cmake)
134+
#message("-- files: ${FILES_${CMAKE_INSTALL_COMPONENT}}")
135+
endforeach()
136+
137+
# Write gathered information to the output file.
138+
# Note: Original file() command was redefined above!
139+
140+
_file(WRITE ${MANIFEST_FILE}
141+
"# Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.\n"
142+
"# This is generated file.\n\n"
143+
"set(COMPONENTS ${COMPONENTS})\n\n"
144+
)
145+
146+
foreach(COMP ${COMPONENTS})
147+
_file(APPEND ${MANIFEST_FILE}
148+
"set(FILES_${COMP} ${FILES_${COMP}})\n"
149+
)
150+
endforeach()
151+
152+
message("Wrote: ${MANIFEST_FILE}")

0 commit comments

Comments
 (0)