fix for cmake not having the correct svn revision in buildinfo, now generate a header...
[blender-staging.git] / build_files / cmake / buildinfo.cmake
1 # this is called by cmake as an extermal process from
2 # ./source/creator/CMakeLists.txt to write ./source/creator/buildinfo.h
3
4 # the FindSubversion.cmake module is part of the standard distribution
5 include(FindSubversion)
6 # extract working copy information for SOURCE_DIR into MY_XXX variables
7 if(Subversion_FOUND)
8         Subversion_WC_INFO(${SOURCE_DIR} MY)
9 else()
10         set(MY_WC_REVISION "unknown")
11 endif()
12
13 # BUILD_PLATFORM and BUILD_PLATFORM are taken from CMake
14 if(UNIX)
15         execute_process(COMMAND date "+%Y-%m-%d" OUTPUT_VARIABLE BUILD_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
16         execute_process(COMMAND date "+%H:%M:%S" OUTPUT_VARIABLE BUILD_TIME OUTPUT_STRIP_TRAILING_WHITESPACE)  
17 endif()
18
19 if(WIN32)
20         execute_process(COMMAND cmd /c date /t OUTPUT_VARIABLE BUILD_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
21         execute_process(COMMAND cmd /c time /t OUTPUT_VARIABLE BUILD_TIME OUTPUT_STRIP_TRAILING_WHITESPACE)  
22 endif()
23
24 # write a file with the SVNVERSION define
25 file(WRITE buildinfo.h.txt
26         "#define BUILD_REV ${MY_WC_REVISION}\n"
27         "#define BUILD_DATE ${BUILD_DATE}\n"
28         "#define BUILD_TIME ${BUILD_TIME}\n"
29 )
30
31 # copy the file to the final header only if the version changes
32 # reduces needless rebuilds
33 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
34                         buildinfo.h.txt buildinfo.h)