CMakeLists.txt 50.2 KB
Newer Older
1
############################################################################
Ghislain MARY's avatar
Ghislain MARY committed
2
# CMakeLists.txt
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# 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
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 21 22
#
############################################################################

23
include(CMakeDependentOption)
24
include(ExternalProject)
25
include(FeatureSummary)
26

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

30

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


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


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

macro(linphone_builder_expand_external_project_vars)
Ghislain MARY's avatar
Ghislain MARY committed
55 56 57 58 59 60 61 62 63 64
	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()
65
endmacro()
66 67 68 69

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


140 141
# This macro can be used to add an option. Give it option name and description,
# default value and optionally dependent predicate and value
142
macro(lcb_add_dependent_option NAME DESCRIPTION DEFAULT_VALUE CONDITION CONDITION_VALUE)
143 144 145 146 147 148 149
	string(TOUPPER ${NAME} UPPERCASE_NAME)
	string(REGEX REPLACE  " " "_" UPPERCASE_NAME ${UPPERCASE_NAME})
	string(REGEX REPLACE  "\\+" "P" UPPERCASE_NAME ${UPPERCASE_NAME})
	cmake_dependent_option(ENABLE_${UPPERCASE_NAME} "${DESCRIPTION}" "${DEFAULT_VALUE}" "${CONDITION}" "${CONDITION_VALUE}")
	add_feature_info("${NAME}" "ENABLE_${UPPERCASE_NAME}" "${DESCRIPTION}")
endmacro()

150 151
macro(lcb_add_strict_dependent_option NAME DESCRIPTION DEFAULT_VALUE CONDITION CONDITION_VALUE STRICT_CONDITION ERROR_MSG)
	lcb_add_dependent_option("${NAME}" "${DESCRIPTION}" "${DEFAULT_VALUE}" "${CONDITION}" "${CONDITION_VALUE}")
152 153 154 155 156 157 158 159
	string(TOUPPER ${NAME} UPPERCASE_NAME)
	string(REGEX REPLACE  " " "_" UPPERCASE_NAME ${UPPERCASE_NAME})
	string(REGEX REPLACE  "\\+" "P" UPPERCASE_NAME ${UPPERCASE_NAME})
	if(${ENABLE_${UPPERCASE_NAME}} AND NOT ${STRICT_CONDITION})
		message(FATAL_ERROR "Trying to enable ${NAME} but ${ERROR_MSG}")
	endif()
endmacro()

160
macro(lcb_add_option NAME DESCRIPTION DEFAULT_VALUE)
161 162 163 164 165 166 167
	string(TOUPPER ${NAME} UPPERCASE_NAME)
	string(REGEX REPLACE  " " "_" UPPERCASE_NAME ${UPPERCASE_NAME})
	string(REGEX REPLACE  "\\+" "P" UPPERCASE_NAME ${UPPERCASE_NAME})
	option(ENABLE_${UPPERCASE_NAME} "Enable ${NAME}: ${DESCRIPTION}" "${DEFAULT_VALUE}")
	add_feature_info("${NAME}" "ENABLE_${UPPERCASE_NAME}" "${DESCRIPTION}")
endmacro()

168
macro(linphone_builder_get_autotools_configuration)
169 170 171 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 199 200 201
	if(MSVC)
		set(_generator "MinGW Makefiles")
	else()
		set(_generator "${CMAKE_GENERATOR}")
	endif()
	set(_autotools_command ${CMAKE_COMMAND} -G "${_generator}")
	if(CMAKE_TOOLCHAIN_FILE)
		list(APPEND _autotools_command "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
	endif()
	if(CMAKE_OSX_ARCHITECTURES)
		list(APPEND _autotools_command "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}")
	endif()
	if(CMAKE_C_COMPILER_LAUNCHER)
		list(APPEND _autotools_command "-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}")
	endif()
	if(CMAKE_CXX_COMPILER_LAUNCHER)
		list(APPEND _autotools_command "-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}")
	endif()
	list(APPEND _autotools_command
		"-DAUTOTOOLS_AS_FLAGS=${AUTOTOOLS_AS_FLAGS}"
		"-DAUTOTOOLS_C_FLAGS=${AUTOTOOLS_C_FLAGS}"
		"-DAUTOTOOLS_CPP_FLAGS=${AUTOTOOLS_CPP_FLAGS}"
		"-DAUTOTOOLS_CXX_FLAGS=${AUTOTOOLS_CXX_FLAGS}"
		"-DAUTOTOOLS_OBJC_FLAGS=${AUTOTOOLS_OBJC_FLAGS}"
		"-DAUTOTOOLS_LINKER_FLAGS=${AUTOTOOLS_LINKER_FLAGS}"
	)
	list(APPEND _autotools_command "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Autotools/")
	execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/Autotools)
	execute_process(COMMAND ${_autotools_command} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Autotools)
	unset(_autotools_command)
	unset(_extra_generator)
	unset(_generator)
	include(${CMAKE_BINARY_DIR}/Autotools/Autotools.cmake)
202
endmacro()
203 204


