I am having problems exporting cmake PROJECT_VERSION_MAJORto a file config.h. In my main CMakeLists.txtI set this variable according to the cmake documentation, calling project()in the main file CMakeLists.txt:
cmake_minimum_required(VERSION 3.2.2)
cmake_policy(SET CMP0048 NEW)
set(PROJECT "SampleName")
project(${PROJECT}
VERSION "0.0.0")
configure_file(${CMAKE_SOURCE_DIR}/cmake/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
Through configure_file()invokation I am trying to export some cmake variables to a header file config.h. Please see mine config.h.cmake.file:
#ifndef CONFIG_H
#define CONFIG_H
#cmakedefine PROJECT "@PROJECT@"
#cmakedefine PROJECT_VERSION "@PROJECT_VERSION@"
#cmakedefine PROJECT_VERSION_MAJOR "@PROJECT_VERSION_MAJOR@"
#cmakedefine PROJECT_VERSION_MINOR "@PROJECT_VERSION_MINOR@"
#cmakedefine PROJECT_VERSION_PATCH "@PROJECT_VERSION_PATCH@"
#endif
After running the command cmake ..in my build directory it is config.hcreated, but it looks something like this:
#ifndef CONFIG_H
#define CONFIG_H
#define PROJECT "SampleName"
#define PROJECT_VERSION "0.0.0"
#endif
I assume the reason for this behavior is a note in the cmake documentation for the function configure_file():
, @VAR@ ${VAR} . , . , :
#cmakedefine VAR ...
:
#define VAR ...
/* #undef VAR */
, VAR CMake , if(). "..." , , , , . #cmakedefine01 VAR #define VAR 1 #define VAR 0.
, cmake PROJECT_VERSION_MAJOR , ? PROJECT_VERSION define ?
hank :
#ifndef CONFIG_H
#define CONFIG_H
#define PROJECT "SampleName"
#define PROJECT_VERSION "0.0.0"
#define PROJECT_VERSION_MAJOR "0"
#define PROJECT_VERSION_MINOR "0"
#define PROJECT_VERSION_PATCH "0"
#endif