CMakeLists.txt 58.1 KB
Newer Older
1
############################################################################
2
# CMakeLists.txt
3
# Copyright (C) 2014-2018  Belledonne Communications, Grenoble France
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#
############################################################################
#
# 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
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 21 22 23
#
############################################################################

include(ExternalProject)
24
include(${CMAKE_CURRENT_LIST_DIR}/LinphoneOptions.cmake)
25

26
set(ep_base "${LINPHONE_BUILDER_WORK_DIR}/${CONFIG_NAME}")
27
set_property(DIRECTORY PROPERTY EP_BASE ${ep_base})
28
set(LINPHONE_BUILDER_OPTIONS_DIR "${CMAKE_CURRENT_LIST_DIR}/../options")
29

30

31 32 33
# Define the architecture. It will be used to generate the URL to get prebuilt dependencies.
if(WIN32)
	set(LINPHONE_BUILDER_ARCHITECTURE "Win32")
34 35 36 37
elseif(UNIX)
	if(APPLE)
		set(LINPHONE_BUILDER_ARCHITECTURE "OsX64")
	endif()
38 39 40
endif()


41
if(CMAKE_VERBOSE_MAKEFILE)
42
	set(AUTOTOOLS_VERBOSE_MAKEFILE 1)
43
else()
44
	set(AUTOTOOLS_VERBOSE_MAKEFILE 0)
45
endif()
46 47


48
set(LINPHONE_BUILDER_EP_VARS)
49
set(LINPHONE_BUILDER_INCLUDED_BUILDERS)
50
set(LINPHONE_BUILDER_INCLUDED_BUILDERS_TO_EXCLUDE)
51
set(LINPHONE_BUILDER_SOURCE_PACKAGE_BUILDERS)
52
set(LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS)
53
set(LINPHONE_BUILDER_SYSTEM_DEPENDENCIES_BUILDERS)
54 55

macro(linphone_builder_expand_external_project_vars)
Ghislain MARY's avatar
Ghislain MARY committed
56 57 58 59 60 61 62
	set(LINPHONE_BUILDER_EP_ARGS "")
	set(LINPHONE_BUILDER_EP_VARNAMES "")
	foreach(arg ${LINPHONE_BUILDER_EP_VARS})
		string(REPLACE ":" ";" varname_and_vartype ${arg})
		set(target_info_list ${target_info_list})
		list(GET varname_and_vartype 0 _varname)
		list(GET varname_and_vartype 1 _vartype)
63 64 65 66
		if (DEFINED ${_varname})
			list(APPEND LINPHONE_BUILDER_EP_ARGS -D${_varname}:${_vartype}=${${_varname}})
			list(APPEND LINPHONE_BUILDER_EP_VARNAMES ${_varname})
		endif()
Ghislain MARY's avatar
Ghislain MARY committed
67
	endforeach()
68
endmacro()
69 70 71 72

list(APPEND LINPHONE_BUILDER_EP_VARS
	CMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH
	CMAKE_BUILD_TYPE:STRING
73
	CMAKE_BUILD_WITH_INSTALL_RPATH:BOOL
74
	CMAKE_BUNDLE_OUTPUT_DIRECTORY:PATH
75
	CMAKE_C_COMPILER_LAUNCHER:PATH
76 77 78 79
	CMAKE_C_FLAGS_DEBUG:STRING
	CMAKE_C_FLAGS_MINSIZEREL:STRING
	CMAKE_C_FLAGS_RELEASE:STRING
	CMAKE_C_FLAGS_RELWITHDEBINFO:STRING
80
	CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES:LIST
81
	CMAKE_CXX_COMPILER_LAUNCHER:PATH
82 83 84 85
	CMAKE_CXX_FLAGS_DEBUG:STRING
	CMAKE_CXX_FLAGS_MINSIZEREL:STRING
	CMAKE_CXX_FLAGS_RELEASE:STRING
	CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING
86 87
	CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES:LIST
	CMAKE_EXE_LINKER_FLAGS:STRING
88 89 90 91 92
	CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING
	CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING
	CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING
	CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING
	CMAKE_EXTRA_GENERATOR:STRING
93
	CMAKE_GENERATOR_PLATFORM:STRING
94
	CMAKE_INSTALL_MESSAGE:STRING
95
	CMAKE_INSTALL_PREFIX:PATH
96
	CMAKE_SYSTEM_PREFIX_PATH:LIST
97 98
	CMAKE_INSTALL_RPATH:PATH
	CMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL
99 100 101 102 103 104
	CMAKE_LIBRARY_OUTPUT_DIRECTORY:PATH
	CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING
	CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING
	CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING
	CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING
	CMAKE_MODULE_PATH:PATH
105
	CMAKE_NO_BUILD_TYPE:BOOL
106
	CMAKE_NO_SYSTEM_FROM_IMPORTED:BOOL
107
	CMAKE_PREFIX_PATH:STRING
108
	CMAKE_STAGING_PREFIX:STRING
109
	CMAKE_PROGRAM_PATH:STRING
110 111 112 113 114
	CMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH
	CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING
	CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING
	CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING
	CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING
115
	CMAKE_SKIP_INSTALL_RPATH:BOOL
116
	CMAKE_SKIP_RPATH:BOOL
117
	CMAKE_SKIP_BUILD_RPATH:BOOL
118
	CMAKE_VERBOSE_MAKEFILE:BOOL
119
	LINPHONE_IOS_DEPLOYMENT_TARGET:STRING
120 121 122
	MSVC_C_ARCHITECTURE_ID:STRING
	MSVC_CXX_ARCHITECTURE_ID:STRING
	MSVC_VERSION:STRING
123
)
124
if(CMAKE_CROSSCOMPILING)
Ghislain MARY's avatar
Ghislain MARY committed
125
	list(APPEND LINPHONE_BUILDER_EP_VARS
126
		CMAKE_SYSTEM_NAME:STRING
127
		CMAKE_SYSTEM_PROCESSOR:STRING
128 129 130
		CMAKE_SYSTEM_VERSION:STRING
	)
endif()
131 132
if(APPLE)
	list(APPEND LINPHONE_BUILDER_EP_VARS
133
		CMAKE_MACOSX_RPATH:BOOL
134 135 136
		CMAKE_OSX_ARCHITECTURES:STRING
		CMAKE_OSX_DEPLOYMENT_TARGET:STRING
	)
137
endif()
138 139 140 141 142 143 144
if(MSVC)
	if(CMAKE_VERSION VERSION_GREATER "3.3")
		list(APPEND LINPHONE_BUILDER_EP_VARS
			CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD:BOOL
		)
	endif()
endif()
145 146 147
if(CMAKE_TOOLCHAIN_FILE)
	list(APPEND LINPHONE_BUILDER_EP_VARS CMAKE_TOOLCHAIN_FILE:PATH)
endif()
148 149


150
macro(linphone_builder_get_autotools_configuration)
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
	if(MSVC)
		set(_generator "MinGW Makefiles")
	else()
		set(_generator "${CMAKE_GENERATOR}")
	endif()
	set(_autotools_command ${CMAKE_COMMAND} -G "${_generator}")
	if(CMAKE_TOOLCHAIN_FILE)
		list(APPEND _autotools_command "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
	endif()
	if(CMAKE_OSX_ARCHITECTURES)
		list(APPEND _autotools_command "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}")
	endif()
	if(CMAKE_C_COMPILER_LAUNCHER)
		list(APPEND _autotools_command "-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}")
	endif()
	if(CMAKE_CXX_COMPILER_LAUNCHER)
		list(APPEND _autotools_command "-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}")
	endif()
	list(APPEND _autotools_command
		"-DAUTOTOOLS_AS_FLAGS=${AUTOTOOLS_AS_FLAGS}"
		"-DAUTOTOOLS_C_FLAGS=${AUTOTOOLS_C_FLAGS}"
		"-DAUTOTOOLS_CPP_FLAGS=${AUTOTOOLS_CPP_FLAGS}"
		"-DAUTOTOOLS_CXX_FLAGS=${AUTOTOOLS_CXX_FLAGS}"
		"-DAUTOTOOLS_OBJC_FLAGS=${AUTOTOOLS_OBJC_FLAGS}"
		"-DAUTOTOOLS_LINKER_FLAGS=${AUTOTOOLS_LINKER_FLAGS}"
	)
	list(APPEND _autotools_command "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Autotools/")
	execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/Autotools)
	execute_process(COMMAND ${_autotools_command} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Autotools)
	unset(_autotools_command)
	unset(_extra_generator)
	unset(_generator)
	include(${CMAKE_BINARY_DIR}/Autotools/Autotools.cmake)
184
endmacro()
185 186


187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
macro(lcb_add_target_dependencies TARGET_NAME)
	set(_args2 "${ARGN}")
	foreach(_arg IN LISTS _args2)
		set(_list ${TARGET_${_arg}_DEPENDENCIES})
		if(_list)
			list(REMOVE_ITEM _list "${_arg}")
		endif()
		if(_list)
			lcb_add_target_dependencies("${TARGET_NAME}" ${_list})
		endif()
		list(FIND TARGET_${TARGET_NAME}_DEPENDENCIES "${_arg}" _target_found)
		if(_target_found LESS 0)
			list(APPEND TARGET_${TARGET_NAME}_DEPENDENCIES "${_arg}")
		endif()
	endforeach()
