Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass variable to cpack?

Tags:

cmake

cpack

I have a cmake project which one of the install targets is a collection of files. This files change depending on the configuration (Release, Debug...). I would like to be able to install the files like so:

install(DIRECTORY $<TARGET_FILE_DIR:tgt>
    DESTINATION bin
    COMPONENT files)

But cmake does not support that. Generator variables do not apply to DIRECTORY. So I was wondering if there is a way to either save the directory somewhere. Either the cache or a file and then load it into cpack.

So I guess the question is how to pass a variable from cmake to cpack?

like image 916
Mac Avatar asked Feb 26 '16 08:02

Mac


1 Answers

This is a rather late answer, but I happened upon this question trying to solve a somewhat different problem that could also be summarized as: "How do I pass a variable to CPack?" In my case, I was making this call from a customized version of CPackDeb.cmake copied to my workspace:

find_program(OPKG_CMD NAMES opkg-build HINTS "${OPKG_HINT}")
#                                             ^^^^^^^^^^^^
#                                 This is what I wanted to pass to CPack 

I was setting OPKG_HINT in a file included from my top-level CMakeLists.txt, but it was not getting passed through to cpack; the above find_program() invocation was seeing an empty string for OPKG_HINT.

The solution turned out to be stupid simple: just prepend CPACK_ to the variable name!

If I do this in CMakeLists.txt:

set(CPACK_OPKG_HINT "${_sysroot_top}/aarch64-poky-linux/usr/bin")

then I can put this in my CPackDeb.cmake file and it works fine:

find_program(OPKG_CMD NAMES opkg-build HINTS "${CPACK_OPKG_HINT}")

Anyway, this wound up being a bit of an X-Y problem for the OP, but... if you really need to set a variable at CMake time in such a way that it's accessible to cpack, prefixing the variable name with CPACK_ seems to do the trick nicely...

like image 123
evadeflow Avatar answered Sep 22 '22 07:09

evadeflow