[CMake] Setting target destination and rpath per generator
Eric Noulard
eric.noulard at gmail.com
Tue Feb 15 04:00:17 EST 2011
2011/2/15 Daryl N <darylhouse2004 at yahoo.com>:
> Hi,
>
> I have a question on the use of CPack. I have CMake setup to generate
> binaries and shared libraries. Up until now I have only created a TGZ with
> rpath set to ".". This has worked nicely, but now I would like to create a
> Debian package for proper installation. I have added DEB to CPACK_GENERATOR
> and I've created my own cpack_config.cmake file. My goal is:
>
> 1. Run cmake/make package once and create the tar.gz file with all exe/libs
> in the root folder of the tar.gz file with rpath set to ".".
> 2. Create new .deb package with exes in /usr/local/bin and libs in
> /usr/local/lib. Alternatively, since files are private, all could be put in
> /usr/local/<some folder>.
>
> I've attempted this by creating my own cpack_config.cmake file to try to
> override some settings per generator. Some observations:
>
> 1. I've been unable to set the install(<target> DESTINATION) path per
> generator in my cpack_config.cmake file. Whatever the variable is set to
> when the install(...) is processed in the CMakeLists.txt file is what is
> used for all generators. Just want to confirm changing this isn't an option
> per generator.
>
> The above has prevented me from having my install lines like:
> install(<target> DESTINATION ${BIN_PATH})
> install(<target> DESTINATION ${LIB_PATH})
> and then setting BIN_PATH to bin and LIB_PATH to lib for DEB, but setting
> them to "." for TGZ, since I can't change the variable in
> .
I suppose cpack_config.cmake is your CPACK_PROJECT_CONFIG_FILE.
As far as I know you cannot change install rules on "CPack generator basis".
install rules belongs to CMakeLists.txt and they are evaluated at CMake-time
(not CPack-time).
cpack_config.cmake is evaluated at CPack-time, i.e. when CPack runs.
You can do CPack-generator specific actions in this file.
(like setting CPACK_SET_DESTDIR OFF or ON or changing
CPACK_PACKAGING_INSTALL_PREFIX etc...)
I did not tried playing with rpath but may be you can
if(CPACK_GENERATOR MATCHES "TGZ")
set(CMAKE_INSTALL_RPATH ".")
set(CPACK_SET_DESTDIR "OFF")
endif(CPACK_GENERATOR MATCHES "TGZ")
if(CPACK_GENERATOR MATCHES "DEB")
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local/<somefolder>")
endif(CPACK_GENERATOR MATCHES "DEB")
> 2. I would also like to set the rpath per generator. So the targets in the
> TGZ only look in "." while the DEB installed targets only look in
> /usr/local/<some folder>. But I haven't been able to update the rpath per
> generator in cpack_config.cmake. I've tried both setting
> CMAKE_INSTALL_RPATH and using set_target_properties(... PROPERTIES
> INSTALL_RPATH). Again, I'm assuming this can't be changed at CPack time.
I don't know whether if CMAKE_INSTALL_RPATH can be changed at CPack time
(as I suggested in my previous example) you'll have to try and
may be verify in the CMake source code in order to check when it is handled.
Whatever the current status,
I don't see why it couldn't be handled at CPack time
(but I may be missing something).
>Do I need to run cpack
> separately changing the variables before hand? I suppose that would mean 2
> builds cycles also, once for each generator.
2 build cycles will definitely work.
However if you gives us more information on what's inside your
"cpack_config.cmake"
what works what does not work with it, may be we can see if it it can
be done in a single build.
I think the main issue is the fact that as far as I understand your
need you want
to put all files (libs, exe) in a single folder for the TGZ and have
prefix+/lib, prefix+/bin
in the DEB case?
Changing the prefix is easy but adding (or removing) the extra /lib
and /bin I don't
currently know how to do that. Why won't you keep the lib and bin
suffix in the TGZ case?
--
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
More information about the CMake
mailing list