summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-11-17 18:33:33 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-12-16 07:59:37 -0800
commit268fbf3fb152bba485b4924d2b686889d8b10532 (patch)
tree21df7f1f7f7c92804ef82e4614891d44e7c277b5 /cmake
parentf60e86b19c6d785a91bc126ac587bf9f3ee87369 (diff)
downloadsubsurface-268fbf3fb152bba485b4924d2b686889d8b10532.tar.gz
Handle VersionGeneration outside of the main CMakeFile
This is actually a good change: we used to write a new CMake file in configure time just to move it outside of the source to the build dir at compile time. Now this file is pre-created and it's only moved. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Modules/HandleVersionGeneration.cmake17
-rw-r--r--cmake/Modules/version.cmake39
2 files changed, 56 insertions, 0 deletions
diff --git a/cmake/Modules/HandleVersionGeneration.cmake b/cmake/Modules/HandleVersionGeneration.cmake
new file mode 100644
index 000000000..801140462
--- /dev/null
+++ b/cmake/Modules/HandleVersionGeneration.cmake
@@ -0,0 +1,17 @@
+# Generate the ssrf-config.h every 'make'
+file(WRITE ${CMAKE_BINARY_DIR}/version.h.in
+"#define VERSION_STRING \"@VERSION_STRING@\"
+#define GIT_VERSION_STRING \"@GIT_VERSION_STRING@\"
+#define CANONICAL_VERSION_STRING \"@CANONICAL_VERSION_STRING@\"
+")
+
+file(COPY cmake/Modules/version.cmake
+ DESTINATION ${CMAKE_BINARY_DIR})
+
+add_custom_target(
+ version ALL COMMAND ${CMAKE_COMMAND} ${CMAKE_COMMAND}
+ -D SRC=${CMAKE_BINARY_DIR}/version.h.in
+ -D DST=${CMAKE_BINARY_DIR}/ssrf-version.h
+ -D CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
+ -P ${CMAKE_BINARY_DIR}/version.cmake
+)
diff --git a/cmake/Modules/version.cmake b/cmake/Modules/version.cmake
new file mode 100644
index 000000000..bd42e3e73
--- /dev/null
+++ b/cmake/Modules/version.cmake
@@ -0,0 +1,39 @@
+if(${APPLE})
+ set(VER_OS darwin)
+elseif(${WIN32})
+ set(VER_OS win)
+else()
+ set(VER_OS linux)
+endif()
+
+if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
+ set(VER_OS win)
+endif()
+execute_process(
+ COMMAND sh scripts/get-version ${VER_OS}
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ OUTPUT_VARIABLE VERSION_STRING
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+execute_process(
+ COMMAND sh scripts/get-version linux
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ OUTPUT_VARIABLE GIT_VERSION_STRING
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+execute_process(
+ COMMAND sh scripts/get-version full
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ OUTPUT_VARIABLE CANONICAL_VERSION_STRING
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+
+configure_file(${SRC} ${DST} @ONLY)
+if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
+ execute_process(
+ COMMAND cat ${CMAKE_SOURCE_DIR}/packaging/windows/subsurface.nsi.in
+ COMMAND sed -e \"s/VERSIONTOKEN/\${GIT_VERSION_STRING}/\"
+ COMMAND sed -e \"s/PRODVTOKEN/\${CANONICAL_VERSION_STRING}/\"
+ OUTPUT_FILE ${CMAKE_BINARY_DIR}/staging/subsurface.nsi
+ )
+endif()