Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

packaging c++ program using boost libraries with cmake/cpack

I have written a simple c++ program which use boost that I want to deploy on machines of same architecture with any linux flavor (for the time being) that may or may not have some boost versions installed. I'm new to deployment but tried to read docs and come up with a CMakeLists.txt which looks like :

cmake_minimum_required(VERSION 2.8)
project( myprog )
FIND_PACKAGE( Boost 1.50 COMPONENTS thread system chrono program_options REQUIRED )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
add_executable( myprog myprog.cpp )
target_link_libraries( myprog -lpthread -lboost_system -lboost_chrono -lboost_program_options )

INSTALL( TARGETS myprog DESTINATION . )
SET( CPACK_GENERATOR "TGZ")
INCLUDE( CPack )

Everything compile and run fine, but packaging (make package) only package the executable and not the dependent boost libraries ".so"

When I run : ldd myprog it tells me it depends on : linux-vdso.so, libpthread.so, libboost_system.so, libboost_chrono.so, libboost_program_options.so libstdc++.so libgcc_s.so libc.so librt.so libm.so

Those are the shared libraries I want to pack (maybe I don't need to pack the standard ones)

How can I tell cmake to grab the correct shared object libraries, and put them next to the executable so that the user only has to untar the folder and launch executable without any installation ?

Static linking is not an option here as I will have a bunch of executables that will use the same boost libraries, and there may also be some license issues with statically linking against libgcc.

like image 852
darkblue Avatar asked Oct 01 '14 13:10

darkblue


1 Answers

on Ubuntu, perhaps standard way to packaging is following the DEBIAN rules:

Instead of re-distribute so files, specify dependency by setting CPACK_DEBIAN_PACKAGE_DEPENDS before include CPack, take look at this example:

https://github.com/thomas-moulard/visp-deb/blob/master/CMakeModules/CPackConfigDeb.cmake

dpkg will install dependent packages automatically for you.

like image 194
TingQian LI Avatar answered Oct 04 '22 01:10

TingQian LI