ref: 471bfe94f6abb8f624d9dfb0baaef789e5083b4c
parent: 8dccafbc15132ad5ecff064a19d36d31d72b11c7
author: gkostka <kostka.grzegorz@gmail.com>
date: Wed Dec 30 20:33:28 EST 2015
makefile: add version definitions to makefile & CMakeLists
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,6 +8,8 @@
set(BLOCKDEV_TYPE none)
+add_definitions(-DVERSION="${VERSION}")
+
#Examples
if (CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m0)
#...
@@ -44,9 +46,9 @@
#DISTRIBUTION
-set(CPACK_PACKAGE_VERSION_MAJOR "0")
-set(CPACK_PACKAGE_VERSION_MINOR "8")
-set(CPACK_PACKAGE_VERSION_PATCH "0")
+set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
+set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
+set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
set(CPACK_SOURCE_GENERATOR "TBZ2")
set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
@@ -53,5 +55,6 @@
set(CPACK_SOURCE_IGNORE_FILES
"/build" ".git")
include(CPack)
+
add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
--- a/Makefile
+++ b/Makefile
@@ -3,51 +3,80 @@
#Debug
BUILD_TYPE = Release
-#Check: http://www.cmake.org/Wiki/CMake_Generator_Specific_Information
-#"Unix Makefiles"
-#"Eclipse CDT4 - Unix Makefiles"
-PROJECT_SETUP = "Unix Makefiles"
+ifneq ($(shell test -d .git), 0)
+GIT_SHORT_HASH:= $(shell git rev-parse --short HEAD)
+endif
+VERSION_MAJOR = 0
+VERSION_MINOR = 8
+VERSION_PATCH = 0
+
+VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)-$(GIT_SHORT_HASH)
+
+COMMON_DEFINITIONS = \
+ -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
+ -DVERSION_MAJOR=$(VERSION_MAJOR) \
+ -DVERSION_MINOR=$(VERSION_MINOR) \
+ -DVERSION_PATCH=$(VERSION_PATCH) \
+ -DVERSION=$(VERSION) \
+
+
generic:
rm -R -f build_generic
mkdir build_generic
- cd build_generic && cmake -G$(PROJECT_SETUP) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_TOOLCHAIN_FILE=../toolchain/generic.cmake ..
+ cd build_generic && cmake -G"Unix Makefiles" \
+ $(COMMON_DEFINITIONS) \
+ -DCMAKE_TOOLCHAIN_FILE=../toolchain/generic.cmake ..
bf518:
rm -R -f build_bf518
mkdir build_bf518
- cd build_bf518 && cmake -G$(PROJECT_SETUP) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_TOOLCHAIN_FILE=../toolchain/bf518.cmake ..
+ cd build_bf518 && cmake -G"Unix Makefiles" \
+ $(COMMON_DEFINITIONS) \
+ -DCMAKE_TOOLCHAIN_FILE=../toolchain/bf518.cmake ..
avrxmega7:
rm -R -f build_avrxmega7
mkdir build_avrxmega7
- cd build_avrxmega7 && cmake -G$(PROJECT_SETUP) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_TOOLCHAIN_FILE=../toolchain/avrxmega7.cmake ..
+ cd build_avrxmega7 && cmake -G"Unix Makefiles" \
+ $(COMMON_DEFINITIONS) \
+ -DCMAKE_TOOLCHAIN_FILE=../toolchain/avrxmega7.cmake ..
msp430:
rm -R -f build_msp430
mkdir build_msp430
- cd build_msp430 && cmake -G$(PROJECT_SETUP) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_TOOLCHAIN_FILE=../toolchain/msp430.cmake ..
+ cd build_msp430 && cmake -G"Unix Makefiles" \
+ $(COMMON_DEFINITIONS) \
+ -DCMAKE_TOOLCHAIN_FILE=../toolchain/msp430.cmake ..
cortex-m0:
rm -R -f build_cortex-m0
mkdir build_cortex-m0
- cd build_cortex-m0 && cmake -G$(PROJECT_SETUP) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_TOOLCHAIN_FILE=../toolchain/cortex-m0.cmake ..
+ cd build_cortex-m0 && cmake -G"Unix Makefiles" \
+ $(COMMON_DEFINITIONS) \
+ -DCMAKE_TOOLCHAIN_FILE=../toolchain/cortex-m0.cmake ..
cortex-m3:
rm -R -f build_cortex-m3
mkdir build_cortex-m3
- cd build_cortex-m3 && cmake -G$(PROJECT_SETUP) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_TOOLCHAIN_FILE=../toolchain/cortex-m3.cmake ..
+ cd build_cortex-m3 && cmake -G"Unix Makefiles" \
+ $(COMMON_DEFINITIONS) \
+ -DCMAKE_TOOLCHAIN_FILE=../toolchain/cortex-m3.cmake ..
cortex-m4:
rm -R -f build_cortex-m4
mkdir build_cortex-m4
- cd build_cortex-m4 && cmake -G$(PROJECT_SETUP) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_TOOLCHAIN_FILE=../toolchain/cortex-m4.cmake ..
+ cd build_cortex-m4 && cmake -G"Unix Makefiles" \
+ $(COMMON_DEFINITIONS) \
+ -DCMAKE_TOOLCHAIN_FILE=../toolchain/cortex-m4.cmake ..
arm-sim:
rm -R -f build_arm-sim
mkdir build_arm-sim
- cd build_arm-sim && cmake -G$(PROJECT_SETUP) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_TOOLCHAIN_FILE=../toolchain/arm-sim.cmake ..
+ cd build_arm-sim && cmake -G"Unix Makefiles" \
+ $(COMMON_DEFINITIONS) \
+ -DCMAKE_TOOLCHAIN_FILE=../toolchain/arm-sim.cmake ..
all: generic bf518 cortex-m3 cortex-m4 generic