CMakeLists.txt 32.1 KB
Newer Older
1
############################################################################
2
# CMakeLists.txt
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# Copyright (C) 2014  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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
############################################################################

include(ExternalProject)

25
set(ep_base "${LINPHONE_BUILDER_WORK_DIR}/${CONFIG_NAME}")
26 27
set_property(DIRECTORY PROPERTY EP_BASE ${ep_base})

28

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


39
if(CMAKE_VERBOSE_MAKEFILE)
40
	set(AUTOTOOLS_VERBOSE_MAKEFILE 1)
41
else()
42
	set(AUTOTOOLS_VERBOSE_MAKEFILE 0)
43
endif()
44 45


46 47
# Check for build tools and show an error if one of them is not present
include(cmake/CheckBuildTools.cmake)
48

49

50
set(LINPHONE_BUILDER_EP_VARS)
51
set(LINPHONE_BUILDER_INCLUDED_BUILDERS)
52
set(LINPHONE_BUILDER_INCLUDED_BUILDERS_TO_EXCLUDE)
53
set(LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS)
54 55

macro(linphone_builder_expand_external_project_vars)
Ghislain MARY's avatar
Ghislain MARY committed
56 57 58 59 60 61 62 63 64 65
	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)
		list(APPEND LINPHONE_BUILDER_EP_ARGS -D${_varname}:${_vartype}=${${_varname}})
		list(APPEND LINPHONE_BUILDER_EP_VARNAMES ${_varname})
	endforeach()
66
endmacro()
67 68 69 70

list(APPEND LINPHONE_BUILDER_EP_VARS
	CMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH
	CMAKE_BUILD_TYPE:STRING
71
	CMAKE_BUILD_WITH_INSTALL_RPATH:BOOL
72
	CMAKE_BUNDLE_OUTPUT_DIRECTORY:PATH
73
	CMAKE_C_COMPILER_LAUNCHER:PATH
74 75 76 77 78
	CMAKE_C_FLAGS_DEBUG:STRING
	CMAKE_C_FLAGS_MINSIZEREL:STRING
	CMAKE_C_FLAGS_RELEASE:STRING
	CMAKE_C_FLAGS_RELWITHDEBINFO:STRING
	CMAKE_C_FLAGS:STRING
79
	CMAKE_CXX_COMPILER_LAUNCHER:PATH
80 81 82 83 84 85 86 87 88 89 90
	CMAKE_CXX_FLAGS_DEBUG:STRING
	CMAKE_CXX_FLAGS_MINSIZEREL:STRING
	CMAKE_CXX_FLAGS_RELEASE:STRING
	CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING
	CMAKE_CXX_FLAGS:STRING
	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_EXE_LINKER_FLAGS:STRING
	CMAKE_EXTRA_GENERATOR:STRING
91
	CMAKE_GENERATOR_PLATFORM:STRING
92
	CMAKE_INSTALL_MESSAGE:STRING
93
	CMAKE_INSTALL_PREFIX:PATH
94 95
	CMAKE_INSTALL_RPATH:PATH
	CMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL
96 97 98 99 100 101 102
	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_LINKER_FLAGS:STRING
	CMAKE_MODULE_PATH:PATH
103
	CMAKE_NO_BUILD_TYPE:BOOL
104
	CMAKE_PREFIX_PATH:STRING
105 106 107 108 109 110 111
	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
	CMAKE_SHARED_LINKER_FLAGS:STRING
	CMAKE_SKIP_RPATH:BOOL
112
	CMAKE_SKIP_BUILD_RPATH:BOOL
113
	CMAKE_VERBOSE_MAKEFILE:BOOL
114 115 116
	MSVC_C_ARCHITECTURE_ID:STRING
	MSVC_CXX_ARCHITECTURE_ID:STRING
	MSVC_VERSION:STRING
117
)
118
if(CMAKE_CROSSCOMPILING)
Ghislain MARY's avatar
Ghislain MARY committed
119
	list(APPEND LINPHONE_BUILDER_EP_VARS
120 121 122 123
		CMAKE_SYSTEM_NAME:STRING
		CMAKE_SYSTEM_VERSION:STRING
	)
endif()
124 125
if(APPLE)
	list(APPEND LINPHONE_BUILDER_EP_VARS
126
		CMAKE_MACOSX_RPATH:BOOL
127 128 129
		CMAKE_OSX_ARCHITECTURES:STRING
		CMAKE_OSX_DEPLOYMENT_TARGET:STRING
	)
130
endif()
131 132 133
if(CMAKE_TOOLCHAIN_FILE)
	list(APPEND LINPHONE_BUILDER_EP_VARS CMAKE_TOOLCHAIN_FILE:PATH)
endif()
134 135


136 137 138 139 140 141 142 143 144 145
function(linphone_builder_get_autotools_configuration)
	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()
Ghislain MARY's avatar
Ghislain MARY committed
146 147
	if(CMAKE_OSX_ARCHITECTURES)
		list(APPEND _autotools_command "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}")
