File 0001-build-out-of-git.patch of Package linphone-desktop

diff -U 3 -H -b -B -d -r -N -x '*.rej' -x '*.orig' -x '*~' -- linphone-desktop-5.2.6.orig/linphone-app/CMakeLists.txt linphone-desktop-5.2.6/linphone-app/CMakeLists.txt
--- linphone-desktop-5.2.6.orig/linphone-app/CMakeLists.txt
+++ linphone-desktop-5.2.6/linphone-app/CMakeLists.txt
@@ -30,20 +30,182 @@
 
 find_package(BCToolbox)
 if(NOT BCToolbox_FOUND)
-	find_package(bctoolbox CONFIG REQUIRED)
+#	find_package(bctoolbox CONFIG REQUIRED)
 endif()
 if(NOT LINPHONEAPP_VERSION)
-	bc_compute_full_version(LINPHONEAPP_VERSION)
+#	bc_compute_full_version(LINPHONEAPP_VERSION)
 endif()
-set(version_major)
-set(version_minor)
-set(version_patch)
-set(identifiers )
-set(metadata )
+#set(version_major)
+#set(version_minor)
+#set(version_patch)
+#set(identifiers )
+#set(metadata )
+##############################################################
+#
+# Start Fix:
+# Fix error at compilation time on some systems like OpenSUSE build service-
+# Error wording:
+#     ADD_LIBRARY called with SHARED option but the target platform does not
+#     support dynamic linking.
+# Solution:
+#     https://stackoverflow.com/questions/12264299/cmake-on-linux-target-platform-does-not-support-dynamic-linking
+message(STATUS "linphone_app/CMakeLists.txt line 33")
+message(STATUS "Applying patch to fix error: ADD_LIBRARY called with SHARED option but the target platform does not support dynamic linking.")
+message(STATUS "linphone_app/CMakeLists.txt line 35")
+
+# First we copy the functionality here, duplicating the code from BcToolboxCMakeUtils.cmake: 
+# Start copy:
+function(bc_parse_full_version version major minor patch)
+    message("version: '${version}'")
+    if ("${version}" MATCHES "^(0|[1-9][0-9]*)[.](0|[1-9][0-9]*)[.](0|[1-9][0-9]*)(-[.0-9A-Za-z-]+)?([+][.0-9A-Za-z-]+)?$")
+	set(${major}       "${CMAKE_MATCH_1}" PARENT_SCOPE)
+	set(${minor}       "${CMAKE_MATCH_2}" PARENT_SCOPE)
+	set(${patch}       "${CMAKE_MATCH_3}" PARENT_SCOPE)
+	if (ARGC GREATER 4)
+	    set(${ARGV4} "${CMAKE_MATCH_4}" PARENT_SCOPE)
+	endif()
+	if (ARGC GREATER 5)
+	    set(${ARGV5}    "${CMAKE_MATCH_5}" PARENT_SCOPE)
+	endif()
+    else()
+	message(FATAL_ERROR "invalid full version '${version}'")
+    endif()
+endfunction()
+
+function(bc_compute_full_version OUTPUT_VERSION)
+    find_program(GIT_EXECUTABLE git NAMES Git CMAKE_FIND_ROOT_PATH_BOTH)
+    if(GIT_EXECUTABLE)
+	execute_process(
+	    COMMAND "${GIT_EXECUTABLE}" "describe"
+	    OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
+	    OUTPUT_STRIP_TRAILING_WHITESPACE
+	    ERROR_QUIET
+	    WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+	    )
+	# Git may fail because there is no .git folder
+	# cd linphone-sdk
+	# git describe
+	# gives for Linphone SDK: 5.3.1
+	# gives for Linphone APP: 5.2.0
+	
+	if(GIT_DESCRIBE_VERSION)
+	    message("We have GIT_DESCRIBE which gives us ${GIT_DESCRIBE_VERSION}")
+	else()
+	    # Set this to be equal to Linphone APP version,
+	    # not Linphone SDK version!
+	    # set(GIT_DESCRIBE_VERSION "5.3.1") # Linphone SDK Version
+	    # Not allowed to write 5.3.1-2 or 5.3.1-1-g54d3541
+	    set(GIT_DESCRIBE_VERSION "5.2.0") # Linphone APP Version
+	    message(STATUS "GIT_DESCRIBE_VERSION=${GIT_DESCRIBE_VERSION}")
+	endif()
+	
+	# parse git describe version
+	if (NOT (GIT_DESCRIBE_VERSION MATCHES "^([0-9]+)[.]([0-9]+)[.]([0-9]+)(-alpha|-beta)?(-[0-9]+)?(-g[0-9a-f]+)?$"))
+	    # Git may fail because there is no .git folder
+	    # Change FATAL_ERROR to STATUS
+	    # in order not to halt compilation.
+	    message(STATUS "invalid git describe version: '${GIT_DESCRIBE_VERSION}'")
+	endif()
+	set(version_major ${CMAKE_MATCH_1})
+	set(version_minor ${CMAKE_MATCH_2})
+	set(version_patch ${CMAKE_MATCH_3})
+	if (CMAKE_MATCH_4)
+	    string(SUBSTRING "${CMAKE_MATCH_4}" 1 -1 version_prerelease)
+	endif()
+	if (CMAKE_MATCH_5)
+	    string(SUBSTRING "${CMAKE_MATCH_5}" 1 -1 version_commit)
+	endif()
+	if (CMAKE_MATCH_6)
+	    string(SUBSTRING "${CMAKE_MATCH_6}" 2 -1 version_hash)
+	endif()
+	
+	# interpret untagged hotfixes as pre-releases of the next "patch" release
+	if (NOT version_prerelease AND version_commit)
+	    math(EXPR version_patch "${version_patch} + 1")
+	    set(version_prerelease "pre")
+	endif()
+	
+	# format full version
+	set(full_version "${version_major}.${version_minor}.${version_patch}")
+	if (version_prerelease)
+	    string(APPEND full_version "-${version_prerelease}")
+	    if (version_commit)
+		string(APPEND full_version ".${version_commit}+${version_hash}")
+	    endif()
+	endif()
+	
+	# check that the major and minor versions declared by the `project()` command are equal to the ones
+	# that have been found out while parsing `git describe` result.
+	if (PROJECT_VERSION)
+	    set(short_git_version "${version_major}.${version_minor}")
+	    set(short_project_version "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
+	    if(NOT (short_project_version VERSION_EQUAL short_git_version))
+		# Git may fail because there is no .git folder
+		# Change FATAL_ERROR to STATUS
+		# in order not to halt compilation.
+		message(STATUS
+		    "project and git version differ as you may be aware of (project: '${PROJECT_VERSION}', git: '${full_version}'): "
+		    "major and minor version are not equal, but you know what you are doing so this is just for information to avoid halting the compilation."
+		    )
+	    endif()
+	endif()
+	
+	set(${OUTPUT_VERSION} "${full_version}" PARENT_SCOPE)
+    endif()
+endfunction()
+# End copy from BcToolboxCMakeUtils.cmake
+
+# This is the root cause of the error and should be placed AFTER project(linphoneqt VERSION "5.2.0").
+# Move the line below to after calling project(linphoneqt VERSION "5.2.0") and comment out it here:
+# find_package(bctoolbox CONFIG)
+
+set(LINPHONEAPP_VERSION "5.2.0")
+set(LINPHONEAPP_VERSION_BC_COMPUTE )
+bc_compute_full_version(LINPHONEAPP_VERSION_BC_COMPUTE)
+message("-----------------------------------")
+message(STATUS "linphone_app/CMakeLists.txt line 146")
+message("Fix error: ADD_LIBRARY called with SHARED option but the target platform does not support dynamic linking.")
+message("Root cause: find_package(...) is called before project(linphoneqt VERSION 5.2.0)")
+message("LINPHONEAPP_VERSION : ${LINPHONEAPP_VERSION}")
+message("LINPHONEAPP_VERSION_BC_COMPUTE : ${LINPHONEAPP_VERSION_BC_COMPUTE}")
+message("-----------------------------------")
+message(STATUS "linphone_app/CMakeLists.txt line 152")
+
+set(version_major ) # Will become: x (from VERSION x.y.z=5.2.0)
+set(version_minor ) # Will become: y (from VERSION x.y.z=5.2.0)
+set(version_patch ) # Will become: z (from VERSION x.y.z=5.2.0)
+set(identifiers )   # Will for instance become: -alpha-35-geabe561d
+set(metadata )      # Will be empty
+
 bc_parse_full_version("${LINPHONEAPP_VERSION}" version_major version_minor version_patch identifiers metadata)
+message(STATUS "--- bc_parse_full_version ---")
+message(STATUS "linphone_app/CMakeLists.txt line 163")
+set(LINPHONEAPP_VERSION_BC_PARSE "5.2.0")
+bc_parse_full_version("${LINPHONEAPP_VERSION_BC_PARSE}" version_major version_minor version_patch identifiers metadata)
 
+message(STATUS "LINPHONEAPP_VERSION_BC_PARSE : ${LINPHONEAPP_VERSION_BC_PARSE}")
+message(STATUS "version_major : ${version_major}")
+message(STATUS "version_minor : ${version_minor}")
+message(STATUS "version_patch : ${version_patch}")
+message(STATUS "identifiers : ${identifiers}")
+message(STATUS "metadata : ${metadata}")
 
+# Fix error: ADD_LIBRARY called with SHARED option but the target platform does not support dynamic linking.
+# The error occurs when project(linphoneqt VERSION "x.y.z") is defined after find_package(bctoolbox Config)
+# Move the following line to top before calling find_package and comment out it here, or move all find_package(...) below the following line:
 project(linphoneqt VERSION "${version_major}.${version_minor}.${version_patch}")
+# Moving find_package(...) calls to here, after project(...):
+message(STATUS "find_package(bctoolbox CONFIG)")
+message(STATUS "linphone_app/CMakeLists.txt line 180")
+find_package(bctoolbox CONFIG)
+message(STATUS "find_package(bctoolbox CONFIG) was successful.")
+message(STATUS "linphone_app/CMakeLists.txt line 183")
+message(STATUS "End fix error ADD_LIBRARY called with SHARED option but the target platform does not support dynamic linking.")
+message(STATUS "linphone_app/CMakeLists.txt line 186")
+#
+# End fix error ADD_LIBRARY called with SHARED option but the target platform does not support dynamic linking.
+#
+##############################################################
 
 if(ENABLE_BUILD_VERBOSE)
 	#message("CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}")
diff -U 3 -H -b -B -d -r -N -x '*.rej' -x '*.orig' -x '*~' -- linphone-desktop-5.2.6.orig/linphone-app/cmake_builder/linphone_package/CMakeLists.txt linphone-desktop-5.2.6/linphone-app/cmake_builder/linphone_package/CMakeLists.txt
--- linphone-desktop-5.2.6.orig/linphone-app/cmake_builder/linphone_package/CMakeLists.txt
+++ linphone-desktop-5.2.6/linphone-app/cmake_builder/linphone_package/CMakeLists.txt
@@ -48,7 +48,7 @@
     WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../.."
   )
 elseif (NOT(LINPHONEAPP_VERSION))