endmacro()

204
# DEPRECATED: Use lcb_define_targets() instead
205 206 207 208 209 210
macro(lcb_define_target TARGET_NAME)
	set(_args "${ARGN}")
	list(APPEND LINPHONE_BUILDER_TARGETS "${TARGET_NAME}")
	set_property(CACHE LINPHONE_BUILDER_TARGET PROPERTY STRINGS ${LINPHONE_BUILDER_TARGETS})
endmacro()

211 212 213 214 215 216 217
macro(lcb_define_targets)
	set(_args "${ARGN}")
	foreach(_arg IN LISTS _args)
		lcb_define_target("${_arg}")
	endforeach()
endmacro()

218 219 220 221 222 223 224
macro(lcb_add_builder_to_target TARGET_NAME BUILDER_NAME)
	list(APPEND TARGET_${TARGET_NAME}_BUILDERS "${BUILDER_NAME}")
endmacro()

macro(lcb_check_target)
	list(FIND LINPHONE_BUILDER_TARGETS "${LINPHONE_BUILDER_TARGET}" _target_found)
	if(_target_found EQUAL -1)
jehan's avatar
jehan committed
225
		message(FATAL_ERROR "Invalid LINPHONE_BUILDER_TARGET '${LINPHONE_BUILDER_TARGET}'")
226
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
227
endmacro()
228

229 230 231 232 233 234 235 236 237 238
macro(lcb_declare_target TARGET_NAME)
	add_custom_target(TARGET_${TARGET_NAME} ALL)
	add_dependencies(TARGET_linphone_builder TARGET_${TARGET_NAME})
	unset(_dependencies)
	linphone_builder_add_builder_to_target(TARGET_${TARGET_NAME} "${TARGET_NAME}" TRUE _dependencies)
	list(APPEND LINPHONE_BUILDER_INCLUDED_BUILDERS ${_dependencies})
endmacro()

macro(lcb_declare_targets)
	add_custom_target(TARGET_linphone_builder ALL)
239
	lcb_declare_target("${LINPHONE_BUILDER_TARGET}")
240 241
endmacro()

242

243 244
macro(linphone_builder_include_builder BUILDER INCLUDE_AFTER DEPENDENCIES _included)
	set(${_included} -1)
245
	list(FIND LINPHONE_BUILDER_INCLUDED_BUILDERS ${BUILDER} _already_included)
246 247
	list(FIND ${DEPENDENCIES} ${BUILDER} _already_included2)
	if(_already_included EQUAL -1 AND _already_included2 EQUAL -1)
248 249
		unset(_builder_filepath)
		if(LINPHONE_BUILDER_EXTERNAL_BUILDERS_PATH)
250
			set(_builder_filepath "${LINPHONE_BUILDER_EXTERNAL_BUILDERS_PATH}/${BUILDER}.cmake")
251 252 253 254 255
			if(NOT EXISTS "${_builder_filepath}")
				unset(_builder_filepath)
			endif()
		endif()
		if(NOT _builder_filepath)
256 257 258 259
			set(_builder_filepath "${CMAKE_CURRENT_SOURCE_DIR}/builders/${BUILDER}.cmake")
		endif()
		if(EXISTS "${_builder_filepath}")
			message(STATUS "Including builder ${BUILDER}")
260 261 262
			if(EXISTS ${LINPHONE_BUILDER_OPTIONS_DIR}/${BUILDER}.cmake)
				include(${LINPHONE_BUILDER_OPTIONS_DIR}/${BUILDER}.cmake)
			endif()
263 264 265 266 267 268 269 270
			set(LINPHONE_BUILDER_CURRENT_BUILDER "${BUILDER}")
			include(${_builder_filepath})
			if(INCLUDE_AFTER)
				list(APPEND ${DEPENDENCIES} ${BUILDER})
			else()
				list(INSERT ${DEPENDENCIES} 0 ${BUILDER})
			endif()
			set(${_included} 1)
271
			unset(LINPHONE_BUILDER_CURRENT_BUILDER)
272
		endif()
273 274
	endif()
	unset(_already_included)
Ghislain MARY's avatar
Ghislain MARY committed
275
endmacro()
276 277


278 279 280 281 282
macro(linphone_builder_add_builder_to_target TARGETNAME BUILDER INCLUDE_AFTER DEPENDENCIES)
	linphone_builder_include_builder(${BUILDER} ${INCLUDE_AFTER} ${DEPENDENCIES} _included)
	if(_included GREATER -1)
		if(LINPHONE_BUILDER_USE_SYSTEM_DEPENDENCIES AND EP_${BUILDER}_MAY_BE_FOUND_ON_SYSTEM)
			list(FIND LINPHONE_BUILDER_SYSTEM_DEPENDENCIES_BUILDERS ${BUILDER} _already_included)
283
			if(_already_included EQUAL -1)
284 285 286 287
				message("    Using ${BUILDER} from the system")
				list(APPEND LINPHONE_BUILDER_INCLUDED_BUILDERS_TO_EXCLUDE ${BUILDER})
				list(APPEND LINPHONE_BUILDER_SYSTEM_DEPENDENCIES_BUILDERS ${BUILDER})
			endif()