205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
macro(lcb_add_target_dependencies TARGET_NAME)
	set(_args2 "${ARGN}")
	foreach(_arg IN LISTS _args2)
		set(_list ${TARGET_${_arg}_DEPENDENCIES})
		if(_list)
			list(REMOVE_ITEM _list "${_arg}")
		endif()
		if(_list)
			lcb_add_target_dependencies("${TARGET_NAME}" ${_list})
		endif()
		list(FIND TARGET_${TARGET_NAME}_DEPENDENCIES "${_arg}" _target_found)
		if(_target_found LESS 0)
			list(APPEND TARGET_${TARGET_NAME}_DEPENDENCIES "${_arg}")
		endif()
	endforeach()
endmacro()

Ghislain MARY's avatar
Ghislain MARY committed
222 223 224
macro(lcb_define_target TARGET_NAME)
	unset(TARGET_${TARGET_NAME}_DEPENDENCIES)
	set(_args "${ARGN}")
225
	lcb_add_target_dependencies("${TARGET_NAME}" ${_args})
Ghislain MARY's avatar
Ghislain MARY committed
226 227 228 229 230 231 232 233 234 235 236 237
	list(APPEND TARGET_${TARGET_NAME}_DEPENDENCIES "${TARGET_NAME}")
	list(APPEND LINPHONE_BUILDER_TARGETS "${TARGET_NAME}")
	set_property(CACHE LINPHONE_BUILDER_TARGET PROPERTY STRINGS ${LINPHONE_BUILDER_TARGETS})
endmacro()

macro(lcb_add_builder_to_target TARGET_NAME BUILDER_NAME)
	list(APPEND TARGET_${TARGET_NAME}_BUILDERS "${BUILDER_NAME}")
endmacro()

macro(lcb_check_target)
	list(FIND LINPHONE_BUILDER_TARGETS "${LINPHONE_BUILDER_TARGET}" _target_found)
	if(_target_found EQUAL -1)
jehan's avatar
jehan committed
238
		message(FATAL_ERROR "Invalid LINPHONE_BUILDER_TARGET '${LINPHONE_BUILDER_TARGET}'")
239
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
240
endmacro()
241

Ghislain MARY's avatar
Ghislain MARY committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
macro(lcb_declare_target TARGET_NAME)
	add_custom_target(TARGET_${TARGET_NAME} ALL)
	add_dependencies(TARGET_linphone_builder TARGET_${TARGET_NAME})
	foreach(_dependency IN LISTS TARGET_${TARGET_NAME}_DEPENDENCIES)
		if(NOT _dependency STREQUAL "${TARGET_NAME}")
			add_dependencies(TARGET_${TARGET_NAME} TARGET_${_dependency})
		endif()
	endforeach()
	unset(_dependencies)
	linphone_builder_add_builder_to_target(TARGET_${TARGET_NAME} "${TARGET_NAME}" TRUE _dependencies)
	list(APPEND LINPHONE_BUILDER_INCLUDED_BUILDERS ${_dependencies})
endmacro()

macro(lcb_declare_targets)
	add_custom_target(TARGET_linphone_builder ALL)
	foreach(_target IN LISTS TARGET_${LINPHONE_BUILDER_TARGET}_DEPENDENCIES)
		lcb_declare_target("${_target}")
	endforeach()
endmacro()

262

Ghislain MARY's avatar
Ghislain MARY committed
263 264
macro(linphone_builder_include_builder BUILDER INCLUDE_AFTER DEPENDENCIES _included)
	set(${_included} -1)
265
	list(FIND LINPHONE_BUILDER_INCLUDED_BUILDERS ${BUILDER} _already_included)
Ghislain MARY's avatar
Ghislain MARY committed
266 267
	list(FIND ${DEPENDENCIES} ${BUILDER} _already_included2)
	if(_already_included EQUAL -1 AND _already_included2 EQUAL -1)
268 269
		unset(_builder_filepath)
		if(LINPHONE_BUILDER_EXTERNAL_BUILDERS_PATH)
Ghislain MARY's avatar
Ghislain MARY committed
270
			set(_builder_filepath "${LINPHONE_BUILDER_EXTERNAL_BUILDERS_PATH}/${BUILDER}.cmake")
271 272 273 274 275
			if(NOT EXISTS "${_builder_filepath}")
				unset(_builder_filepath)
			endif()
		endif()
		if(NOT _builder_filepath)
Ghislain MARY's avatar
Ghislain MARY committed
276 277 278 279 280 281 282 283 284 285 286 287
			set(_builder_filepath "${CMAKE_CURRENT_SOURCE_DIR}/builders/${BUILDER}.cmake")
		endif()
		if(EXISTS "${_builder_filepath}")
			message(STATUS "Including builder ${BUILDER}")
			set(LINPHONE_BUILDER_CURRENT_BUILDER "${BUILDER}")
			include(${_builder_filepath})
			if(INCLUDE_AFTER)
				list(APPEND ${DEPENDENCIES} ${BUILDER})
			else()
				list(INSERT ${DEPENDENCIES} 0 ${BUILDER})
			endif()
			set(${_included} 1)
288
		endif()
289 290
	endif()
	unset(_already_included)
