From c14c6d647f9b31a37657e02fcfaea4d299b3072e Mon Sep 17 00:00:00 2001
From: Jeffrey Pfau <jeffrey@endrift.com>
Date: Mon, 19 Sep 2016 19:49:58 -0700
Subject: [PATCH] All: Only update version info if needed

---
 CHANGES        | 4 ++++
 CMakeLists.txt | 2 +-
 version.cmake  | 8 ++++++--
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/CHANGES b/CHANGES
index 7a0f2d766..dbab77ae2 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+0.6.0: (Future)
+Misc:
+ - All: Only update version info if needed
+
 0.5.0: (2016-09-19)
 Features:
  - Game Boy support
diff --git a/CMakeLists.txt b/CMakeLists.txt
index af387274f..c181d9dd8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -122,7 +122,7 @@ function(find_feature FEATURE_NAME FEATURE_REQUIRES)
 endfunction()
 
 # Version information
-add_custom_target(version-info ALL ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_SOURCE_DIR}/src/core/version.c.in
+add_custom_target(version-info ALL
 	COMMAND ${CMAKE_COMMAND}
 	-DBINARY_NAME=${BINARY_NAME}
 	-DCONFIG_FILE=${CMAKE_CURRENT_SOURCE_DIR}/src/core/version.c.in
diff --git a/version.cmake b/version.cmake
index b11ac7b3c..0bd13337b 100644
--- a/version.cmake
+++ b/version.cmake
@@ -43,6 +43,10 @@ if(NOT GIT_BRANCH)
 	set(GIT_BRANCH "(unknown)")
 endif()
 
-if(CONFIG_FILE AND OUT_FILE)
-	configure_file("${CONFIG_FILE}" "${OUT_FILE}")
+if(NOT VERSION_STRING_CACHE OR NOT VERSION_STRING STREQUAL VERSION_STRING_CACHE)
+	set(VERSION_STRING_CACHE ${VERSION_STRING} CACHE STRING "" FORCE)
+
+	if(CONFIG_FILE AND OUT_FILE)
+		configure_file("${CONFIG_FILE}" "${OUT_FILE}")
+	endif()
 endif()