148
	endif()
149 150 151 152 153 154
	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()
155
	list(APPEND _autotools_command "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Autotools/")
156 157
	execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/Autotools)
	execute_process(COMMAND ${_autotools_command} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Autotools)
158 159 160
	unset(_autotools_command)
	unset(_extra_generator)
	unset(_generator)
161
	include(${CMAKE_BINARY_DIR}/Autotools/Autotools.cmake)
Ghislain MARY's avatar
Ghislain MARY committed
162
endfunction()
163 164


165 166
macro(linphone_builder_create_targets_list)
	set(LINPHONE_BUILDER_TARGETS )
Ghislain MARY's avatar
Ghislain MARY committed
167
	if(LINPHONE_BUILDER_TARGET STREQUAL "belle-sip")
168
		list(APPEND LINPHONE_BUILDER_TARGETS "belle-sip")
Ghislain MARY's avatar
Ghislain MARY committed
169
	elseif(LINPHONE_BUILDER_TARGET STREQUAL "ortp")
170
		list(APPEND LINPHONE_BUILDER_TARGETS "ortp")
Ghislain MARY's avatar
Ghislain MARY committed
171
	elseif(LINPHONE_BUILDER_TARGET STREQUAL "ms2")
172
		list(APPEND LINPHONE_BUILDER_TARGETS "ortp" "ms2")
Ghislain MARY's avatar
Ghislain MARY committed
173
	elseif(LINPHONE_BUILDER_TARGET STREQUAL "ms2-plugins")
174
		list(APPEND LINPHONE_BUILDER_TARGETS "ortp" "ms2" "ms2-plugins")
Ghislain MARY's avatar
Ghislain MARY committed
175
	elseif(LINPHONE_BUILDER_TARGET STREQUAL "linphone")
176
		list(APPEND LINPHONE_BUILDER_TARGETS "belle-sip" "ortp" "ms2" "ms2-plugins" "linphone")
Ghislain MARY's avatar
Ghislain MARY committed
177
	elseif(LINPHONE_BUILDER_TARGET STREQUAL "flexisip")
178
		list(APPEND LINPHONE_BUILDER_TARGETS "ortp" "flexisip")
Ghislain MARY's avatar
Ghislain MARY committed
179
	elseif(LINPHONE_BUILDER_TARGET STREQUAL "odb")
180
		list(APPEND LINPHONE_BUILDER_TARGETS "odb" )
181 182 183
	else()
		message(FATAL_ERROR "Invalid LINPHONE_BUILDER_TARGET '${LINPHONE_BUILDER_TARGET}'")
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
184
endmacro()
185 186 187 188 189 190 191 192 193 194


macro(linphone_builder_include_builder BUILDER)
	list(FIND LINPHONE_BUILDER_INCLUDED_BUILDERS ${BUILDER} _already_included)
	if(_already_included EQUAL -1)
		message(STATUS "Including builder ${BUILDER}")
		include(${CMAKE_CURRENT_SOURCE_DIR}/builders/${BUILDER}.cmake)
		list(APPEND LINPHONE_BUILDER_INCLUDED_BUILDERS ${BUILDER})
	endif()
	unset(_already_included)
Ghislain MARY's avatar
Ghislain MARY committed
195
endmacro()
196 197 198 199


macro(linphone_builder_add_builder_to_target TARGETNAME BUILDER)
	linphone_builder_include_builder(${BUILDER})
200
	if(LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH AND (LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS OR LINPHONE_BUILDER_BUILD_ONLY_EXTERNAL_SOURCE_PATH))
201
		foreach(SUBDIR ${EP_${BUILDER}_EXTERNAL_SOURCE_PATHS})
202 203
			set(_source_dir "${LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH}/${SUBDIR}")
			if(EXISTS "${_source_dir}")
Ghislain MARY's avatar
Ghislain MARY committed
204
				#message("    ${TARGETNAME} depends on external source path ${LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH}/${SUBDIR}")
205
				set(_build_from_external_source_path 1)
206
				break()
207 208 209 210 211
			endif()
		endforeach()
		if(_build_from_external_source_path)
			list(FIND LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS ${BUILDER} _already_included)
			if(_already_included EQUAL -1)
Ghislain MARY's avatar
Ghislain MARY committed
212
				message("    external source path builder ${BUILDER}")
213 214
				set(EP_${BUILDER}_SOURCE_DIR "${_source_dir}")
				list(APPEND LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS ${BUILDER})
215 216
			endif()
			unset(_already_included)
217
		elseif(LINPHONE_BUILDER_BUILD_ONLY_EXTERNAL_SOURCE_PATH)
218
			list(APPEND LINPHONE_BUILDER_INCLUDED_BUILDERS_TO_EXCLUDE ${BUILDER})
219
		else()
Ghislain MARY's avatar
Ghislain MARY committed
220
			#message("     ${TARGETNAME} depends on external project EP_${BUILDER}")