Ghislain MARY's avatar
Ghislain MARY committed
291
endmacro()
292 293


Ghislain MARY's avatar
Ghislain MARY committed
294 295 296 297 298
macro(linphone_builder_add_builder_to_target TARGETNAME BUILDER INCLUDE_AFTER DEPENDENCIES)
	linphone_builder_include_builder(${BUILDER} ${INCLUDE_AFTER} ${DEPENDENCIES} _included)
	if(_included GREATER -1)
		if(LINPHONE_BUILDER_USE_SYSTEM_DEPENDENCIES AND EP_${BUILDER}_MAY_BE_FOUND_ON_SYSTEM)
			list(FIND LINPHONE_BUILDER_SYSTEM_DEPENDENCIES_BUILDERS ${BUILDER} _already_included)
299
			if(_already_included EQUAL -1)
Ghislain MARY's avatar
Ghislain MARY committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
				message("    Using ${BUILDER} from the system")
				list(APPEND LINPHONE_BUILDER_INCLUDED_BUILDERS_TO_EXCLUDE ${BUILDER})
				list(APPEND LINPHONE_BUILDER_SYSTEM_DEPENDENCIES_BUILDERS ${BUILDER})
			endif()
		elseif(LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH AND LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
			foreach(SUBDIR ${EP_${BUILDER}_EXTERNAL_SOURCE_PATHS})
				if(SUBDIR STREQUAL "<LINPHONE_BUILDER_TOP_DIR>")
					set(_source_dir "${LINPHONE_BUILDER_TOP_DIR}")
				else()
					set(_source_dir "${LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH}/${SUBDIR}")
				endif()
				if(EXISTS "${_source_dir}")
					#message("    ${TARGETNAME} depends on external source path ${_source_dir}")
					set(_build_from_external_source_path 1)
					break()
				endif()
			endforeach()
			if(_build_from_external_source_path)
				list(FIND LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS ${BUILDER} _already_included)
				if(_already_included EQUAL -1)
					# message("    external source path builder ${BUILDER}: ${_source_dir}")
					set(EP_${BUILDER}_SOURCE_DIR "${_source_dir}")
					list(APPEND LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS ${BUILDER})
				endif()
				unset(_already_included)
			else()
				#message("     ${TARGETNAME} depends on external project EP_${BUILDER}")
				add_dependencies(${TARGETNAME} EP_${BUILDER})
328
			endif()
Ghislain MARY's avatar
Ghislain MARY committed
329
			unset(_build_from_external_source_path)
330
		else()
Ghislain MARY's avatar
Ghislain MARY committed
331
			#message("    ${TARGETNAME} depends on external project EP_${BUILDER}")
332
			add_dependencies(${TARGETNAME} EP_${BUILDER})
333
		endif()
Ghislain MARY's avatar
Ghislain MARY committed
334 335 336 337
		foreach(_dependency IN LISTS EP_${BUILDER}_DEPENDENCIES)
			string(REGEX REPLACE "^EP_" "" _dep ${_dependency})
			linphone_builder_add_builder_to_target(${TARGETNAME} "${_dep}" FALSE ${DEPENDENCIES})
		endforeach()
338
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
339
endmacro()
340 341


342
macro(linphone_builder_apply_flags)
343
	string(TOUPPER "${CMAKE_BUILD_TYPE}" BUILD_TYPE)
Ghislain MARY's avatar
Ghislain MARY committed
344 345 346 347 348 349 350 351 352 353
	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)
354 355
		set(CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_CPPFLAGS}")
		set(CMAKE_CXX_FLAGS_${BUILD_TYPE} "${CMAKE_CXX_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_CPPFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
356 357 358 359
		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)
