[CMake] How to detect whether CMake scripts are executing under / within CPack environment?

David Cole david.cole at kitware.com
Mon Dec 20 07:34:19 EST 2010


On Sun, Dec 19, 2010 at 3:50 PM, Mike McQuaid <mike at mikemcquaid.com> wrote:

> On 16 December 2010 08:34, Andreas Mohr <andi at lisas.de> wrote:
> > I'd like to know how to possibly detect this within CMake code.
>
> This works for me:
> INSTALL( CODE "
> IF( \${CMAKE_INSTALL_PREFIX} MATCHES .*/_CPack_Packages/.* )
> ....
> ENDIF( \${CMAKE_INSTALL_PREFIX} MATCHES .*/_CPack_Packages/.* )
> " )
>
> However, you then need to put all your CMake logic in INSTALL(CODE
> ...) logic. Either later tonight or tomorrow I'll post my suggestions
> to this list for possible patches I will try and get included to
> improve this situation as INSTALL(CODE ...) escaping isn't trivial.
>
> --
> Mike McQuaid
> http://mikemcquaid.com
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>


When you find yourself in the "must escape too much" situation in an
INSTALL(CODE scenario.... you should switch to writing out a script that you
then include with an INSTALL(SCRIPT command. They are absolutely equivalent,
except with CODE you specify the code inline when it does not need
significant escaping, or if it's just a line or two. If it does need lots of
escaping or is longer than 1-3 lines, I would say it should be the SCRIPT
form anyway.

And honestly, I think that Eric's suggestion of using a
CPACK_PROJECT_CONFIG_FILE is the way to go here. If you have one, CPack will
include it before running your install rules. You can use any sentinel you
like within that file: it will only ever be included by CPack, so if you're
in its context, then you know you're being run by CPack.


HTH,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20101220/332d98a7/attachment.htm>


More information about the CMake mailing list