221
			add_dependencies(${TARGETNAME} EP_${BUILDER})
222 223 224
		endif()
		unset(_build_from_external_source_path)
	else()
Ghislain MARY's avatar
Ghislain MARY committed
225
		#message("    ${TARGETNAME} depends on external project EP_${BUILDER}")
226 227
		add_dependencies(${TARGETNAME} EP_${BUILDER})
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
228
endmacro()
229 230


231
macro(linphone_builder_apply_flags)
Ghislain MARY's avatar
Ghislain MARY committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
	set(BUILD_TYPES "Debug" "Release" "RelWithDebInfo" "MinSizeRel")
	list(FIND BUILD_TYPES "${CMAKE_BUILD_TYPE}" BUILD_TYPE_FOUND)
	set(BUILD_TYPE_SUFFIX "")
	if(NOT ${BUILD_TYPE_FOUND} EQUAL -1)
		string(TOUPPER "${CMAKE_BUILD_TYPE}" UPPER_BUILD_TYPE)
		set(BUILD_TYPE_SUFFIX "_${UPPER_BUILD_TYPE}")
	endif()

	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)
		set(CMAKE_C_FLAGS${BUILD_TYPE_SUFFIX} "${CMAKE_C_FLAGS${BUILD_TYPE_SUFFIX}} ${LINPHONE_BUILDER_CPPFLAGS}")
		set(CMAKE_CXX_FLAGS${BUILD_TYPE_SUFFIX} "${CMAKE_CXX_FLAGS${BUILD_TYPE_SUFFIX}} ${LINPHONE_BUILDER_CPPFLAGS}")
		set(AUTOTOOLS_C_FLAGS "${AUTOTOOLS_C_FLAGS} ${LINPHONE_BUILDER_CPPFLAGS}")
		set(AUTOTOOLS_CXX_FLAGS "${AUTOTOOLS_CXX_FLAGS} ${LINPHONE_BUILDER_CPPFLAGS}")
	endif()
	if(LINPHONE_BUILDER_CFLAGS)
		set(CMAKE_C_FLAGS${BUILD_TYPE_SUFFIX} "${CMAKE_C_FLAGS${BUILD_TYPE_SUFFIX}} ${LINPHONE_BUILDER_CFLAGS}")
		set(AUTOTOOLS_C_FLAGS "${AUTOTOOLS_C_FLAGS} ${LINPHONE_BUILDER_CFLAGS}")
	endif()
	if(LINPHONE_BUILDER_CXXFLAGS)
		set(CMAKE_CXX_FLAGS${BUILD_TYPE_SUFFIX} "${CMAKE_CXX_FLAGS${BUILD_TYPE_SUFFIX}} ${LINPHONE_BUILDER_CXXFLAGS}")
		set(AUTOTOOLS_CXX_FLAGS "{AUTOTOOLS_CXX_FLAGS} ${LINPHONE_BUILDER_CXX_FLAGS}")
	endif()
	if(LINPHONE_BUILDER_OBJCFLAGS)
		set(CMAKE_C_FLAGS${BUILD_TYPE_SUFFIX} "${CMAKE_C_FLAGS${BUILD_TYPE_SUFFIX}} ${LINPHONE_BUILDER_OBJCFLAGS}")
		set(AUTOTOOLS_OBJC_FLAGS "${AUTOTOOLS_OBJC_FLAGS} ${LINPHONE_BUILDER_OBJCFLAGS}")
	endif()
	if(LINPHONE_BUILDER_LDFLAGS)
		set(CMAKE_EXE_LINKER_FLAGS${BUILD_TYPE_SUFFIX} "${CMAKE_EXE_LINKER_FLAGS${BUILD_TYPE_SUFFIX}} ${LINPHONE_BUILDER_LDFLAGS}")
		set(CMAKE_MODULE_LINKER_FLAGS${BUILD_TYPE_SUFFIX} "${CMAKE_MODULE_LINKER_FLAGS${BUILD_TYPE_SUFFIX}} ${LINPHONE_BUILDER_LDFLAGS}")
		set(CMAKE_SHARED_LINKER_FLAGS${BUILD_TYPE_SUFFIX} "${CMAKE_SHARED_LINKER_FLAGS${BUILD_TYPE_SUFFIX}} ${LINPHONE_BUILDER_LDFLAGS}")
		set(AUTOTOOLS_LINKER_FLAGS "${AUTOTOOLS_LINKER_FLAGS} ${LINPHONE_BUILDER_LDFLAGS}")
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
273
endmacro()
274 275


276
macro(linphone_builder_apply_cmake_flags_to_autotools_project PROJNAME)
Ghislain MARY's avatar
Ghislain MARY committed
277
	if(EP_${PROJNAME}_BUILD_METHOD STREQUAL "autotools")
Ghislain MARY's avatar
Ghislain MARY committed
278 279 280 281 282 283
		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}")
284
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
285
endmacro()
286 287


