Fix tarball generator
authorHenning Rogge <henning.rogge@fkie.fraunhofer.de>
Mon, 14 May 2018 08:58:05 +0000 (10:58 +0200)
committerHenning Rogge <henning.rogge@fkie.fraunhofer.de>
Mon, 14 May 2018 09:30:02 +0000 (11:30 +0200)
CMakeLists.txt
CMakeListsGlobal.cmake
cmake/generate_archive.cmake
cmake/get_version.cmake

index a207c23..522dfa3 100644 (file)
@@ -53,6 +53,14 @@ endif(DOXYGEN_FOUND)
 #### add tarball targets ####
 #############################
 
+ADD_CUSTOM_TARGET(tar    COMMAND ${CMAKE_COMMAND}
+                                 -D SOURCE:STRING=${CMAKE_SOURCE_DIR}
+                                 -D BINARY:STRING=${PROJECT_BINARY_DIR}
+                                 -D VERSION:STRING=${VERSION}
+                                 -D FORMAT:STRING=tar
+                                 -D TARBALL:STRING=${TARBALL}
+                                 -D TARPREFIX:STRING=${TARPREFIX}
+                                 -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/generate_archive.cmake)
 ADD_CUSTOM_TARGET(targz  COMMAND ${CMAKE_COMMAND}
                                  -D SOURCE:STRING=${CMAKE_SOURCE_DIR}
                                  -D BINARY:STRING=${PROJECT_BINARY_DIR}
@@ -61,7 +69,6 @@ ADD_CUSTOM_TARGET(targz  COMMAND ${CMAKE_COMMAND}
                                  -D TARBALL:STRING=${TARBALL}
                                  -D TARPREFIX:STRING=${TARPREFIX}
                                  -P ${CMAKE_CURRENT_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}
index 2134c3d..697e717 100644 (file)
@@ -12,7 +12,8 @@ project (OONF C)
 SET(APP_DATA_C_IN ${CMAKE_CURRENT_LIST_DIR}/src/main/app_data.c.in)
 SET(MAIN_C ${CMAKE_CURRENT_LIST_DIR}/src/main/main.c)
 SET(VERSION_CMAKE_IN ${CMAKE_CURRENT_LIST_DIR}/cmake/files/version.cmake.in)
-SET(VERSION_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR})
+SET(VERSION_SOURCE_DIR ${CMAKE_SOURCE_DIR})
+SET(VERSION_SOURCE_SUB_DIR ${CMAKE_CURRENT_LIST_DIR})
 
 #################################
 #### add include directories ####
index 857dd72..e63f363 100644 (file)
@@ -6,23 +6,16 @@ SET(found_git false)
 find_program(found_git git)
 
 IF(${found_git} STREQUAL "found_git-NOTFOUND")
-  message (FATAL "Git executable not found")
+  message (FATAL_ERROR "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")
+  message (FATAL_ERROR "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)
-
 IF (NOT TARBALL)
     SET(TARBALL "${SOURCE}/oonf_${VERSION}.${FORMAT}")
 ENDIF (NOT TARBALL)
@@ -31,8 +24,22 @@ IF (NOT TARPREFIX)
     SET (TARPREFIX "oonf_${VERSION}")
 ENDIF (NOT TARPREFIX)
 
+IF (EXISTS ${SOURCE}/.gitmodules AND NOT "${TARBALL}" MATCHES ".tar\$")
+    message (FATAL_ERROR "Submodules are only supported with uncompressed tarballs")
+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=${TARPREFIX}/ -o ${TARBALL} ${COMMIT} WORKING_DIRECTORY ${SOURCE})
+execute_process(COMMAND git submodule foreach "git archive --prefix=${TARPREFIX}/\$name/ -o submodule.tar HEAD" WORKING_DIRECTORY ${SOURCE})
+execute_process(COMMAND git submodule foreach tar --concatenate --file=${TARBALL} submodule.tar WORKING_DIRECTORY ${SOURCE})
+execute_process(COMMAND git submodule foreach rm submodule.tar WORKING_DIRECTORY ${SOURCE})
 
 # remove version file
 FILE (REMOVE ${SOURCE}/${VERSIONFILE})
index d0c21f8..1f02ad8 100644 (file)
@@ -1,7 +1,7 @@
 #!/bin/cmake
-IF(EXISTS "${CMAKE_SOURCE_DIR}/version.cmake")
+IF(EXISTS "${VERSION_SOURCE_DIR}/version.cmake")
   # preconfigured version data
-  FILE (COPY ${VERSION_CMAKE_DIR}/version.cmake DESTINATION ${PROJECT_BINARY_DIR})
+  FILE (COPY ${VERSION_SOURCE_DIR}/version.cmake DESTINATION ${PROJECT_BINARY_DIR})
 ELSEIF(NOT OONF_LIB_GIT OR NOT OONF_VERSION)
   # look for git executable
   SET(found_git false) 
@@ -12,20 +12,43 @@ ELSEIF(NOT OONF_LIB_GIT OR NOT OONF_VERSION)
   IF(NOT ${found_git} STREQUAL "found_git-NOTFOUND")
     # get git description WITH dirty flag
     execute_process(COMMAND git describe --always --long --tags --dirty --match "v[0-9]*"
-      WORKING_DIRECTORY ${VERSION_CMAKE_DIR}
+      WORKING_DIRECTORY ${VERSION_SOURCE_DIR}
       OUTPUT_VARIABLE LIB_GIT OUTPUT_STRIP_TRAILING_WHITESPACE)
 
-    # get git description WITH dirty flag
+    # get tag name
     execute_process(COMMAND git describe --abbrev=0 --match "v[0-9]*"
-      WORKING_DIRECTORY ${VERSION_CMAKE_DIR} RESULT_VARIABLE result
+      WORKING_DIRECTORY ${VERSION_SOURCE_DIR} RESULT_VARIABLE result
       OUTPUT_VARIABLE VERSION_TAG OUTPUT_STRIP_TRAILING_WHITESPACE)
 
     IF(NOT ${result} STREQUAL "0")
-        SET(VERSION_TAG "v0.1")
+        SET(VERSION_TAG "")
+    ENDIF()
+
+    IF(NOT ${VERSION_SOURCE_DIR} STREQUAL ${VERSION_SOURCE_SUB_DIR})
+        # get git description for submodule WITH dirty flag
+        execute_process(COMMAND git describe --always --long --tags --dirty --match "v[0-9]*"
+          WORKING_DIRECTORY ${VERSION_SOURCE_SUB_DIR}
+          OUTPUT_VARIABLE LIB_SUB_GIT OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+        # get tag name for submodule
+        execute_process(COMMAND git describe --abbrev=0 --match "v[0-9]*"
+          WORKING_DIRECTORY ${VERSION_SOURCE_SUB_DIR} RESULT_VARIABLE result
+          OUTPUT_VARIABLE VERSION_SUB_TAG OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+        IF(NOT ${result} STREQUAL "0")
+            SET(VERSION_SUB_TAG "v0.1")
+        ENDIF()
+
+        SET(LIB_GIT "${LIB_GIT}_sub_${LIB_SUB_GIT}")
+    ENDIF()
+
+    IF("${VERSION_TAG}" STREQUAL "")
+        SET(VERSION_TAG "${VERSION_SUB_TAG}")
     ENDIF()
-    
+
     # strip "v" from tag
     string(SUBSTRING ${VERSION_TAG} 1 -1 VERSION)
+
   ENDIF()
   
   message ("Git commit: ${LIB_GIT}, Git version: ${VERSION}")