360
		set(CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_CFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
361 362 363
		set(AUTOTOOLS_C_FLAGS "${AUTOTOOLS_C_FLAGS} ${LINPHONE_BUILDER_CFLAGS}")
	endif()
	if(LINPHONE_BUILDER_CXXFLAGS)
364
		set(CMAKE_CXX_FLAGS_${BUILD_TYPE} "${CMAKE_CXX_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_CXXFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
365 366 367
		set(AUTOTOOLS_CXX_FLAGS "{AUTOTOOLS_CXX_FLAGS} ${LINPHONE_BUILDER_CXX_FLAGS}")
	endif()
	if(LINPHONE_BUILDER_OBJCFLAGS)
368
		set(CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_OBJCFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
369 370 371
		set(AUTOTOOLS_OBJC_FLAGS "${AUTOTOOLS_OBJC_FLAGS} ${LINPHONE_BUILDER_OBJCFLAGS}")
	endif()
	if(LINPHONE_BUILDER_LDFLAGS)
372 373 374
		set(CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_LDFLAGS}")
		set(CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_LDFLAGS}")
		set(CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE}} ${LINPHONE_BUILDER_LDFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
375 376
		set(AUTOTOOLS_LINKER_FLAGS "${AUTOTOOLS_LINKER_FLAGS} ${LINPHONE_BUILDER_LDFLAGS}")
	endif()
377
	unset(BUILD_TYPE)
Ghislain MARY's avatar
Ghislain MARY committed
378
endmacro()
379 380


381
macro(linphone_builder_apply_cmake_flags_to_autotools_project PROJNAME)
Ghislain MARY's avatar
Ghislain MARY committed
382
	if(EP_${PROJNAME}_BUILD_METHOD STREQUAL "autotools")
Ghislain MARY's avatar
Ghislain MARY committed
383 384 385 386 387 388
		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}")
389
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
390
endmacro()
391 392


393
macro(linphone_builder_apply_extra_flags PROJNAME)
394
	string(TOUPPER "${CMAKE_BUILD_TYPE}" BUILD_TYPE)
395 396 397 398 399
	if(MSVC)
		set(_no_warnings_flag "/W0")
	else()
		set(_no_warnings_flag "-w")
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
400
	if(EP_${PROJNAME}_BUILD_METHOD STREQUAL "autotools")
401 402 403 404 405 406
		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}")
407 408 409
		if(EP_${PROJNAME}_IGNORE_WARNINGS)
			set(ep_cppflags "${ep_cppflags} ${_no_warnings_flag}")
		endif()
410
	else()
411 412 413 414 415
		set(SAVED_CMAKE_C_FLAGS "${CMAKE_C_FLAGS_${BUILD_TYPE}}")
		set(SAVED_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_${BUILD_TYPE}}")
		set(SAVED_CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE}}")
		set(SAVED_CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE}}")
		set(SAVED_CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE}}")
416
		if(EP_${PROJNAME}_EXTRA_CFLAGS)
417
			set(CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${BUILD_TYPE}} ${EP_${PROJNAME}_EXTRA_CFLAGS}")
418 419
		endif()
		if(EP_${PROJNAME}_EXTRA_CXXFLAGS)
420
			set(CMAKE_CXX_FLAGS_${BUILD_TYPE} "${CMAKE_CXX_FLAGS_${BUILD_TYPE}} ${EP_${PROJNAME}_EXTRA_CXXFLAGS}")
421 422
		endif()
		if(EP_${PROJNAME}_EXTRA_LDFLAGS)
423 424 425
			set(CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE}} ${EP_${PROJNAME}_EXTRA_LDFLAGS}")
			set(CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE}} ${EP_${PROJNAME}_EXTRA_LDFLAGS}")
			set(CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE} "${CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE}} ${EP_${PROJNAME}_EXTRA_LDFLAGS}")
426
		endif()
427
		if(EP_${PROJNAME}_IGNORE_WARNINGS)
428 429
			set(CMAKE_C_FLAGS_${BUILD_TYPE} "${CMAKE_C_FLAGS_${BUILD_TYPE}} ${_no_warnings_flag}")
			set(CMAKE_CXX_FLAGS_${BUILD_TYPE} "${CMAKE_CXX_FLAGS_${BUILD_TYPE}} ${_no_warnings_flag}")
430
		endif()
431
	endif()
432
	unset(BUILD_TYPE)
Ghislain MARY's avatar
Ghislain MARY committed
433
endmacro()
434 435


436
macro(linphone_builder_restore_flags)
437 438 439 440 441 442 443
	string(TOUPPER "${CMAKE_BUILD_TYPE}" BUILD_TYPE)
	set(CMAKE_C_FLAGS_${BUILD_TYPE} "${SAVED_CMAKE_C_FLAGS}")
	set(CMAKE_CXX_FLAGS_${BUILD_TYPE} "${SAVED_CMAKE_CXX_FLAGS}")
	set(CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE} "${SAVED_CMAKE_EXE_LINKER_FLAGS}")
	set(CMAKE_MODULE_LINKER_FLAGS_${BUILD_TYPE} "${SAVED_CMAKE_MODULE_LINKER_FLAGS}")
	set(CMAKE_SHARED_LINKER_FLAGS_${BUILD_TYPE} "${SAVED_CMAKE_SHARED_LINKER_FLAGS}")
	unset(BUILD_TYPE)
444 445 446
endmacro()


447
macro(linphone_builder_set_ep_directories PROJNAME)
448 449 450 451 452
	if(EP_${PROJNAME}_SOURCE_DIR)
		set(ep_source "${EP_${PROJNAME}_SOURCE_DIR}")
	else()
		set(ep_source "${ep_base}/Source/EP_${PROJNAME}")
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
453
	if(EP_${PROJNAME}_BUILD_IN_SOURCE_TREE)
454
		set(ep_build "${ep_source}")
Ghislain MARY's avatar
Ghislain MARY committed
455
	else()
456
		set(ep_build "${ep_base}/Build/${PROJNAME}")
457

458 459 460 461 462 463 464 465
		# replace "//" with "/" in paths
		string(FIND "${ep_build}" "//" must_trim)
		while (must_trim GREATER -1)
			string(REPLACE "//" "/" ep_build_trim ${ep_build})
			set(ep_build ${ep_build_trim})
			string(FIND "${ep_build}" "//" must_trim)
		endwhile()

