cmake fix: generate build timestamp
authorRalf Habacker <ralf.habacker@freenet.de>
Tue, 20 Sep 2011 07:57:52 +0000 (09:57 +0200)
committerRalf Habacker <ralf.habacker@freenet.de>
Thu, 22 Sep 2011 17:55:13 +0000 (19:55 +0200)
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=41029
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
cmake/CMakeLists.txt
cmake/modules/Macros.cmake [new file with mode: 0644]

index f475876bd9fb60653383f643de90431c26ef8a3f..905a6b81a65664c04e8a5677feb503e7dd321145 100644 (file)
@@ -13,11 +13,6 @@ set (DBUS_VERSION ${DBUS_MAJOR_VERSION}.${DBUS_MINOR_VERSION}.${DBUS_MICRO_VERSI
 
 set (DBUS_VERSION_STRING "${DBUS_VERSION}")
 
-if (NOT DBUS_BUILD_TIMESTAMP)
-    message(STATUS "FIXME set DBUS_BUILD_TIMESTAMP to current date or fix current time stamp generation for having actual build date in version file info")
-    set (DBUS_BUILD_TIMESTAMP 20091231)
-endif (NOT DBUS_BUILD_TIMESTAMP)
-
 # we need to be up to date
 CMAKE_MINIMUM_REQUIRED(VERSION 2.4.4 FATAL_ERROR)
 if(COMMAND cmake_policy)
@@ -27,6 +22,9 @@ endif(COMMAND cmake_policy)
 # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules")
 
+include(Macros)
+TIMESTAMP(DBUS_BUILD_TIMESTAMP)
+
 ########### basic vars ###############
 
 
diff --git a/cmake/modules/Macros.cmake b/cmake/modules/Macros.cmake
new file mode 100644 (file)
index 0000000..b637156
--- /dev/null
@@ -0,0 +1,15 @@
+
+MACRO(TIMESTAMP RESULT)
+    IF(WIN32)
+        EXECUTE_PROCESS(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE DATE)
+        string(REGEX REPLACE "(..)[/.](..)[/.](....).*" "\\3\\2\\1" DATE ${DATE})
+        EXECUTE_PROCESS(COMMAND "cmd" " /C time /T" OUTPUT_VARIABLE TIME)
+        string(REGEX REPLACE "(..):(..)" "\\1\\2" TIME ${TIME})
+        set (${RESULT} "${DATE}${TIME}")
+    ELSEIF(UNIX)
+        EXECUTE_PROCESS(COMMAND "date" "+%Y%m%d%H%M" OUTPUT_VARIABLE ${RESULT})
+    ELSE()
+        MESSAGE(SEND_ERROR "date not implemented")
+        SET(${RESULT} 000000000000)
+    ENDIF()
+ENDMACRO()