288
		elseif((LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH OR LINPHONE_BUILDER_ALTERNATE_EXTERNAL_SOURCE_PATH) AND LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
289 290 291 292
			foreach(SUBDIR ${EP_${BUILDER}_EXTERNAL_SOURCE_PATHS})
				if(SUBDIR STREQUAL "<LINPHONE_BUILDER_TOP_DIR>")
					set(_source_dir "${LINPHONE_BUILDER_TOP_DIR}")
				else()
293 294 295 296 297
					if(LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH AND EXISTS "${LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH}/${SUBDIR}")
						set(_source_dir "${LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH}/${SUBDIR}")
					else()
						set(_source_dir "${LINPHONE_BUILDER_ALTERNATE_EXTERNAL_SOURCE_PATH}/${SUBDIR}")
					endif()
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
				endif()
				if(EXISTS "${_source_dir}")
					#message("    ${TARGETNAME} depends on external source path ${_source_dir}")
					set(_build_from_external_source_path 1)
					break()
				endif()
			endforeach()
			if(_build_from_external_source_path)
				list(FIND LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS ${BUILDER} _already_included)
				if(_already_included EQUAL -1)
					# message("    external source path builder ${BUILDER}: ${_source_dir}")
					set(EP_${BUILDER}_SOURCE_DIR "${_source_dir}")
					list(APPEND LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS ${BUILDER})
				endif()
				unset(_already_included)
			else()
				#message("     ${TARGETNAME} depends on external project EP_${BUILDER}")
				add_dependencies(${TARGETNAME} EP_${BUILDER})
316
			endif()
317
			unset(_build_from_external_source_path)
318
		else()
319
			#message("    ${TARGETNAME} depends on external project EP_${BUILDER}")
320
			add_dependencies(${TARGETNAME} EP_${BUILDER})
321
		endif()
322 323 324 325
		foreach(_dependency IN LISTS EP_${BUILDER}_DEPENDENCIES)
			string(REGEX REPLACE "^EP_" "" _dep ${_dependency})
			linphone_builder_add_builder_to_target(${TARGETNAME} "${_dep}" FALSE ${DEPENDENCIES})
		endforeach()
326
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
327
endmacro()
328 329


330
macro(linphone_builder_apply_flags)
331 332 333 334 335 336 337 338 339 340 341 342
	if (CMAKE_CONFIGURATION_TYPES)
  	FOREACH(CONFIG_NAME ${CMAKE_CONFIGURATION_TYPES})
	    string(TOUPPER "${CONFIG_NAME}" CONFIG_NAME_UPPER)
	    linphone_builder_apply_flags_for_build_type(${CONFIG_NAME_UPPER})
  	ENDFOREACH(CONFIG_NAME)
	else()
	  string(TOUPPER "${CMAKE_BUILD_TYPE}" BUILD_TYPE)
	  linphone_builder_apply_flags_for_build_type(${BUILD_TYPE})
	endif()
endmacro()

macro(linphone_builder_apply_flags_for_build_type BUILD_TYPE)
Ghislain MARY's avatar
Ghislain MARY committed
343 344 345 346 347 348 349 350 351 352
	if(LINPHONE_BUILDER_OSX_ARCHITECTURES)
		set(CMAKE_OSX_ARCHITECTURES ${LINPHONE_BUILDER_OSX_ARCHITECTURES})
		set(AUTOTOOLS_ARCH "-arch ${CMAKE_OSX_ARCHITECTURES}")
		set(AUTOTOOLS_C_FLAGS "${AUTOTOOLS_C_FLAGS} ${AUTOTOOLS_ARCH}")
		set(AUTOTOOLS_CXX_FLAGS "${AUTOTOOLS_CXX_FLAGS} ${AUTOTOOLS_ARCH}")
		set(AUTOTOOLS_OBJC_FLAGS "${AUTOTOOLS_OBJC_FLAGS} ${AUTOTOOLS_ARCH}")
		set(AUTOTOOLS_LINKER_FLAGS "${AUTOTOOLS_LINKER_FLAGS} ${AUTOTOOLS_ARCH}")
	endif()

	if(LINPHONE_BUILDER_CPPFLAGS)
353 354
		set(CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_CPPFLAGS}")
		set(CMAKE_CXX_FLAGS_${BUILD_TYPE} "${CMAKE_CXX_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_CPPFLAGS}")
355 356
		set(AUTOTOOLS_C_FLAGS "${AUTOTOOLS_C_FLAGS} ${LINPHONE_BUILDER_CPPFLAGS} ")
		set(AUTOTOOLS_CXX_FLAGS "${AUTOTOOLS_CXX_FLAGS} ${LINPHONE_BUILDER_CPPFLAGS} ")
Ghislain MARY's avatar
Ghislain MARY committed
357 358
	endif()
	if(LINPHONE_BUILDER_CFLAGS)
359
		set(CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_CFLAGS}")
360
		set(AUTOTOOLS_C_FLAGS "${AUTOTOOLS_C_FLAGS} ${LINPHONE_BUILDER_CFLAGS} ")
Ghislain MARY's avatar
Ghislain MARY committed
361 362
	endif()
	if(LINPHONE_BUILDER_CXXFLAGS)
363
		set(CMAKE_CXX_FLAGS_${BUILD_TYPE} "${CMAKE_CXX_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_CXXFLAGS}")
364
		set(AUTOTOOLS_CXX_FLAGS "${AUTOTOOLS_CXX_FLAGS} ${LINPHONE_BUILDER_CXX_FLAGS} ")
Ghislain MARY's avatar
Ghislain MARY committed
365 366
	endif()
	if(LINPHONE_BUILDER_OBJCFLAGS)
367
		set(CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_OBJCFLAGS}")
368
		set(AUTOTOOLS_OBJC_FLAGS "${AUTOTOOLS_OBJC_FLAGS} ${LINPHONE_BUILDER_OBJCFLAGS} ")
Ghislain MARY's avatar
Ghislain MARY committed
369 370
	endif()
	if(LINPHONE_BUILDER_LDFLAGS)
371 372 373
		set(CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_LDFLAGS}")
		set(CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_LDFLAGS}")
		set(CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_LDFLAGS}")
374
		set(AUTOTOOLS_LINKER_FLAGS "${AUTOTOOLS_LINKER_FLAGS} ${LINPHONE_BUILDER_LDFLAGS} ")
Ghislain MARY's avatar
Ghislain MARY committed
375
	endif()
376
	unset(BUILD_TYPE)
377 378 379 380 381 382
	if(WIN32)
		string(REGEX REPLACE "/[a-zA-Z0-9]+ " "" AUTOTOOLS_C_FLAGS "${AUTOTOOLS_C_FLAGS}")
		string(REGEX REPLACE "/[a-zA-Z0-9]+ " "" AUTOTOOLS_CXX_FLAGS "${AUTOTOOLS_CXX_FLAGS}")
		string(REGEX REPLACE "/[a-zA-Z0-9]+ " "" AUTOTOOLS_OBJC_FLAGS "${AUTOTOOLS_OBJC_FLAGS}")
		string(REGEX REPLACE "/[a-zA-Z0-9]+ " "" AUTOTOOLS_LINKER_FLAGS "${AUTOTOOLS_LINKER_FLAGS}")
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
383
endmacro()
384 385


386
macro(linphone_builder_apply_cmake_flags_to_autotools_project PROJNAME)
Ghislain MARY's avatar
Ghislain MARY committed
387
	if(EP_${PROJNAME}_BUILD_METHOD STREQUAL "autotools")
Ghislain MARY's avatar
Ghislain MARY committed
388 389 390 391 392 393
		set(ep_asflags "${AUTOTOOLS_AS_FLAGS}")
		set(ep_cppflags "${AUTOTOOLS_CPP_FLAGS}")
		set(ep_cflags "${AUTOTOOLS_C_FLAGS}")
		set(ep_cxxflags "${AUTOTOOLS_CXX_FLAGS}")
		set(ep_objcflags "${AUTOTOOLS_OBJC_FLAGS}")
		set(ep_ldflags "${AUTOTOOLS_LINKER_FLAGS}")
394
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
395
endmacro()
396 397


398
macro(linphone_builder_apply_extra_flags PROJNAME)
399 400 401 402 403 404 405 406 407 408 409 410
	if (CMAKE_CONFIGURATION_TYPES)
		FOREACH(CONFIG_NAME ${CMAKE_CONFIGURATION_TYPES})
		  string(TOUPPER "${CONFIG_NAME}" CONFIG_NAME_UPPER)
		  linphone_builder_apply_extra_flags_for_build_type(${PROJNAME} ${CONFIG_NAME_UPPER})
		ENDFOREACH(CONFIG_NAME)
	else()
		string(TOUPPER "${CMAKE_BUILD_TYPE}" BUILD_TYPE)
		linphone_builder_apply_extra_flags_for_build_type(${PROJNAME} ${BUILD_TYPE})
	endif()
endmacro()

macro(linphone_builder_apply_extra_flags_for_build_type PROJNAME BUILD_TYPE)
411 412 413 414 415
	if(MSVC)
		set(_no_warnings_flag "/W0")
	else()
		set(_no_warnings_flag "-w")
	endif()
416 417 418 419 420
	set(SAVED_CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${BUILD_TYPE}}")
	set(SAVED_CMAKE_CXX_FLAGS_${BUILD_TYPE} "${CMAKE_CXX_FLAGS_${BUILD_TYPE}}")
	set(SAVED_CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE}}")
	set(SAVED_CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE}}")
	set(SAVED_CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE}}")
Ghislain MARY's avatar
Ghislain MARY committed
421
	if(EP_${PROJNAME}_BUILD_METHOD STREQUAL "autotools")
422 423 424 425 426 427
		set(ep_asflags "${ep_asflags} ${EP_${PROJNAME}_EXTRA_ASFLAGS}")
		set(ep_cppflags "${ep_cppflags} ${EP_${PROJNAME}_EXTRA_CPPFLAGS}")
		set(ep_cflags "${ep_cflags} ${EP_${PROJNAME}_EXTRA_CFLAGS}")
		set(ep_cxxflags "${ep_cxxflags} ${EP_${PROJNAME}_EXTRA_CXXFLAGS}")
		set(ep_objcflags "${ep_objcflags} ${EP_${PROJNAME}_EXTRA_OBJCFLAGS}")
		set(ep_ldflags "${ep_ldflags} ${EP_${PROJNAME}_EXTRA_LDFLAGS}")
428 429 430
		if(EP_${PROJNAME}_IGNORE_WARNINGS)
			set(ep_cppflags "${ep_cppflags} ${_no_warnings_flag}")
		endif()
431
	else()
432
		if(EP_${PROJNAME}_EXTRA_CFLAGS)
433
			set(CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${BUILD_TYPE}} ${EP_${PROJNAME}_EXTRA_CFLAGS}")
434 435
		endif()
		if(EP_${PROJNAME}_EXTRA_CXXFLAGS)
436
			set(CMAKE_CXX_FLAGS_${BUILD_TYPE} "${CMAKE_CXX_FLAGS_${BUILD_TYPE}} ${EP_${PROJNAME}_EXTRA_CXXFLAGS}")
437 438
		endif()
		if(EP_${PROJNAME}_EXTRA_LDFLAGS)
439 440 441
			set(CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE}} ${EP_${PROJNAME}_EXTRA_LDFLAGS}")
			set(CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE}} ${EP_${PROJNAME}_EXTRA_LDFLAGS}")
			set(CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE}} ${EP_${PROJNAME}_EXTRA_LDFLAGS}")
442
		endif()
443
		if(EP_${PROJNAME}_IGNORE_WARNINGS)
444 445
			set(CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${BUILD_TYPE}} ${_no_warnings_flag}")
			set(CMAKE_CXX_FLAGS_${BUILD_TYPE} "${CMAKE_CXX_FLAGS_${BUILD_TYPE}} ${_no_warnings_flag}")
446
		endif()
447
		if(ENABLE_SANITIZER AND EP_${PROJNAME}_SANITIZABLE)
448
			set(sanitize_flags "-fsanitize=address,undefined")
449 450 451 452 453 454 455
			set(CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${BUILD_TYPE}} ${sanitize_flags}")
			set(CMAKE_CXX_FLAGS_${BUILD_TYPE} "${CMAKE_CXX_FLAGS_${BUILD_TYPE}} ${sanitize_flags}")
			set(CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE}} ${sanitize_flags}")
			set(CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE}} ${sanitize_flags}")
			set(CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE}} ${sanitize_flags}")
			unset(sanitize_flags)
		endif()
456
	endif()
457
	unset(BUILD_TYPE)
Ghislain MARY's avatar
Ghislain MARY committed
458
endmacro()
459 460


