LinphoneCMakeBuilder.cmake 29.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
############################################################################
# LinphoneCMakeBuilder.cmake
# 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})
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 40 41 42 43 44 45
if(${CMAKE_VERBOSE_MAKEFILE})
	set(AUTOTOOLS_VERBOSE_MAKEFILE 1)
else(${CMAKE_VERBOSE_MAKEFILE})
	set(AUTOTOOLS_VERBOSE_MAKEFILE 0)
endif(${CMAKE_VERBOSE_MAKEFILE})


46 47 48
find_package(PythonInterp)
if(NOT PYTHONINTERP_FOUND)
	message(FATAL_ERROR "Could not find python!")
49
endif()
50

51 52 53 54 55 56 57 58
if(MSVC)
	find_program(SH_PROGRAM
		NAMES sh.exe
		HINTS "C:/MinGW/msys/1.0/bin"
	)
	if(NOT SH_PROGRAM)
		message(FATAL_ERROR "Could not find MinGW!")
	endif(NOT SH_PROGRAM)
59

60 61 62 63 64 65 66 67 68 69 70 71
	if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsPhone")
		find_file(GCC_LIBRARY
			NAMES libgcc.a
			HINTS "C:/MinGW/lib/gcc/mingw32/*"
		)
		execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${GCC_LIBRARY}" "${CMAKE_INSTALL_PREFIX}/lib/gcc.lib")
		find_file(MINGWEX_LIBRARY
			NAMES libmingwex.a
			HINTS "C:/MinGW/lib"
		)
		execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${MINGWEX_LIBRARY}" "${CMAKE_INSTALL_PREFIX}/lib/mingwex.lib")
	endif()
72 73
endif()

74
if(WIN32)
75
	set(_windows_tools_dir ${CMAKE_BINARY_DIR}/windows_tools)
