1+ # Copyright 2019 Google
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ # Handles creation of the C++ package zip using cpack
16+
17+ # All functions do nothing unless FIREBASE_CPP_BUILD_PACKAGE is enabled.
18+ if (${FIREBASE_CPP_BUILD_PACKAGE} )
19+ # Including CPack multiple times can cause it to break, so guard against that.
20+ if (DEFINED CPACK_GENERATOR)
21+ return ()
22+ endif ()
23+
24+ # iOS will get the platform name of Darwin if we dont change it here
25+ if (IOS)
26+ set (CPACK_SYSTEM_NAME "iOS" )
27+ endif ()
28+
29+ set (CPACK_GENERATOR "ZIP" )
30+ if (NOT DEFINED FIREBASE_CPP_VERSION OR FIREBASE_CPP_VERSION STREQUAL "" )
31+ # Parse the version number from the json file.
32+ file (STRINGS ${FIREBASE_CPP_SDK_ROOT_DIR} /cpp_sdk_version.json version_file)
33+ string (REGEX MATCH "[0-9\. ]+" FIREBASE_CPP_VERSION "${version_file} " )
34+ endif ()
35+ set (CPACK_PACKAGE_VERSION "${FIREBASE_CPP_VERSION} " )
36+ set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0) # DO NOT pack the root directory.
37+
38+ include (CPack)
39+
40+ if (ANDROID)
41+ set (FIREBASE_LIB_CONFIG_PATH "android" )
42+ elseif (IOS)
43+ set (FIREBASE_LIB_CONFIG_PATH "ios" )
44+ elseif (MSVC )
45+ set (FIREBASE_LIB_CONFIG_PATH "windows" )
46+ elseif (APPLE )
47+ set (FIREBASE_LIB_CONFIG_PATH "darwin" )
48+ else ()
49+ set (FIREBASE_LIB_CONFIG_PATH "linux" )
50+ endif ()
51+ endif ()
52+
53+ # Packs the given target library into the libs folder, under the correct config
54+ # and given subdirectory.
55+ function (cpp_pack_library TARGET SUBDIRECTORY)
56+ if (NOT ${FIREBASE_CPP_BUILD_PACKAGE} )
57+ return ()
58+ endif ()
59+
60+ install (
61+ TARGETS "${TARGET} "
62+ ARCHIVE DESTINATION "libs/${FIREBASE_LIB_CONFIG_PATH} /${SUBDIRECTORY} "
63+ )
64+ endfunction ()
65+
66+ # Packs the given file into the libs folder, under the correct config
67+ # and given subdirectory.
68+ function (cpp_pack_library_file FILE_TO_PACK SUBDIRECTORY)
69+ cpp_pack_file(${FILE_TO_PACK}
70+ "libs/${FIREBASE_LIB_CONFIG_PATH} /${SUBDIRECTORY} " )
71+ endfunction ()
72+
73+ # Packs the given file into the given destination.
74+ function (cpp_pack_file FILE_TO_PACK DESTINATION )
75+ if (NOT ${FIREBASE_CPP_BUILD_PACKAGE} )
76+ return ()
77+ endif ()
78+
79+ # Get the real file path, for cases like symlinks.
80+ get_filename_component (path_to_file ${FILE_TO_PACK} REALPATH)
81+
82+ install (
83+ FILES ${path_to_file}
84+ DESTINATION ${DESTINATION}
85+ )
86+ endfunction ()
87+
88+ # Packs the given directory into the given destination.
89+ function (cpp_pack_dir DIR_TO_PACK DESTINATION )
90+ if (NOT ${FIREBASE_CPP_BUILD_PACKAGE} )
91+ return ()
92+ endif ()
93+
94+ install (
95+ DIRECTORY ${DIR_TO_PACK}
96+ DESTINATION ${DESTINATION}
97+ )
98+ endfunction ()
0 commit comments