What I&#39;m trying to do: use cpack to turn a directory of python and shell files into a debian package.  The wrinkle: I want the package to install the python files into /usr/lib/python2.6/dist-packages/thingy and the shell scripts into /etc/sv/thingy, and I want to be able to run the entire build process without requiring superuser privileges.  In order to do this, I&#39;m using a python virtualenv (<a href="http://pypi.python.org/pypi/virtualenv">http://pypi.python.org/pypi/virtualenv</a>) as the build destination.<br>

<br>The problem: cpack keeps prepending &#39;/usr&#39; to the install paths in install_manifest.txt, and hence in the generated deb package.<br><br>The cmake file, slightly edited for clarity:<br><br><div style="margin-left: 40px;">

PROJECT(thingy)<br><br>SET(VIRTUAL_ENV $ENV{VIRTUAL_ENV})<br>IF(VIRTUAL_ENV)<br>  MESSAGE(STATUS &quot;Detected a python virtualenv in use, setting install prefix to ${VIRTUAL_ENV}&quot;)<br>  SET(CMAKE_INSTALL_PREFIX ${VIRTUAL_ENV} )<br>

ELSE(VIRTUAL_ENV)<br>  SET(CMAKE_INSTALL_PREFIX / )<br>ENDIF(VIRTUAL_ENV)<br><br>EXEC_PROGRAM(&quot;python -c &#39;from sys import version; print version[:3]&#39;&quot; OUTPUT_VARIABLE PYTHON_VERSION)<br>SET(thingy_python_install_DIR usr/lib/python${PYTHON_VERSION}/dist-packages/herd)<br>

<br>SET(thingy_python_SOURCES __init__.py main.py)<br>SET(thingy_service_DIR rc )<br><br>INSTALL(FILES ${thingy_python_SOURCES} DESTINATION ${thingy_python_install_DIR})<br>INSTALL(DIRECTORY ${thingy_service_DIR} DESTINATION etc <br>

        FILE_PERMISSIONS WORLD_EXECUTE WORLD_READ<br>        PATTERN &quot;supervise&quot; EXCLUDE )<br><br># cpack comes at the end<br>SET(CPACK_GENERATOR &quot;DEB&quot;)<br>SET(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)<br>SET(CPACK_PACKAGE_NAME &quot;thingy&quot;)<br>

SET(CPACK_PACKAGE_CONTACT &quot;<a href="mailto:memory@blank.org">memory@blank.org</a>&quot;)<br>SET(CPACK_PACKAGE_VENDOR &quot;<a href="http://blank.org">blank.org</a>&quot;)<br>SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY &quot;Thingy Runner&quot;)<br>

SET(CPACK_PACKAGE_VERSION_MAJOR &quot;0&quot;)<br>SET(CPACK_PACKAGE_VERSION_MINOR &quot;2&quot;)<br>SET(CPACK_PACKAGE_INSTALL_DIRECTORY &quot;/&quot;)<br>SET(CPACK_TOPLEVEL_TAG &quot;/&quot;)<br>SET(CPACK_DEBIAN_PACKAGE_NAME &quot;thingy&quot;)<br>

SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE &quot;amd64&quot;)<br>SET(CPACK_DEBIAN_PACKAGE_DEPENDS &quot;python&quot;)<br>SET(CPACK_DEBIAN_PACKAGE_MAINTAINER &quot;<a href="mailto:memory@blank.org">memory@blank.org</a>&quot;)<br>

SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA <br>  &quot;${CMAKE_CURRENT_SOURCE_DIR}/debian/postinst;${CMAKE_CURRENT_SOURCE_DIR}/debian/postrm;&quot; <br>)<br>include(CPack)<br clear="all"></div><br>What this produces is a correct direct installation (the files end up in $VIRTUAL_ENV/usr/lib/python2.6), but a broken package:<br>

<br><div style="margin-left: 40px;">$ VIRTUAL_ENV=/home/memory/sandbox cmake ..<br>[standard output elided]<br>-- Detected a python virtualenv in use, setting install prefix to /home/memory/sandbox<br>-- Configuring done<br>

-- Generating done<br>-- Build files have been written to: /home/memory/thingy/build<br><br>$ make install<br>Install the project...<br>-- Install configuration: &quot;&quot;<br>-- Installing: /home/memory/sandbox/usr/lib/python2.6/dist-packages/thingy/__init__.py<br>