76
	file(MAKE_DIRECTORY ${_windows_tools_dir})
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
	if(NOT EXISTS "${CMAKE_BINARY_DIR}/linphone_builder_windows_tools.zip")
		message(STATUS "Installing windows tools")
		file(DOWNLOAD https://www.linphone.org/files/linphone_builder_windows_tools.zip "${CMAKE_BINARY_DIR}/linphone_builder_windows_tools.zip")
		execute_process(
			COMMAND "${CMAKE_COMMAND}" "-E" "tar" "x" "${CMAKE_BINARY_DIR}/linphone_builder_windows_tools.zip"
			WORKING_DIRECTORY ${_windows_tools_dir}
		)
		file(MAKE_DIRECTORY "${LINPHONE_BUILDER_WORK_DIR}/windows_tools")
		file(RENAME "${_windows_tools_dir}/awk.exe" "${LINPHONE_BUILDER_WORK_DIR}/windows_tools/awk.exe")
		file(RENAME "${_windows_tools_dir}/nasm.exe" "${LINPHONE_BUILDER_WORK_DIR}/windows_tools/nasm.exe")
		file(RENAME "${_windows_tools_dir}/patch.exe" "${LINPHONE_BUILDER_WORK_DIR}/windows_tools/patch.exe")
		file(RENAME "${_windows_tools_dir}/sed.exe" "${LINPHONE_BUILDER_WORK_DIR}/windows_tools/sed.exe")
		if(CMAKE_SIZEOF_VOID_P EQUAL 8)
			file(RENAME "${_windows_tools_dir}/yasm-1.3.0-win64.exe" "C:/MinGW/bin/yasm.exe")
		else()
			file(RENAME "${_windows_tools_dir}/yasm-1.3.0-win32.exe" "C:/MinGW/bin/yasm.exe")
		endif()
94 95 96
	endif()
endif()

97 98
find_program(PATCH_PROGRAM
	NAMES patch patch.exe
99
	HINTS "${LINPHONE_BUILDER_WORK_DIR}/windows_tools"
100 101 102 103 104 105 106 107 108 109 110
)
if(NOT PATCH_PROGRAM)
	if(WIN32)
		message(FATAL_ERROR "Could not find the patch.exe program. Please install it from http://gnuwin32.sourceforge.net/packages/patch.htm")
	else()
		message(FATAL_ERROR "Could not find the patch program.")
	endif()
endif()

find_program(SED_PROGRAM
	NAMES sed sed.exe
111
	HINTS "${LINPHONE_BUILDER_WORK_DIR}/windows_tools"
112 113 114 115 116 117 118 119
)
if(NOT SED_PROGRAM)
	if(WIN32)
		message(FATAL_ERROR "Could not find the sed.exe program. Please install it from http://gnuwin32.sourceforge.net/packages/sed.htm")
	else()
		message(FATAL_ERROR "Could not find the sed program.")
	endif()
endif()
120

121 122 123 124 125 126
find_program(PKG_CONFIG_PROGRAM
	NAMES pkg-config pkg-config.exe
	HINTS "C:/MinGW/bin"
)

if(NOT PKG_CONFIG_PROGRAM)
127
	if(WIN32)
128
		message(STATUS "Installing pkg-config to C:/MinGW/bin")
129
		set(_pkg_config_dir ${CMAKE_BINARY_DIR}/pkg-config)
130
		file(MAKE_DIRECTORY ${_pkg_config_dir})
131
		file(DOWNLOAD http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config_0.26-1_win32.zip "${CMAKE_BINARY_DIR}/pkg-config.zip")
132
		execute_process(
133
			COMMAND "${CMAKE_COMMAND}" "-E" "tar" "x" "${CMAKE_BINARY_DIR}/pkg-config.zip"
134 135
			WORKING_DIRECTORY ${_pkg_config_dir}
		)
136
		file(DOWNLOAD http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config-dev_0.26-1_win32.zip "${CMAKE_BINARY_DIR}/pkg-config-dev.zip")
137
		execute_process(
138
			COMMAND "${CMAKE_COMMAND}" "-E" "tar" "x" "${CMAKE_BINARY_DIR}/pkg-config-dev.zip"
139 140
			WORKING_DIRECTORY ${_pkg_config_dir}
		)
141
		file(DOWNLOAD http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/gettext-runtime_0.18.1.1-2_win32.zip "${CMAKE_BINARY_DIR}/gettext-runtime.zip")
142
		execute_process(
143
			COMMAND "${CMAKE_COMMAND}" "-E" "tar" "x" "${CMAKE_BINARY_DIR}/gettext-runtime.zip"
144 145
			WORKING_DIRECTORY ${_pkg_config_dir}
		)
146
		file(DOWNLOAD http://ftp.acc.umu.se/pub/gnome/binaries/win32/glib/2.28/glib_2.28.8-1_win32.zip "${CMAKE_BINARY_DIR}/glib.zip")
147
		execute_process(
148
			COMMAND "${CMAKE_COMMAND}" "-E" "tar" "x" "${CMAKE_BINARY_DIR}/glib.zip"
149 150 151
			WORKING_DIRECTORY ${_pkg_config_dir}
		)
		file(RENAME "${_pkg_config_dir}/bin/pkg-config.exe" "C:/MinGW/bin/pkg-config.exe")
152
		file(RENAME "${_pkg_config_dir}/share/aclocal/pkg.m4" "C:/MinGW/share/aclocal/pkg.m4")
153 154 155 156 157 158 159 160 161 162 163
		file(RENAME "${_pkg_config_dir}/bin/libglib-2.0-0.dll" "C:/MinGW/bin/libglib-2.0-0.dll")
		file(RENAME "${_pkg_config_dir}/bin/intl.dll" "C:/MinGW/bin/intl.dll")
		unset(_pkg_config_dir)
	endif()

	find_program(PKG_CONFIG_PROGRAM
		NAMES pkg-config pkg-config.exe
		HINTS "C:/MinGW/bin"
	)
endif()

164
if(NOT PKG_CONFIG_PROGRAM AND NOT MSVC)
165 166 167
	message(FATAL_ERROR "Could not find the pkg-config program.")
endif()

168 169
find_program(INTLTOOLIZE_PROGRAM
	NAMES intltoolize
170
	HINTS "C:/MinGW/msys/1.0/bin"
Ghislain MARY's avatar
Ghislain MARY committed
171
)
172

173 174
if(NOT INTLTOOLIZE_PROGRAM)
	if(WIN32)
175
		message(STATUS "Installing intltoolize to C:/MinGW/bin")
176
		set(_intltoolize_dir ${CMAKE_BINARY_DIR}/intltoolize)
177
		file(MAKE_DIRECTORY ${_intltoolize_dir})
178
		file(DOWNLOAD http://ftp.gnome.org/pub/gnome/binaries/win32/intltool/0.40/intltool_0.40.4-1_win32.zip "${CMAKE_BINARY_DIR}/intltoolize.zip")
179
		execute_process(
180
			COMMAND "${CMAKE_COMMAND}" "-E" "tar" "x" "${CMAKE_BINARY_DIR}/intltoolize.zip"
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
			WORKING_DIRECTORY ${_intltoolize_dir}
		)
		execute_process(
			COMMAND "${SED_PROGRAM}" "-i" "s;/opt/perl/bin/perl;/bin/perl;g" "${_intltoolize_dir}/bin/intltool-extract"
			COMMAND "${SED_PROGRAM}" "-i" "s;/opt/perl/bin/perl;/bin/perl;g" "${_intltoolize_dir}/bin/intltool-merge"
			COMMAND "${SED_PROGRAM}" "-i" "s;/opt/perl/bin/perl;/bin/perl;g" "${_intltoolize_dir}/bin/intltool-prepare"
			COMMAND "${SED_PROGRAM}" "-i" "s;/opt/perl/bin/perl;/bin/perl;g" "${_intltoolize_dir}/bin/intltool-update"
		)
		file(RENAME "${_intltoolize_dir}/bin/intltoolize" "C:/MinGW/msys/1.0/bin/intltoolize")
		file(RENAME "${_intltoolize_dir}/bin/intltool-extract" "C:/MinGW/bin/intltool-extract")
		file(RENAME "${_intltoolize_dir}/bin/intltool-merge" "C:/MinGW/bin/intltool-merge")
		file(RENAME "${_intltoolize_dir}/bin/intltool-prepare" "C:/MinGW/bin/intltool-prepare")
		file(RENAME "${_intltoolize_dir}/bin/intltool-update" "C:/MinGW/bin/intltool-update")
		file(RENAME "${_intltoolize_dir}/share/aclocal/intltool.m4" "C:/MinGW/share/aclocal/intltool.m4")
		file(MAKE_DIRECTORY "C:/MinGW/msys/1.0/share/intltool")
		file(RENAME "${_intltoolize_dir}/share/intltool/Makefile.in.in" "C:/MinGW/msys/1.0/share/intltool/Makefile.in.in")
		unset(_intltoolize_dir)
	endif()

	find_program(INTLTOOLIZE_PROGRAM
		NAMES intltoolize
202
		HINTS "C:/MinGW/msys/1.0/bin"
203
	)
204
endif()
205

206
if(NOT INTLTOOLIZE_PROGRAM AND NOT MSVC)
207 208
	message(FATAL_ERROR "Could not find the intltoolize program.")
endif()
209

210 211 212 213 214 215 216
if(MSVC)
	# Install headers needed by MSVC
	file(GLOB MSVC_HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/MSVC/*.h")
	file(MAKE_DIRECTORY "${CMAKE_INSTALL_PREFIX}/include/MSVC")
	file(INSTALL ${MSVC_HEADER_FILES} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/MSVC")
endif()

217
set(LINPHONE_BUILDER_EP_VARS)
218
set(LINPHONE_BUILDER_INCLUDED_BUILDERS)
219 220

macro(linphone_builder_expand_external_project_vars)
Ghislain MARY's avatar
Ghislain MARY committed
221 222 223 224 225 226 227 228 229 230
	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()
231
endmacro()
232 233 234 235

list(APPEND LINPHONE_BUILDER_EP_VARS
	CMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH
	CMAKE_BUILD_TYPE:STRING
236
	CMAKE_BUILD_WITH_INSTALL_RPATH:BOOL
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
	CMAKE_BUNDLE_OUTPUT_DIRECTORY:PATH
	CMAKE_C_FLAGS_DEBUG:STRING
	CMAKE_C_FLAGS_MINSIZEREL:STRING
	CMAKE_C_FLAGS_RELEASE:STRING
	CMAKE_C_FLAGS_RELWITHDEBINFO:STRING
	CMAKE_C_FLAGS:STRING
	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
254
	CMAKE_GENERATOR_PLATFORM:STRING
255
	CMAKE_INSTALL_PREFIX:PATH
256 257
	CMAKE_INSTALL_RPATH:PATH
	CMAKE_INSTALL_RPATH_USE_LINK_PATH:BOOL
258 259 260 261 262 263 264
	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
265
	CMAKE_NO_BUILD_TYPE:BOOL
266
	CMAKE_PREFIX_PATH:STRING
267 268 269 270 271 272 273
	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
274
	CMAKE_SKIP_BUILD_RPATH:BOOL
275
	CMAKE_VERBOSE_MAKEFILE:BOOL
276 277 278
	MSVC_C_ARCHITECTURE_ID:STRING
	MSVC_CXX_ARCHITECTURE_ID:STRING
	MSVC_VERSION:STRING
279
)
280
if(CMAKE_CROSSCOMPILING)
Ghislain MARY's avatar
Ghislain MARY committed
281
	list(APPEND LINPHONE_BUILDER_EP_VARS
282 283 284 285
		CMAKE_SYSTEM_NAME:STRING
		CMAKE_SYSTEM_VERSION:STRING
	)
endif()
286 287
if(APPLE)
	list(APPEND LINPHONE_BUILDER_EP_VARS
288
		CMAKE_MACOSX_RPATH:BOOL
289 290 291
		CMAKE_OSX_ARCHITECTURES:STRING
		CMAKE_OSX_DEPLOYMENT_TARGET:STRING
	)
292
endif()
293 294 295
if(CMAKE_TOOLCHAIN_FILE)
	list(APPEND LINPHONE_BUILDER_EP_VARS CMAKE_TOOLCHAIN_FILE:PATH)
endif()
296 297


298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
function(linphone_builder_get_autotools_configuration)
	if(MSVC)
		set(_generator "MinGW Makefiles")
	else()
		set(_generator "${CMAKE_GENERATOR}")
		if(CMAKE_EXTRA_GENERATOR)
			set(_extra_generator "${CMAKE_EXTRA_GENERATOR}")
		endif()
	endif()
	set(_autotools_command ${CMAKE_COMMAND} -G "${_generator}")
	if(_extra_generator)
		list(APPEND _autotools_command -T "${_extra_generator}")
	endif()
	if(CMAKE_TOOLCHAIN_FILE)
		list(APPEND _autotools_command "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
	endif()
	list(APPEND _autotools_command "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Autotools/")
315 316
	execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/Autotools)
	execute_process(COMMAND ${_autotools_command} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Autotools)
317 318 319
	unset(_autotools_command)
	unset(_extra_generator)
	unset(_generator)
320
	include(${CMAKE_BINARY_DIR}/Autotools/Autotools.cmake)
Ghislain MARY's avatar
Ghislain MARY committed
321
endfunction()
322 323


324 325 326 327 328 329 330 331 332 333 334 335
macro(linphone_builder_create_targets_list)
	set(LINPHONE_BUILDER_TARGETS )
	if("${LINPHONE_BUILDER_TARGET}" STREQUAL "belle-sip")
		list(APPEND LINPHONE_BUILDER_TARGETS "belle-sip")
	elseif("${LINPHONE_BUILDER_TARGET}" STREQUAL "ortp")
		list(APPEND LINPHONE_BUILDER_TARGETS "ortp")
	elseif("${LINPHONE_BUILDER_TARGET}" STREQUAL "ms2")
		list(APPEND LINPHONE_BUILDER_TARGETS "ortp" "ms2")
	elseif("${LINPHONE_BUILDER_TARGET}" STREQUAL "ms2-plugins")
		list(APPEND LINPHONE_BUILDER_TARGETS "ortp" "ms2" "ms2-plugins")
	elseif("${LINPHONE_BUILDER_TARGET}" STREQUAL "linphone")
		list(APPEND LINPHONE_BUILDER_TARGETS "belle-sip" "ortp" "ms2" "ms2-plugins" "linphone")
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
336 337
	elseif("${LINPHONE_BUILDER_TARGET}" STREQUAL "flexisip")
		list(APPEND LINPHONE_BUILDER_TARGETS "ortp" "flexisip")
338 339
	elseif("${LINPHONE_BUILDER_TARGET}" STREQUAL "odb")
		list(APPEND LINPHONE_BUILDER_TARGETS "odb" )
340 341 342
	else()
		message(FATAL_ERROR "Invalid LINPHONE_BUILDER_TARGET '${LINPHONE_BUILDER_TARGET}'")
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
343
endmacro()
344 345 346 347 348 349 350 351 352 353


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
354
endmacro()
355 356 357 358


macro(linphone_builder_add_builder_to_target TARGETNAME BUILDER)
	linphone_builder_include_builder(${BUILDER})
Ghislain MARY's avatar
Ghislain MARY committed
359
	add_dependencies(${TARGETNAME} EP_${BUILDER})
Ghislain MARY's avatar
Ghislain MARY committed
360
endmacro()
361 362


363
macro(linphone_builder_apply_flags)
364
	foreach(BUILD_CONFIG "" "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
365 366 367
		if(NOT "${LINPHONE_BUILDER_CPPFLAGS}" STREQUAL "")
			set(CMAKE_C_FLAGS${BUILD_CONFIG} "${CMAKE_C_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CPPFLAGS}")
			set(CMAKE_CXX_FLAGS${BUILD_CONFIG} "${CMAKE_CXX_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CPPFLAGS}")
368 369
			set(AUTOTOOLS_C_FLAGS${BUILD_CONFIG} "${AUTOTOOLS_C_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CPPFLAGS}")
			set(AUTOTOOLS_CXX_FLAGS${BUILD_CONFIG} "${AUTOTOOLS_CXX_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CPPFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
370
		endif()
371 372
		if(NOT "${LINPHONE_BUILDER_CFLAGS}" STREQUAL "")
			set(CMAKE_C_FLAGS${BUILD_CONFIG} "${CMAKE_C_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CFLAGS}")
373
			set(AUTOTOOLS_C_FLAGS${BUILD_CONFIG} "${AUTOTOOLS_C_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
374
		endif()
375 376
		if(NOT "${LINPHONE_BUILDER_CXXFLAGS}" STREQUAL "")
			set(CMAKE_CXX_FLAGS${BUILD_CONFIG} "${CMAKE_CXX_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CXXFLAGS}")
377
			set(AUTOTOOLS_CXX_FLAGS${BUILD_CONFIG} "{AUTOTOOLS_CXX_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CXX_FLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
378
		endif()
Ghislain MARY's avatar
Ghislain MARY committed
379 380 381
		if(NOT "${LINPHONE_BUILDER_OBJCFLAGS}" STREQUAL "")
			set(CMAKE_C_FLAGS${BUILD_CONFIG} "${CMAKE_C_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_OBJCFLAGS}")
			set(AUTOTOOLS_OBJC_FLAGS${BUILD_CONFIG} "${AUTOTOOLS_OBJC_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_OBJCFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
382
		endif()
383
		if(NOT "${LINPHONE_BUILDER_LDFLAGS}" STREQUAL "")
384
			# TODO: The two following lines should not be here
385 386
			set(CMAKE_C_FLAGS${BUILD_CONFIG} "${CMAKE_C_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_LDFLAGS}")
			set(CMAKE_CXX_FLAGS${BUILD_CONFIG} "${CMAKE_CXX_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_LDFLAGS}")
387

388 389 390
			set(CMAKE_EXE_LINKER_FLAGS${BUILD_CONFIG} "${CMAKE_EXE_LINKER_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_LDFLAGS}")
			set(CMAKE_MODULE_LINKER_FLAGS${BUILD_CONFIG} "${CMAKE_MODULE_LINKER_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_LDFLAGS}")
			set(CMAKE_SHARED_LINKER_FLAGS${BUILD_CONFIG} "${CMAKE_SHARED_LINKER_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_LDFLAGS}")
391
			set(AUTOTOOLS_LINKER_FLAGS${BUILD_CONFIG} "${AUTOTOOLS_LINKER_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_LDFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
392 393 394
		endif()
	endforeach()
endmacro()
395 396


397
macro(linphone_builder_apply_cmake_flags_to_autotools_project PROJNAME)
398
	if("${EP_${PROJNAME}_BUILD_METHOD}" STREQUAL "autotools")
399 400 401 402 403 404
		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}")
Ghislain MARY's avatar
Ghislain MARY committed
405
		endif()
406 407 408 409 410
		set(ep_asflags "${AUTOTOOLS_AS_FLAGS${BUILD_TYPE_SUFFIX}}")
		set(ep_cppflags "${AUTOTOOLS_CPP_FLAGS${BUILD_TYPE_SUFFIX}}")
		set(ep_cflags "${AUTOTOOLS_C_FLAGS${BUILD_TYPE_SUFFIX}}")
		set(ep_cxxflags "${AUTOTOOLS_CXX_FLAGS${BUILD_TYPE_SUFFIX}}")
		set(ep_objcflags "${AUTOTOOLS_OBJC_FLAGS${BUILD_TYPE_SUFFIX}}")
Ghislain MARY's avatar
Ghislain MARY committed
411
		set(ep_ldflags "${AUTOTOOLS_LINKER_FLAGS${BUILD_TYPE_SUFFIX}}")
412
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
413
endmacro()
414 415


416
macro(linphone_builder_apply_extra_flags PROJNAME)
417
	if("${EP_${PROJNAME}_BUILD_METHOD}" STREQUAL "autotools")
418 419 420 421 422 423
		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}")
424
	else()
425 426 427
		foreach(BUILD_CONFIG "" "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
			if(NOT "${EP_${PROJNAME}_EXTRA_CFLAGS}" STREQUAL "")
				set(CMAKE_C_FLAGS${BUILD_CONFIG} "${CMAKE_C_FLAGS${BUILD_CONFIG}} ${EP_${PROJNAME}_EXTRA_CFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
428
			endif()
429 430
			if(NOT "${EP_${PROJNAME}_EXTRA_CXXFLAGS}" STREQUAL "")
				set(CMAKE_CXX_FLAGS${BUILD_CONFIG} "${CMAKE_CXX_FLAGS${BUILD_CONFIG}} ${EP_${PROJNAME}_EXTRA_CXXFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
431
			endif()
432 433 434 435 436
			if(NOT "${EP_${PROJNAME}_EXTRA_LDFLAGS}" STREQUAL "")
				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}")
			endif(NOT "${EP_${PROJNAME}_EXTRA_LDFLAGS}" STREQUAL "")
Ghislain MARY's avatar
Ghislain MARY committed
437
		endforeach()
438
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
439
endmacro()
440 441


442
macro(linphone_builder_set_ep_directories PROJNAME)
443 444
	get_filename_component(CONFIG_NAME ${LINPHONE_BUILDER_CONFIG_FILE} NAME_WE)
	string(REGEX REPLACE "config-" "" CONFIG_NAME ${CONFIG_NAME})
445
	set(ep_source "${ep_base}/Source/EP_${PROJNAME}")
446
	set(ep_tmp "${ep_base}/tmp-${CONFIG_NAME}/${PROJNAME}")
447 448
	if("${EP_${PROJNAME}_BUILD_IN_SOURCE}" STREQUAL "yes")
		set(ep_build "${ep_source}")
Ghislain MARY's avatar
Ghislain MARY committed
449
	else()
450
		set(ep_build "${ep_base}/Build-${CONFIG_NAME}/${PROJNAME}")
Ghislain MARY's avatar
Ghislain MARY committed
451
	endif()
452
	unset(CONFIG_NAME)
Ghislain MARY's avatar
Ghislain MARY committed
453
endmacro()
454

455 456 457 458 459 460 461

macro(linphone_builder_create_autogen_command PROJNAME)
	if("${EP_${PROJNAME}_USE_AUTOGEN}" STREQUAL "yes")
		if("${EP_${PROJNAME}_CONFIGURE_OPTIONS_PASSED_TO_AUTOGEN}" STREQUAL "yes")
			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
462
			endforeach()
463
		endif()
464
		set(ep_autogen_command "${ep_source}/autogen.sh ${ep_autogen_options}")
465
	else()
466
		set(ep_autogen_command "")
467
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
468
endmacro()
469 470 471 472 473


macro(linphone_builder_create_configure_command PROJNAME)
	if("${EP_${PROJNAME}_CONFIGURE_OPTIONS_PASSED_TO_AUTOGEN}" STREQUAL "yes")
		set(ep_configure_command "")
474
	else()
475 476 477
		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
478
		endforeach()
479
		set(ep_configure_env "${EP_${PROJNAME}_CONFIGURE_ENV}")
480
		set(ep_configure_command "${ep_source}/configure ${ep_configure_options}")
481
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
482
endmacro()
483 484


485 486 487 488 489 490 491 492 493 494 495 496
# this function invokes configure_file() for the project, using the default file if 
# the specific file is not defined
function(linphone_builder_configure_file_for_project PROJNAME CMD DEFAULT_CONF_FILE OUTPUT)
	if("${EP_${PROJNAME}_${CMD}_COMMAND_SOURCE}" STREQUAL "")
		MESSAGE(STATUS "Using default file ${DEFAULT_CONF_FILE} for ${CMD} step of ${PROJNAME}")
		configure_file(${DEFAULT_CONF_FILE} ${OUTPUT})
	else()
		MESSAGE(STATUS "Using specific file ${EP_${PROJNAME}_${CMD}_COMMAND_SOURCE} for ${CMD} step of ${PROJNAME}")
		configure_file(${EP_${PROJNAME}_${CMD}_COMMAND_SOURCE} ${OUTPUT})	  
	endif()
endfunction()

497
function(linphone_builder_add_project PROJNAME)
498
	linphone_builder_set_ep_directories(${PROJNAME})
499
	linphone_builder_apply_cmake_flags_to_autotools_project(${PROJNAME})
500
	linphone_builder_apply_extra_flags(${PROJNAME})
501 502
	linphone_builder_expand_external_project_vars()

503 504 505 506 507 508 509 510
	if("${EP_${PROJNAME}_BUILD_METHOD}" STREQUAL "prebuilt")
		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
		)
	elseif("${EP_${PROJNAME}_BUILD_METHOD}" STREQUAL "custom")
511
		set(ep_redirect_to_file "2>&1 >> ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}.log")
512 513 514 515 516 517 518 519 520 521 522 523
		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()
524
		set(BUILD_COMMANDS
525 526 527
			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}
528 529
		)
	elseif("${EP_${PROJNAME}_BUILD_METHOD}" STREQUAL "autotools")
530 531 532 533
		linphone_builder_create_autogen_command(${PROJNAME})
		linphone_builder_create_configure_command(${PROJNAME})
		if("${EP_${PROJNAME}_CONFIG_H_FILE}" STREQUAL "")
			set(ep_config_h_file config.h)
Ghislain MARY's avatar
Ghislain MARY committed
534
		else()
535
			set(ep_config_h_file ${EP_${PROJNAME}_CONFIG_H_FILE})
Ghislain MARY's avatar
Ghislain MARY committed
536
		endif()
537 538
		if("${EP_${PROJNAME}_INSTALL_TARGET}" STREQUAL "")
			set(ep_install_target "install")
Ghislain MARY's avatar
Ghislain MARY committed
539
		else()
540
			set(ep_install_target "${EP_${PROJNAME}_INSTALL_TARGET}")
Ghislain MARY's avatar
Ghislain MARY committed
541
		endif()
542

543
		set(ep_redirect_to_file "2>&1 >> ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}.log")
544
		if(WIN32)
545 546 547 548 549 550 551
			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
			set(ep_build ${ep_source})
552 553 554 555 556 557
			if(NOT "${ep_autogen_command}" STREQUAL "")
				set(ep_autogen_redirect_to_file ${ep_redirect_to_file})
			endif()
			if(NOT "${ep_configure_command}" STREQUAL "")
				set(ep_configure_redirect_to_file ${ep_redirect_to_file})
			endif()
558
		else()
559
			set(SCRIPT_EXTENSION sh)
560
		endif()
561

562
		if("${EP_${PROJNAME}_PKG_CONFIG}" STREQUAL "")
563
			set(LINPHONE_BUILDER_PKG_CONFIG "${PKG_CONFIG_PROGRAM}")
Ghislain MARY's avatar
Ghislain MARY committed
564
		else()
565
			set(LINPHONE_BUILDER_PKG_CONFIG "${EP_${PROJNAME}_PKG_CONFIG}")
Ghislain MARY's avatar
Ghislain MARY committed
566
		endif()
567

568 569 570
		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
571 572

		set(BUILD_COMMANDS
573 574 575
			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
576
		)
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
	elseif("${EP_${PROJNAME}_BUILD_METHOD}" STREQUAL "rpm")
		
		if(WIN32)
			message( SEND_ERROR "rpm build not supported on WIN32")
		endif()

		linphone_builder_create_autogen_command(${PROJNAME})
		linphone_builder_create_configure_command(${PROJNAME})
		
		if("${EP_${PROJNAME}_CONFIG_H_FILE}" STREQUAL "")
			set(ep_config_h_file config.h)
		else()
			set(ep_config_h_file ${EP_${PROJNAME}_CONFIG_H_FILE})
		endif()
		
		if("${EP_${PROJNAME}_INSTALL_TARGET}" STREQUAL "")
			set(ep_install_target "install")
		else()
			set(ep_install_target "${EP_${PROJNAME}_INSTALL_TARGET}")
		endif()

		if("${EP_${PROJNAME}_SPEC_FILE}" STREQUAL "")
			message( SEND_ERROR "rpm build requires EP_${PROJNAME}_SPEC_FILE to be defined")
		else()
			set(LINPHONE_BUILDER_SPEC_FILE "${EP_${PROJNAME}_SPEC_FILE}")
		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
		if("${EP_${PROJNAME}_RPMBUILD_NAME}" STREQUAL "")
			set(LINPHONE_BUILDER_RPMBUILD_NAME "${PROJNAME}")
		else()
			set(LINPHONE_BUILDER_RPMBUILD_NAME "${EP_${PROJNAME}_RPMBUILD_NAME}")
		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
		if(NOT "${EP_${PROJNAME}_RPMBUILD_OPTIONS}" STREQUAL "")
			set(LINPHONE_BUILDER_RPMBUILD_OPTIONS "${EP_${PROJNAME}_RPMBUILD_OPTIONS}")
		endif()

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

		if("${EP_${PROJNAME}_PKG_CONFIG}" STREQUAL "")
			set(LINPHONE_BUILDER_PKG_CONFIG "${PKG_CONFIG_PROGRAM}")
		else()
			set(LINPHONE_BUILDER_PKG_CONFIG "${EP_${PROJNAME}_PKG_CONFIG}")
		endif()

		if(NOT "${EP_${PROJNAME}_CONFIGURE_EXTRA_CMD}" STREQUAL "")
			set(LINPHONE_BUILDER_CONFIGURE_EXTRA_CMD "${EP_${PROJNAME}_CONFIGURE_EXTRA_CMD}")
		endif()

630 631 632 633
		# 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)
634 635 636 637 638 639

		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
		)
640 641
	else()
		# Use CMake build method
642 643 644 645
		set(BUILD_COMMANDS
			CMAKE_ARGS ${EP_${PROJNAME}_CMAKE_OPTIONS} ${EP_${PROJNAME}_LINKING_TYPE}
			CMAKE_CACHE_ARGS ${LINPHONE_BUILDER_EP_ARGS}
		)
646
	endif()
647

648 649 650
	if(LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH)
		foreach(SUBDIR ${EP_${PROJNAME}_EXTERNAL_SOURCE_PATHS})
			if(NOT EP_${PROJNAME}_SOURCE_DIR)
Ghislain MARY's avatar
Ghislain MARY committed
651
				if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH}/${SUBDIR}/CMakeLists.txt")
652
					set(EP_${PROJNAME}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH}/${SUBDIR}")
653 654
				endif()
			endif()
655 656 657 658
		endforeach()
	endif()

	if(LINPHONE_BUILDER_LATEST AND EP_${PROJNAME}_GIT_TAG_LATEST)
659
		set(DOWNLOAD_SOURCE GIT_REPOSITORY ${EP_${PROJNAME}_GIT_REPOSITORY} GIT_TAG ${EP_${PROJNAME}_GIT_TAG_LATEST})
660 661 662 663 664 665 666
	elseif(EP_${PROJNAME}_SOURCE_DIR)
		set(DOWNLOAD_SOURCE SOURCE_DIR ${EP_${PROJNAME}_SOURCE_DIR})
	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()
667
	else()
668
		set(DOWNLOAD_SOURCE GIT_REPOSITORY ${EP_${PROJNAME}_GIT_REPOSITORY} GIT_TAG ${EP_${PROJNAME}_GIT_TAG})
669
	endif()
670

671 672 673 674
	ExternalProject_Add(EP_${PROJNAME}
		DEPENDS ${EP_${PROJNAME}_DEPENDENCIES}
		TMP_DIR ${ep_tmp}
		BINARY_DIR ${ep_build}
675
		${DOWNLOAD_SOURCE}
676 677
		PATCH_COMMAND ${EP_${PROJNAME}_PATCH_COMMAND}
		CMAKE_GENERATOR ${CMAKE_GENERATOR}
Ghislain MARY's avatar
Ghislain MARY committed
678
		${BUILD_COMMANDS}
679
	)
680

681 682 683 684 685 686 687
	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
			COMMENT "Performing post-installation step"
			DEPENDEES mkdir update patch download configure build install
			WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
		)
688
	endif()
689 690 691 692 693 694 695 696 697
	if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/builders/${PROJNAME}/postconfig.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
			COMMENT "Performing post-installation step"
			DEPENDEES mkdir update patch download configure build install
			WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
		)
	endif()

Ghislain MARY's avatar
Ghislain MARY committed
698
endfunction()
Ghislain MARY's avatar
Ghislain MARY committed
699

700
function(linphone_builder_add_external_projects)
701
	foreach(BUILDER ${LINPHONE_BUILDER_INCLUDED_BUILDERS})
Ghislain MARY's avatar
Ghislain MARY committed
702
		linphone_builder_add_project(${BUILDER})
Ghislain MARY's avatar
Ghislain MARY committed
703 704
	endforeach()
endfunction()