Code

UseGlibMarshal.cmake - Don't overwrite the file if it hasn't changed
authortweenk <tweenk@users.sourceforge.net>
Sun, 11 Jan 2009 21:21:20 +0000 (21:21 +0000)
committertweenk <tweenk@users.sourceforge.net>
Sun, 11 Jan 2009 21:21:20 +0000 (21:21 +0000)
CMakeScripts/UseGlibMarshal.cmake

index 6f81730e5a2e943dae2b7ad7610f1630b1116202..63d501a5798696bf7b4b97a8a76e58bcf42b85b4 100644 (file)
@@ -21,8 +21,16 @@ MACRO(GLIB_MARSHAL GLIB_MARSHAL_PREFIX GLIB_MARSHAL_FILE GLIB_MARSHAL_OUTPUT_LOC
         EXECUTE_PROCESS(COMMAND ${GLIB_MARSHAL_EXECUTABLE} --prefix=${GLIB_MARSHAL_PREFIX} --body ${CMAKE_CURRENT_SOURCE_DIR}/${GLIB_MARSHAL_FILE}.list
                                 OUTPUT_VARIABLE GLIB_MARSHAL_OUTPUT_CPP )
 
-        FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${GLIB_MARSHAL_FILE}.h "${GLIB_MARSHAL_OUTPUT_HEADER}")
-        FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${GLIB_MARSHAL_FILE}.cpp "${GLIB_MARSHAL_OUTPUT_EXTRA_LINE}")
-        FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/${GLIB_MARSHAL_FILE}.cpp "${GLIB_MARSHAL_OUTPUT_CPP}")
-    ENDIF(GLIB_MARSHAL_EXECUTABLE)
-ENDMACRO(GLIB_MARSHAL)
+        # check whether the generated file is the same as the existing one
+        FILE(READ ${CMAKE_CURRENT_BINARY_DIR}/${GLIB_MARSHAL_FILE}.h GLIB_MARSHAL_HEADER_OLD)
+        IF(NOT GLIB_MARSHAL_HEADER_OLD STREQUAL GLIB_MARSHAL_OUTPUT_HEADER)
+            MESSAGE(STATUS "${GLIB_MARSHAL_FILE}.h changed; overwriting")
+            FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${GLIB_MARSHAL_FILE}.h "${GLIB_MARSHAL_OUTPUT_HEADER}")
+            FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${GLIB_MARSHAL_FILE}.cpp "${GLIB_MARSHAL_OUTPUT_EXTRA_LINE}")
+            FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}/${GLIB_MARSHAL_FILE}.cpp "${GLIB_MARSHAL_OUTPUT_CPP}")
+        ELSE()
+            MESSAGE(STATUS "${GLIB_MARSHAL_FILE}.h unchanged")
+        ENDIF()
+    ENDIF()
+ENDMACRO()
+