[CMake] How to assign version numbers from a source header to CMake variables?

Alexey Livshits livchits at web.de
Wed Jan 12 08:26:34 EST 2011


Here is the code:

find_file(myproject_BUILD_NUMBER_FILE_FOUND myproject_build_number.txt
PATHS ${myproject_SOURCE_DIR})

if(${myproject_BUILD_NUMBER_FILE_FOUND} MATCHES "NOTFOUND")
	set(myproject_CURRENT_BUILD_NUM 1)
else()
	file(READ ${myproject_SOURCE_DIR}/myproject_build_number.txt OLD_BUILD_NUM)
	if(BUILD_VERSION)
		math(EXPR myproject_CURRENT_BUILD_NUM "${OLD_BUILD_NUM} + 1")
		file(WRITE ${myproject_SOURCE_DIR}/myproject_build_number.txt
"${myproject_CURRENT_BUILD_NUM}")
	else()	
		set(myproject_CURRENT_BUILD_NUM ${OLD_BUILD_NUM})
	endif()	
endif()

configure_file(${myproject_SOURCE_DIR}/version/myproject_version.h.in
${myproject_SOURCE_DIR}/version/myproject_version.h @ONLY)


-- 
BG,
Alexey


More information about the CMake mailing list