11# support creating some basic binpkgs via `make package`
22set (CPACK_SET_DESTDIR ON )
3- set (CPACK_GENERATOR TGZ;DEB )
3+ set (CPACK_GENERATOR TGZ)
44
5- FIND_PROGRAM (RPMBUILD_CMD rpmbuild)
6- if (RPMBUILD_CMD)
7- set (CPACK_PACKAGE_RELOCATABLE OFF )
5+ # Top level settings
6+ set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
7+ set (CPACK_PACKAGE_VERSION_MAJOR ${LIBIIO_VERSION_MAJOR} )
8+ set (CPACK_PACKAGE_VERSION_MINOR ${LIBIIO_VERSION_MINOR} )
9+ set (CPACK_PACKAGE_VERSION_PATCH g${LIBIIO_VERSION_GIT} )
10+ set (CPACK_BUNDLE_NAME libiio)
11+ set (CPACK_PACKAGE_VERSION ${LIBIIO_VERSION} )
12+
13+ # Determine the distribution we are on
14+ file (STRINGS /etc/os-release distro REGEX "^NAME=" )
15+ string (REGEX REPLACE "NAME=\" (.*)\" " "\\ 1" distro "${distro} " )
16+ file (STRINGS /etc/os-release disversion REGEX "^VERSION_ID=" )
17+ string (REGEX REPLACE "VERSION_ID=\" (.*)\" " "\\ 1" disversion "${disversion} " )
18+
19+ if (distro MATCHES "\\ .*Ubuntu\\ .*" )
20+ set (CPACK_GENERATOR ${CPACK_GENERATOR} ;DEB)
21+ elseif (distro MATCHES "\\ .*Debian\\ .*" )
22+ set (CPACK_GENERATOR ${CPACK_GENERATOR} ;DEB)
23+ elseif (distro MATCHES "\\ .*Fedora\\ .*" )
24+ set (CPACK_GENERATOR ${CPACK_GENERATOR} ;RPM)
25+ elseif (distro MATCHES "\\ .*CentOS\\ .*" )
826 set (CPACK_GENERATOR ${CPACK_GENERATOR} ;RPM)
9- set (CPACK_RPM_PACKAGE_REQUIRES "libaio >= 0.3.107, avahi >= 0.6.25, libusb1 >= 1.0.9, libxml2 >= 2.7.6" )
27+ elseif (distro MATCHES "\\ .*SUSE\\ .*" )
28+ set (CPACK_GENERATOR ${CPACK_GENERATOR} ;RPM)
29+ else ()
30+ message (STATUS "found unknown distribution ${distro} , Version : ${disversion} " )
31+ message (FATAL_ERROR "please report an error to https:\\ /\\ /github.com\\ /analogdevicesinc\\ /libiio\\ /issues" )
32+ endif ()
33+
34+ if (CPACK_GENERATOR MATCHES "RPM" )
35+ FIND_PROGRAM (RPMBUILD rpmbuild)
36+ FIND_PROGRAM (RPM_CMD rpm)
37+ set (CPACK_PACKAGE_RELOCATABLE OFF )
38+ if (NOT RPMBUILD)
39+ message (FATAL_ERROR "To build packages, please install rpmbuild" )
40+ elseif (NOT RPM_CMD)
41+ message (STATUS "assuming default package versions" )
42+ else ()
43+ message (STATUS "querying ${RPM_CMD} for package dependencies" )
44+ endif ()
1045
1146 # Add these for CentOS 7
1247 set (CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
@@ -21,121 +56,180 @@ if (RPMBUILD_CMD)
2156 )
2257endif ()
2358
24- set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
25- set (CPACK_PACKAGE_VERSION_MAJOR ${LIBIIO_VERSION_MAJOR} )
26- set (CPACK_PACKAGE_VERSION_MINOR ${LIBIIO_VERSION_MINOR} )
27- set (CPACK_PACKAGE_VERSION_PATCH g${LIBIIO_VERSION_GIT} )
28- set (CPACK_BUNDLE_NAME libiio)
29- set (CPACK_PACKAGE_VERSION ${LIBIIO_VERSION} )
30- # debian specific package settings
31- set (CPACK_PACKAGE_CONTACT "Engineerzone <https://ez.analog.com/community/linux-device-drivers>" )
32-
33- option (DEB_DETECT_DEPENDENCIES "Detect dependencies for .deb packages" OFF )
34-
3559# if we are going to be looking for things, make sure we have the utilities
36- if (DEB_DETECT_DEPENDENCIES )
60+ if (CPACK_GENERATOR MATCHES "DEB" )
3761 FIND_PROGRAM (DPKG_CMD dpkg)
3862 FIND_PROGRAM (DPKGQ_CMD dpkg-query)
63+ if (NOT DPKG_CMD)
64+ message (FATAL_ERROR "To build packages, please install dpkg" )
65+ elseif (NOT DPKGQ_CMD)
66+ message (STATUS "assuming default package versions" )
67+ else ()
68+ message (STATUS "querying ${DPKGQ_CMD} for package dependencies" )
69+ endif ()
70+ # debian specific package settings
71+ set (CPACK_PACKAGE_CONTACT "Engineerzone <https://ez.analog.com/community/linux-device-drivers>" )
3972endif ()
4073
41- # if we want to, and have the capabilities find what is needed,
42- # based on what backends are turned on and what libraries are installed
43- if (DEB_DETECT_DEPENDENCIES AND DPKG_CMD AND DPKGQ_CMD)
44- message (STATUS "querying installed packages on system for dependencies" )
45- execute_process (COMMAND "${DPKG_CMD} " --print-architecture
74+ if (NOT CMAKE_CROSSCOMPILING )
75+ execute_process (COMMAND "${DPKG_CMD} " --print-architecture
4676 OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
4777 OUTPUT_STRIP_TRAILING_WHITESPACE)
48- # don't add a package dependency if it is not installed locally
49- # these should be the debian package names
78+ else ()
79+ message (FATAL_ERROR "package building with cross compile not handled - please -DENABLE_PACKAGING=OFF" )
80+ endif ()
81+
82+ # don't add a package dependency if it is not installed locally
83+ # these should be the debian package names
84+ if (CPACK_GENERATOR MATCHES "DEB" )
5085 set (PACKAGES "libc6" )
51- if (WITH_LOCAL_BACKEND)
52- set (PACKAGES "${PACKAGES} libaio" )
86+ set (DEFAULT_DEB "libc6 (>= 2.17), " )
87+ elseif (CPACK_GENERATOR MATCHES "RPM" )
88+ set (PACKAGES "glibc" )
89+ set (DEFAULT_RPM "glibc >=2.17, " )
90+ endif ()
91+
92+ if (WITH_ZSTD)
93+ set (PACKAGES "${PACKAGES} libzstd" )
94+ if (CPACK_GENERATOR MATCHES "DEB" )
95+ set (DEFAULT_DEB "${DEFAULT_DEB} libzstd (>= 1.5.0), " )
96+ elseif (CPACK_GENERATOR MATCHES "RPM" )
97+ set (DEFAULT_RPM "${DEFAULT_RPM} libzstd >= 1.5.0, " )
98+ endif ()
99+ endif ()
100+ # libpthread.so is provided by libc6, so don't check NEED_THREADS
101+ if (WITH_LOCAL_BACKEND)
102+ set (PACKAGES "${PACKAGES} libaio" )
103+ if (CPACK_GENERATOR MATCHES "DEB" )
104+ set (DEFAULT_DEB "${DEFAULT_DEB} libaio (>= 0.3.109), " )
105+ elseif (CPACK_GENERATOR MATCHES "RPM" )
106+ set (DEFAULT_RPM "${DEFAULT_RPM} libaio >=0.3.109, " )
53107 endif ()
54- if (HAVE_AVAHI)
108+ # librt.so is provided by libc6 which is already included
109+ endif ()
110+ if (HAVE_AVAHI)
111+ if (CPACK_GENERATOR MATCHES "DEB" )
55112 set (PACKAGES "${PACKAGES} libavahi-client libavahi-common" )
113+ set (DEFAULT_DEB "${DEFAULT_DEB} libavahi-client3 (>= 0.6.31), libavahi-common3 (>= 0.6.31), " )
114+ elseif (CPACK_GENERATOR MATCHES "RPM" )
115+ set (PACKAGES "${PACKAGES} avahi" )
116+ set (DEFAULT_RPM "${DEFAULT_RPM} avahi >= 0.6.31, avahi-libs >= 0.6.31, " )
56117 endif ()
57- if (WITH_USB_BACKEND)
118+ endif ()
119+ if (WITH_USB_BACKEND)
120+ if (CPACK_GENERATOR MATCHES "DEB" )
58121 set (PACKAGES "${PACKAGES} libusb-1" )
122+ set (DEFAULT_DEB "${DEFAULT_DEB} libusb-1 (<2:1.0.5), " )
123+ elseif (CPACK_GENERATOR MATCHES "RPM" )
124+ set (PACKAGES "${PACKAGES} libusb" )
125+ set (DEFAULT_RPM "${DEFAULT_RPM} libuse>= 0.1.5, " )
59126 endif ()
60- if (WITH_XML_BACKEND)
61- set (PACKAGES "${PACKAGES} libxml2" )
62- endif ()
63- if (WITH_SERIAL_BACKEND)
127+ endif ()
128+ if (WITH_XML_BACKEND)
129+ set (PACKAGES "${PACKAGES} libxml2" )
130+ if (CPACK_GENERATOR MATCHES "DEB" )
131+ set (DEFAULT_DEB "${DEFAULT_DEB} libxml2 (>= 2.9.4), " )
132+ elseif (CPACK_GENERATOR MATCHES "RPM" )
133+ set (DEFAULT_RPM "${DEFAULT_RPM} libxml2 >= 2.9.4, " )
134+ endif ()
135+ endif ()
136+ if (WITH_SERIAL_BACKEND)
137+ if (CPACK_GENERATOR MATCHES "DEB" )
64138 set (PACKAGES "${PACKAGES} libserialport0" )
139+ set (DEFAULT_DEB "${DEFAULT_DEB} libserialport0 (>= 0.1.1), " )
140+ else ()
141+ set (PACKAGES "${PACKAGES} libserialport" )
142+ set (DEFAULT_RPM "${DEFAULT_RPM} libserialport >= 0.1.1, " )
65143 endif ()
66- # find the version of the installed package, which is hard to do in
67- # cmake first, turn the list into an list (separated by semicolons)
68- string (REGEX REPLACE " " ";" PACKAGES ${PACKAGES} )
69- # then iterate over each
70- foreach (package ${PACKAGES} )
71- # List packages matching given pattern ${package},
72- # key is the glob (*) at the end of the ${package} name,
73- # so we don't need to be so specific
144+ endif ()
145+
146+ # find the version of the installed package, which is hard to do in
147+ # cmake first, turn the list into a list (separated by semicolons)
148+ string (REGEX REPLACE " " ";" PACKAGES ${PACKAGES} )
149+ # then iterate over each
150+ foreach (package ${PACKAGES} )
151+ # List packages matching given pattern ${package},
152+ # key is the glob (*) at the end of the ${package} name,
153+ # so we don't need to be so specific
154+ if (CPACK_GENERATOR MATCHES "DEB" AND DPKG_CMD)
74155 execute_process (COMMAND "${DPKG_CMD} " -l ${package} *
75156 OUTPUT_VARIABLE DPKG_PACKAGES)
76157 # returns a string, in a format:
77158 # ii libxml2:amd64 2.9.4+dfsg1- amd64 GNOME XML library
78159 # 'ii' means installed - which is what we are looking for
79- STRING (REGEX MATCHALL "ii ${package} [a-z0-9A-Z.-]*"
160+ STRING (REGEX MATCHALL "ii ${package} [a-z0-9A-Z.-]*: ${CPACK_DEBIAN_PACKAGE_ARCHITECTURE} "
80161 DPKG_INSTALLED_PACKAGES ${DPKG_PACKAGES} )
81162 # get rid of the 'ii', and split things up, so we can look
82163 # at the name
83164 STRING (REGEX REPLACE "ii " ";" NAME_INSTALLED_PACKAGES
84165 ${DPKG_INSTALLED_PACKAGES} )
85- foreach (match ${NAME_INSTALLED_PACKAGES} )
86- # ignore packages marked as dev, debug,
87- # documentations, or utils
88- STRING (REGEX MATCHALL "dev|dbg|doc|utils" TEMP_TEST
89- ${match} )
166+ elseif (CPACK_GENERATOR MATCHES "RPM" AND RPM_CMD)
167+ execute_process (COMMAND "${RPM_CMD} " -qa --qf "%{n};" "${package} *"
168+ OUTPUT_VARIABLE NAME_INSTALLED_PACKAGES)
169+ else ()
170+ set (NAME_INSTALLED_PACKAGES ${package} )
171+ endif ()
172+ list (REMOVE_DUPLICATES NAME_INSTALLED_PACKAGES)
173+ string (STRIP "${NAME_INSTALLED_PACKAGES} " NAME_INSTALLED_PACKAGES)
174+ if (NAME_INSTALLED_PACKAGES STREQUAL "" )
175+ message (FATAL_ERROR "could not find ${package} installed" )
176+ endif ()
177+ foreach (match ${NAME_INSTALLED_PACKAGES} )
178+ # ignore packages marked as dev, debug,
179+ # documentations, utils, data or cross
180+ STRING (REGEX MATCHALL "-dev|-dbg|-doc|-lang|-extra|-data|-utils|-cross|-plugins|-python|-headers|-gobject|-locale|-tools|glibc-common|libusbmuxd|libusbx" TEMP_TEST
181+ ${match} )
182+ if (NOT "${TEMP_TEST} " STREQUAL "" )
183+ continue ()
184+ endif ()
185+ if (CPACK_GENERATOR MATCHES "DEB" AND DPKGQ_CMD)
186+ # find the actual version, executes:
187+ # dpkg-query --showformat='\${Version}'
188+ # --show libusb-1.0-0
189+ execute_process (COMMAND "${DPKGQ_CMD} "
190+ --showformat='\${Version} '
191+ --show "${match} "
192+ OUTPUT_VARIABLE DPKGQ_VER)
193+ # debian standard is package_ver-debian_ver,
194+ # "'2.9.4+dfsg1-2.1'"
195+ # ignore patches and debian suffix version, and
196+ # remove single quote
197+ string (REGEX REPLACE "[+-][a-z0-9A-Z.]*" "" DPKGQ_VER ${DPKGQ_VER} )
198+ string (REGEX REPLACE "'" "" DPKGQ_VER ${DPKGQ_VER} )
199+ # build the string for the Debian dependency
200+ STRING (REGEX REPLACE ":.*" "" TEMP_TEST ${match} )
201+ set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS} "
202+ "${TEMP_TEST} (>= ${DPKGQ_VER} ), " )
203+ elseif (CPACK_GENERATOR MATCHES "RPM" AND RPM_CMD)
204+ # find the actual version, executes:
205+ # rpm -qp --queryformat '%{VERSION}' libusb1
206+ execute_process (COMMAND "${RPM_CMD} " -q --queryformat '%{VERSION }' ${match}
207+ OUTPUT_VARIABLE RPM_VER)
208+ STRING (REGEX REPLACE "'" "" RPM_VER ${RPM_VER} )
209+ set (CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES} "
210+ "${match} >= ${RPM_VER} , " )
211+ endif ()
90212 if ("${TEMP_TEST} " STREQUAL "" )
91- # find the actual version, executes:
92- # dpkg-query --showformat='\${Version}'
93- # --show libusb-1.0-0
94- execute_process (COMMAND "${DPKGQ_CMD} "
95- --showformat='\${Version} '
96- --show "${match} "
97- OUTPUT_VARIABLE DPKGQ_VER)
98- # debian standard is package_ver-debian_ver,
99- # "'2.9.4+dfsg1-2.1'"
100- # ignore patches and debian suffix version, and
101- # remove single quote
102- string (REGEX REPLACE "[+-][a-z0-9A-Z.]*" ""
103- DPKGQ_VER ${DPKGQ_VER} )
104- string (REGEX REPLACE "'" "" DPKGQ_VER
105- ${DPKGQ_VER} )
106- # build the string for the Debian dependency
107- set (CPACK_DEBIAN_PACKAGE_DEPENDS
108- "${CPACK_DEBIAN_PACKAGE_DEPENDS} "
109- "${match} (>= ${DPKGQ_VER} ), " )
213+ continue ()
110214 endif ()
111- endforeach (match)
112- endforeach (package)
215+ endforeach (match)
216+ endforeach (package)
217+
218+ if (CPACK_GENERATOR MATCHES "DEB" )
219+ if (NOT DPKGQ_CMD)
220+ set (CPACK_DEBIAN_PACKAGE_DEPENDS "${DEFAULT_DEB} " )
221+ endif ()
113222 # remove the dangling end comma
114223 string (REGEX REPLACE ", $" "" CPACK_DEBIAN_PACKAGE_DEPENDS
115224 ${CPACK_DEBIAN_PACKAGE_DEPENDS} )
116- else ()
117- # assume everything is turned on, and running on a modern OS
118- set (CPACK_DEBIAN_PACKAGE_DEPENDS "libaio1 (>= 0.3.109), libavahi-client3 (>= 0.6.31), libavahi-common3 (>= 0.6.31), libavahi-common-data (>= 0.6.31), libc6 (>= 2.19), libusb-1.0-0 (>= 2:1.0.17), libxml2 (>= 2.9.1), libserialport0 (>=0.1.1)" )
119- message (STATUS "Using default dependencies for packaging" )
120- endif ()
121-
122- message (STATUS "Package dependencies (.deb): " ${CPACK_DEBIAN_PACKAGE_DEPENDS} )
123- if (CPACK_RPM_PACKAGE_REQUIRES)
124- message (STATUS "Package dependencies (.rpm): " ${CPACK_RPM_PACKAGE_REQUIRES} )
125- endif ()
126-
127- if (${CMAKE_MAJOR_VERSION} LESS 3)
128- # old versions of cmake dont include this, but the same vintage of dpkg requires it
129- IF (NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
130- FIND_PROGRAM (DPKG_CMD dpkg)
131- IF (NOT DPKG_CMD)
132- MESSAGE (STATUS "Can not find dpkg in your path, default to i386." )
133- SET (CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
134- ENDIF (NOT DPKG_CMD)
135- EXECUTE_PROCESS (COMMAND "${DPKG_CMD} " --print-architecture
136- OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
137- OUTPUT_STRIP_TRAILING_WHITESPACE)
138- ENDIF (NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
225+ message (STATUS "Dependencies (.deb): " ${CPACK_DEBIAN_PACKAGE_DEPENDS} )
226+ elseif (CPACK_GENERATOR MATCHES "RPM" )
227+ if (NOT RPM_CMD)
228+ set (CPACK_RPM_PACKAGE_REQUIRES "${DEFAULT_RPM} " )
229+ endif ()
230+ string (REGEX REPLACE ", $" "" CPACK_RPM_PACKAGE_REQUIRES
231+ ${CPACK_RPM_PACKAGE_REQUIRES} )
232+ message (STATUS "Dependencies (.rpm): " ${CPACK_RPM_PACKAGE_REQUIRES} )
139233endif ()
140234
141235# Make sure the generated .deb cannot be installed alongside the Debian ones
0 commit comments