[CMake] Expected behaviour of #cmakedefine

Ian Cullen ian.james.cullen at gmail.com
Wed Aug 15 08:31:38 EDT 2018


Hi,

I'm trying to create a header file containing version number details but 
am not sure if the following behaviour is expected or a bug.

Simplified example has 2 files

==> CMakeLists.txt <==
cmake_minimum_required(VERSION 3.11)
project (
   VersionTest
   VERSION 1.0.4
   )

configure_file (
   "${PROJECT_SOURCE_DIR}/config.h.in"
   "${PROJECT_BINARY_DIR}/config.h"
   @ONLY
   )

==> config.h.in <==
#cmakedefine VersionTest_VERSION_MAJOR @VersionTest_VERSION_MAJOR@
#cmakedefine VersionTest_VERSION_MINOR @VersionTest_VERSION_MINOR@
#define VersionTest_VERSION_MINOR @VersionTest_VERSION_MINOR@


Running cmake creates the output file as required but it has the 
following contents

==> config.h <==
#define VersionTest_VERSION_MAJOR 1
/* #undef VersionTest_VERSION_MINOR */
#define VersionTest_VERSION_MINOR 0


Looking at the manual 
(https://cmake.org/cmake/help/v3.12/command/configure_file.html), this 
appears to be because the number '0' is considered false by the if() 
command, however '0' is valid within a version number, so perhaps should 
not be considered false in this context.

Is this a known issue? Is it recommended to use #define rather than 
#cmakedefine for these types of files?

Thanks



More information about the CMake mailing list