-  set(LINPHONEAPP_VERSION "0.0.0")
+  set(LINPHONEAPP_VERSION "5.2.0")
 endif ()
 
 set(LINPHONE_MAJOR_VERSION)
diff -U 3 -H -b -B -d -r -N -x '*.rej' -x '*.orig' -x '*~' -- linphone-desktop-5.2.6.orig/linphone-sdk/bctoolbox/cmake/BCToolboxCMakeUtils.cmake linphone-desktop-5.2.6/linphone-sdk/bctoolbox/cmake/BCToolboxCMakeUtils.cmake
--- linphone-desktop-5.2.6.orig/linphone-sdk/bctoolbox/cmake/BCToolboxCMakeUtils.cmake
+++ linphone-desktop-5.2.6/linphone-sdk/bctoolbox/cmake/BCToolboxCMakeUtils.cmake
@@ -20,6 +20,27 @@
 #
 ############################################################################
 
+# Start description of difficulties:
+# STATUS: Clean-up of the added modification cod
+# BcToolbox has to work without .git folder and therefore each
+# place that requires .git folder information must not halt the
+# compilation in abscence of .git folder
+# Reason: OBS OpenSUSE build service (https://build.opensuse.org)
+# has no possibility to include git files to run commands like:
+#     git describe
+# because the tar file does not contain any .git directory.
+# TODO: To be able to compile the software, each part dependent on git
+# must also compile if .git folder is not present.
+# TODO: Somehow implement:
+#     git describe --always
+#     git describe --abbrev=0
+#     git rev-parse <branch>..HEAD
+#     git rev-list --count <branch>..HEAD
+# to work without the presence of .git folder, which usually is very large.
+# A possible solution would be to supply a text file with the information that
+# git describe is supposed to output if .git folder was present.
+# End description of difficulties
+
 macro(bc_init_compilation_flags CPP_FLAGS C_FLAGS CXX_FLAGS STRICT_COMPILATION)
 	set(${CPP_FLAGS} )
 	set(${C_FLAGS} )
