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

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to