LinphoneCMakeBuilder.cmake 18.3 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 32 33 34 35
if(${CMAKE_VERBOSE_MAKEFILE})
	set(AUTOTOOLS_VERBOSE_MAKEFILE 1)
else(${CMAKE_VERBOSE_MAKEFILE})
	set(AUTOTOOLS_VERBOSE_MAKEFILE 0)
endif(${CMAKE_VERBOSE_MAKEFILE})


36 37 38 39 40
find_package(PythonInterp)
if(NOT PYTHONINTERP_FOUND)
	message(FATAL_ERROR "Could not find python!")
endif(NOT PYTHONINTERP_FOUND)

41 42 43 44 45 46 47 48 49 50
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)
endif(MSVC)

Ghislain MARY's avatar
Ghislain MARY committed
51 52 53 54 55 56 57 58 59 60
find_program(PATCH_PROGRAM
	NAMES patch patch.exe
)
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(WIN32)
		message(FATAL_ERROR "Could not find the patch program.")
	endif(WIN32)
endif(NOT PATCH_PROGRAM)
61

62
set(LINPHONE_BUILDER_EP_VARS)
63
set(LINPHONE_BUILDER_INCLUDED_BUILDERS)
64 65

macro(linphone_builder_expand_external_project_vars)
Ghislain MARY's avatar
Ghislain MARY committed
66 67 68 69 70 71 72 73 74 75
	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()
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
endmacro(linphone_builder_expand_external_project_vars)

list(APPEND LINPHONE_BUILDER_EP_VARS
	CMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH
	CMAKE_BUILD_TYPE:STRING
	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
	CMAKE_INSTALL_PREFIX:PATH
	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
106
	CMAKE_NO_BUILD_TYPE:BOOL
107
	CMAKE_PREFIX_PATH:STRING
108 109 110 111 112 113 114 115
	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
	CMAKE_VERBOSE_MAKEFILE:BOOL
116 117 118
	MSVC_C_ARCHITECTURE_ID:STRING
	MSVC_CXX_ARCHITECTURE_ID:STRING
	MSVC_VERSION:STRING
119 120 121 122 123 124 125
)
if(APPLE)
	list(APPEND LINPHONE_BUILDER_EP_VARS
		CMAKE_OSX_ARCHITECTURES:STRING
		CMAKE_OSX_DEPLOYMENT_TARGET:STRING
	)
endif(APPLE)
126 127 128
if(CMAKE_TOOLCHAIN_FILE)
	list(APPEND LINPHONE_BUILDER_EP_VARS CMAKE_TOOLCHAIN_FILE:PATH)
endif()
129 130


131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
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)
endfunction(linphone_builder_get_autotools_configuration)


157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
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")
	else()
		message(FATAL_ERROR "Invalid LINPHONE_BUILDER_TARGET '${LINPHONE_BUILDER_TARGET}'")
	endif()
endmacro(linphone_builder_create_targets_list)


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)
endmacro(linphone_builder_include_builder)


macro(linphone_builder_add_builder_to_target TARGETNAME BUILDER)
	linphone_builder_include_builder(${BUILDER})
	add_dependencies(${TARGETNAME} ${BUILDER})
endmacro(linphone_builder_add_builder_to_target)


192
macro(linphone_builder_apply_flags)
193
	foreach(BUILD_CONFIG "" "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
194 195 196
		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}")
197 198
			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}")
199 200 201
		endif(NOT "${LINPHONE_BUILDER_CPPFLAGS}" STREQUAL "")
		if(NOT "${LINPHONE_BUILDER_CFLAGS}" STREQUAL "")
			set(CMAKE_C_FLAGS${BUILD_CONFIG} "${CMAKE_C_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CFLAGS}")
202
			set(AUTOTOOLS_C_FLAGS${BUILD_CONFIG} "${AUTOTOOLS_C_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CFLAGS}")
203 204 205
		endif(NOT "${LINPHONE_BUILDER_CFLAGS}" STREQUAL "")
		if(NOT "${LINPHONE_BUILDER_CXXFLAGS}" STREQUAL "")
			set(CMAKE_CXX_FLAGS${BUILD_CONFIG} "${CMAKE_CXX_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CXXFLAGS}")
206
			set(AUTOTOOLS_CXX_FLAGS${BUILD_CONFIG} "{AUTOTOOLS_CXX_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_CXX_FLAGS}")
207 208
		endif(NOT "${LINPHONE_BUILDER_CXXFLAGS}" STREQUAL "")
		if(NOT "${LINPHONE_BUILDER_LDFLAGS}" STREQUAL "")
209
			# TODO: The two following lines should not be here
210 211
			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}")
212

213 214 215
			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}")
216
			set(AUTOTOOLS_LINKER_FLAGS${BUILD_CONFIG} "${AUTOTOOLS_LINKER_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_LDFLAGS}")
217
		endif(NOT "${LINPHONE_BUILDER_LDFLAGS}" STREQUAL "")
218
	endforeach(BUILD_CONFIG)
219
endmacro(linphone_builder_apply_flags)
220 221


