cleanup revision section, make hg launch tolerant to config errors, drop deprecated exec_prog for desktop configuration in favour of execute_process
authorkoda
Wed, 21 Nov 2012 18:34:45 +0100 (2012-11-21)
changeset 8090 38d9cc60b14c
parent 8089 56bf04303311
child 8091 e0a76056a633
cleanup revision section, make hg launch tolerant to config errors, drop deprecated exec_prog for desktop configuration in favour of execute_process
CMakeLists.txt
QTfrontend/hwconsts.cpp.in
hedgewars/CMakeLists.txt
share/CMakeLists.txt
--- a/CMakeLists.txt	Wed Nov 21 15:03:33 2012 +0100
+++ b/CMakeLists.txt	Wed Nov 21 18:34:45 2012 +0100
@@ -11,34 +11,48 @@
 #use available modules, fallback to ours if not present (CMP0017 helps)
 set(CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules" "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules")
 
+#set some default values
+option(NOREVISION "Build Hedgewars without revision information" OFF)
+
+option(NOSERVER "Disable gameServer build [default: auto]" OFF)
+option(NOPNG "Disable screenshoot compression [default: auto]" OFF)
+option(NOVIDEOREC "Disable video recording [default: auto]" OFF)
+
+option(BUILD_ENGINE_LIBRARY "Enable hwengine library [default: off]" OFF)
+option(ANDROID "Enable Android build [default: off]" OFF)
+option(NOAUTOUPDATE "Disable OS X Sparkle update checking" OFF)
+option(CROSSAPPLE "Enable OSX when not on OSX [default: off]" OFF)
+option(MINIMAL_FLAGS "Respect system flags as much as possible [default: off]" OFF)
 
 #detect Mercurial revision (if present)
-set(version_suffix "-dev") #UNSET THIS VARIABLE AT RELEASE TIME
-set(HGCHANGED "")
-IF(version_suffix MATCHES "-dev")
-    set(HW_DEV true)
+IF(NOT NOREVISION)
     set(default_build_type "DEBUG")
-    IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.hg)
-        FIND_PROGRAM(HGCOMMAND hg)
-        IF(HGCOMMAND)
-            exec_program(${HGCOMMAND}
-                     ARGS identify -in ${CMAKE_CURRENT_SOURCE_DIR}
-                     OUTPUT_VARIABLE version_suffix
-                     )
-            STRING(REGEX REPLACE "[^+]" "" HGCHANGED ${version_suffix})
-            STRING(REGEX REPLACE "([0-9a-zA-Z]+)(.*) ([0-9]+)(.*)" "\\3-\\1" version_suffix ${version_suffix})
-            IF (HGCHANGED)
-                MESSAGE(STATUS "Building revision ${version_suffix} (SOURCE CODE MODIFIED)")
-            ELSE()
-                MESSAGE(STATUS "Building revision ${version_suffix}")
-            ENDIF()
-            set(version_suffix "-${version_suffix}")
+    set(version_suffix "-development_version")
+    set(HW_DEV true)
+    FIND_PROGRAM(HGCOMMAND hg)
+    IF(HGCOMMAND AND (EXISTS ${CMAKE_SOURCE_DIR}/.hg))
+        execute_process(COMMAND ${HGCOMMAND} identify -in
+                        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+                        OUTPUT_VARIABLE internal_version
+                        ERROR_QUIET
+                    )
+        #check local repo status
+        STRING(REGEX REPLACE "[^+]" "" HGCHANGED ${internal_version})
+
+        STRING(REGEX REPLACE "[0-9a-zA-Z]+(.*) ([0-9]+)(.*)" "\\2" revision_number ${internal_version})
+        STRING(REGEX REPLACE "([0-9a-zA-Z]+)(.*) [0-9]+(.*)" "\\1" revision_hash ${internal_version})
+
+        MESSAGE(STATUS "Building revision ${revision_number} from hash ${revision_hash} ${HGCHANGED}")
+        IF(HGCHANGED)
+            MESSAGE(WARNING "You have uncommitted changes")
         ENDIF()