466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
		# Compute the relative path to the source directory from the build directory
		set(common TRUE)
		set(not_finished TRUE)
		set(idx 1)
		string(LENGTH "${ep_source}" ep_source_length)
		string(LENGTH "${ep_build}" ep_build_length)
		while(common AND not_finished)
			string(SUBSTRING "${ep_source}" 0 ${idx} common_ep_source)
			string(SUBSTRING "${ep_build}" 0 ${idx} common_ep_build)
			math(EXPR idx "${idx}+1")
			if(NOT common_ep_source STREQUAL common_ep_build)
				set(common FALSE)
			endif()
			if((idx EQUAL ep_source_length) OR (idx EQUAL ep_build_length))
				set(not_finished FALSE)
			endif()
		endwhile()
		math(EXPR idx "${idx}-2")
		math(EXPR relative_source_length "${ep_source_length}-${idx}")
		math(EXPR relative_build_length "${ep_build_length}-${idx}")
		string(SUBSTRING "${ep_source}" ${idx} ${relative_source_length} ep_relative_source)
		string(SUBSTRING "${ep_build}" ${idx} ${relative_build_length} ep_relative_build)
		set(updirs "")
		string(FIND "${ep_relative_build}" "/" idx)
		while(idx GREATER -1)
			string(CONCAT updirs "${updirs}" "../")
			math(EXPR idx "${idx}+1")
493
			math(EXPR relative_build_length "${relative_build_length}-${idx}")
494 495 496 497 498 499 500
			string(SUBSTRING "${ep_relative_build}" ${idx} ${relative_build_length} ep_relative_build)
			string(FIND "${ep_relative_build}" "/" idx)
		endwhile()
		if(ep_relative_build)
			string(CONCAT updirs "${updirs}" "../")
		endif()
		set(ep_source_relative_to_build "${updirs}/${ep_relative_source}")
Ghislain MARY's avatar
Ghislain MARY committed
501 502
	endif()
endmacro()
503

504

505 506 507 508 509 510 511 512 513
macro(linphone_builder_set_ep_generator)
	if(CMAKE_EXTRA_GENERATOR)
		set(ep_generator "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
	else()
		set(ep_generator "${CMAKE_GENERATOR}")
	endif()
endmacro()


514
macro(linphone_builder_create_autogen_command PROJNAME)
515 516
	if(EP_${PROJNAME}_USE_AUTOGEN)
		if(EP_${PROJNAME}_CONFIGURE_OPTIONS_PASSED_TO_AUTOGEN)
517 518 519
			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
520
			endforeach()
521
		endif()
522
		set(ep_autogen_command "\"${ep_source}/autogen.sh\" ${ep_autogen_options}")
523 524
	elseif(EP_${PROJNAME}_USE_AUTORECONF)
		set(ep_autogen_command "autoreconf -vfi ${ep_source}")
525
	else()
526
		set(ep_autogen_command "")
527
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
528
endmacro()
529 530 531


macro(linphone_builder_create_configure_command PROJNAME)
532
	if(EP_${PROJNAME}_CONFIGURE_OPTIONS_PASSED_TO_AUTOGEN)
533
		set(ep_configure_command "")
534
	else()
535 536 537
		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
538
		endforeach()
539
		set(ep_configure_env "${EP_${PROJNAME}_CONFIGURE_ENV}")
540
		set(ep_configure_command "\"${ep_source}/configure\" ${ep_configure_options}")
541
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
542
endmacro()
543 544


Ghislain MARY's avatar
Ghislain MARY committed
545 546 547 548 549
macro(linphone_builder_create_build_command PROJNAME)
	set(ep_make_options "${EP_${PROJNAME}_MAKE_OPTIONS}")
endmacro()


550
# this macro invokes configure_file() for the project, using the default file if
551
# the specific file is not defined
552
macro(linphone_builder_configure_file_for_project PROJNAME CMD DEFAULT_CONF_FILE OUTPUT)
Ghislain MARY's avatar
Ghislain MARY committed
553
	if(NOT EP_${PROJNAME}_${CMD}_COMMAND_SOURCE)
554
		message(STATUS "Using default file ${DEFAULT_CONF_FILE} for ${CMD} step of ${PROJNAME}")
555 556
		configure_file(${DEFAULT_CONF_FILE} ${OUTPUT})
	else()
557
		message(STATUS "Using specific file ${EP_${PROJNAME}_${CMD}_COMMAND_SOURCE} for ${CMD} step of ${PROJNAME}")
558
		configure_file(${EP_${PROJNAME}_${CMD}_COMMAND_SOURCE} ${OUTPUT})
559
	endif()
560
endmacro()
561

562 563 564 565
macro(linphone_builder_filter_out_inexistent_dependencies PROJNAME)
	if(EP_${PROJNAME}_DEPENDENCIES)
		set(_new_deps )
		foreach(_dep ${EP_${PROJNAME}_DEPENDENCIES})
566 567
			string(REGEX REPLACE "^EP_" "" _dep2 ${_dep})
			list(FIND LINPHONE_BUILDER_INCLUDED_BUILDERS ${_dep2} _found)
568
			list(FIND LINPHONE_BUILDER_INCLUDED_BUILDERS_TO_EXCLUDE ${_dep2} _excluded_found)
569
			list(FIND LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS ${_dep2} _external_source_path_found)
570
			if((_found GREATER -1) AND (_excluded_found EQUAL -1) AND ((_external_source_path_found EQUAL -1) OR (NOT EP_${_dep2}_GROUPABLE) OR (NOT LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)))
571 572 573 574 575 576 577 578 579 580 581
				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()

582
macro(linphone_builder_add_external_project PROJNAME)
583 584 585
	if(LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH)
		foreach(SUBDIR ${EP_${PROJNAME}_EXTERNAL_SOURCE_PATHS})
			if(NOT EP_${PROJNAME}_SOURCE_DIR)
586 587 588 589 590 591 592
				if(SUBDIR STREQUAL "<LINPHONE_BUILDER_TOP_DIR>")
					set(_source_dir "${LINPHONE_BUILDER_TOP_DIR}")
				else()
					set(_source_dir "${LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH}/${SUBDIR}")
				endif()
				if(EXISTS "${_source_dir}")
					set(EP_${PROJNAME}_SOURCE_DIR "${_source_dir}")
593 594 595 596 597
				endif()
			endif()
		endforeach()
	endif()

598
	linphone_builder_set_ep_directories(${PROJNAME})
599
	linphone_builder_set_ep_generator()
Ghislain MARY's avatar
Ghislain MARY committed
600 601 602
	if(NOT EP_${PROJNAME}_DO_NOT_USE_CMAKE_FLAGS)
		linphone_builder_apply_cmake_flags_to_autotools_project(${PROJNAME})
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
603 604 605 606 607
	if(EP_${PROJNAME}_USE_C_COMPILER_FOR_ASSEMBLER)
		set(ep_use_c_compiler_for_assembler TRUE)
	else()
		unset(ep_use_c_compiler_for_assembler)
	endif()
608
	linphone_builder_apply_extra_flags(${PROJNAME})
609 610
	linphone_builder_expand_external_project_vars()

Ghislain MARY's avatar
Ghislain MARY committed
611 612 613 614 615 616 617 618
	if(EP_${PROJNAME}_BUILD_METHOD STREQUAL "dummy")
		set(BUILD_COMMANDS
			CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo ""
			BUILD_COMMAND ${CMAKE_COMMAND} -E echo ""
			INSTALL_COMMAND ${CMAKE_COMMAND} -E echo ""
		)
		set(EP_${PROJNAME}_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}")
	elseif(EP_${PROJNAME}_BUILD_METHOD STREQUAL "prebuilt")
619 620 621 622 623 624
		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
625
	elseif(EP_${PROJNAME}_BUILD_METHOD STREQUAL "custom")
626 627 628
		if(WIN32)
			set(ep_redirect_to_file "2>&1 >> \"${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}.log\"")
		endif()
629 630 631 632 633 634 635 636 637 638 639 640
		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()
641
		set(BUILD_COMMANDS
642 643 644
			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}
645
		)