461
macro(linphone_builder_restore_flags)
462 463 464 465 466 467 468 469 470 471 472 473
	if (CMAKE_CONFIGURATION_TYPES)
	  FOREACH(CONFIG_NAME ${CMAKE_CONFIGURATION_TYPES})
		  string(TOUPPER "${CONFIG_NAME}" CONFIG_NAME_UPPER)
		  linphone_builder_restore_flags_for_build_type(${CONFIG_NAME_UPPER})
	  ENDFOREACH(CONFIG_NAME)
	else()
	  string(TOUPPER "${CMAKE_BUILD_TYPE}" BUILD_TYPE)
	  linphone_builder_restore_flags_for_build_type(${BUILD_TYPE})
	endif()
endmacro()

macro(linphone_builder_restore_flags_for_build_type BUILD_TYPE)
474 475 476 477 478
	set(CMAKE_C_FLAGS_${BUILD_TYPE} "${SAVED_CMAKE_C_FLAGS_${BUILD_TYPE}}")
	set(CMAKE_CXX_FLAGS_${BUILD_TYPE} "${SAVED_CMAKE_CXX_FLAGS_${BUILD_TYPE}}")
	set(CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE} "${SAVED_CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE}}")
	set(CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE} "${SAVED_CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE}}")
	set(CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE} "${SAVED_CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE}}")
479
	unset(BUILD_TYPE)
480 481 482
endmacro()


483
macro(linphone_builder_set_ep_directories PROJNAME)
484 485 486 487 488
	if(EP_${PROJNAME}_SOURCE_DIR)
		set(ep_source "${EP_${PROJNAME}_SOURCE_DIR}")
	else()
		set(ep_source "${ep_base}/Source/EP_${PROJNAME}")
	endif()
489
	if(EP_${PROJNAME}_BUILD_IN_SOURCE_TREE)
490
		set(ep_build "${ep_source}")
Ghislain MARY's avatar
Ghislain MARY committed
491
	else()
492
		set(ep_build "${ep_base}/Build/${PROJNAME}")
493

494 495 496 497 498 499 500 501
		# replace "//" with "/" in paths
		string(FIND "${ep_build}" "//" must_trim)
		while (must_trim GREATER -1)
			string(REPLACE "//" "/" ep_build_trim ${ep_build})
			set(ep_build ${ep_build_trim})
			string(FIND "${ep_build}" "//" must_trim)
		endwhile()

502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
		# Compute the relative path to the source directory from the build directory
		set(common TRUE)
		set(not_finished TRUE)
		set(idx 1)
		string(LENGTH "${ep_source}" ep_source_length)
		string(LENGTH "${ep_build}" ep_build_length)
		while(common AND not_finished)
			string(SUBSTRING "${ep_source}" 0 ${idx} common_ep_source)
			string(SUBSTRING "${ep_build}" 0 ${idx} common_ep_build)
			math(EXPR idx "${idx}+1")
			if(NOT common_ep_source STREQUAL common_ep_build)
				set(common FALSE)
			endif()
			if((idx EQUAL ep_source_length) OR (idx EQUAL ep_build_length))
				set(not_finished FALSE)
			endif()
		endwhile()
		math(EXPR idx "${idx}-2")
		math(EXPR relative_source_length "${ep_source_length}-${idx}")
		math(EXPR relative_build_length "${ep_build_length}-${idx}")
		string(SUBSTRING "${ep_source}" ${idx} ${relative_source_length} ep_relative_source)
		string(SUBSTRING "${ep_build}" ${idx} ${relative_build_length} ep_relative_build)
		set(updirs "")
		string(FIND "${ep_relative_build}" "/" idx)
		while(idx GREATER -1)
			string(CONCAT updirs "${updirs}" "../")
			math(EXPR idx "${idx}+1")
529
			math(EXPR relative_build_length "${relative_build_length}-${idx}")
530 531 532 533 534 535 536
			string(SUBSTRING "${ep_relative_build}" ${idx} ${relative_build_length} ep_relative_build)
			string(FIND "${ep_relative_build}" "/" idx)
		endwhile()
		if(ep_relative_build)
			string(CONCAT updirs "${updirs}" "../")
		endif()
		set(ep_source_relative_to_build "${updirs}/${ep_relative_source}")
Ghislain MARY's avatar
Ghislain MARY committed
537 538
	endif()
endmacro()
539

540

