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
	find_file(GCC_LIBRARY
61 62 63
		NAMES libgcc.a
		HINTS "C:/MinGW/lib/gcc/mingw32/*"
	)
64 65 66 67 68 69
	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")
70 71
endif()

72
if(WIN32)
73
	message(STATUS "Installing windows tools")
74 75 76 77 78 79 80
	set(_windows_tools_dir ${CMAKE_CURRENT_BINARY_DIR}/windows_tools)
	file(MAKE_DIRECTORY ${_windows_tools_dir})
	file(DOWNLOAD https://www.linphone.org/files/linphone_builder_windows_tools.zip "${CMAKE_CURRENT_BINARY_DIR}/linphone_builder_windows_tools.zip")
	execute_process(
		COMMAND "${CMAKE_COMMAND}" "-E" "tar" "x" "${CMAKE_CURRENT_BINARY_DIR}/linphone_builder_windows_tools.zip"
		WORKING_DIRECTORY ${_windows_tools_dir}
	)
81 82 83 84 85
	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")
86
	if(CMAKE_SIZEOF_VOID_P EQUAL 8)
87
		file(RENAME "${_windows_tools_dir}/yasm-1.3.0-win64.exe" "C:/MinGW/bin/yasm.exe")
88
	else()
89
		file(RENAME "${_windows_tools_dir}/yasm-1.3.0-win32.exe" "C:/MinGW/bin/yasm.exe")
90 91 92 93
	endif()
	unset(_pkg_config_dir)
endif()

94 95
find_program(PATCH_PROGRAM
	NAMES patch patch.exe
96
	HINTS "${LINPHONE_BUILDER_WORK_DIR}/windows_tools"
97 98 99 100 101 102 103 104 105 106 107
)
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
108
	HINTS "${LINPHONE_BUILDER_WORK_DIR}/windows_tools"
109 110 111 112 113 114 115 116
)
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()
117

118 119 120 121 122 123
find_program(PKG_CONFIG_PROGRAM
	NAMES pkg-config pkg-config.exe
	HINTS "C:/MinGW/bin"
)

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

161
if(NOT PKG_CONFIG_PROGRAM AND NOT MSVC)
162 163 164
	message(FATAL_ERROR "Could not find the pkg-config program.")
endif()

165 166
find_program(INTLTOOLIZE_PROGRAM
	NAMES intltoolize
167
	HINTS "C:/MinGW/msys/1.0/bin"
Ghislain MARY's avatar
Ghislain MARY committed
168
)
169

170 171
if(NOT INTLTOOLIZE_PROGRAM)
	if(WIN32)
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
		message(STATUS "Installing intltoolize to C:/MinGW/bin")
		set(_intltoolize_dir ${CMAKE_CURRENT_BINARY_DIR}/intltoolize)
		file(MAKE_DIRECTORY ${_intltoolize_dir})
		file(DOWNLOAD http://ftp.gnome.org/pub/gnome/binaries/win32/intltool/0.40/intltool_0.40.4-1_win32.zip "${CMAKE_CURRENT_BINARY_DIR}/intltoolize.zip")
		execute_process(
			COMMAND "${CMAKE_COMMAND}" "-E" "tar" "x" "${CMAKE_CURRENT_BINARY_DIR}/intltoolize.zip"
			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
199
		HINTS "C:/MinGW/msys/1.0/bin"
200
	)
201
endif()
202

203
if(NOT INTLTOOLIZE_PROGRAM AND NOT MSVC)
204 205
	message(FATAL_ERROR "Could not find the intltoolize program.")
endif()
206

207 208 209 210 211 212 213
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()

214
set(LINPHONE_BUILDER_EP_VARS)
215
set(LINPHONE_BUILDER_INCLUDED_BUILDERS)
216 217

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

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


295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
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/")
	execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/Autotools)
	execute_process(COMMAND ${_autotools_command} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Autotools)
	unset(_autotools_command)
	unset(_extra_generator)
	unset(_generator)
	include(${CMAKE_CURRENT_BINARY_DIR}/Autotools/Autotools.cmake)
Ghislain MARY's avatar
Ghislain MARY committed
318
endfunction()
319 320


321 322 323 324 325 326 327 328 329 330 331 332
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
333 334
	elseif("${LINPHONE_BUILDER_TARGET}" STREQUAL "flexisip")
		list(APPEND LINPHONE_BUILDER_TARGETS "ortp" "flexisip")
335 336
	elseif("${LINPHONE_BUILDER_TARGET}" STREQUAL "odb")
		list(APPEND LINPHONE_BUILDER_TARGETS "odb" )
337 338 339
	else()
		message(FATAL_ERROR "Invalid LINPHONE_BUILDER_TARGET '${LINPHONE_BUILDER_TARGET}'")
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
340
endmacro()
341 342 343 344 345 346 347 348 349 350


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
351
endmacro()
352 353 354 355


