build: allow to pass version via CMake
authorJo-Philipp Wich <jo@mein.io>
Sat, 18 Feb 2017 14:45:53 +0000 (15:45 +0100)
committerJo-Philipp Wich <jo@mein.io>
Sat, 18 Feb 2017 14:45:53 +0000 (15:45 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
CMakeLists.txt

index 52d01f78d3f4e789ac5587f0097893b68cb1d03f..206bc261d3b276a6bb22c1ed1b8894448f8a09ea 100644 (file)
@@ -5,6 +5,7 @@ PROJECT(opkg C)
 SET(HOST_CPU "" CACHE STRING "Override Host CPU")
 SET(BUILD_CPU "" CACHE STRING "Override Host CPU")
 SET(LOCK_FILE "/var/lock/opkg.lock" CACHE STRING "Override lock file path")
+SET(VERSION "" CACHE STRING "Override version")
 
 OPTION(STATIC_UBOX "Statically link libubox" OFF)
 OPTION(BUILD_TESTS "Build test programs" ON)
@@ -17,13 +18,15 @@ IF(NOT BUILD_CPU)
        SET(BUILD_CPU "${CMAKE_SYSTEM_PROCESSOR}")
 ENDIF()
 
-EXECUTE_PROCESS(COMMAND git log -1 "--format=%h (%ci)"
-       OUTPUT_VARIABLE GIT_VERSION
-       OUTPUT_STRIP_TRAILING_WHITESPACE
-)
+IF(NOT VERSION)
+       EXECUTE_PROCESS(COMMAND git log -1 "--format=%h (%ci)"
+               OUTPUT_VARIABLE VERSION
+               OUTPUT_STRIP_TRAILING_WHITESPACE
+       )
+ENDIF()
 
-IF(NOT GIT_VERSION)
-       SET(GIT_VERSION "unknown")
+IF(NOT VERSION)
+       SET(VERSION "unknown")
 ENDIF()
 
 ADD_DEFINITIONS(-Os -Wall --std=gnu99 -g3 -Wmissing-declarations
@@ -33,7 +36,7 @@ ADD_DEFINITIONS(-Os -Wall --std=gnu99 -g3 -Wmissing-declarations
        -DOPKGLIBDIR="/usr/lib"
        -DHOST_CPU_STR="${HOST_CPU}"
        -DBUILD_CPU=${BUILD_CPU}
-       -DVERSION="${GIT_VERSION}"
+       -DVERSION="${VERSION}"
 )
 
 ADD_SUBDIRECTORY(libbb)