541 542 543 544 545 546 547 548 549
macro(linphone_builder_set_ep_generator)
	if(CMAKE_EXTRA_GENERATOR)
		set(ep_generator "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
	else()
		set(ep_generator "${CMAKE_GENERATOR}")
	endif()
endmacro()


550
macro(linphone_builder_create_autogen_command PROJNAME)
551 552
	if(EP_${PROJNAME}_USE_AUTOGEN)
		if(EP_${PROJNAME}_CONFIGURE_OPTIONS_PASSED_TO_AUTOGEN)
553 554 555
			set(ep_autogen_options "")
			foreach(OPTION ${EP_${PROJNAME}_CROSS_COMPILATION_OPTIONS} ${EP_${PROJNAME}_LINKING_TYPE} ${EP_${PROJNAME}_CONFIGURE_OPTIONS})
				set(ep_autogen_options "${ep_autogen_options} \"${OPTION}\"")
Ghislain MARY's avatar
Ghislain MARY committed
556
			endforeach()
557
		endif()
558
		set(ep_autogen_command "\"${ep_source}/autogen.sh\" ${ep_autogen_options}")
559 560
	elseif(EP_${PROJNAME}_USE_AUTORECONF)
		set(ep_autogen_command "autoreconf -vfi ${ep_source}")
561
	else()
562
		set(ep_autogen_command "")
563
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
564
endmacro()
565 566 567


macro(linphone_builder_create_configure_command PROJNAME)
568
	if(EP_${PROJNAME}_CONFIGURE_OPTIONS_PASSED_TO_AUTOGEN)
569
		set(ep_configure_command "")
570
	else()
571 572 573
		set(ep_configure_options "")
		foreach(OPTION ${EP_${PROJNAME}_CROSS_COMPILATION_OPTIONS} ${EP_${PROJNAME}_LINKING_TYPE} ${EP_${PROJNAME}_CONFIGURE_OPTIONS})
			set(ep_configure_options "${ep_configure_options} \"${OPTION}\"")
Ghislain MARY's avatar
Ghislain MARY committed
574
		endforeach()
575
		set(ep_configure_env "${EP_${PROJNAME}_CONFIGURE_ENV}")
576
		set(ep_configure_command "\"${ep_source}/configure\" ${ep_configure_options}")
577
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
578
endmacro()
579 580


581 582 583 584 585
macro(linphone_builder_create_build_command PROJNAME)
	set(ep_make_options "${EP_${PROJNAME}_MAKE_OPTIONS}")
endmacro()


586
# this macro invokes configure_file() for the project, using the default file if
587
# the specific file is not defined
588
macro(linphone_builder_configure_file_for_project PROJNAME CMD DEFAULT_CONF_FILE OUTPUT)
Ghislain MARY's avatar
Ghislain MARY committed
589
	if(NOT EP_${PROJNAME}_${CMD}_COMMAND_SOURCE)
590
		message(STATUS "Using default file ${DEFAULT_CONF_FILE} for ${CMD} step of ${PROJNAME}")
591 592
		configure_file(${DEFAULT_CONF_FILE} ${OUTPUT})
	else()
593
		message(STATUS "Using specific file ${EP_${PROJNAME}_${CMD}_COMMAND_SOURCE} for ${CMD} step of ${PROJNAME}")
594
		configure_file(${EP_${PROJNAME}_${CMD}_COMMAND_SOURCE} ${OUTPUT})
595
	endif()
596
endmacro()
597

598 599 600 601
macro(linphone_builder_filter_out_inexistent_dependencies PROJNAME)
	if(EP_${PROJNAME}_DEPENDENCIES)
		set(_new_deps )
		foreach(_dep ${EP_${PROJNAME}_DEPENDENCIES})
602 603
			string(REGEX REPLACE "^EP_" "" _dep2 ${_dep})
			list(FIND LINPHONE_BUILDER_INCLUDED_BUILDERS ${_dep2} _found)
604
			list(FIND LINPHONE_BUILDER_INCLUDED_BUILDERS_TO_EXCLUDE ${_dep2} _excluded_found)
605
			list(FIND LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS ${_dep2} _external_source_path_found)
606
			if((_found GREATER -1) AND (_excluded_found EQUAL -1) AND ((_external_source_path_found EQUAL -1) OR (NOT EP_${_dep2}_GROUPABLE) OR (NOT LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)))
607 608 609 610 611 612 613 614 615 616 617
				list(APPEND _new_deps ${_dep})
			endif()
		endforeach()
		unset(_dep)
		unset(_found)
		unset(_external_source_path_found)
		set(EP_${PROJNAME}_DEPENDENCIES ${_new_deps})
		unset(_new_deps)
	endif()
endmacro()

618
macro(linphone_builder_add_external_project PROJNAME)
619
	if(LINPHONE_BUILDER_ENABLE_RPM_PACKAGING AND NOT EP_${PROJNAME}_BUILD_METHOD STREQUAL "dummy")
620 621 622
		set(EP_${PROJNAME}_BUILD_METHOD "rpm")
	endif()

623
	if(LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH OR LINPHONE_BUILDER_ALTERNATE_EXTERNAL_SOURCE_PATH)
624 625
		foreach(SUBDIR ${EP_${PROJNAME}_EXTERNAL_SOURCE_PATHS})
			if(NOT EP_${PROJNAME}_SOURCE_DIR)
626 627 628
				if(SUBDIR STREQUAL "<LINPHONE_BUILDER_TOP_DIR>")
					set(_source_dir "${LINPHONE_BUILDER_TOP_DIR}")
				else()
629 630 631 632 633
					if(LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH AND EXISTS "${LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH}/${SUBDIR}")
						set(_source_dir "${LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH}/${SUBDIR}")
					else()
						set(_source_dir "${LINPHONE_BUILDER_ALTERNATE_EXTERNAL_SOURCE_PATH}/${SUBDIR}")
					endif()
634 635 636
				endif()
				if(EXISTS "${_source_dir}")
					set(EP_${PROJNAME}_SOURCE_DIR "${_source_dir}")
637 638 639 640
				endif()
			endif()
		endforeach()
	endif()
641 642 643
	if(EP_${PROJNAME}_PACKAGE_SOURCE)
		list(APPEND LINPHONE_BUILDER_SOURCE_PACKAGE_BUILDERS ${PROJNAME})
	endif()
644

645
	linphone_builder_set_ep_directories(${PROJNAME})
646
	linphone_builder_set_ep_generator()
Ghislain MARY's avatar
Ghislain MARY committed
647 648 649
	if(NOT EP_${PROJNAME}_DO_NOT_USE_CMAKE_FLAGS)
		linphone_builder_apply_cmake_flags_to_autotools_project(${PROJNAME})
	endif()
650 651 652 653 654
	if(EP_${PROJNAME}_USE_C_COMPILER_FOR_ASSEMBLER)
		set(ep_use_c_compiler_for_assembler TRUE)
	else()
		unset(ep_use_c_compiler_for_assembler)
	endif()
655
	linphone_builder_apply_extra_flags(${PROJNAME})
656 657
	linphone_builder_expand_external_project_vars()

658 659 660 661 662 663 664 665
	if(EP_${PROJNAME}_BUILD_METHOD STREQUAL "dummy")
		set(BUILD_COMMANDS
			CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo ""
			BUILD_COMMAND ${CMAKE_COMMAND} -E echo ""
			INSTALL_COMMAND ${CMAKE_COMMAND} -E echo ""
		)
		set(EP_${PROJNAME}_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}")
	elseif(EP_${PROJNAME}_BUILD_METHOD STREQUAL "prebuilt")
666 667 668 669 670 671
		message("Using prebuilt ${PROJNAME}")
		set(BUILD_COMMANDS
			CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo ""
			BUILD_COMMAND ${CMAKE_COMMAND} -E echo ""
			INSTALL_COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=<SOURCE_DIR> -DINSTALL_DIR=${CMAKE_INSTALL_PREFIX} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/install_prebuilt.cmake
		)
Ghislain MARY's avatar
Ghislain MARY committed
672
	elseif(EP_${PROJNAME}_BUILD_METHOD STREQUAL "custom")
673 674 675
		if(WIN32)
			set(ep_redirect_to_file "2>&1 >> \"${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}.log\"")
		endif()
676 677 678 679 680 681 682 683 684 685 686 687
		configure_file(${EP_${PROJNAME}_CONFIGURE_COMMAND_SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_configure.sh)
		configure_file(${EP_${PROJNAME}_BUILD_COMMAND_SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_build.sh)
		configure_file(${EP_${PROJNAME}_INSTALL_COMMAND_SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_install.sh)
		if(WIN32)
			set(SCRIPT_EXTENSION bat)
			set(MSVC_PROJNAME ${PROJNAME})
			configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/mingw_configure.bat.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_configure.bat)
			configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/mingw_build.bat.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_build.bat)
			configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/mingw_install.bat.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_install.bat)
		else()
			set(SCRIPT_EXTENSION sh)
		endif()
688
		set(BUILD_COMMANDS
689 690 691
			CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_configure.${SCRIPT_EXTENSION}
			BUILD_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_build.${SCRIPT_EXTENSION}
			INSTALL_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_install.${SCRIPT_EXTENSION}
692
		)
693 694
	elseif(EP_${PROJNAME}_BUILD_METHOD STREQUAL "autotools")
		linphone_builder_create_autogen_command(${PROJNAME})
695
		linphone_builder_create_configure_command(${PROJNAME})
696
		linphone_builder_create_build_command(${PROJNAME})
Ghislain MARY's avatar
Ghislain MARY committed
697
		if(EP_${PROJNAME}_CONFIG_H_FILE)
698
			set(ep_config_h_file ${EP_${PROJNAME}_CONFIG_H_FILE})
Ghislain MARY's avatar
Ghislain MARY committed
699
		else()
Ghislain MARY's avatar
Ghislain MARY committed
700 701 702
			set(ep_config_h_file config.h)
		endif()
		if(EP_${PROJNAME}_INSTALL_TARGET)
703
			set(ep_install_target "${EP_${PROJNAME}_INSTALL_TARGET}")
Ghislain MARY's avatar
Ghislain MARY committed
704 705
		else()
			set(ep_install_target "install")
Ghislain MARY's avatar
Ghislain MARY committed
706
		endif()
707

708
		if(WIN32)
709
			set(ep_redirect_to_file "2>&1 >> \"${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}.log\"")
710 711 712 713 714
			set(SCRIPT_EXTENSION bat)
			set(MSVC_PROJNAME ${PROJNAME})
			configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/mingw_configure.bat.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_configure.bat)
			configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/mingw_build.bat.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_build.bat)
			configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/mingw_install.bat.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_install.bat)
Ghislain MARY's avatar
Ghislain MARY committed
715
			if(ep_autogen_command)
716 717
				set(ep_autogen_redirect_to_file ${ep_redirect_to_file})
			endif()
Ghislain MARY's avatar
Ghislain MARY committed
718
			if(ep_configure_command)
719 720
				set(ep_configure_redirect_to_file ${ep_redirect_to_file})
			endif()
721
		else()
722
			set(SCRIPT_EXTENSION sh)
723
		endif()
724

Ghislain MARY's avatar
Ghislain MARY committed
725
		if(EP_${PROJNAME}_PKG_CONFIG)
726
			set(LINPHONE_BUILDER_PKG_CONFIG "${EP_${PROJNAME}_PKG_CONFIG}")
Ghislain MARY's avatar
Ghislain MARY committed
727 728
		else()
			set(LINPHONE_BUILDER_PKG_CONFIG "${PKG_CONFIG_PROGRAM}")
Ghislain MARY's avatar
Ghislain MARY committed
729
		endif()
730

731 732 733
		configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/configure.sh.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_configure.sh)
		configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/build.sh.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_build.sh)
		configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/install.sh.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_install.sh)
Ghislain MARY's avatar
Ghislain MARY committed
734 735

		set(BUILD_COMMANDS
736 737 738
			CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_configure.${SCRIPT_EXTENSION}
			BUILD_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_build.${SCRIPT_EXTENSION}
			INSTALL_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_install.${SCRIPT_EXTENSION}
Ghislain MARY's avatar
Ghislain MARY committed
739
		)
Ghislain MARY's avatar
Ghislain MARY committed
740
	elseif(EP_${PROJNAME}_BUILD_METHOD STREQUAL "rpm")
741

742
		if(WIN32)
743
			message(SEND_ERROR "rpm build not supported on WIN32")
744 745 746 747
		endif()

		linphone_builder_create_autogen_command(${PROJNAME})
		linphone_builder_create_configure_command(${PROJNAME})
748

Ghislain MARY's avatar
Ghislain MARY committed
749
		if(EP_${PROJNAME}_CONFIG_H_FILE)
750
			set(ep_config_h_file ${EP_${PROJNAME}_CONFIG_H_FILE})
Ghislain MARY's avatar
Ghislain MARY committed
751 752
		else()
			set(ep_config_h_file config.h)
753
		endif()
754

Ghislain MARY's avatar
Ghislain MARY committed
755
		if(EP_${PROJNAME}_INSTALL_TARGET)
756
			set(ep_install_target "${EP_${PROJNAME}_INSTALL_TARGET}")
Ghislain MARY's avatar
Ghislain MARY committed
757 758
		else()
			set(ep_install_target "install")
759 760
		endif()

Ghislain MARY's avatar
Ghislain MARY committed
761
		if(EP_${PROJNAME}_SPEC_FILE)
762
			set(LINPHONE_BUILDER_SPEC_FILE "${EP_${PROJNAME}_SPEC_FILE}")
Ghislain MARY's avatar
Ghislain MARY committed
763 764
		else()
			message(SEND_ERROR "rpm build requires EP_${PROJNAME}_SPEC_FILE to be defined")
765 766 767 768
		endif()

		# a distinctive name of the generated RPM. It is used to find the rpms to install
		# in the install step. Defaults to $PROJNAME but could be something else
Ghislain MARY's avatar
Ghislain MARY committed
769
		if(EP_${PROJNAME}_RPMBUILD_NAME)
770
			set(LINPHONE_BUILDER_RPMBUILD_NAME "${EP_${PROJNAME}_RPMBUILD_NAME}")
