[CMake] How to set CPACK_PACKAGE_VERSION from a gengetopt configuration file

Eric Noulard eric.noulard at gmail.com
Mon Sep 21 06:17:55 EDT 2009


2009/9/21 Yegor Yefremov <yegor_sub1 at visionsystems.de>:
> Hello,
>
> I use gengetopt to generate command line parser for my application. The configuration file *.ggo also specifies programs version like this:
>
> # Name of your program
> package "hwtest" # don't use package if you're using automake
> # Version of your program
> version "1.2.1"   # don't use version if you're using automake
> ....
>
> I'd like to automatically extract these version numbers and assign them to
>
> CPACK_PACKAGE_VERSION_MAJOR, CPACK_PACKAGE_VERSION_MINOR and CPACK_PACKAGE_VERSION_PATCH
>
> What were the best solution for my problem?

I would say that the simplest solution is to keep those number in your
CMakeLists.txt
and use CONFIGURE_FILE(yourfile.ggo.in yourfile.ggo @ONLY)

yourfile.ggo.in could then contain:

# Name of your program
package "hwtest" # don't use package if you're using automake
# Version of your program
version "@PACKAGE_VERSION_MAJOR at .@PACKAGE_VERSION_MINOR at .@PACKAGE_VERSION_PATCH@"
  # don't use version if you're using automake

or even
# Name of your program
package "hwtest" # don't use package if you're using automake
# Version of your program
version @PACKAGE_VERSION@  # don't use version if you're using automake

alternatively you can use a config.h which contains a VERSION macro
and compile your gengetopt generated C files with
-DHAVE_CONFIG_H=1

(just add ADD_DEFINITION(-DHAVE_CONFIG_H=1) to your CMakeLists.txt)

in this second case YOU MUST NOT define version inside *.ggo because
the VERSION will comes from config.h.

I use the latter method because it was the method used by our previous
autotools build system. Choosing between those 2 is a matter of taste.

-- 
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org


More information about the CMake mailing list