buildinfo.cmake 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # generates BuildInfo.h
  2. #
  3. # this module expects
  4. # ETH_SOURCE_DIR - main CMAKE_SOURCE_DIR
  5. # ETH_DST_DIR - main CMAKE_BINARY_DIR
  6. # ETH_BUILD_TYPE
  7. # ETH_BUILD_PLATFORM
  8. # ETH_BUILD_NUMBER
  9. # ETH_VERSION_SUFFIX
  10. #
  11. # example usage:
  12. # cmake -DETH_SOURCE_DIR=. -DETH_DST_DIR=build -DETH_BUILD_TYPE=Debug -DETH_BUILD_PLATFORM=mac -DETH_BUILD_NUMBER=45 -DETH_VERSION_SUFFIX="-rc1" -P scripts/buildinfo.cmake
  13. if (NOT ETH_BUILD_TYPE)
  14. set(ETH_BUILD_TYPE "unknown")
  15. endif()
  16. if (NOT ETH_BUILD_PLATFORM)
  17. set(ETH_BUILD_PLATFORM "unknown")
  18. endif()
  19. execute_process(
  20. COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} rev-parse HEAD
  21. OUTPUT_VARIABLE ETH_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
  22. )
  23. if (NOT ETH_COMMIT_HASH)
  24. set(ETH_COMMIT_HASH 0)
  25. endif()
  26. execute_process(
  27. COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} diff HEAD --shortstat
  28. OUTPUT_VARIABLE ETH_LOCAL_CHANGES OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
  29. )
  30. if (ETH_LOCAL_CHANGES)
  31. set(ETH_CLEAN_REPO 0)
  32. else()
  33. set(ETH_CLEAN_REPO 1)
  34. endif()
  35. set(TMPFILE "${ETH_DST_DIR}/BuildInfo.h.tmp")
  36. set(OUTFILE "${ETH_DST_DIR}/BuildInfo.h")
  37. configure_file("${ETH_BUILDINFO_IN}" "${TMPFILE}")
  38. include("${ETH_CMAKE_DIR}/EthUtils.cmake")
  39. replace_if_different("${TMPFILE}" "${OUTFILE}" CREATE)