• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# support creating some basic binpkgs via `make package`
2set(CPACK_SET_DESTDIR ON)
3set(CPACK_GENERATOR TGZ;DEB)
4
5FIND_PROGRAM(RPMBUILD_CMD rpmbuild)
6if (RPMBUILD_CMD)
7	set(CPACK_PACKAGE_RELOCATABLE OFF)
8	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")
10endif()
11
12# Add these for CentOS 7
13set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
14	/lib
15	/lib/udev
16	/lib/udev/rules.d
17	/usr/sbin
18	/usr/lib/python2.7
19	/usr/lib/python2.7/site-packages
20	/usr/lib/pkgconfig
21	/usr/lib64/pkgconfig
22)
23
24set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
25set(CPACK_PACKAGE_VERSION_MAJOR ${LIBIIO_VERSION_MAJOR})
26set(CPACK_PACKAGE_VERSION_MINOR ${LIBIIO_VERSION_MINOR})
27set(CPACK_PACKAGE_VERSION_PATCH g${LIBIIO_VERSION_GIT})
28set(CPACK_BUNDLE_NAME libiio)
29set(CPACK_PACKAGE_VERSION ${LIBIIO_VERSION})
30# debian specific package settings
31set(CPACK_PACKAGE_CONTACT "Engineerzone <https://ez.analog.com/community/linux-device-drivers>")
32
33option(DEB_DETECT_DEPENDENCIES "Detect dependencies for .deb packages" OFF)
34
35# if we are going to be looking for things, make sure we have the utilities
36if(DEB_DETECT_DEPENDENCIES)
37	FIND_PROGRAM(DPKG_CMD dpkg)
38	FIND_PROGRAM(DPKGQ_CMD dpkg-query)
39endif()
40
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
43if(DEB_DETECT_DEPENDENCIES AND DPKG_CMD AND DPKGQ_CMD)
44	message(STATUS "querying installed packages on system for dependancies")
45	execute_process(COMMAND "${DPKG_CMD}" --print-architecture
46		OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
47		OUTPUT_STRIP_TRAILING_WHITESPACE)
48	# don't add a package dependancy if it is not installed locally
49	# these should be the debian package names
50	set(PACKAGES "libc6")
51	if (WITH_LOCAL_BACKEND)
52		set(PACKAGES "${PACKAGES} libaio")
53	endif()
54	if(HAVE_AVAHI)
55		set(PACKAGES "${PACKAGES} libavahi-client libavahi-common")
56	endif()
57	if(WITH_USB_BACKEND)
58		set(PACKAGES "${PACKAGES} libusb-1")
59	endif()
60	if(WITH_XML_BACKEND)
61		set(PACKAGES "${PACKAGES} libxml2")
62	endif()
63	if(WITH_SERIAL_BACKEND)
64		set(PACKAGES "${PACKAGES} libserialport0")
65	endif()
66	# find the version of the installed package, which is hard to do in
67	# cmake first, turn the list into an list (seperated 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
74		execute_process(COMMAND "${DPKG_CMD}" -l ${package}*
75			OUTPUT_VARIABLE DPKG_PACKAGES)
76		# returns a string, in a format:
77		# ii  libxml2:amd64  2.9.4+dfsg1- amd64 GNOME XML library
78		# 'ii' means installed - which is what we are looking for
79		STRING(REGEX MATCHALL "ii  ${package}[a-z0-9A-Z.-]*"
80				DPKG_INSTALLED_PACKAGES ${DPKG_PACKAGES})
81		# get rid of the 'ii', and split things up, so we can look
82		# at the name
83		STRING(REGEX REPLACE "ii  " ";" NAME_INSTALLED_PACKAGES
84			${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})
90			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 dependancy
107				set(CPACK_DEBIAN_PACKAGE_DEPENDS
108					"${CPACK_DEBIAN_PACKAGE_DEPENDS}"
109					"${match} (>= ${DPKGQ_VER}), ")
110			endif()
111		endforeach(match)
112	endforeach(package)
113	# remove the dangling end comma
114	string(REGEX REPLACE ", $" "" CPACK_DEBIAN_PACKAGE_DEPENDS
115		${CPACK_DEBIAN_PACKAGE_DEPENDS})
116else()
117	# assume everything is turned on, and running on a modern OS
118	set(CPACK_DEBIAN_PACKAGE_DEPENDS "libaio (>= 0.3.109), libavahi-client (>= 0.6.31), libavahi-common (>= 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")
120endif()
121
122message(STATUS "Package dependencies (.deb): " ${CPACK_DEBIAN_PACKAGE_DEPENDS})
123if (CPACK_RPM_PACKAGE_REQUIRES)
124	message(STATUS "Package dependencies (.rpm): " ${CPACK_RPM_PACKAGE_REQUIRES})
125endif()
126
127if(${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)
139endif()
140include(CPack)
141