Ghislain MARY's avatar
Ghislain MARY committed
771 772
		else()
			set(LINPHONE_BUILDER_RPMBUILD_NAME "${PROJNAME}")
773
		endif()
774

775
		# some specific RPMBUILD options to pass for this particular project
Ghislain MARY's avatar
Ghislain MARY committed
776
		if(EP_${PROJNAME}_RPMBUILD_OPTIONS)
777
			string(REPLACE ";" " " LINPHONE_BUILDER_RPMBUILD_OPTIONS "${EP_${PROJNAME}_RPMBUILD_OPTIONS}")
778 779
		else()
			set(LINPHONE_BUILDER_RPMBUILD_OPTIONS "")
780 781 782 783
		endif()

		set(LINPHONE_BUILDER_SPEC_PREFIX "${EP_${PROJNAME}_SPEC_PREXIX}")

Ghislain MARY's avatar
Ghislain MARY committed
784
		if(EP_${PROJNAME}_PKG_CONFIG)
785
			set(LINPHONE_BUILDER_PKG_CONFIG "${EP_${PROJNAME}_PKG_CONFIG}")
Ghislain MARY's avatar
Ghislain MARY committed
786 787
		else()
			set(LINPHONE_BUILDER_PKG_CONFIG "${PKG_CONFIG_PROGRAM}")
788 789
		endif()

Ghislain MARY's avatar
Ghislain MARY committed
790
		if(EP_${PROJNAME}_CONFIGURE_EXTRA_CMD)
791
			set(LINPHONE_BUILDER_CONFIGURE_EXTRA_CMD "${EP_${PROJNAME}_CONFIGURE_EXTRA_CMD}")
792 793
		else()
			set(LINPHONE_BUILDER_CONFIGURE_EXTRA_CMD "")
794 795
		endif()

796 797 798 799 800 801 802 803
		if(NOT EP_${PROJNAME}_LINKING_TYPE) # Apply default CMake linking type if not set explicitely
			if(EP_${PROJNAME}_PLUGIN)
				set(EP_${PROJNAME}_LINKING_TYPE ${DEFAULT_VALUE_CMAKE_PLUGIN_LINKING_TYPE})
			else()
				set(EP_${PROJNAME}_LINKING_TYPE ${DEFAULT_VALUE_CMAKE_LINKING_TYPE})
			endif()
		endif()

804
		# allow to have special command steps
805 806 807 808
		if(EP_${PROJNAME}_USE_AUTOTOOLS_FOR_RPM)
			linphone_builder_configure_file_for_project(${PROJNAME} CONFIGURE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Autotools/configure.rpm.sh.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_configure_rpm.sh)
			linphone_builder_configure_file_for_project(${PROJNAME} BUILD ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Autotools/build.rpm.sh.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_build_rpm.sh)
		else()
809 810
			set(CURRENT_PROJ_CMAKE_OPTIONS ${EP_${PROJNAME}_CMAKE_OPTIONS} ${EP_${PROJNAME}_LINKING_TYPE})
			string(REPLACE ";" " " CURRENT_PROJ_CMAKE_OPTIONS  "${CURRENT_PROJ_CMAKE_OPTIONS}")
811 812
			linphone_builder_configure_file_for_project(${PROJNAME} CONFIGURE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/configure.rpm.sh.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_configure_rpm.sh)
			linphone_builder_configure_file_for_project(${PROJNAME} BUILD ${CMAKE_CURRENT_SOURCE_DIR}/cmake/build.rpm.sh.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_build_rpm.sh)
813
			unset(CURRENT_PROJ_CMAKE_OPTIONS)
814
		endif()
815
		linphone_builder_configure_file_for_project(${PROJNAME} INSTALL ${CMAKE_CURRENT_SOURCE_DIR}/cmake/install.rpm.sh.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_install_rpm.sh)
816 817 818 819 820 821

		set(BUILD_COMMANDS
			CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_configure_rpm.sh
			BUILD_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_build_rpm.sh
			INSTALL_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_install_rpm.sh
		)
822 823
	else()
		# Use CMake build method
824 825 826 827 828 829 830
		if(NOT EP_${PROJNAME}_LINKING_TYPE) # Apply default CMake linking type if not set explicitely
			if(EP_${PROJNAME}_PLUGIN)
				set(EP_${PROJNAME}_LINKING_TYPE ${DEFAULT_VALUE_CMAKE_PLUGIN_LINKING_TYPE})
			else()
				set(EP_${PROJNAME}_LINKING_TYPE ${DEFAULT_VALUE_CMAKE_LINKING_TYPE})
			endif()
		endif()
831 832 833 834
		set(BUILD_COMMANDS
			CMAKE_ARGS ${EP_${PROJNAME}_CMAKE_OPTIONS} ${EP_${PROJNAME}_LINKING_TYPE}
			CMAKE_CACHE_ARGS ${LINPHONE_BUILDER_EP_ARGS}
		)
835
	endif()
836

837
	if(LINPHONE_BUILDER_LATEST AND EP_${PROJNAME}_GIT_TAG_LATEST)
838
		set(DOWNLOAD_SOURCE GIT_REPOSITORY ${EP_${PROJNAME}_GIT_REPOSITORY} GIT_TAG ${EP_${PROJNAME}_GIT_TAG_LATEST})
839
	elseif(EP_${PROJNAME}_SOURCE_DIR)
840
		set(DOWNLOAD_SOURCE SOURCE_DIR "${EP_${PROJNAME}_SOURCE_DIR}")
841 842 843 844 845
	elseif(EP_${PROJNAME}_URL)
		set(DOWNLOAD_SOURCE URL ${EP_${PROJNAME}_URL})
		if(EP_${PROJNAME}_URL_HASH)
			list(APPEND DOWNLOAD_SOURCE URL_HASH ${EP_${PROJNAME}_URL_HASH})
		endif()
846 847 848
	elseif(EP_${PROJNAME}_SVN_REPOSITORY)
		set(DOWNLOAD_SOURCE SVN_REPOSITORY ${EP_${PROJNAME}_SVN_REPOSITORY})
	else()
849
		set(DOWNLOAD_SOURCE GIT_REPOSITORY ${EP_${PROJNAME}_GIT_REPOSITORY} GIT_TAG ${EP_${PROJNAME}_GIT_TAG})
850
	endif()
851

852 853
	linphone_builder_filter_out_inexistent_dependencies(${PROJNAME})

854 855
	ExternalProject_Add(EP_${PROJNAME}
		DEPENDS ${EP_${PROJNAME}_DEPENDENCIES}
856
		BINARY_DIR "${ep_build}"
857
		${DOWNLOAD_SOURCE}
858
		PATCH_COMMAND ${EP_${PROJNAME}_PATCH_COMMAND}
859
		CMAKE_GENERATOR ${ep_generator}
Ghislain MARY's avatar
Ghislain MARY committed
860
		${BUILD_COMMANDS}
861
	)
862

863 864
	if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/builders/${PROJNAME}/postinstall.cmake)
		ExternalProject_Add_Step(EP_${PROJNAME} postinstall
865
			COMMAND ${CMAKE_COMMAND} -DTOOLCHAIN_RANLIB=${TOOLCHAIN_RANLIB} -DCMAKE_RANLIB=${CMAKE_RANLIB} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DINSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -P ${CMAKE_CURRENT_SOURCE_DIR}/builders/${PROJNAME}/postinstall.cmake
866 867
			COMMENT "Performing post-installation for 'EP_${PROJNAME}'"
			DEPENDEES install
868 869
			WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
		)
870
	endif()
871
	if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/builders/${PROJNAME}/postconfig.cmake)
872
		ExternalProject_Add_Step(EP_${PROJNAME} postconfig
873
			COMMAND ${CMAKE_COMMAND} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DINSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -P ${CMAKE_CURRENT_SOURCE_DIR}/builders/${PROJNAME}/postinstall.cmake
874 875 876 877 878
			COMMENT "Performing post-configuration for 'EP_${PROJNAME}'"
			DEPENDEES install
			WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
		)
	endif()
879 880 881 882 883 884 885 886
	if(ENABLE_SOURCE_PACKAGING AND EP_${PROJNAME}_PACKAGE_SOURCE)
		ExternalProject_Add_Step(EP_${PROJNAME} package_source
			COMMAND ${CMAKE_COMMAND} --build ${ep_build} --target package_source
			COMMENT "Creating source package for 'EP_${PROJNAME}'"
			DEPENDEES install
			WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
		)
	endif()
887 888 889 890 891 892 893

	if(EP_${PROJNAME}_GROUPED_SOURCE_DIRS OR EP_${PROJNAME}_SOURCE_DIR)
		if(EP_${PROJNAME}_GROUPED_SOURCE_DIRS)
			set(_source_dirs ${EP_${PROJNAME}_GROUPED_SOURCE_DIRS})
		else()
			set(_source_dirs ${EP_${PROJNAME}_SOURCE_DIR})
		endif()
894 895 896 897
		ExternalProject_Add_Step(EP_${PROJNAME} force_build
			COMMENT "Forcing build for 'EP_${PROJNAME}'"
			DEPENDEES configure
			DEPENDERS build
898 899 900
			ALWAYS 1
		)
		unset(_source_dirs)
