Building/Configuring with CMake

General talk about packaging procedures and packages.
Post Reply
marcxjo
Posts: 27
Joined: 1. Apr 2014, 18:56

Building/Configuring with CMake

Post by marcxjo »

I'm just getting into slkbuilds, but so far they seem pretty straightforward. That said, configuring programs built with CMake is tripping me up. So far, this is holding me up from releasing packages for Guayadeque (an excellent lightweight but feature-rich media player) and an updated Whisker Menu (what can I say? I really wanted the custom menu support :ugeek:). The ones I've built for myself are definitely not ready for primetime.

I think I've found CMake variables that correspond to all the required configure script options except one. Here are the original ones for quick reference.

Code: Select all

./configure \
           --prefix=/usr \
           --libdir=/usr/lib${LIBDIRSUFFIX} \
           --localstatedir=/var \
           --sysconfdir=/etc \
           --mandir=/usr/man
And here are the ones that seem to correspond in CMake after scouring the CMake Wiki, a few slkbuilds (thanks djemos!) and the rest of the internet for documentation:

Code: Select all

cmake \
-DCMAKE_INSTALL_PREFIX=/usr \
-DDLIB_INSTALL_DIR:PATH=/usr/lib${LIBDIRSUFFIX} \
-DLIB_SUFFIX=${LIBDIRSUFFIX} \
-(localstatedir variable)
-DSYSCONF_INSTALL_DIR:PATH=/etc \
-DMAN_INSTALL_DIR:PATH=/usr/man
So now two questions arise. First off, do I actually have to set LIB_SUFFIX in order to set LIB_INSTALL_DIR properly? This doesn't seem to be the case with Make, but I admittedly know little about CMake or build systems in general at this stage.

Second, you'll notice above that I can't seem to find any variable that corresponds to the localstatedir option. Anyone know of a viable equivalent for CMake? It's not in their documentation that I can find, so I'm not too optimistic that that it's particularly straightforward to come up with an equivalent in CMake.

I'd appreciate any input, including on whether I'm getting too pedantic here. I notice that not all slkbuilds for available packages, even in the official repos, cover all of the necessary variables, but I'd at least like to get this stuff down both for the sake of thoroughness and my own curiosity.
User avatar
gapan
Salix Wizard
Posts: 6241
Joined: 6. Jun 2009, 17:40

Re: Building/Configuring with CMake

Post by gapan »

No wonder you're confused, this is very tricky indeed...

First of all, forget what you wrote above. Those options may work for a certain package, but not for another. There is nothing that is global in the same sense that configure options are.

What you have to do, for each package individually, is to find out the options it supports.

One way to do it is to scan through the CMakeLists.txt file for variables manually. This is what I usually do (out of habit), but certainly not easy for the untrained eye, but in general variables have sane names and you can understand what they do. For example if you see a line like this:

Code: Select all

SET(ADM_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}")
that means that you can run cmake with a "-DCMAKE_INSTALL_PREFIX" option ("-D" is for "define"). Careful, you cannot define "ADM_INSTALL_DIR" directly like that from the cmake command line. That one is only set by cmake to whatever the CMAKE_INSTALL_PREFIX is set. For this particular example, it may be common to have a "MAKE_INSTALL_PREFIX" variable, but there could be cases where the same thing might be named something else, like just "INSTALL_PREFIX". You'll have to find out the hard way...

To save you the nuisance of scanning that file for variables manually, an automated way of discovering variables is to run ccmake. After you have entered the root directory of your source (where your CMakeLists.txt file is), do:

Code: Select all

mkdir build
cd build
ccmake ../
and then press "c". This gives a list of the "basic" options. If you then press "t", you'll go to advanced mode and see all of the options... You can quit with "q".

Here's a link with more details: http://clubjuggler.livejournal.com/138364.html
Image
Image
marcxjo
Posts: 27
Joined: 1. Apr 2014, 18:56

Re: Building/Configuring with CMake

Post by marcxjo »

:oops: I wonder if it's not a bit generous of you to say that that was "tricky," but it certainly helps me feel a bit less embarrassed! :lol:

Thank you, gapan, I definitely had no idea that CMake options weren't universal. I probably should have at least glanced at CMakeLists.txt a little longer before I went off asking silly questions.

That was a great explanation, though, and both your link and the pointer on ccmake helps a ton! It seems that Guayadeque is surprisingly more limited on the relevant types of options than I'd have expected. I'll send up a copy of my slkbuild for when I'm satisfied that I've done all I can to get it up to spec for comments and corrections. Thanks again!
User avatar
gapan
Salix Wizard
Posts: 6241
Joined: 6. Jun 2009, 17:40

Re: Building/Configuring with CMake

Post by gapan »

No, the question wasn't silly at all. I'm sure it troubles everyone that tries to understand cmake.

I should add that running

Code: Select all

cmake ../
before running

Code: Select all

ccmake ../
might reveal more options...
Image
Image
Post Reply