288
macro(linphone_builder_apply_extra_flags PROJNAME)
Ghislain MARY's avatar
Ghislain MARY committed
289
	if(EP_${PROJNAME}_BUILD_METHOD STREQUAL "autotools")
290 291 292 293 294 295
		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}")
296
	else()
297
		foreach(BUILD_CONFIG "" "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
Ghislain MARY's avatar
Ghislain MARY committed
298
			if(EP_${PROJNAME}_EXTRA_CFLAGS)
299
				set(CMAKE_C_FLAGS${BUILD_CONFIG} "${CMAKE_C_FLAGS${BUILD_CONFIG}} ${EP_${PROJNAME}_EXTRA_CFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
300
			endif()
Ghislain MARY's avatar
Ghislain MARY committed
301
			if(EP_${PROJNAME}_EXTRA_CXXFLAGS)
302
				set(CMAKE_CXX_FLAGS${BUILD_CONFIG} "${CMAKE_CXX_FLAGS${BUILD_CONFIG}} ${EP_${PROJNAME}_EXTRA_CXXFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
303
			endif()
Ghislain MARY's avatar
Ghislain MARY committed
304
			if(EP_${PROJNAME}_EXTRA_LDFLAGS)
305 306 307
				set(CMAKE_EXE_LINKER_FLAGS${BUILD_CONFIG} "${CMAKE_EXE_LINKER_FLAGS${BUILD_CONFIG}} ${EP_${PROJNAME}_EXTRA_LDFLAGS}")
				set(CMAKE_MODULE_LINKER_FLAGS${BUILD_CONFIG} "${CMAKE_MODULE_LINKER_FLAGS${BUILD_CONFIG}} ${EP_${PROJNAME}_EXTRA_LDFLAGS}")
				set(CMAKE_SHARED_LINKER_FLAGS${BUILD_CONFIG} "${CMAKE_SHARED_LINKER_FLAGS${BUILD_CONFIG}} ${EP_${PROJNAME}_EXTRA_LDFLAGS}")
308
			endif()
Ghislain MARY's avatar
Ghislain MARY committed
309
		endforeach()
310
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
311
endmacro()
312 313


314
macro(linphone_builder_set_ep_directories PROJNAME)
315 316 317 318 319
	if(EP_${PROJNAME}_SOURCE_DIR)
		set(ep_source "${EP_${PROJNAME}_SOURCE_DIR}")
	else()
		set(ep_source "${ep_base}/Source/EP_${PROJNAME}")
	endif()
320
	if(EP_${PROJNAME}_BUILD_IN_SOURCE)
321
		set(ep_build "${ep_source}")
Ghislain MARY's avatar
Ghislain MARY committed
322
	else()
323
		set(ep_build "${ep_base}/Build/${PROJNAME}")
Ghislain MARY's avatar
Ghislain MARY committed
324 325
	endif()
endmacro()
326

327 328

macro(linphone_builder_create_autogen_command PROJNAME)
329 330
	if(EP_${PROJNAME}_USE_AUTOGEN)
		if(EP_${PROJNAME}_CONFIGURE_OPTIONS_PASSED_TO_AUTOGEN)
331 332 333
			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
334
			endforeach()
335
		endif()
336
		set(ep_autogen_command "\"${ep_source}/autogen.sh\" ${ep_autogen_options}")
337
	else()
338
		set(ep_autogen_command "")
339
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
340
endmacro()
341 342 343


macro(linphone_builder_create_configure_command PROJNAME)
344
	if(EP_${PROJNAME}_CONFIGURE_OPTIONS_PASSED_TO_AUTOGEN)
345
		set(ep_configure_command "")
346
	else()
347 348 349
		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
350
		endforeach()
351
		set(ep_configure_env "${EP_${PROJNAME}_CONFIGURE_ENV}")
352
		set(ep_configure_command "\"${ep_source}/configure\" ${ep_configure_options}")
353
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
354
endmacro()
355 356


357 358 359 360 361
macro(linphone_builder_create_build_command PROJNAME)
	set(ep_make_options "${EP_${PROJNAME}_MAKE_OPTIONS}")
endmacro()


362
# this function invokes configure_file() for the project, using the default file if
363 364
# the specific file is not defined
function(linphone_builder_configure_file_for_project PROJNAME CMD DEFAULT_CONF_FILE OUTPUT)
Ghislain MARY's avatar
Ghislain MARY committed
365
	if(NOT EP_${PROJNAME}_${CMD}_COMMAND_SOURCE)
366
		message(STATUS "Using default file ${DEFAULT_CONF_FILE} for ${CMD} step of ${PROJNAME}")
367 368
		configure_file(${DEFAULT_CONF_FILE} ${OUTPUT})
	else()
369
		message(STATUS "Using specific file ${EP_${PROJNAME}_${CMD}_COMMAND_SOURCE} for ${CMD} step of ${PROJNAME}")
370
		configure_file(${EP_${PROJNAME}_${CMD}_COMMAND_SOURCE} ${OUTPUT})
371 372 373
	endif()
endfunction()

374 375 376 377
macro(linphone_builder_filter_out_inexistent_dependencies PROJNAME)
	if(EP_${PROJNAME}_DEPENDENCIES)
		set(_new_deps )
		foreach(_dep ${EP_${PROJNAME}_DEPENDENCIES})
378 379
			string(REGEX REPLACE "^EP_" "" _dep2 ${_dep})
			list(FIND LINPHONE_BUILDER_INCLUDED_BUILDERS ${_dep2} _found)
380
			list(FIND LINPHONE_BUILDER_INCLUDED_BUILDERS_TO_EXCLUDE ${_dep2} _excluded_found)
381
			list(FIND LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS ${_dep2} _external_source_path_found)
382
			if((_found GREATER -1) AND (_excluded_found EQUAL -1) AND ((_external_source_path_found EQUAL -1) OR (NOT EP_${_dep2}_GROUPABLE)))
383 384 385 386 387 388 389 390 391 392 393
				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()

394
function(linphone_builder_add_external_project PROJNAME)
395 396 397 398 399 400 401 402 403 404
	if(LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH)
		foreach(SUBDIR ${EP_${PROJNAME}_EXTERNAL_SOURCE_PATHS})
			if(NOT EP_${PROJNAME}_SOURCE_DIR)
				if(EXISTS "${LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH}/${SUBDIR}")
					set(EP_${PROJNAME}_SOURCE_DIR "${LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH}/${SUBDIR}")
				endif()
			endif()
		endforeach()
	endif()

405
	linphone_builder_set_ep_directories(${PROJNAME})
Ghislain MARY's avatar
Ghislain MARY committed
406 407 408
	if(NOT EP_${PROJNAME}_DO_NOT_USE_CMAKE_FLAGS)
		linphone_builder_apply_cmake_flags_to_autotools_project(${PROJNAME})
	endif()
409
	linphone_builder_apply_extra_flags(${PROJNAME})
410 411
	linphone_builder_expand_external_project_vars()

Ghislain MARY's avatar
Ghislain MARY committed
412
	if(EP_${PROJNAME}_BUILD_METHOD STREQUAL "prebuilt")
413 414 415 416 417 418
		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
419
	elseif(EP_${PROJNAME}_BUILD_METHOD STREQUAL "custom")
420 421 422
		if(WIN32)
			set(ep_redirect_to_file "2>&1 >> \"${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}.log\"")
		endif()
423 424 425 426 427 428 429 430 431 432 433 434
		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()
435
		set(BUILD_COMMANDS
436 437 438
			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}
439
		)
Ghislain MARY's avatar
Ghislain MARY committed
440
	elseif(EP_${PROJNAME}_BUILD_METHOD STREQUAL "autotools")
441 442
		linphone_builder_create_autogen_command(${PROJNAME})
		linphone_builder_create_configure_command(${PROJNAME})
443
		linphone_builder_create_build_command(${PROJNAME})
Ghislain MARY's avatar
Ghislain MARY committed
444
		if(EP_${PROJNAME}_CONFIG_H_FILE)
445
			set(ep_config_h_file ${EP_${PROJNAME}_CONFIG_H_FILE})
Ghislain MARY's avatar
Ghislain MARY committed
446
		else()
Ghislain MARY's avatar
Ghislain MARY committed
447 448 449
			set(ep_config_h_file config.h)
		endif()
		if(EP_${PROJNAME}_INSTALL_TARGET)
450
			set(ep_install_target "${EP_${PROJNAME}_INSTALL_TARGET}")
Ghislain MARY's avatar
Ghislain MARY committed
451 452
		else()
			set(ep_install_target "install")
Ghislain MARY's avatar
Ghislain MARY committed
453
		endif()
454

455
		if(WIN32)
456
			set(ep_redirect_to_file "2>&1 >> \"${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}.log\"")
457 458 459 460 461 462
			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)
			# Build in source with MinGW as build out-of-source does not work
463
			set(ep_build "${ep_source}")
Ghislain MARY's avatar
Ghislain MARY committed
464
			if(ep_autogen_command)
465 466
				set(ep_autogen_redirect_to_file ${ep_redirect_to_file})
			endif()
Ghislain MARY's avatar
Ghislain MARY committed
467
			if(ep_configure_command)
468 469
				set(ep_configure_redirect_to_file ${ep_redirect_to_file})
			endif()
470
		else()
471
			set(SCRIPT_EXTENSION sh)
472
		endif()
473

Ghislain MARY's avatar
Ghislain MARY committed
474
		if(EP_${PROJNAME}_PKG_CONFIG)
475
			set(LINPHONE_BUILDER_PKG_CONFIG "${EP_${PROJNAME}_PKG_CONFIG}")
Ghislain MARY's avatar
Ghislain MARY committed
476 477
		else()
			set(LINPHONE_BUILDER_PKG_CONFIG "${PKG_CONFIG_PROGRAM}")
Ghislain MARY's avatar
Ghislain MARY committed
478
		endif()
479

480 481 482
		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
483 484

		set(BUILD_COMMANDS
485 486 487
			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
488
		)
Ghislain MARY's avatar
Ghislain MARY committed
489
	elseif(EP_${PROJNAME}_BUILD_METHOD STREQUAL "rpm")
490

491
		if(WIN32)
492
			message(SEND_ERROR "rpm build not supported on WIN32")
493 494 495 496
		endif()

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

Ghislain MARY's avatar
Ghislain MARY committed
498
		if(EP_${PROJNAME}_CONFIG_H_FILE)
499
			set(ep_config_h_file ${EP_${PROJNAME}_CONFIG_H_FILE})
Ghislain MARY's avatar
Ghislain MARY committed
500 501
		else()
			set(ep_config_h_file config.h)
502
		endif()
503

Ghislain MARY's avatar
Ghislain MARY committed
504
		if(EP_${PROJNAME}_INSTALL_TARGET)
505
			set(ep_install_target "${EP_${PROJNAME}_INSTALL_TARGET}")
Ghislain MARY's avatar
Ghislain MARY committed
506 507
		else()
			set(ep_install_target "install")
508 509
		endif()

Ghislain MARY's avatar
Ghislain MARY committed
510
		if(EP_${PROJNAME}_SPEC_FILE)
511
			set(LINPHONE_BUILDER_SPEC_FILE "${EP_${PROJNAME}_SPEC_FILE}")
Ghislain MARY's avatar
Ghislain MARY committed
512 513
		else()
			message(SEND_ERROR "rpm build requires EP_${PROJNAME}_SPEC_FILE to be defined")
514 515 516 517
		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
518
		if(EP_${PROJNAME}_RPMBUILD_NAME)
519
			set(LINPHONE_BUILDER_RPMBUILD_NAME "${EP_${PROJNAME}_RPMBUILD_NAME}")
Ghislain MARY's avatar
Ghislain MARY committed
520 521
		else()
			set(LINPHONE_BUILDER_RPMBUILD_NAME "${PROJNAME}")
522
		endif()
523

524 525
		# 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
526
		if(EP_${PROJNAME}_RPMBUILD_OPTIONS)
527 528 529 530 531
			set(LINPHONE_BUILDER_RPMBUILD_OPTIONS "${EP_${PROJNAME}_RPMBUILD_OPTIONS}")
		endif()

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

Ghislain MARY's avatar
Ghislain MARY committed
532
		if(EP_${PROJNAME}_PKG_CONFIG)
533
			set(LINPHONE_BUILDER_PKG_CONFIG "${EP_${PROJNAME}_PKG_CONFIG}")
Ghislain MARY's avatar
Ghislain MARY committed
534 535
		else()
			set(LINPHONE_BUILDER_PKG_CONFIG "${PKG_CONFIG_PROGRAM}")
536 537
		endif()

Ghislain MARY's avatar
Ghislain MARY committed
538
		if(EP_${PROJNAME}_CONFIGURE_EXTRA_CMD)
539 540 541
			set(LINPHONE_BUILDER_CONFIGURE_EXTRA_CMD "${EP_${PROJNAME}_CONFIGURE_EXTRA_CMD}")
		endif()

542 543 544 545
		# allow to have special command steps
		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)
		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)