@@ -102,7 +123,12 @@
 		)
 	endif()
 	if (NOT PROJECT_VERSION_BUILD)
-		set(PROJECT_VERSION_BUILD 0)
+	# Start fix
+	# git rev-list --count --branches master
+	# gives: 2300 (assumed: no need to change it really, makes no real difference)
+	#set(PROJECT_VERSION_BUILD 0)
+	    set(PROJECT_VERSION_BUILD 2300)
+	# End fix
 	endif()
 endmacro()
 
@@ -129,6 +155,10 @@
 endmacro()
 
 # Rules are following https://semver.org/
+# Start Fix:
+# function(bc_compute_full_version OUTPUT_VERSION)
+# need to be rewritten so it works when .git folder is missing.
+# End Fix
 function(bc_compute_full_version OUTPUT_VERSION)
 	find_program(GIT_EXECUTABLE git NAMES Git CMAKE_FIND_ROOT_PATH_BOTH)
 	if(GIT_EXECUTABLE)
@@ -140,13 +170,33 @@
 			RESULT_VARIABLE GIT_DESCRIBE_STATUS
 			WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
 		)
+		# Start Fix:
+		# Git may fail because there is no .git folder
+		# cd linphone-sdk
+		# git describe
+		# gives: 5.3.1
+		if(GIT_DESCRIBE_VERSION)
+		    message("We have GIT_DESCRIBE which gives us ${GIT_DESCRIBE_VERSION}")
+		else()
+		    message(STATUS "We probably miss .git folder ...")
+		    message(STATUS "Fix: hard code GIT_DESCRIBE_VERSION to 5.3.1")
+		    set(GIT_DESCRIBE_VERSION "5.3.1")
+		    set(GIT_DESCRIBE_STATUS 0)
+		    message(STATUS "GIT_DESCRIBE_VERSION=${GIT_DESCRIBE_VERSION}")
+		    message(STATUS "End Fix BcToolboxMakeUtils.cmake line 185")
+		endif()
+		# End Fix
 		if(NOT GIT_DESCRIBE_STATUS EQUAL 0)
 			message(FATAL_ERROR "fail to get GIT describe version")
 		endif()
 
 		# parse git describe version
 		if (NOT (GIT_DESCRIBE_VERSION MATCHES "^([0-9]+)[.]([0-9]+)[.]([0-9]+)(-alpha|-beta)?(-[0-9]+)?(-g[0-9a-f]+)?$"))
