[CMake] Working directory for install-time CMake scripts?

Kevin Ushey kevinushey at gmail.com
Sun Dec 17 16:37:44 EST 2017


Hi,

It's possible to request a CMake script to be run at installation time,
with e.g.

    install(SCRIPT <script>.cmake)

I think this is most commonly used for fixing up bundles generating during
install time (e.g. rpath munging or other muckery). Within such a script,
I'd like to execute a shell script that does the heavy lifting, e.g. within
the above script I might have:

    execute_process(COMMAND sh <script>.sh)

I'd like to have this bash script run within the install directory. It
seems like one can get this directory with e.g.

    $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}

but this sort of usage seems somewhat thinly documented.
https://cmake.org/cmake/help/v3.10/variable/CMAKE_INSTALL_PREFIX.html
suggests DESTDIR can be used when one is using 'make' to build the project,
but I'm guessing this may not be portable to other generators. For example,
NSIS suggests that the following build directory is used (
https://cmake.org/Wiki/CMake:CPackNSISAdvancedTips):


${CMAKE_BINARY_DIR}\_CPack_Packages\${CPACK_TOPLEVEL_TAG}\${CPACK_GENERATOR}\

For what it's worth, I'm trying this out on Linux when using CPack to
generate DEB/RPM packages, and all seems well so far, but I suspect there
may be a simpler, or more idiomatic, way to accomplish what I'm trying to
do.

tl;dr: Is there a portable way to get the path to the directory being used
during the install phase? Or do I need to rethink the way I'm approaching
this?

Thanks,
Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cmake.org/pipermail/cmake/attachments/20171217/03219e5b/attachment.html>


More information about the CMake mailing list