646 647
	elseif(EP_${PROJNAME}_BUILD_METHOD STREQUAL "autotools")
		linphone_builder_create_autogen_command(${PROJNAME})
648
		linphone_builder_create_configure_command(${PROJNAME})
Ghislain MARY's avatar
Ghislain MARY committed
649
		linphone_builder_create_build_command(${PROJNAME})
Ghislain MARY's avatar
Ghislain MARY committed
650
		if(EP_${PROJNAME}_CONFIG_H_FILE)
651
			set(ep_config_h_file ${EP_${PROJNAME}_CONFIG_H_FILE})
Ghislain MARY's avatar
Ghislain MARY committed
652
		else()
Ghislain MARY's avatar
Ghislain MARY committed
653 654 655
			set(ep_config_h_file config.h)
		endif()
		if(EP_${PROJNAME}_INSTALL_TARGET)
656
			set(ep_install_target "${EP_${PROJNAME}_INSTALL_TARGET}")
Ghislain MARY's avatar
Ghislain MARY committed
657 658
		else()
			set(ep_install_target "install")
Ghislain MARY's avatar
Ghislain MARY committed
659
		endif()
660

661
		if(WIN32)
662
			set(ep_redirect_to_file "2>&1 >> \"${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}.log\"")
663 664 665 666 667
			set(SCRIPT_EXTENSION bat)
			set(MSVC_PROJNAME ${PROJNAME})
			configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/mingw_configure.bat.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_configure.bat)
			configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/mingw_build.bat.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_build.bat)
			configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/mingw_install.bat.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_install.bat)
Ghislain MARY's avatar
Ghislain MARY committed
668
			if(ep_autogen_command)
669 670
				set(ep_autogen_redirect_to_file ${ep_redirect_to_file})
			endif()
Ghislain MARY's avatar
Ghislain MARY committed
671
			if(ep_configure_command)
672 673
				set(ep_configure_redirect_to_file ${ep_redirect_to_file})
			endif()
674
		else()
675
			set(SCRIPT_EXTENSION sh)
676
		endif()
677

Ghislain MARY's avatar
Ghislain MARY committed
678
		if(EP_${PROJNAME}_PKG_CONFIG)