222
macro(linphone_builder_apply_cmake_flags_to_autotools_project PROJNAME)
223
	if("${EP_${PROJNAME}_BUILD_METHOD}" STREQUAL "autotools")
224 225 226 227 228 229 230 231 232 233 234 235
		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(NOT ${BUILD_TYPE_FOUND} EQUAL -1)
		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
236
		set(ep_ldflags "${AUTOTOOLS_LINKER_FLAGS${BUILD_TYPE_SUFFIX}}")
237
	endif()
238 239 240
endmacro(linphone_builder_apply_cmake_flags_to_autotools_project)


241
macro(linphone_builder_apply_extra_flags PROJNAME)
242
	if("${EP_${PROJNAME}_BUILD_METHOD}" STREQUAL "autotools")
243 244 245 246 247 248
		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}")
249
	else()
250 251 252 253 254 255 256 257 258 259 260 261 262
		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}")
			endif(NOT "${EP_${PROJNAME}_EXTRA_CFLAGS}" STREQUAL "")
			if(NOT "${EP_${PROJNAME}_EXTRA_CXXFLAGS}" STREQUAL "")
				set(CMAKE_CXX_FLAGS${BUILD_CONFIG} "${CMAKE_CXX_FLAGS${BUILD_CONFIG}} ${EP_${PROJNAME}_EXTRA_CXXFLAGS}")
			endif(NOT "${EP_${PROJNAME}_EXTRA_CXXFLAGS}" STREQUAL "")
			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 "")
		endforeach(BUILD_CONFIG)
263
	endif()
264 265 266
endmacro(linphone_builder_apply_extra_flags)


267
macro(linphone_builder_set_ep_directories PROJNAME)
268 269
	get_filename_component(CONFIG_NAME ${LINPHONE_BUILDER_CONFIG_FILE} NAME_WE)
	string(REGEX REPLACE "config-" "" CONFIG_NAME ${CONFIG_NAME})
270
	set(ep_source "${ep_base}/Source/EP_${PROJNAME}")
271
	set(ep_tmp "${ep_base}/tmp-${CONFIG_NAME}/${PROJNAME}")
272 273 274
	if("${EP_${PROJNAME}_BUILD_IN_SOURCE}" STREQUAL "yes")
		set(ep_build "${ep_source}")
	else("${EP_${PROJNAME}_BUILD_IN_SOURCE}" STREQUAL "yes")
275
		set(ep_build "${ep_base}/Build-${CONFIG_NAME}/${PROJNAME}")
276
	endif("${EP_${PROJNAME}_BUILD_IN_SOURCE}" STREQUAL "yes")
277
	unset(CONFIG_NAME)
278 279
endmacro(linphone_builder_set_ep_directories)

280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303

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}\"")
			endforeach(OPTION)
		endif("${EP_${PROJNAME}_CONFIGURE_OPTIONS_PASSED_TO_AUTOGEN}" STREQUAL "yes")
		set(ep_autogen_command "${ep_source}/autogen.sh ${ep_autogen_options}")
	else("${EP_${PROJNAME}_USE_AUTOGEN}" STREQUAL "yes")
		set(ep_autogen_command "")
	endif("${EP_${PROJNAME}_USE_AUTOGEN}" STREQUAL "yes")
endmacro(linphone_builder_create_autogen_command)


macro(linphone_builder_create_configure_command PROJNAME)
	if("${EP_${PROJNAME}_CONFIGURE_OPTIONS_PASSED_TO_AUTOGEN}" STREQUAL "yes")
		set(ep_configure_command "")
	else("${EP_${PROJNAME}_CONFIGURE_OPTIONS_PASSED_TO_AUTOGEN}" STREQUAL "yes")
		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}\"")
		endforeach(OPTION)
304
		set(ep_configure_env "${EP_${PROJNAME}_CONFIGURE_ENV}")
305 306 307 308 309
		set(ep_configure_command "${ep_source}/configure ${ep_configure_options}")
	endif("${EP_${PROJNAME}_CONFIGURE_OPTIONS_PASSED_TO_AUTOGEN}" STREQUAL "yes")
endmacro(linphone_builder_create_configure_command)


310
function(linphone_builder_add_project PROJNAME)
311
	linphone_builder_set_ep_directories(${PROJNAME})
312
	linphone_builder_apply_cmake_flags_to_autotools_project(${PROJNAME})
313
	linphone_builder_apply_extra_flags(${PROJNAME})
314 315
	linphone_builder_expand_external_project_vars()

316 317 318 319 320 321 322
	if("${EP_${PROJNAME}_BUILD_METHOD}" STREQUAL "custom")
		set(BUILD_COMMANDS
			CONFIGURE_COMMAND ${EP_${PROJNAME}_CONFIGURE_COMMAND}
			BUILD_COMMAND ${EP_${PROJNAME}_BUILD_COMMAND}
			INSTALL_COMMAND ${EP_${PROJNAME}_INSTALL_COMMAND}
		)
	elseif("${EP_${PROJNAME}_BUILD_METHOD}" STREQUAL "autotools")