-			message(FATAL_ERROR "invalid git describe version: '${GIT_DESCRIBE_VERSION}'")
+			# Start Fix:
+			# Git may fail because there is no .git folder
+			# message(FATAL_ERROR "invalid git describe version: '${GIT_DESCRIBE_VERSION}'")
+			message(STATUS "invalid git describe version: '${GIT_DESCRIBE_VERSION}'")
+			# End Fix
 		endif()
 		set(version_major ${CMAKE_MATCH_1})
 		set(version_minor ${CMAKE_MATCH_2})
@@ -182,10 +232,21 @@
 			set(short_git_version "${version_major}.${version_minor}")
 			set(short_project_version "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
 			if(NOT (short_project_version VERSION_EQUAL short_git_version))
-				message(FATAL_ERROR
-					"project and git version are not compatible (project: '${PROJECT_VERSION}', git: '${full_version}', at: '${CMAKE_CURRENT_SOURCE_DIR}'): "
-					"major and minor version are not equal !"
+				# Start Fix:
+				# Git may fail because there is no .git folder
+				# When .git folder is not present,
+				# we cannot dynamically control version checks.
+				# Instead we have to know that everything is compatible.
+				# When .git folder is not present,
+				# change the FATAL_ERROR to STATUS to avoid cmake to
+				# terminate compilation:
+				#message(FATAL_ERROR
+				#"project and git version are not compatible (project: '${PROJECT_VERSION}', git: '${full_version}'): "
+				message(STATUS
+				    "project and git version differ as you may be aware of (project: '${PROJECT_VERSION}', git: '${full_version}'): "
+				    "major and minor version are not equal, but you know what you are doing so this is just for information to avoid halting the compilation."
 				)
+				# End Fix
 			endif()
 		endif()
 
@@ -248,7 +309,25 @@
 			set(${ARGV5}    "${CMAKE_MATCH_5}" PARENT_SCOPE)
 		endif()
 	else()
-		message(FATAL_ERROR "invalid full version '${version}'")
+		# Start Fix:
+		message("bc_parse_full_version alpha format example: 5.3.1-alpha.1-g12abcdef")
+		message("bc_parse_full_version beta format example: 5.3.1-beta.1-g12abcdef")
+		message("bc_parse_full_version release format example: 5.3.1")
+		# Not allowed to write 5.3.1-2 or 5.3.1-2-g1234567
+		set(${version} "5.3.1")
+		set(${major} "5") # from (VERSION 5.3.1)
+		set(${minor} "3") # from (VERSION 5.3.1)
+		set(${patch} "1") # from (VERSION 5.3.1)
+		# set(${ARGV4} "-alpha.1-gabcdefab")
+		# Set empty for release:
+		set(${ARGV4} "")
+		# set(${ARGV4} "-1-g123abcdef")
+		# Last argument appears to always be empty in every occasion.
+		set(${ARGV5} "")
+		# To avoid halting the compilation when .git folder is missing:
+		# message(FATAL_ERROR "invalid full version '${version}'")
+		message(STATUS "invalid full version '${version}'")
+		# End Fix
 	endif()
 endfunction()
 
openSUSE Build Service is sponsored by