create_version.cmake 2.05 KB
Newer Older
Pierre Aubert's avatar
Pierre Aubert committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

# Create the version header of the given program
#	projectName : name of the project
#	projectVersion : version of the project
function(create_version projectName projectVersion)
	message(STATUS "Program ${projectName} version ${projectVersion}")
	string(REPLACE "." ";" VERSION_STR_LIST ${projectVersion})
	
	set(VERSION_LIST ${VERSION_STR_LIST})
	list(LENGTH VERSION_LIST listLength)
	
	list(GET VERSION_LIST 0 MAJOR_PROG_VERSION)
	list(GET VERSION_LIST 1 MINOR_PROG_VERSION)
	list(GET VERSION_LIST 2 PATCH_PROG_VERSION)
	
	string(TOUPPER ${projectName} PROGRAM_UPPER_NAME)
	string(TOLOWER ${projectName} PROGRAM_LOWER_NAME)
	set(OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROGRAM_LOWER_NAME}_version.h)
	
	set(DEFINE_MACRO_HEADER "__${PROGRAM_UPPER_NAME}_VERSION_H__")
	file(WRITE ${OUTPUT_FILE} "\n")
	file(APPEND ${OUTPUT_FILE} "/***************************************\n")
	file(APPEND ${OUTPUT_FILE} "	Auteur : Pierre Aubert\n")
	file(APPEND ${OUTPUT_FILE} "	Mail : aubertp7@gmail.com\n")
	file(APPEND ${OUTPUT_FILE} "	Licence : CeCILL-C\n")
	file(APPEND ${OUTPUT_FILE} "****************************************/\n")
	file(APPEND ${OUTPUT_FILE} "\n")
	file(APPEND ${OUTPUT_FILE} "#ifndef ${DEFINE_MACRO_HEADER}\n")
	file(APPEND ${OUTPUT_FILE} "#define ${DEFINE_MACRO_HEADER}\n\n")
	
	file(APPEND ${OUTPUT_FILE} "#define ${PROGRAM_UPPER_NAME}_VERSION_MAJOR ${MAJOR_PROG_VERSION}\n")
	file(APPEND ${OUTPUT_FILE} "#define ${PROGRAM_UPPER_NAME}_VERSION_MINOR ${MINOR_PROG_VERSION}\n")
	file(APPEND ${OUTPUT_FILE} "#define ${PROGRAM_UPPER_NAME}_VERSION_PATCH ${PATCH_PROG_VERSION}\n\n")

	file(APPEND ${OUTPUT_FILE} "#define ${PROGRAM_UPPER_NAME}_MAKE_VERSION(major, minor, patch) ((major) *10000 + (minor) *100 + (patch))\n\n")
	file(APPEND ${OUTPUT_FILE} "#define ${PROGRAM_UPPER_NAME}_VERSION ${PROGRAM_UPPER_NAME}_MAKE_VERSION (${PROGRAM_UPPER_NAME}_VERSION_MAJOR, ${PROGRAM_UPPER_NAME}_VERSION_MINOR, ${PROGRAM_UPPER_NAME}_VERSION_PATCH)\n\n")
	
	file(APPEND ${OUTPUT_FILE} "#endif\n\n")
	
	install(FILES ${OUTPUT_FILE} DESTINATION include/${projectName})
endfunction(create_version)