macro(linphone_builder_add_builder_to_target TARGETNAME BUILDER)
	linphone_builder_include_builder(${BUILDER})
Ghislain MARY's avatar
Ghislain MARY committed
356
	add_dependencies(${TARGETNAME} EP_${BUILDER})
Ghislain MARY's avatar
Ghislain MARY committed
357
endmacro()
358 359


360
macro(linphone_builder_apply_flags)
361
	foreach(BUILD_CONFIG "" "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
362 363 364
		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}")
365 366
			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
367
		endif()
368 369
		if(NOT "${LINPHONE_BUILDER_CFLAGS}" STREQUAL "")
			set(CMAKE_C_FLAGS${BUILD_CONFIG} "${CMAKE_C_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CFLAGS}")
370
			set(AUTOTOOLS_C_FLAGS${BUILD_CONFIG} "${AUTOTOOLS_C_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
371
		endif()
372 373
		if(NOT "${LINPHONE_BUILDER_CXXFLAGS}" STREQUAL "")
			set(CMAKE_CXX_FLAGS${BUILD_CONFIG} "${CMAKE_CXX_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CXXFLAGS}")
374
			set(AUTOTOOLS_CXX_FLAGS${BUILD_CONFIG} "{AUTOTOOLS_CXX_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CXX_FLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
375
		endif()
Ghislain MARY's avatar
Ghislain MARY committed
376 377 378
		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
379
		endif()
380
		if(NOT "${LINPHONE_BUILDER_LDFLAGS}" STREQUAL "")
381
			# TODO: The two following lines should not be here
382 383
			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}")
384

385 386 387
			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}")
388
			set(AUTOTOOLS_LINKER_FLAGS${BUILD_CONFIG} "${AUTOTOOLS_LINKER_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_LDFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
389 390 391
		endif()
	endforeach()
endmacro()
392 393


394
macro(linphone_builder_apply_cmake_flags_to_autotools_project PROJNAME)
395
	if("${EP_${PROJNAME}_BUILD_METHOD}" STREQUAL "autotools")
396 397 398 399 400 401
		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
402
		endif()
403 404 405 406 407
		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
408
		set(ep_ldflags "${AUTOTOOLS_LINKER_FLAGS${BUILD_TYPE_SUFFIX}}")
409
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
410
endmacro()
411 412


413
macro(linphone_builder_apply_extra_flags PROJNAME)
414
	if("${EP_${PROJNAME}_BUILD_METHOD}" STREQUAL "autotools")
415 416 417 418 419 420
		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}")
421
	else()
422 423 424
		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
425
			endif()
426 427
			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
428
			endif()
429 430 431 432 433
			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
434
		endforeach()
435
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
436
endmacro()
437 438


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

452 453 454 455 456 457 458

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
459
			endforeach()
460
		endif()
461
		set(ep_autogen_command "${ep_source}/autogen.sh ${ep_autogen_options}")
462
	else()
463
		set(ep_autogen_command "")
464
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
465
endmacro()
466 467 468 469 470


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


482 483 484 485 486 487 488 489 490 491 492 493
# 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()

494
function(linphone_builder_add_project PROJNAME)
495
	linphone_builder_set_ep_directories(${PROJNAME})
496
	linphone_builder_apply_cmake_flags_to_autotools_project(${PROJNAME})
497
	linphone_builder_apply_extra_flags(${PROJNAME})
498 499
	linphone_builder_expand_external_project_vars()

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

540
		set(ep_redirect_to_file "2>&1 >> ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}.log")
541
		if(WIN32)
542 543 544 545 546 547 548
			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})
549 550 551 552 553 554
			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()
555
		else()
556
			set(SCRIPT_EXTENSION sh)
557
		endif()
558

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

565 566 567
		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
568 569

		set(BUILD_COMMANDS
570 571 572
			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
573
		)
574 575 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
	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()

627 628 629 630
		# 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)
631 632 633 634 635 636

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

645 646 647
	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
648
				if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH}/${SUBDIR}/CMakeLists.txt")
649
					set(EP_${PROJNAME}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH}/${SUBDIR}")
650 651
				endif()
			endif()
652 653 654 655
		endforeach()
	endif()

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

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

678 679 680 681 682 683 684
	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}
		)
685
	endif()
686 687 688 689 690 691 692 693 694
	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
695
endfunction()
Ghislain MARY's avatar
Ghislain MARY committed
696

697
function(linphone_builder_add_external_projects)
698
	foreach(BUILDER ${LINPHONE_BUILDER_INCLUDED_BUILDERS})
Ghislain MARY's avatar
Ghislain MARY committed
699
		linphone_builder_add_project(${BUILDER})
Ghislain MARY's avatar
Ghislain MARY committed
700 701
	endforeach()
endfunction()