901 902
	endif()

903 904
	linphone_builder_restore_flags()

905
endmacro()
Ghislain MARY's avatar
Ghislain MARY committed
906

907
macro(linphone_builder_add_grouped_external_source_path_project PROJNAME FILENAME)
908
	linphone_builder_filter_out_inexistent_dependencies(${PROJNAME})
909
	file(APPEND "${FILENAME}" "add_subdirectory(\"${EP_${PROJNAME}_SOURCE_DIR}\" \"${LINPHONE_BUILDER_WORK_DIR}/Build/${PROJNAME}\")\n")
910
	list(APPEND EP_linphone_builder_LINKING_TYPE "${EP_${PROJNAME}_LINKING_TYPE}")
911
	list(APPEND EP_linphone_builder_CMAKE_OPTIONS "${EP_${PROJNAME}_CMAKE_OPTIONS}")
912 913 914
	list(APPEND EP_linphone_builder_EXTRA_CFLAGS "${EP_${PROJNAME}_EXTRA_CFLAGS}")
	list(APPEND EP_linphone_builder_EXTRA_CPPFLAGS "${EP_${PROJNAME}_EXTRA_CPPFLAGS}")
	list(APPEND EP_linphone_builder_EXTRA_CXXFLAGS "${EP_${PROJNAME}_EXTRA_CXXFLAGS}")
915
	list(APPEND EP_linphone_builder_EXTRA_LDFLAGS "${EP_${PROJNAME}_EXTRA_LDFLAGS}")
916
	list(APPEND EP_linphone_builder_EXTRA_OBJCFLAGS "${EP_${PROJNAME}_EXTRA_OBJCFLAGS}")
917 918
	list(APPEND EP_linphone_builder_ADDITIONAL_CMAKE_OPTIONS "-DEP_${PROJNAME}_INCLUDE_DIR=${EP_${PROJNAME}_SOURCE_DIR}/include")
	list(APPEND EP_linphone_builder_ADDITIONAL_CMAKE_OPTIONS "-DEP_${PROJNAME}_CONFIG_DIR=${LINPHONE_BUILDER_WORK_DIR}/Build/${PROJNAME}")
919
	if(EP_${PROJNAME}_DEPENDENCIES)
920
		list(APPEND EP_linphone_builder_DEPENDENCIES ${EP_${PROJNAME}_DEPENDENCIES})
921
	endif()
922
endmacro()
923

924
macro(linphone_builder_add_external_projects)
925
	foreach(BUILDER ${LINPHONE_BUILDER_INCLUDED_BUILDERS})
926 927
		list(FIND LINPHONE_BUILDER_INCLUDED_BUILDERS_TO_EXCLUDE ${BUILDER} _excluded_found)
		list(FIND LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS ${BUILDER} _external_source_path_found)
928
		if((_excluded_found EQUAL -1) AND ((_external_source_path_found EQUAL -1) OR (NOT LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS) OR (NOT EP_${BUILDER}_GROUPABLE)))
929 930 931
			linphone_builder_add_external_project(${BUILDER})
		endif()
	endforeach()
932
endmacro()
933

934 935 936
macro(detect_variable_conflict VARIABLE_NAME ERROR_MESSAGE)
	if(EP_linphone_builder_${VARIABLE_NAME})
		list(REMOVE_DUPLICATES EP_linphone_builder_${VARIABLE_NAME})
937
		set(_new_options )
938
		foreach(_option ${EP_linphone_builder_${VARIABLE_NAME}})
939 940 941
			string(REGEX MATCH "^-D(.+)=(.*)$" _match "${_option}")
			if(_match)
				set(_new_option "-D${CMAKE_MATCH_1}=")
942
				set(_varname ${CMAKE_MATCH_1})
943
				set(_value ${CMAKE_MATCH_2})
944
				if(_varname MATCHES "^ENABLE_.*$")
945 946
					if(_value)
						set(_conflicting_option "${_new_option}OFF")
947
						set(_new_option "${_new_option}ON")
948 949
					else()
						set(_conflicting_option "${_new_option}ON")
950
						set(_new_option "${_new_option}OFF")
951
					endif()
952
				else()
953
					set(_new_option "${_new_option}${_value}")
954 955 956 957 958 959 960
				endif()
				list(FIND _new_options "${_new_option}" _found)
				list(FIND _new_options "${_conflicting_option}" _conflict_found)
				if(_found EQUAL -1)
					list(APPEND _new_options "${_new_option}")
				endif()
				if(_conflict_found GREATER -1)
961
					message(FATAL_ERROR ${ERROR_MESSAGE})
962
				endif()
963
			endif()
964 965
		endforeach()
		if(_new_options)
966
			set(EP_linphone_builder_${VARIABLE_NAME} ${_new_options})
967 968 969 970
		endif()
	endif()
endmacro()

971 972 973 974 975 976 977 978 979
macro(detect_conflicting_cmake_options)
	detect_variable_conflict(CMAKE_OPTIONS "Conflicting options \${_new_option} and \${_conflicting_option}")
endmacro()

macro(detect_conflicting_linking_types)
	detect_variable_conflict(LINKING_TYPE "Conflicing linking types in grouped external source path projects: \${EP_linphone_builder_LINKING_TYPE}")
endmacro()

macro(linphone_builder_add_grouped_external_source_path_projects)
980 981
	set(_grouped_builders)
	if(LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS)
982 983 984 985 986 987
		foreach (_builder ${LINPHONE_BUILDER_INCLUDED_BUILDERS})
			list(FIND LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS ${_builder} _found)
			if(NOT _found EQUAL -1)
				if(EP_${_builder}_GROUPABLE)
					list(APPEND _grouped_builders ${_builder})
				endif()
988 989 990
			endif()
		endforeach()
	endif()
991
	
992
	if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS AND _grouped_builders)
993 994 995 996
		make_directory("${LINPHONE_BUILDER_WORK_DIR}/Source/EP_linphone_builder")
		set(_linphone_builder_file "${LINPHONE_BUILDER_WORK_DIR}/Source/EP_linphone_builder/CMakeLists.txt")
		file(WRITE "${_linphone_builder_file}" "cmake_minimum_required(VERSION 3.0)\n")
		file(APPEND "${_linphone_builder_file}" "project(EP_linphone_builder)\n")
997
		file(APPEND "${_linphone_builder_file}" "option(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS \"Group external source path builders.\" ON)\n")
998
		set(EP_linphone_builder_CMAKE_OPTIONS )
999
		set(EP_linphone_builder_LINKING_TYPE )
1000 1001 1002
		set(EP_linphone_builder_EXTRA_CFLAGS )
		set(EP_linphone_builder_EXTRA_CPPFLAGS )
		set(EP_linphone_builder_EXTRA_CXXFLAGS )
1003
		set(EP_linphone_builder_EXTRA_LDFLAGS )
1004
		set(EP_linphone_builder_EXTRA_OBJCFLAGS )
1005
		set(EP_linphone_builder_DEPENDENCIES )
1006
		set(EP_linphone_builder_GROUPED_SOURCE_DIRS )
1007
		foreach(BUILDER ${_grouped_builders})
1008
			list(APPEND EP_linphone_builder_GROUPED_SOURCE_DIRS ${EP_${BUILDER}_SOURCE_DIR})
1009
			linphone_builder_add_grouped_external_source_path_project(${BUILDER} "${_linphone_builder_file}")
1010
		endforeach()
1011
		detect_conflicting_linking_types()
1012
		detect_conflicting_cmake_options()
1013 1014 1015 1016 1017 1018 1019 1020 1021
		if(EP_linphone_builder_EXTRA_CFLAGS)
			list(REMOVE_DUPLICATES EP_linphone_builder_EXTRA_CFLAGS)
		endif()
		if(EP_linphone_builder_EXTRA_CPPFLAGS)
			list(REMOVE_DUPLICATES EP_linphone_builder_EXTRA_CPPFLAGS)
		endif()
		if(EP_linphone_builder_EXTRA_CXXFLAGS)
			list(REMOVE_DUPLICATES EP_linphone_builder_EXTRA_CXXFLAGS)
		endif()
1022 1023 1024
		if(EP_linphone_builder_EXTRA_LDFLAGS)
			list(REMOVE_DUPLICATES EP_linphone_builder_EXTRA_LDFLAGS)
		endif()
1025 1026 1027
		if(EP_linphone_builder_EXTRA_OBJCFLAGS)
			list(REMOVE_DUPLICATES EP_linphone_builder_EXTRA_OBJCFLAGS)
		endif()
1028 1029 1030
		if(EP_linphone_builder_DEPENDENCIES)
			list(REMOVE_DUPLICATES EP_linphone_builder_DEPENDENCIES)
		endif()
1031 1032 1033 1034 1035
		list(APPEND EP_linphone_builder_CMAKE_OPTIONS ${EP_linphone_builder_ADDITIONAL_CMAKE_OPTIONS})
		linphone_builder_add_external_project("linphone_builder")
		add_dependencies(TARGET_linphone_builder EP_linphone_builder)
		unset(_conflicting_linking_types)
		unset(_linphone_builder_file)
