Reputation: 1715
Is there a way to create install and package (I need a deb package) targets using CMake, where install path is read from some configuration file (e.g. /etc/myconfig.cfg) in install-time. I can do it using shell scripts, but I'd like to use CMake's and CPack's possibilities. I'd like a generated deb package to read myconfig.cfg in install time
A very simple example of start CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR)
project("My project")
add_executable(a.out main.cpp)
/etc/myconfig.cfg:
set(INSTALL_PATH "/var/path1")
or:
INSTALL_PATH = /var/path1
or something similar.
Upvotes: 0
Views: 1383
Reputation: 854
I realise this question is as old as the hills...
What you're proposing isn't possible with Apt (or RPM, or numerous other package types) - and so cpack can't provide the facilities either.
The reasoning being that the package is supposed to describe the things it will install into the system - and most critically, the things it'll remove if the package is uninstalled, or if a subsequent version of it no longer include files in the older version. You can understand that this wouldn't be possible if a config file could alter the way the package landed on the system because after install the config could change, making the on-going maintenance of files impossible.
What you're asking for is somewhat "non standard" for a package, and somewhat problematic for running systems. Instead, you have a number of options...
Personally, I'd recommend option 3. Option 1 is a lot of work, Option 2 is "messy" in so much as the administrator will be left with a load of files and directories which aren't owned by any package, making uninstall difficult. It also encourages the creation of a handful of Bash scripts which are hard to maintain and most likely won't do what they're supposed to in all the places your package gets deployed.
The Third option leaves the sysadmin in control, and they'll have the knowledge of what's on their system, what to remove if they need to, etc.
Upvotes: 0
Reputation: 2035
Why not use CMAKE_INSTALL_PREFIX? For example:
cmake -DCMAKE_INSTALL_PREFIX=/usr/boob ..
Upvotes: 1