546 547 548 549 550 551

		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
		)
552 553
	else()
		# Use CMake build method
554 555 556 557
		set(BUILD_COMMANDS
			CMAKE_ARGS ${EP_${PROJNAME}_CMAKE_OPTIONS} ${EP_${PROJNAME}_LINKING_TYPE}
			CMAKE_CACHE_ARGS ${LINPHONE_BUILDER_EP_ARGS}
		)
558
	endif()
559

560
	if(LINPHONE_BUILDER_LATEST AND EP_${PROJNAME}_GIT_TAG_LATEST)
561
		set(DOWNLOAD_SOURCE GIT_REPOSITORY ${EP_${PROJNAME}_GIT_REPOSITORY} GIT_TAG ${EP_${PROJNAME}_GIT_TAG_LATEST})
562
	elseif(EP_${PROJNAME}_SOURCE_DIR)
563
		set(DOWNLOAD_SOURCE SOURCE_DIR "${EP_${PROJNAME}_SOURCE_DIR}")
564 565 566 567 568
	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()
569
	else()
570
		set(DOWNLOAD_SOURCE GIT_REPOSITORY ${EP_${PROJNAME}_GIT_REPOSITORY} GIT_TAG ${EP_${PROJNAME}_GIT_TAG})
571
	endif()
