]> git.jsancho.org Git - lugaru.git/blobdiff - CMakeLists.txt
Unify platform-specific definitions and clean .rc file
[lugaru.git] / CMakeLists.txt
index d798d41248764aae96c64d062e7d17d6df88da81..0965b30f6e4eda498060069f824edbc3521e55c9 100644 (file)
@@ -16,12 +16,61 @@ if(UNIX AND NOT APPLE)
 endif()
 
 
+### Version
+
+# Version for the current (stable) or next (development) release
+set(LUGARU_VERSION_MAJOR 1)
+set(LUGARU_VERSION_MINOR 2)
+set(LUGARU_VERSION_PATCH 0)
+
+# MAJOR.MINOR, or MAJOR.MINOR.PATCH if PATCH != 0
+set(LUGARU_VERSION_NUMBER "${LUGARU_VERSION_MAJOR}.${LUGARU_VERSION_MINOR}")
+if(LUGARU_VERSION_PATCH)
+    set(LUGARU_VERSION_NUMBER "${LUGARU_VERSION_NUMBER}.${LUGARU_VERSION_PATCH}")
+endif()
+
+# Set to "" for stable (tagged) builds, "-dev" for dev builds
+set(LUGARU_VERSION_SUFFIX "-dev")  # development
+#set(LUGARU_VERSION_SUFFIX "")  # stable
+
+# Set to 7-char git commit hash if available, otherwise "".
+# On stable (tagged) builds, this is ignored.
+set(LUGARU_VERSION_HASH "")
+if(LUGARU_VERSION_SUFFIX STREQUAL "-dev" AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
+    find_package(Git)
+    if(GIT_FOUND)
+        execute_process(
+            COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
+            WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+            OUTPUT_VARIABLE "LUGARU_VERSION_HASH"
+            ERROR_QUIET
+            OUTPUT_STRIP_TRAILING_WHITESPACE)
+        message(STATUS "Git commit hash: ${LUGARU_VERSION_HASH}")
+    endif()
+endif()
+
+set(LUGARU_VERSION_RELEASE "" CACHE STRING "Optional release string, e.g. for distro packages release number")
+
+# Final string built from the above constants, following the scheme:
+# MAJOR.MINOR[.PATCH][-dev] [(git HASH)] [[RELEASE]]
+set(LUGARU_VERSION_STRING "${LUGARU_VERSION_NUMBER}${LUGARU_VERSION_SUFFIX}")
+if(NOT LUGARU_VERSION_HASH STREQUAL "")
+    set(LUGARU_VERSION_STRING "${LUGARU_VERSION_STRING} (git ${LUGARU_VERSION_HASH})")
+endif()
+if(NOT LUGARU_VERSION_RELEASE STREQUAL "")
+    set(LUGARU_VERSION_STRING "${LUGARU_VERSION_STRING} [${LUGARU_VERSION_RELEASE}]")
+endif()
+
+message(STATUS "Version string: ${LUGARU_VERSION_STRING}")
+configure_file(${SRCDIR}/Version.hpp.in ${SRCDIR}/Version.hpp ESCAPE_QUOTES @ONLY)
+
+
 ### CMake config
 
 if(NOT CMAKE_BUILD_TYPE)
     set(CMAKE_BUILD_TYPE RelWithDebInfo)
 endif(NOT CMAKE_BUILD_TYPE)
-message("CMake build type: ${CMAKE_BUILD_TYPE}")
+message(STATUS "CMake build type: ${CMAKE_BUILD_TYPE}")
 
 set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-parentheses -pedantic --std=gnu++11 ${CMAKE_CXX_FLAGS}")
 
@@ -70,6 +119,8 @@ set(LUGARU_SRCS
     ${SRCDIR}/Objects/Object.cpp
     ${SRCDIR}/Objects/Person.cpp
     ${SRCDIR}/Objects/Weapons.cpp
+    ${SRCDIR}/Platform/PlatformUnix.cpp
+    ${SRCDIR}/Platform/PlatformWindows.cpp
     ${SRCDIR}/User/Account.cpp
     ${SRCDIR}/User/Settings.cpp
     ${SRCDIR}/Utils/Folders.cpp
@@ -115,6 +166,7 @@ set(LUGARU_H
     ${SRCDIR}/Objects/Object.hpp
     ${SRCDIR}/Objects/Person.hpp
     ${SRCDIR}/Objects/Weapons.hpp
+    ${SRCDIR}/Platform/Platform.hpp
     ${SRCDIR}/Thirdparty/optionparser.h
     ${SRCDIR}/User/Account.hpp
     ${SRCDIR}/User/Settings.hpp
@@ -128,35 +180,13 @@ set(LUGARU_H
 
 )
 
-if(UNIX)
-    set(LUGARU_SRCS
-        ${LUGARU_SRCS}
-        ${SRCDIR}/MacCompatibility.cpp
-    )
-    set(LUGARU_H
-        ${LUGARU_H}
-        ${SRCDIR}/MacCompatibility.hpp
-    )
-endif(UNIX)
-
 if(WIN32)
     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
                        COMMAND ${CMAKE_RC_COMPILER}
-                       -I${SRCDIR}/win-res
                        -o ${CMAKE_CURRENT_BINARY_DIR}/lugaru_resource.obj
-                       -i${SRCDIR}/win-res/Lugaru.rc
-                       DEPENDS ${SRCDIR}/win-res/Lugaru.rc
+                       -i${SRCDIR}/Lugaru.rc
+                       DEPENDS ${SRCDIR}/Lugaru.rc
     )
-
-    # FIXME: get rid of this.
-    set(LUGARU_SRCS
-        ${LUGARU_SRCS}
-        ${SRCDIR}/WinDefs.cpp)
-
-    set(LUGARU_H
-        ${LUGARU_H}
-        ${SRCDIR}/WinDefs.hpp
-        ${SRCDIR}/win-res/resource.hpp)
 endif(WIN32)
 
 if(APPLE)