679
			set(LINPHONE_BUILDER_PKG_CONFIG "${EP_${PROJNAME}_PKG_CONFIG}")
Ghislain MARY's avatar
Ghislain MARY committed
680 681
		else()
			set(LINPHONE_BUILDER_PKG_CONFIG "${PKG_CONFIG_PROGRAM}")
Ghislain MARY's avatar
Ghislain MARY committed
682
		endif()
683

684 685 686
		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
687 688

		set(BUILD_COMMANDS
689 690 691
			CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_configure.${SCRIPT_EXTENSION}
			BUILD_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_build.${SCRIPT_EXTENSION}
			INSTALL_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_install.${SCRIPT_EXTENSION}
Ghislain MARY's avatar
Ghislain MARY committed
692
		)
Ghislain MARY's avatar
Ghislain MARY committed
693
	elseif(EP_${PROJNAME}_BUILD_METHOD STREQUAL "rpm")
694

695
		if(WIN32)
Ghislain MARY's avatar
Ghislain MARY committed
696
			message(SEND_ERROR "rpm build not supported on WIN32")
697 698 699 700
		endif()

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

Ghislain MARY's avatar
Ghislain MARY committed
702
		if(EP_${PROJNAME}_CONFIG_H_FILE)
703
			set(ep_config_h_file ${EP_${PROJNAME}_CONFIG_H_FILE})
Ghislain MARY's avatar
Ghislain MARY committed
704 705
		else()
			set(ep_config_h_file config.h)
706
		endif()
707

Ghislain MARY's avatar
Ghislain MARY committed
708
		if(EP_${PROJNAME}_INSTALL_TARGET)
709
			set(ep_install_target "${EP_${PROJNAME}_INSTALL_TARGET}")
Ghislain MARY's avatar
Ghislain MARY committed
710 711
		else()
			set(ep_install_target "install")
712 713
		endif()

Ghislain MARY's avatar
Ghislain MARY committed
714
		if(EP_${PROJNAME}_SPEC_FILE)
715
			set(LINPHONE_BUILDER_SPEC_FILE "${EP_${PROJNAME}_SPEC_FILE}")
Ghislain MARY's avatar
Ghislain MARY committed
716 717
		else()
			message(SEND_ERROR "rpm build requires EP_${PROJNAME}_SPEC_FILE to be defined")
718 719 720 721
		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
722
		if(EP_${PROJNAME}_RPMBUILD_NAME)
723
			set(LINPHONE_BUILDER_RPMBUILD_NAME "${EP_${PROJNAME}_RPMBUILD_NAME}")
Ghislain MARY's avatar
Ghislain MARY committed
724 725
		else()
			set(LINPHONE_BUILDER_RPMBUILD_NAME "${PROJNAME}")
726
		endif()
727

728
		# some specific RPMBUILD options to pass for this particular project
Ghislain MARY's avatar
Ghislain MARY committed
729
		if(EP_${PROJNAME}_RPMBUILD_OPTIONS)
730
			set(LINPHONE_BUILDER_RPMBUILD_OPTIONS "${EP_${PROJNAME}_RPMBUILD_OPTIONS}")
731 732
		else()
			set(LINPHONE_BUILDER_RPMBUILD_OPTIONS "")
733 734 735 736
		endif()

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

Ghislain MARY's avatar
Ghislain MARY committed
737
		if(EP_${PROJNAME}_PKG_CONFIG)
738
			set(LINPHONE_BUILDER_PKG_CONFIG "${EP_${PROJNAME}_PKG_CONFIG}")
Ghislain MARY's avatar
Ghislain MARY committed
739 740
		else()
			set(LINPHONE_BUILDER_PKG_CONFIG "${PKG_CONFIG_PROGRAM}")
741 742
		endif()

Ghislain MARY's avatar
Ghislain MARY committed
743
		if(EP_${PROJNAME}_CONFIGURE_EXTRA_CMD)
744
			set(LINPHONE_BUILDER_CONFIGURE_EXTRA_CMD "${EP_${PROJNAME}_CONFIGURE_EXTRA_CMD}")
745 746
		else()
			set(LINPHONE_BUILDER_CONFIGURE_EXTRA_CMD "")
747 748
		endif()

749 750 751 752
		# 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)
753 754 755 756 757 758

		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
		)
759 760
	else()
		# Use CMake build method
Ghislain MARY's avatar
Ghislain MARY committed
761 762 763 764 765 766 767
		if(NOT EP_${PROJNAME}_LINKING_TYPE) # Apply default CMake linking type if not set explicitely
			if(EP_${PROJNAME}_PLUGIN)
				set(EP_${PROJNAME}_LINKING_TYPE ${DEFAULT_VALUE_CMAKE_PLUGIN_LINKING_TYPE})
			else()
				set(EP_${PROJNAME}_LINKING_TYPE ${DEFAULT_VALUE_CMAKE_LINKING_TYPE})
			endif()
		endif()
768 769 770 771
		set(BUILD_COMMANDS
			CMAKE_ARGS ${EP_${PROJNAME}_CMAKE_OPTIONS} ${EP_${PROJNAME}_LINKING_TYPE}
			CMAKE_CACHE_ARGS ${LINPHONE_BUILDER_EP_ARGS}
		)