572

573 574
	linphone_builder_filter_out_inexistent_dependencies(${PROJNAME})

575 576
	ExternalProject_Add(EP_${PROJNAME}
		DEPENDS ${EP_${PROJNAME}_DEPENDENCIES}
577
		BINARY_DIR "${ep_build}"
578
		${DOWNLOAD_SOURCE}
579 580
		PATCH_COMMAND ${EP_${PROJNAME}_PATCH_COMMAND}
		CMAKE_GENERATOR ${CMAKE_GENERATOR}
Ghislain MARY's avatar
Ghislain MARY committed
581
		${BUILD_COMMANDS}
582
	)
583

584 585 586
	if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/builders/${PROJNAME}/postinstall.cmake)
		ExternalProject_Add_Step(EP_${PROJNAME} postinstall
			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
587 588
			COMMENT "Performing post-installation for 'EP_${PROJNAME}'"
			DEPENDEES install
589 590
			WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
		)
591
	endif()
592
	if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/builders/${PROJNAME}/postconfig.cmake)
593
		ExternalProject_Add_Step(EP_${PROJNAME} postconfig
594
			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
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
			COMMENT "Performing post-configuration for 'EP_${PROJNAME}'"
			DEPENDEES install
			WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
		)
	endif()

	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()
		ExternalProject_Add_Step(EP_${PROJNAME} check_changes
			COMMENT "Checking for source code changes for 'EP_${PROJNAME}'"
			DEPENDEES update patch
610
			WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
611 612 613 614 615 616
			ALWAYS 1
		)
		_ep_get_step_stampfile(EP_${PROJNAME} check_changes _stamp_file) # Private API of ExternalProject module
		add_custom_command(OUTPUT "${ep_build}/check_changes.txt"
			COMMAND ${CMAKE_COMMAND} -DSOURCE_DIRS=${_source_dirs} -DBINARY_DIR=${ep_build} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_changes.cmake
			DEPENDS ${_stamp_file}
617
		)
