18bf80f4bSopenharmony_ciexecute_process(COMMAND git log --pretty=format:'%h' -n 1 28bf80f4bSopenharmony_ci OUTPUT_VARIABLE GIT_REV 38bf80f4bSopenharmony_ci WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} 48bf80f4bSopenharmony_ci ERROR_QUIET) 58bf80f4bSopenharmony_ci 68bf80f4bSopenharmony_ci# Check whether we got any revision (which isn't 78bf80f4bSopenharmony_ci# always the case, e.g. when someone downloaded a zip 88bf80f4bSopenharmony_ci# file instead of a checkout) 98bf80f4bSopenharmony_ciif ("${GIT_REV}" STREQUAL "") 108bf80f4bSopenharmony_ci set(GIT_REV "N/A") 118bf80f4bSopenharmony_ci set(GIT_DIFF "") 128bf80f4bSopenharmony_ci set(GIT_TAG "N/A") 138bf80f4bSopenharmony_ci set(GIT_BRANCH "N/A") 148bf80f4bSopenharmony_cielse() 158bf80f4bSopenharmony_ci execute_process( 168bf80f4bSopenharmony_ci COMMAND git diff --quiet --exit-code 178bf80f4bSopenharmony_ci WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} 188bf80f4bSopenharmony_ci RESULT_VARIABLE GIT_DIFF) 198bf80f4bSopenharmony_ci 208bf80f4bSopenharmony_ci execute_process( 218bf80f4bSopenharmony_ci COMMAND git rev-parse --abbrev-ref HEAD 228bf80f4bSopenharmony_ci WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} 238bf80f4bSopenharmony_ci OUTPUT_VARIABLE GIT_BRANCH) 248bf80f4bSopenharmony_ci 258bf80f4bSopenharmony_ci execute_process( 268bf80f4bSopenharmony_ci COMMAND git describe --tags --dirty 278bf80f4bSopenharmony_ci WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} 288bf80f4bSopenharmony_ci OUTPUT_VARIABLE GIT_TAG ERROR_QUIET) 298bf80f4bSopenharmony_ci 308bf80f4bSopenharmony_ci string(STRIP "${GIT_REV}" GIT_REV) 318bf80f4bSopenharmony_ci 328bf80f4bSopenharmony_ci string(SUBSTRING "${GIT_REV}" 1 7 GIT_REV) 338bf80f4bSopenharmony_ci if (GIT_DIFF) 348bf80f4bSopenharmony_ci set(GIT_DIFF "-dirty") 358bf80f4bSopenharmony_ci else() 368bf80f4bSopenharmony_ci set(GIT_DIFF "") 378bf80f4bSopenharmony_ci endif() 388bf80f4bSopenharmony_ci 398bf80f4bSopenharmony_ci string(STRIP "${GIT_TAG}" GIT_TAG) 408bf80f4bSopenharmony_ci if (NOT GIT_TAG) 418bf80f4bSopenharmony_ci set(GIT_TAG "${GIT_REV}${GIT_DIFF}") 428bf80f4bSopenharmony_ci endif() 438bf80f4bSopenharmony_ci 448bf80f4bSopenharmony_ci string(STRIP "${GIT_BRANCH}" GIT_BRANCH) 458bf80f4bSopenharmony_ciendif() 468bf80f4bSopenharmony_ci 478bf80f4bSopenharmony_ciset(VERSION_STRING 488bf80f4bSopenharmony_ci) 498bf80f4bSopenharmony_ciset(VERSION " 508bf80f4bSopenharmony_cinamespace Dotfield { 518bf80f4bSopenharmony_ciconst char* GetVersionInfo() { return \"GIT_TAG: ${GIT_TAG} GIT_REVISION: ${GIT_REV}${GIT_DIFF} GIT_BRANCH: ${GIT_BRANCH}\"; } 528bf80f4bSopenharmony_ci} 538bf80f4bSopenharmony_ci") 548bf80f4bSopenharmony_ci 558bf80f4bSopenharmony_ciif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp) 568bf80f4bSopenharmony_ci file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp VERSION_) 578bf80f4bSopenharmony_cielse() 588bf80f4bSopenharmony_ci set(VERSION_ "") 598bf80f4bSopenharmony_ciendif() 608bf80f4bSopenharmony_ci 618bf80f4bSopenharmony_ciif (NOT "${VERSION}" STREQUAL "${VERSION_}") 628bf80f4bSopenharmony_ci file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp "${VERSION}") 638bf80f4bSopenharmony_ci message(${VERSION}) 648bf80f4bSopenharmony_ciendif()