772
	endif()
773

774
	if(LINPHONE_BUILDER_LATEST AND EP_${PROJNAME}_GIT_TAG_LATEST)
775
		set(DOWNLOAD_SOURCE GIT_REPOSITORY ${EP_${PROJNAME}_GIT_REPOSITORY} GIT_TAG ${EP_${PROJNAME}_GIT_TAG_LATEST})
776
	elseif(EP_${PROJNAME}_SOURCE_DIR)
777
		set(DOWNLOAD_SOURCE SOURCE_DIR "${EP_${PROJNAME}_SOURCE_DIR}")
778 779 780 781 782
	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()
Ghislain MARY's avatar
Ghislain MARY committed
783 784 785
	elseif(EP_${PROJNAME}_SVN_REPOSITORY)
		set(DOWNLOAD_SOURCE SVN_REPOSITORY ${EP_${PROJNAME}_SVN_REPOSITORY})
	else()
786
		set(DOWNLOAD_SOURCE GIT_REPOSITORY ${EP_${PROJNAME}_GIT_REPOSITORY} GIT_TAG ${EP_${PROJNAME}_GIT_TAG})
787
	endif()
788

789 790
	linphone_builder_filter_out_inexistent_dependencies(${PROJNAME})

791 792
	ExternalProject_Add(EP_${PROJNAME}
		DEPENDS ${EP_${PROJNAME}_DEPENDENCIES}
793
		BINARY_DIR "${ep_build}"
794
		${DOWNLOAD_SOURCE}
795
		PATCH_COMMAND ${EP_${PROJNAME}_PATCH_COMMAND}
796
		CMAKE_GENERATOR ${ep_generator}
Ghislain MARY's avatar
Ghislain MARY committed
797
		${BUILD_COMMANDS}
798
	)
799

800 801
	if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/builders/${PROJNAME}/postinstall.cmake)
		ExternalProject_Add_Step(EP_${PROJNAME} postinstall
802
			COMMAND ${CMAKE_COMMAND} -DTOOLCHAIN_RANLIB=${TOOLCHAIN_RANLIB} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DINSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -P ${CMAKE_CURRENT_SOURCE_DIR}/builders/${PROJNAME}/postinstall.cmake
803 804
			COMMENT "Performing post-installation for 'EP_${PROJNAME}'"
			DEPENDEES install
805 806
			WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
		)
807
	endif()
808
	if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/builders/${PROJNAME}/postconfig.cmake)
809
		ExternalProject_Add_Step(EP_${PROJNAME} postconfig
810
			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
811 812 813 814 815 816 817 818 819 820 821 822
			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()
823 824 825 826
		ExternalProject_Add_Step(EP_${PROJNAME} force_build
			COMMENT "Forcing build for 'EP_${PROJNAME}'"
			DEPENDEES configure
			DEPENDERS build
827 828 829
			ALWAYS 1
		)
		unset(_source_dirs)
830 831
	endif()

832 833
	linphone_builder_restore_flags()

834
endmacro()
Ghislain MARY's avatar
Ghislain MARY committed
835

836
macro(linphone_builder_add_grouped_external_source_path_project PROJNAME FILENAME)
837
	linphone_builder_filter_out_inexistent_dependencies(${PROJNAME})
838
	file(APPEND "${FILENAME}" "add_subdirectory(\"${EP_${PROJNAME}_SOURCE_DIR}\" \"${LINPHONE_BUILDER_WORK_DIR}/Build/${PROJNAME}\")\n")
839
	list(APPEND EP_linphone_builder_LINKING_TYPE "${EP_${PROJNAME}_LINKING_TYPE}")
840
	list(APPEND EP_linphone_builder_CMAKE_OPTIONS "${EP_${PROJNAME}_CMAKE_OPTIONS}")
841 842 843
	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}")
844
	list(APPEND EP_linphone_builder_EXTRA_LDFLAGS "${EP_${PROJNAME}_EXTRA_LDFLAGS}")
845
	list(APPEND EP_linphone_builder_EXTRA_OBJCFLAGS "${EP_${PROJNAME}_EXTRA_OBJCFLAGS}")
846 847
	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}")
848
	if(EP_${PROJNAME}_DEPENDENCIES)
849
		list(APPEND EP_linphone_builder_DEPENDENCIES ${EP_${PROJNAME}_DEPENDENCIES})
850
	endif()
851
endmacro()
852

853
macro(linphone_builder_add_external_projects)
854
	foreach(BUILDER ${LINPHONE_BUILDER_INCLUDED_BUILDERS})
855 856
		list(FIND LINPHONE_BUILDER_INCLUDED_BUILDERS_TO_EXCLUDE ${BUILDER} _excluded_found)
		list(FIND LINPHONE_BUILDER_EXTERNAL_SOURCE_PATH_BUILDERS ${BUILDER} _external_source_path_found)
857
		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)))
858 859 860
			linphone_builder_add_external_project(${BUILDER})
		endif()
	endforeach()
861
endmacro()