Add custom targets to generate tarballs with stored versions
authorHenning Rogge <hrogge@gmail.com>
Sun, 5 Apr 2015 20:38:20 +0000 (22:38 +0200)
committerHenning Rogge <hrogge@gmail.com>
Sun, 5 Apr 2015 20:38:20 +0000 (22:38 +0200)
.gitignore
CMakeLists.txt
cmake/generate_archive.cmake [new file with mode: 0644]
cmake/get_version.cmake

index 03dc4ed..f97c1e3 100644 (file)
@@ -3,5 +3,8 @@
 /.settings
 /html
 /cmake/version.cmake
-.kdev4/
+/.kdev4/
 /*.kdev4
+/*.tar.gz
+/*.tar.bz2
+/*.zip
index e2dabcf..2d11356 100644 (file)
@@ -26,14 +26,41 @@ if(DOXYGEN_FOUND)
     )
 endif(DOXYGEN_FOUND)
 
-#########################
-#### Compile targets ####
-#########################
+########################################
+#### get repository tag and version ####
+########################################
 
-# get repository tag and version
 include (cmake/get_version.cmake)
 include (${PROJECT_BINARY_DIR}/version.cmake)
 
+#############################
+#### add tarball targets ####
+#############################
+
+ADD_CUSTOM_TARGET(targz  COMMAND ${CMAKE_COMMAND}
+                                 -D SOURCE:STRING=${CMAKE_SOURCE_DIR}
+                                 -D BINARY:STRING=${PROJECT_BINARY_DIR}
+                                 -D VERSION:STRING=${VERSION}
+                                 -D FORMAT:STRING=tar.gz
+                                 -P ${CMAKE_SOURCE_DIR}/cmake/generate_archive.cmake)
+                                
+ADD_CUSTOM_TARGET(tarbz2 COMMAND ${CMAKE_COMMAND}
+                                 -D SOURCE:STRING=${CMAKE_SOURCE_DIR}
+                                 -D BINARY:STRING=${PROJECT_BINARY_DIR}
+                                 -D VERSION:STRING=${VERSION}
+                                 -D FORMAT:STRING=tar.bz2
+                                 -P ${CMAKE_SOURCE_DIR}/cmake/generate_archive.cmake)
+ADD_CUSTOM_TARGET(zip    COMMAND ${CMAKE_COMMAND}
+                                 -D SOURCE:STRING=${CMAKE_SOURCE_DIR}
+                                 -D BINARY:STRING=${PROJECT_BINARY_DIR}
+                                 -D VERSION:STRING=${VERSION}
+                                 -D FORMAT:STRING=zip
+                                 -P ${CMAKE_SOURCE_DIR}/cmake/generate_archive.cmake)
+
+#########################
+#### Compile targets ####
+#########################
+
 # add define for length of base path
 string(LENGTH "${CMAKE_SOURCE_DIR}/" BASELENGTH)
 add_definitions(-DBASEPATH_LENGTH=${BASELENGTH})
diff --git a/cmake/generate_archive.cmake b/cmake/generate_archive.cmake
new file mode 100644 (file)
index 0000000..980a6fc
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/cmake
+SET(VERSIONFILE version.cmake)
+
+# look for git executable
+SET(found_git false) 
+find_program(found_git git)
+
+IF(${found_git} STREQUAL "found_git-NOTFOUND")
+  message (FATAL "Git executable not found")
+ENDIF()
+
+SET(found_tar false) 
+find_program(found_tar tar)
+
+IF(${found_tar} STREQUAL "found_tar-NOTFOUND")
+  message (FATAL "Tar executable not found")
+ENDIF()
+
+# add fixed version data
+FILE (COPY ${BINARY}/${VERSIONFILE} DESTINATION ${SOURCE})
+
+# add it to git and stash it away
+execute_process(COMMAND git add ${SOURCE}/${VERSIONFILE} WORKING_DIRECTORY ${SOURCE})
+execute_process(COMMAND git stash create OUTPUT_VARIABLE COMMIT WORKING_DIRECTORY ${SOURCE} OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+# generate archive
+execute_process(COMMAND git archive --prefix=oonf_${VERSION}/ -o ${SOURCE}/oonf_${VERSION}.${FORMAT} ${COMMIT} WORKING_DIRECTORY ${SOURCE})
+
+# remove version file
+FILE (REMOVE ${SOURCE}/${VERSIONFILE})
+execute_process(COMMAND git rm --quiet ${SOURCE}/${VERSIONFILE} WORKING_DIRECTORY ${SOURCE})
index 44ac29f..53bbf7a 100644 (file)
@@ -1,7 +1,7 @@
 #!/bin/cmake
-IF(EXISTS "${CMAKE_SOURCE_DIR}/cmake/version.cmake")
+IF(EXISTS "${CMAKE_SOURCE_DIR}/version.cmake")
   # preconfigured version data
-  FILE (COPY ${CMAKE_SOURCE_DIR}/cmake/version.cmake DESTINATION ${PROJECT_BINARY_DIR})
+  FILE (COPY ${CMAKE_SOURCE_DIR}/version.cmake DESTINATION ${PROJECT_BINARY_DIR})
 ELSEIF(NOT OONF_LIB_GIT AND NOT OONF_VERSION)
   # look for git executable
   SET(found_git false)