1036
		unset(_grouped_builders)
1037
	endif()
1038
endmacro()
1039

1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
macro(linphone_builder_sort_builders)
	set(_ordered_builders)
	set(_to_process_builders ${LINPHONE_BUILDER_INCLUDED_BUILDERS})
	list(LENGTH _to_process_builders _remaining_builders_count)
	while(_remaining_builders_count GREATER 0)
		set(_processed_builders)
		foreach(_builder IN LISTS _to_process_builders)
			if(NOT EP_${_builder}_DEPENDENCIES)
				list(APPEND _ordered_builders ${_builder})
				list(APPEND _processed_builders ${_builder})
			else()
				set(_to_add TRUE)
				foreach(_dep IN LISTS EP_${_builder}_DEPENDENCIES)
					string(SUBSTRING "${_dep}" 3 -1 _dep)
					list(FIND _ordered_builders ${_dep} _found)
					if(_found EQUAL -1)
						set(_to_add FALSE)
					endif()
				endforeach()
				if(_to_add)
					list(APPEND _ordered_builders ${_builder})
					list(APPEND _processed_builders ${_builder})
				endif()
			endif()
		endforeach()
		foreach(_builder IN LISTS _processed_builders)
			list(REMOVE_ITEM _to_process_builders ${_builder})
		endforeach()
		list(LENGTH _to_process_builders _remaining_builders_count)
	endwhile()
	set(LINPHONE_BUILDER_INCLUDED_BUILDERS ${_ordered_builders})
endmacro()

1073
macro(linphone_builder_add_projects)
1074
	linphone_builder_sort_builders()
1075
	linphone_builder_add_external_projects()
1076
	linphone_builder_add_grouped_external_source_path_projects()
1077
endmacro()
1078 1079 1080 1081

macro(linphone_builder_add_dummy_libraries_generation)
	if(LINPHONE_BUILDER_DUMMY_LIBRARIES)
		linphone_builder_set_ep_directories(dummy_libraries)
1082
		linphone_builder_set_ep_generator()
1083
		linphone_builder_expand_external_project_vars()
1084
		ExternalProject_Add(EP_dummy_libraries
1085
			DEPENDS TARGET_linphone_builder
1086 1087
			TMP_DIR "${ep_tmp}"
			BINARY_DIR "${ep_build}"
1088
			SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/cmake/dummy_libraries"
1089
			DOWNLOAD_COMMAND ""
1090
			CMAKE_GENERATOR ${ep_generator}
1091 1092 1093 1094
			CMAKE_ARGS ${LINPHONE_BUILDER_EP_ARGS} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DLINPHONE_BUILDER_DUMMY_LIBRARIES=${LINPHONE_BUILDER_DUMMY_LIBRARIES}
		)
	endif()
endmacro()
1095

1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
macro(linphone_builder_add_package_source_check_project)
	if(ENABLE_SOURCE_PACKAGING AND LINPHONE_BUILDER_SOURCE_PACKAGE_BUILDERS)
		string(REPLACE ";" " " LINPHONE_BUILDER_SOURCE_PACKAGE_BUILDERS "${LINPHONE_BUILDER_SOURCE_PACKAGE_BUILDERS}")
		linphone_builder_set_ep_directories(package_source_check)
		linphone_builder_set_ep_generator()
		linphone_builder_expand_external_project_vars()
		ExternalProject_Add(EP_package_source_check
			DEPENDS TARGET_linphone_builder
			TMP_DIR "${ep_tmp}"
			BINARY_DIR "${ep_build}"
			SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/cmake/package_source_check"
			DOWNLOAD_COMMAND ""
			CMAKE_GENERATOR ${ep_generator}
			CMAKE_ARGS -DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}/package_source_check -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/package_source_check -DLINPHONE_BUILDER_WORK_DIR=${LINPHONE_BUILDER_WORK_DIR} -DLINPHONE_BUILDER_SOURCE_PACKAGE_BUILDERS=${LINPHONE_BUILDER_SOURCE_PACKAGE_BUILDERS} -DGENERATOR=${ep_generator}
		)
	endif()
endmacro()

1114 1115 1116 1117 1118 1119
macro(lcb_check_current_builder)
	if(NOT DEFINED LINPHONE_BUILDER_CURRENT_BUILDER)
		message(FATAL_ERROR "lcb_ macro used outside of builder definition")
	endif()
endmacro()

1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134
macro(lcb_builder_cmake_options BUILDER)
	set(_args "${ARGN}")
	foreach(_arg IN LISTS _args)
		string(REGEX MATCH "^-D(.+)=(.*)$" _match "${_arg}")
		if(_match)
			set(_varname ${CMAKE_MATCH_1})
			foreach(_option ${EP_${BUILDER}_CMAKE_OPTIONS})
				string(REGEX MATCH "^-D${_varname}=(.*)$" _match2 "${_option}")
				if(_match2)
					list(REMOVE_ITEM EP_${BUILDER}_CMAKE_OPTIONS ${_option})
				endif()
			endforeach()
		endif()
		list(APPEND EP_${BUILDER}_CMAKE_OPTIONS ${_arg})
	endforeach()
1135
endmacro()
1136

1137
macro(lcb_cmake_options)
1138
	lcb_check_current_builder()
1139
	lcb_builder_cmake_options("${LINPHONE_BUILDER_CURRENT_BUILDER}" ${ARGN})
1140 1141
endmacro()

1142 1143 1144 1145 1146
macro(lcb_builder_configure_options BUILDER)
	set(_args "${ARGN}")
	foreach(_option IN LISTS _args)
		list(APPEND EP_${BUILDER}_CONFIGURE_OPTIONS ${_option})
	endforeach()
1147
endmacro()
1148

1149
macro(lcb_configure_options)
1150
	lcb_check_current_builder()
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
	lcb_builder_configure_options("${LINPHONE_BUILDER_CURRENT_BUILDER}" ${ARGN})
endmacro()

macro(lcb_builder_cross_compilation_options BUILDER)
	unset(EP_${BUILDER}_CROSS_COMPILATION_OPTIONS) # Clear previously set options
	set(_args "${ARGN}")
	foreach(_option IN LISTS _args)
		list(APPEND EP_${BUILDER}_CROSS_COMPILATION_OPTIONS ${_args})
	endforeach()
endmacro()

macro(lcb_cross_compilation_options)
1163
	lcb_check_current_builder()
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174
	lcb_builder_cross_compilation_options("${LINPHONE_BUILDER_CURRENT_BUILDER}" ${ARGN})
endmacro()

macro(lcb_builder_make_options BUILDER)
	set(_args "${ARGN}")
	foreach(_option IN LISTS _args)
		set(EP_${BUILDER}_MAKE_OPTIONS "${EP_${BUILDER}_MAKE_OPTIONS} ${_option}")
	endforeach()
endmacro()

macro(lcb_make_options)
1175
	lcb_check_current_builder()
1176 1177 1178 1179 1180 1181 1182 1183
	lcb_builder_make_options("${LINPHONE_BUILDER_CURRENT_BUILDER}" ${ARGN})
endmacro()

macro(lcb_builder_extra_cflags BUILDER CFLAGS)
	set(EP_${BUILDER}_EXTRA_CFLAGS "${EP_${BUILDER}_EXTRA_CFLAGS} ${CFLAGS}")
endmacro()

macro(lcb_extra_cflags CFLAGS)
1184
	lcb_check_current_builder()
1185 1186 1187 1188 1189 1190 1191 1192
	lcb_builder_extra_cflags("${LINPHONE_BUILDER_CURRENT_BUILDER}" "${CFLAGS}")
endmacro()

macro(lcb_builder_extra_cppflags BUILDER CPPFLAGS)
	set(EP_${BUILDER}_EXTRA_CPPFLAGS "${EP_${BUILDER}_EXTRA_CPPFLAGS} ${CPPFLAGS}")
endmacro()

macro(lcb_extra_cppflags CPPFLAGS)
1193
	lcb_check_current_builder()
1194 1195 1196 1197 1198 1199 1200 1201
	lcb_builder_extra_cppflags("${LINPHONE_BUILDER_CURRENT_BUILDER}" "${CPPFLAGS}")
endmacro()

macro(lcb_builder_extra_cxxflags BUILDER CXXFLAGS)
	set(EP_${BUILDER}_EXTRA_CXXFLAGS "${EP_${BUILDER}_EXTRA_CXXFLAGS} ${CXXFLAGS}")
endmacro()

macro(lcb_extra_cxxflags CPPFLAGS)
1202
	lcb_check_current_builder()
1203 1204 1205 1206 1207 1208 1209 1210
	lcb_builder_extra_cxxflags("${LINPHONE_BUILDER_CURRENT_BUILDER}" "${CXXFLAGS}")
endmacro()

macro(lcb_builder_extra_ldflags BUILDER LDFLAGS)
	set(EP_${BUILDER}_EXTRA_LDFLAGS "${EP_${BUILDER}_EXTRA_LDFLAGS} ${LDFLAGS}")
endmacro()

macro(lcb_extra_ldflags LDFLAGS)
1211
	lcb_check_current_builder()
1212 1213