+        set(version_suffix "-${revision_number}${HGCHANGED}")
     ENDIF()
-ELSE()
-    set(HW_DEV false)
+ELSE(NOT NOREVISION)
     set(default_build_type "RELEASE")
-ENDIF()
+    set(HWDEV false)
+    MESSAGE(STATUS "Building distributable version")
+ENDIF(NOT NOREVISION)
 
 
 #versioning
@@ -49,17 +63,6 @@
 set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
 
 
-#set some default values
-option(NOSERVER "Disable gameServer build [default: auto]" OFF)
-option(NOPNG "Disable screenshoot compression [default: auto]" OFF)
-option(NOVIDEOREC "Disable video recording [default: auto]" OFF)
-
-option(BUILD_ENGINE_LIBRARY "Enable hwengine library [default: off]" OFF)
-option(ANDROID "Enable Android build [default: off]" OFF)
-option(NOAUTOUPDATE "Disable OS X Sparkle update checking" OFF)
-option(CROSSAPPLE "Enable OSX when not on OSX [default: off]" OFF)
-option(MINIMAL_FLAGS "Respect system flags as much as possible [default: off]" OFF)
-
 #bundle .app setup
 if(APPLE OR CROSSAPPLE)
     #paths for creating the bundle
@@ -82,7 +85,7 @@
     #detect on which system we are: if sw_vers cannot be found for any reason (re)use minimum_macosx_version
     find_program(sw_vers sw_vers)
     if(sw_vers)
-        exec_program(${sw_vers} ARGS "-productVersion" OUTPUT_VARIABLE current_macosx_version)
+        execute_process(COMMAND ${sw_vers} "-productVersion" OUTPUT_VARIABLE current_macosx_version)
         string(REGEX REPLACE "([0-9]+.[0-9]+).[0-9]+" "\\1" current_macosx_version ${current_macosx_version})
         else()
         if(NOT minimum_macosx_version)
--- a/QTfrontend/hwconsts.cpp.in	Wed Nov 21 15:03:33 2012 +0100
+++ b/QTfrontend/hwconsts.cpp.in	Wed Nov 21 18:34:45 2012 +0100
@@ -23,7 +23,7 @@
 QString * cProtoVer = new QString("${HEDGEWARS_PROTO_VER}");
 QString * cDataDir = new QString("${HEDGEWARS_DATADIR}");
 QString * cConfigDir = new QString("");
-QString * cVersionString = new QString("${HEDGEWARS_VERSION}${HGCHANGED}");
+QString * cVersionString = new QString("${HEDGEWARS_VERSION}");
 
 QDir * bindir = new QDir("${HEDGEWARS_BINDIR}");
 QDir * cfgdir = new QDir();
--- a/hedgewars/CMakeLists.txt	Wed Nov 21 15:03:33 2012 +0100
+++ b/hedgewars/CMakeLists.txt	Wed Nov 21 18:34:45 2012 +0100
@@ -101,6 +101,7 @@
 endif(BUILD_ENGINE_LIBRARY)
 
 
+#PASCAL DETECTION SECTION
 IF(FPC)
     set(fpc_executable ${FPC})
 ELSE()
@@ -108,23 +109,40 @@
 ENDIF()
 
 if(fpc_executable)
-    exec_program(${fpc_executable} ARGS "-iV" OUTPUT_VARIABLE fpc_output)
+    execute_process(COMMAND ${fpc_executable} -iV OUTPUT_VARIABLE fpc_output)
 endif(fpc_executable)
 
+string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}")
+if(fpc_version)
+    string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" fpc_vers_major "${fpc_version}")
+    string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" fpc_vers_minor "${fpc_version}")
+    string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" fpc_vers_patch "${fpc_version}")
+    message(STATUS "Found Freepascal: ${fpc_executable} (version ${fpc_vers_major}.${fpc_vers_minor})")
+    math(EXPR fpc_version "${fpc_vers_major}*10000 + ${fpc_vers_minor}*100 + ${fpc_vers_patch}")
+
+    if(fpc_version LESS "020200")
+        message(FATAL_ERROR "Minimum required version of FreePascal is 2.2.0")
+    elseif(APPLE AND (fpc_version LESS "020600"))
+        message(FATAL_ERROR "Minimum required version of FreePascal is 2.6.0 on Mac OS X")
+    endif()
+else()
+    message(FATAL_ERROR "No FreePascal compiler found!")
+endif()
+
 set(noexecstack_flags "-k-z" "-knoexecstack")
 file(WRITE ${EXECUTABLE_OUTPUT_PATH}/checkstack.pas "begin end.")
 