618 619 620 621 622 623 624
		# TODO: ExternalProject_Add_StepDependencies is available only from CMake 3.2
		#ExternalProject_Add_StepDependencies(EP_${PROJNAME} configure "${ep_build}/check_changes.txt")
		_ep_get_step_stampfile(EP_${PROJNAME} configure _stamp_file) # Private API of ExternalProject module
		add_custom_command(APPEND
			OUTPUT ${_stamp_file}
			DEPENDS "${ep_build}/check_changes.txt"
		)
625 626
		unset(_source_dirs)
		unset(_stamp_file)
627 628
	endif()

Ghislain MARY's avatar
Ghislain MARY committed
629
endfunction()
Ghislain MARY's avatar
Ghislain MARY committed
630

631
macro(linphone_builder_add_grouped_external_source_path_project PROJNAME FILENAME)
632
	linphone_builder_filter_out_inexistent_dependencies(${PROJNAME})
633 634 635
	file(APPEND "${FILENAME}" "add_subdirectory(\"${EP_${PROJNAME}_SOURCE_DIR}\" \"${LINPHONE_BUILDER_WORK_DIR}/Build/${PROJNAME}\")\n")
	list(APPEND EP_linphone_builder_LINKING_TYPES "${EP_${PROJNAME}_LINKING_TYPE}")
	list(APPEND EP_linphone_builder_CMAKE_OPTIONS "${EP_${PROJNAME}_CMAKE_OPTIONS}")
636 637 638
	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}")
639
	list(APPEND EP_linphone_builder_EXTRA_LDFLAGS "${EP_${PROJNAME}_EXTRA_LDFLAGS}")
640
	list(APPEND EP_linphone_builder_EXTRA_OBJCFLAGS "${EP_${PROJNAME}_EXTRA_OBJCFLAGS}")
641 642
	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}")
643
	if(EP_${PROJNAME}_DEPENDENCIES)
644
		list(APPEND EP_linphone_builder_DEPENDENCIES ${EP_${PROJNAME}_DEPENDENCIES})
645
	endif()
646
endmacro()
647

648
function(linphone_builder_add_external_projects)
649
	foreach(BUILDER ${LINPHONE_BUILDER_INCLUDED_BUILDERS})
650 651
		list(FIND LINPHONE_BUILDER_INCLUDED_BUILDERS_TO_EXCLUDE ${BUILDER} _excluded_found)
		list(FIND LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS ${BUILDER} _external_source_path_found)
652
		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)))
653 654 655 656 657
			linphone_builder_add_external_project(${BUILDER})
		endif()
	endforeach()
endfunction()

658
macro(detect_conflicting_cmake_options)
659 660 661 662 663 664 665
	if(EP_linphone_builder_CMAKE_OPTIONS)
		list(REMOVE_DUPLICATES EP_linphone_builder_CMAKE_OPTIONS)
		set(_new_options )
		foreach(_option ${EP_linphone_builder_CMAKE_OPTIONS})
			string(REGEX MATCH "^-D(.+)=(.*)$" _match "${_option}")
			if(_match)
				set(_new_option "-D${CMAKE_MATCH_1}=")
