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

Mike McQuaid mike at mikemcquaid.com
Mon Dec 20 07:51:33 EST 2010


On 20 December 2010 12:34, David Cole <david.cole at kitware.com> wrote:
> On Sun, Dec 19, 2010 at 3:50 PM, Mike McQuaid <mike at mikemcquaid.com> wrote:
> 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.

That's a good suggestion and could do with being better documented
(like most of CPack)!

I still think the nicest solution would be to provide INSTALL(...
PACKAGE) or something similar so you can do this all easily and
visibly from your existing CMakeLists.txt files. That's my main
reservation with using too many external script files, it's not
obvious to someone reading the CMakeLists file what is actually
happening.

I'm happy to write a patch for this. Would this be accepted? Is this
the wrong approach? If you guide me to creating an acceptable one, I'd
be happy to write this.

I created a bug about this so this is probably a good point of discussion:
http://public.kitware.com/Bug/view.php?id=11142

-- 
Mike McQuaid
http://mikemcquaid.com


More information about the CMake mailing list