LinphoneSdkUtils.cmake 4.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
############################################################################
# LinphoneSdkUtils.cmake
# Copyright (C) 2010-2018 Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
############################################################################

function(linphone_sdk_get_inherited_cmake_args)
	set(_inherited_vars
		CMAKE_BUILD_TYPE:STRING
		CMAKE_C_COMPILER_LAUNCHER:PATH
		CMAKE_CXX_COMPILER_LAUNCHER:PATH
		CMAKE_EXTRA_GENERATOR:STRING
		CMAKE_GENERATOR_PLATFORM:STRING
		CMAKE_INSTALL_MESSAGE:STRING
		CMAKE_VERBOSE_MAKEFILE:BOOL
	)

	set(_inherited_cmake_args)
	foreach(_var ${_inherited_vars})
		string(REPLACE ":" ";" _varname_and_vartype ${_var})
		list(GET _varname_and_vartype 0 _varname)
		list(GET _varname_and_vartype 1 _vartype)
		list(APPEND _inherited_cmake_args "-D${_varname}:${_vartype}=${${_varname}}")
	endforeach()

	set(_inherited_cmake_args ${_inherited_cmake_args} PARENT_SCOPE)
endfunction()

function(linphone_sdk_get_enable_cmake_args)
	set(_enable_cmake_args)
	get_cmake_property(_variable_names VARIABLES)

	foreach(_variable_name ${_variable_names})
		if(_variable_name MATCHES "^ENABLE_.*$" AND NOT _variable_name MATCHES ".*_AVAILABLE$")
			list(APPEND _enable_cmake_args "-D${_variable_name}=${${_variable_name}}")
		endif()
	endforeach()

	set(_enable_cmake_args ${_enable_cmake_args} PARENT_SCOPE)
endfunction()

macro(linphone_sdk_convert_comma_separated_list_to_cmake_list INPUT OUTPUT)
	string(REPLACE " " "" ${OUTPUT} "${INPUT}")
	string(REPLACE "," ";" ${OUTPUT} "${${OUTPUT}}")
endmacro()

Ghislain MARY's avatar
Ghislain MARY committed
63 64 65 66
macro(linphone_sdk_check_git)
	find_package(Git 1.7.10)
endmacro()

67 68
function(linphone_sdk_git_submodule_update)
	if(NOT EXISTS "${LINPHONESDK_DIR}/linphone/CMakeLists.txt")
Ghislain MARY's avatar
Ghislain MARY committed
69
		linphone_sdk_check_git()
70
		execute_process(
Ghislain MARY's avatar
Ghislain MARY committed
71
			COMMAND "${GIT_EXECUTABLE}" "submodule" "update" "--recursive" "--init"
72 73 74 75 76
			WORKING_DIRECTORY "${LINPHONESDK_DIR}"
		)
	endif()
endfunction()

Ghislain MARY's avatar
Ghislain MARY committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
macro(linphone_sdk_compute_full_version OUTPUT_VERSION)
	linphone_sdk_check_git()
	if(GIT_EXECUTABLE)
		execute_process(
			COMMAND "${GIT_EXECUTABLE}" "describe"
			OUTPUT_VARIABLE ${OUTPUT_VERSION}
			OUTPUT_STRIP_TRAILING_WHITESPACE
			ERROR_QUIET
			WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
		)
		if(${OUTPUT_VERSION})
			execute_process(
				COMMAND "${GIT_EXECUTABLE}" "describe" "--abbrev=0"
				OUTPUT_VARIABLE PROJECT_GIT_TAG
				OUTPUT_STRIP_TRAILING_WHITESPACE
				ERROR_QUIET
				WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
			)
			if(NOT PROJECT_GIT_TAG VERSION_EQUAL PROJECT_VERSION)
				message(FATAL_ERROR "Project version (${PROJECT_VERSION}) and git tag (${PROJECT_GIT_TAG}) differ! Please synchronize them.")
			endif()
			unset(PROJECT_GIT_TAG)
		else()
			execute_process(
				COMMAND "${GIT_EXECUTABLE}" "rev-parse" "HEAD"
				OUTPUT_VARIABLE PROJECT_GIT_REVISION
				OUTPUT_STRIP_TRAILING_WHITESPACE
				ERROR_QUIET
				WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
			)
			set(${OUTPUT_VERSION} "${PROJECT_VERSION}-g${PROJECT_GIT_REVISION}")
		endif()
	endif()
endmacro()

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
macro(linphone_sdk_check_is_installed EXECUTABLE_NAME)
	string(TOUPPER "${EXECUTABLE_NAME}" _upper_executable_name)
	find_program(LINPHONESDK_${_upper_executable_name}_PROGRAM ${EXECUTABLE_NAME})
	if(NOT LINPHONESDK_${_upper_executable_name}_PROGRAM)
		message(FATAL_ERROR "${EXECUTABLE_NAME} has not been found on your system. Please install it.")
	endif()
	mark_as_advanced(LINPHONESDK_${_upper_executable_name}_PROGRAM)
endmacro()

function(linphone_sdk_check_python_module_is_installed MODULE_NAME)
	execute_process(
		COMMAND "${PYTHON_EXECUTABLE}" "-c" "import ${MODULE_NAME}"
		RESULT_VARIABLE _result
		OUTPUT_QUIET
		ERROR_QUIET
	)
	if(_result EQUAL 0)
		message(STATUS "'${MODULE_NAME}' python module found")
	else()
		message(FATAL_ERROR "'${MODULE_NAME}' python module not found")
	endif()
endfunction()