666 667 668 669 670 671 672 673 674
				set(_value ${CMAKE_MATCH_2})
				if(CMAKE_MATCH_1 MATCHES "^ENABLE_.*$")
					if(_value)
						set(_new_option "${_new_option}ON")
						set(_conflicting_option "${_new_option}OFF")
					else()
						set(_new_option "${_new_option}OFF")
						set(_conflicting_option "${_new_option}ON")
					endif()
675
				else()
676
					set(_new_option "${_new_option}${_value}")
677 678 679 680 681 682 683 684 685
				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)
					message(FATAL_ERROR "Conflicting options ${_new_option} and ${_conflicting_option}")
				endif()
686
			endif()
687 688 689
		endforeach()
		if(_new_options)
			set(EP_linphone_builder_CMAKE_OPTIONS ${_new_options})
690 691 692 693
		endif()
	endif()
endmacro()

694
function(linphone_builder_add_grouped_external_source_path_projects)
695 696 697 698 699 700 701 702 703
	set(_grouped_builders)
	if(LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS)
		foreach (_builder ${LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS})
			if(EP_${_builder}_GROUPABLE)
				list(APPEND _grouped_builders ${_builder})
			endif()
		endforeach()
	endif()
	if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS AND _grouped_builders)
704 705 706 707
		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")
708
		file(APPEND "${_linphone_builder_file}" "option(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS \"Group external source path builders.\" ON)\n")
709 710
		set(EP_linphone_builder_CMAKE_OPTIONS )
		set(EP_linphone_builder_LINKING_TYPES )
711 712 713
		set(EP_linphone_builder_EXTRA_CFLAGS )
		set(EP_linphone_builder_EXTRA_CPPFLAGS )
		set(EP_linphone_builder_EXTRA_CXXFLAGS )
714
		set(EP_linphone_builder_EXTRA_LDFLAGS )
715
		set(EP_linphone_builder_EXTRA_OBJCFLAGS )
716
		set(EP_linphone_builder_DEPENDENCIES )
717
		set(EP_linphone_builder_GROUPED_SOURCE_DIRS )
718
		foreach(BUILDER ${_grouped_builders})
719
			list(APPEND EP_linphone_builder_GROUPED_SOURCE_DIRS ${EP_${BUILDER}_SOURCE_DIR})
720
			linphone_builder_add_grouped_external_source_path_project(${BUILDER} "${_linphone_builder_file}")
721
		endforeach()
722 723 724 725 726 727 728
		list(REMOVE_DUPLICATES EP_linphone_builder_LINKING_TYPES)
		list(LENGTH EP_linphone_builder_LINKING_TYPES _conflicting_linking_types)
		if(_conflicting_linking_types GREATER 1)
			message(FATAL_ERROR "Conflicing linking types in grouped external source path projects: ${EP_linphone_builder_LINKING_TYPES}")
		else()
			set(EP_linphone_builder_LINKING_TYPE ${EP_linphone_builder_LINKING_TYPES})
		endif()
729
		detect_conflicting_cmake_options()
730 731 732 733 734 735 736 737 738
		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()
739 740 741
		if(EP_linphone_builder_EXTRA_LDFLAGS)
			list(REMOVE_DUPLICATES EP_linphone_builder_EXTRA_LDFLAGS)
		endif()
742 743 744
		if(EP_linphone_builder_EXTRA_OBJCFLAGS)
			list(REMOVE_DUPLICATES EP_linphone_builder_EXTRA_OBJCFLAGS)
		endif()
745 746 747
		if(EP_linphone_builder_DEPENDENCIES)
			list(REMOVE_DUPLICATES EP_linphone_builder_DEPENDENCIES)
		endif()
748 749 750 751 752
		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)
753
		unset(_grouped_builders)
754
	endif()
755 756 757 758
endfunction()

function(linphone_builder_add_projects)
	linphone_builder_add_external_projects()
759
	linphone_builder_add_grouped_external_source_path_projects()
Ghislain MARY's avatar
Ghislain MARY committed
760
endfunction()
761 762 763

macro(linphone_builder_add_dummy_libraries_generation)
	if(LINPHONE_BUILDER_DUMMY_LIBRARIES)
Ghislain MARY's avatar
Ghislain MARY committed
764
		# linphone_builder_apply_flags()
765 766
		linphone_builder_set_ep_directories(dummy_libraries)
		linphone_builder_expand_external_project_vars()
767
		ExternalProject_Add(EP_dummy_libraries
768
			DEPENDS TARGET_linphone_builder
769 770
			TMP_DIR "${ep_tmp}"
			BINARY_DIR "${ep_build}"
771
			SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/cmake/dummy_libraries"
772 773 774 775 776 777
			DOWNLOAD_COMMAND ""
			CMAKE_GENERATOR ${CMAKE_GENERATOR}
			CMAKE_ARGS ${LINPHONE_BUILDER_EP_ARGS} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DLINPHONE_BUILDER_DUMMY_LIBRARIES=${LINPHONE_BUILDER_DUMMY_LIBRARIES}
		)
	endif()
endmacro()