323 324 325 326 327 328 329
		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("${EP_${PROJNAME}_CONFIG_H_FILE}" STREQUAL "")
			set(ep_config_h_file ${EP_${PROJNAME}_CONFIG_H_FILE})
		endif("${EP_${PROJNAME}_CONFIG_H_FILE}" STREQUAL "")
330 331 332 333 334
		if("${EP_${PROJNAME}_INSTALL_TARGET}" STREQUAL "")
			set(ep_install_target "install")
		else("${EP_${PROJNAME}_INSTALL_TARGET}" STREQUAL "")
			set(ep_install_target "${EP_${PROJNAME}_INSTALL_TARGET}")
		endif("${EP_${PROJNAME}_INSTALL_TARGET}" STREQUAL "")
335

336
		if(WIN32)
337 338 339 340 341 342 343
			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})
344
			set(ep_redirect_to_file "2>&1 >> ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}.log")
345
		else()
346
			set(SCRIPT_EXTENSION sh)
347
		endif()
348

349 350 351 352 353 354
		if("${EP_${PROJNAME}_PKG_CONFIG}" STREQUAL "")
			set(LINPHONE_BUILDER_PKG_CONFIG "pkg-config")
		else("${EP_${PROJNAME}_PKG_CONFIG}" STREQUAL "")
			set(LINPHONE_BUILDER_PKG_CONFIG "${EP_${PROJNAME}_PKG_CONFIG}")
		endif("${EP_${PROJNAME}_PKG_CONFIG}" STREQUAL "")

355 356 357
		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
358 359

		set(BUILD_COMMANDS
360 361 362
			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
363
		)
364 365
	else()
		# Use CMake build method
366 367 368 369 370 371 372 373 374 375
		if("${CMAKE_VERSION}" VERSION_GREATER "2.8.3")
			set(BUILD_COMMANDS
				CMAKE_ARGS ${EP_${PROJNAME}_CMAKE_OPTIONS} ${EP_${PROJNAME}_LINKING_TYPE}
				CMAKE_CACHE_ARGS ${LINPHONE_BUILDER_EP_ARGS}
			)
		else("${CMAKE_VERSION}" VERSION_GREATER "2.8.3")
			set(BUILD_COMMANDS
				CMAKE_ARGS ${LINPHONE_BUILDER_EP_ARGS} ${EP_${PROJNAME}_CMAKE_OPTIONS} ${EP_${PROJNAME}_LINKING_TYPE}
			)
		endif("${CMAKE_VERSION}" VERSION_GREATER "2.8.3")
376
	endif()
377

378 379
	if(NOT "${EP_${PROJNAME}_URL}" STREQUAL "")
		set(DOWNLOAD_SOURCE URL ${EP_${PROJNAME}_URL})
380 381 382 383 384 385 386 387 388 389 390
		if(NOT "${EP_${PROJNAME}_URL_HASH}" STREQUAL "")
			if("${CMAKE_VERSION}" VERSION_GREATER "2.8.9")
				list(APPEND DOWNLOAD_SOURCE URL_HASH ${EP_${PROJNAME}_URL_HASH})
			else()
				string(REGEX MATCH "^MD5=([A-Fa-f0-9]+)$" _match ${EP_${PROJNAME}_URL_HASH})
				if(NOT "${_match}" STREQUAL "")
					string(REGEX REPLACE "MD5=" "" _match ${_match})
					list(APPEND DOWNLOAD_SOURCE URL_MD5 ${_match})
				endif()
				unset(_match)
			endif()
391
		endif()
392 393 394 395
	else(NOT "${EP_${PROJNAME}_URL}" STREQUAL "")
		set(DOWNLOAD_SOURCE GIT_REPOSITORY ${EP_${PROJNAME}_GIT_REPOSITORY} GIT_TAG ${EP_${PROJNAME}_GIT_TAG})
	endif(NOT "${EP_${PROJNAME}_URL}" STREQUAL "")

396 397 398 399
	ExternalProject_Add(EP_${PROJNAME}
		DEPENDS ${EP_${PROJNAME}_DEPENDENCIES}
		TMP_DIR ${ep_tmp}
		BINARY_DIR ${ep_build}
400
		${DOWNLOAD_SOURCE}
401 402
		PATCH_COMMAND ${EP_${PROJNAME}_PATCH_COMMAND}
		CMAKE_GENERATOR ${CMAKE_GENERATOR}
Ghislain MARY's avatar
Ghislain MARY committed
403
		${BUILD_COMMANDS}
404
	)
405 406

	if(MSVC)
407
		if("${EP_${PROJNAME}_BUILD_METHOD}" STREQUAL "autotools")
408 409 410 411 412 413
			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}
			)
414
		endif()
415
	endif(MSVC)
416
endfunction(linphone_builder_add_project)
Ghislain MARY's avatar
Ghislain MARY committed
417

418
function(linphone_builder_add_external_projects)
419
	foreach(BUILDER ${LINPHONE_BUILDER_INCLUDED_BUILDERS})
Ghislain MARY's avatar
Ghislain MARY committed
420 421
		linphone_builder_add_project(${BUILDER})
	endforeach(BUILDER)
422
endfunction(linphone_builder_add_external_projects)