-exec_program(${fpc_executable} ${EXECUTABLE_OUTPUT_PATH}
-    ARGS ${noexecstack_flags} checkstack.pas
-    OUTPUT_VARIABLE noout
-    RETURN_VALUE testnoexecstack
+execute_process(COMMAND ${fpc_executable} ${noexecstack_flags} checkstack.pas
+    WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
+    RESULT_VARIABLE testnoexecstack
+    OUTPUT_QUIET
     )
 
 if(${testnoexecstack})
     set (noexecstack_flags "")
 endif(${testnoexecstack})
 
-
+#DEPENDECIES AND EXECUTABLES SECTION
 if(APPLE)
     string(REGEX MATCH "[pP][pP][cC]+" powerpc_build "${CMAKE_OSX_ARCHITECTURES}")
     string(REGEX MATCH "[iI]386+" i386_build "${CMAKE_OSX_ARCHITECTURES}")
@@ -156,28 +174,6 @@
     set(pascal_flags "-k${LIBRARY_OUTPUT_PATH}/libphysfs.a" ${pascal_flags})
 endif(APPLE)
 
-
-#PASCAL DETECTION SECTION
-string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" fpc_version "${fpc_output}")
-
-if(fpc_version)
-    string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" fpc_vers_major "${fpc_version}")
-    string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" fpc_vers_minor "${fpc_version}")
-    string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" fpc_vers_patch "${fpc_version}")
-    message(STATUS "Found Freepascal: ${fpc_executable} (version ${fpc_vers_major}.${fpc_vers_minor})")
-    math(EXPR fpc_version "${fpc_vers_major}*10000 + ${fpc_vers_minor}*100 + ${fpc_vers_patch}")
-
-    if(fpc_version LESS "020200")
-        message(FATAL_ERROR "Minimum required version of FreePascal is 2.2.0")
-    elseif(APPLE AND (fpc_version LESS "020600"))
-        message(FATAL_ERROR "Minimum required version of FreePascal is 2.6.0 on Mac OS X")
-    endif()
-else()
-    message(FATAL_ERROR "No FreePascal compiler found!")
-endif()
-
-
-#DEPENDECIES AND EXECUTABLES SECTION
 if(NOT NOPNG)
     find_package(PNG)
     if(${PNG_FOUND})
--- a/share/CMakeLists.txt	Wed Nov 21 15:03:33 2012 +0100
+++ b/share/CMakeLists.txt	Wed Nov 21 18:34:45 2012 +0100
@@ -4,12 +4,13 @@
 	#needed for CFBundleVersion and CFBundleShortVersionString
 	FIND_PROGRAM(HGCOMMAND hg)
 	IF (HGCOMMAND AND (EXISTS ${hedgewars_SOURCE_DIR}/.hg))
-		exec_program(${HGCOMMAND}
-			     ARGS identify -n ${hedgewars_SOURCE_DIR}
-			     OUTPUT_VARIABLE version_suffix
-			     )
-		STRING(REGEX REPLACE "([0-9]+)(.*)" "\\1" version_suffix ${version_suffix})
-		set (HEDGEWARS_REVISION ${version_suffix})
+            execute_process(COMMAND ${HGCOMMAND} identify -in
+                            WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+                            OUTPUT_VARIABLE internal_version
+                            ERROR_QUIET
+                        )
+		STRING(REGEX REPLACE "([0-9]+)(.*)" "\\1" revision_number ${internal_version})
+		set (HEDGEWARS_REVISION ${revision_number})
 	ELSE ()
 		set (HEDGEWARS_REVISION ${HEDGEWARS_VERSION})
 	ENDIF ()