-- Installing: /home/memory/sandbox/usr/lib/python2.6/dist-packages/thingy/main.py<br>-- Installing: /home/memory/sandbox/etc/rc<br>-- Installing: /home/memory/sandbox/etc/rc/run<br><br>$ make package<br>Run CPack packaging tool...<br>

CPack: Create package using DEB<br>CPack: Install projects<br>CPack: - Run preinstall target for: thingy<br>CPack: - Install project: thingy<br>CPack: Compress package<br>CPack: Finalize package<br>CPack: Package /home/memory/thingy/build/thingy-0.2-Linux.deb generated.<br>

<br>$ dpkg-deb -c thingy-0.2.0-Linux.deb <br>drwxr-xr-x memory/memory     0 2011-02-10 21:23 ./usr/<br>drwxr-xr-x memory/memory     0 2011-02-10 21:23 ./usr/usr/<br>drwxr-xr-x memory/memory     0 2011-02-10 21:23 ./usr/usr/lib/<br>

drwxr-xr-x memory/memory     0 2011-02-10 21:23 ./usr/usr/lib/python2.6/<br>drwxr-xr-x memory/memory     0 2011-02-10 21:23 ./usr/usr/lib/python2.6/dist-packages/<br>drwxr-xr-x memory/memory     0 2011-02-10 21:23 ./usr/usr/lib/python2.6/dist-packages/thingy/<br>

-rw-r--r-- memory/memory 13054 2011-02-03 20:52 ./usr/usr/lib/python2.6/dist-packages/thingy/job.py<br>-rw-r--r-- memory/memory    22 2011-02-03 20:52 ./usr/usr/lib/python2.6/dist-packages/thingy/__init__.py<br>-rw-r--r-- memory/memory  1063 2011-02-03 20:52 ./usr/usr/lib/python2.6/dist-packages/thingy/control.py<br>

-rw-r--r-- memory/memory  5347 2011-02-03 20:52 ./usr/usr/lib/python2.6/dist-packages/thingy/main.py<br>-rw-r--r-- memory/memory  2971 2011-02-03 20:52 ./usr/usr/lib/python2.6/dist-packages/thingy/util.py  <br>drwxr-xr-x memory/memory     0 2011-02-10 21:23 ./usr/etc/<br>

drwxr-xr-x memory/memory     0 2011-02-10 21:23 ./usr/etc/rc/<br>-r-xr-xr-x memory/memory   595 2011-02-10 01:15 ./usr/etc/rc/run<br><br></div>Note the extra /usr prepended to all of the paths inside the debian package.  If I build the package <i>without</i> $VIRTUAL_ENV being set, the same thing happens.<br>

<br>I&#39;ve trawled a bit through the various CPack module files, but can&#39;t see where that /usr is coming from.<br><br>A helpful person on the cmake IRC channel suggested setting CPACK_SET_DESTDIR to ON: this solves the problem only in the case of $VIRTUAL_ENV being unset; if it&#39;s set, the package ends up being installed into a duplicate of the install directory, ie:<br>

<br><div style="margin-left: 40px;">$ dpkg-deb -c herd-0.2.0-Linux.deb<br>drwxr-xr-x memory/memory     0 2011-02-10 21:32 ./home/<br>drwxr-xr-x memory/memory     0 2011-02-10 21:32 ./home/memory/<br>drwxr-xr-x memory/memory     0 2011-02-10 21:32 ./home/memory/sandbox/<br>

drwxr-xr-x memory/memory     0 2011-02-10 21:32 ./home/memory/sandbox/usr/<br>drwxr-xr-x memory/memory     0 2011-02-10 21:32 ./home/memory/sandbox/usr/lib/<br>drwxr-xr-x memory/memory     0 2011-02-10 21:32 ./home/memory/sandbox/usr/lib/python2.6/<br>

drwxr-xr-x memory/memory     0 2011-02-10 21:32 ./home/memory/sandbox/usr/lib/python2.6/dist-packages/<br>drwxr-xr-x memory/memory     0 2011-02-10 21:32 ./home/memory/sandbox/usr/lib/python2.6/dist-packages/herd/<br>-rw-r--r-- memory/memory    22 2011-02-03 20:52 ./home/memory/sandbox/usr/lib/python2.6/dist-packages/herd/__init__.py<br>

</div><br>So... where the heck is cpack picking up that /usr from?<br><br><br>-- <br>Everyone knows history moves in circles;<br>the surprise is how big the circles are.<br>  (--Greil Marcus)<br><br>