Finding a writable directory location for installing Python modules

Does CMake / CPack provide a generic way of identifying the %APPDATA% library on a user’s machine during installation?

I ask because I’m trying to install a large scriptable application which provides various standard Python 2.7 modules with .py files as interfaces to them.

Most of the application is in C++, so of course the executables, DLLs and so on will typically go into C:\Program Files. But I can’t put the .py files in there, since when they’re opened Python immediately compiles them into .pyc files and tries to put them alongside the .py source files [N.B. the location for the .pyc files can in fact be specified for Python 3, but not Python 2]. Therefore the .py files need to be put in a writable location, for example C:\Program Data or (preferably) C:\Users<username>\AppData\Local.

But I can’t figure out how to point CMake at this directory, when I don’t know what the name of the user who ultimately does the installing will be. I don’t want to have to install the whole application, .exe and .dll files and all, in a writable location since that defeats the whole security philosophy of having executables installed in non-writable locations.

You can retrieve environment variable values using syntax $ENV{var}. For example $ENV{APPDATA}.

For more information, see Variable References.

Ah, thank you. Exactly what I needed.