CMakeLists.txt 24.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
############################################################################
# CMakeLists.txt
# 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
find_library(LIBM NAMES m)
24 25

# See: https://cmake.org/cmake/help/v3.12/policy/CMP0072.html
26 27 28
if(${CMAKE_VERSION} VERSION_GREATER "3.11")
	cmake_policy(SET CMP0072 NEW)
endif()
29

Ghislain MARY's avatar
Ghislain MARY committed
30 31
if(ANDROID)
	find_library(ANDROID_CPU_FEATURES_LIBRARY NAMES cpufeatures)
32
	find_library(ANDROID_SUPPORT_LIBRARY NAMES support)
Ghislain MARY's avatar
Ghislain MARY committed
33
endif()
34

35
if(MSVC AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone" AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
36
	find_library(LIBGCC NAMES gcc)
37
	find_library(LIBMINGWEX NAMES mingwex)
38
endif()
Ghislain MARY's avatar
Ghislain MARY committed
39

40 41 42
find_program(AWK_PROGRAM awk)
if(NOT AWK_PROGRAM)
	message(FATAL_ERROR "You need the awk program to build mediastreamer2.")
43
endif()
44

45
set(BASE_SOURCE_FILES_C
46 47
	base/eventqueue.c
	base/mscommon.c
48
	base/msfactory.c
49 50 51 52
	base/msfilter.c
	base/msqueue.c
	base/mssndcard.c
	base/msticker.c
53
	base/msvideopresets.c
54 55
	base/mswebcam.c
	base/mtu.c
56
	base/msasync.c
57 58 59 60 61
	otherfilters/itc.c
	otherfilters/join.c
	otherfilters/tee.c
	otherfilters/void.c
)
62 63 64
if(ANDROID)
	list(APPEND BASE_SOURCE_FILES_C utils/msjava.c)
endif()
65

66 67
bc_git_version(ms2 ${PROJECT_VERSION})

68 69
add_custom_target(ms2-basedescs-header
	COMMAND ${CMAKE_COMMAND} -DAWK_PROGRAM=${AWK_PROGRAM} -DAWK_SCRIPTS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../"
70
		-DINPUT_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR}
71
		-DTYPE=base -DSOURCE_FILES="${BASE_SOURCE_FILES_C}"
72 73
		-P "${CMAKE_CURRENT_SOURCE_DIR}/generate_descs_header.cmake"
	BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/basedescs.h")
74 75 76

add_definitions(
	-D_TRUE_TIME
77
	-DMS2_EXPORTS
78 79
	-DMS2_INTERNAL
	-DMS2_FILTERS
80
	-DBCTBX_LOG_DOMAIN="mediastreamer"
81
)
82

83
set(BASE_LIBS
84
	${BCTOOLBOX_CORE_LIBRARIES} ${ORTP_LIBRARIES}
85
)
86
if(WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone" AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
87
	list(APPEND BASE_LIBS ${LIBGCC} ${LIBMINGWEX} ole32 oleaut32 uuid Winmm Ws2_32)
88 89 90 91
endif()
if(HAVE_DLOPEN)
	list(APPEND BASE_LIBS dl)
endif()
92

93
bc_apply_compile_flags(BASE_SOURCE_FILES_C STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
94

95
if(ENABLE_STATIC)
96
	add_library(mediastreamer_base-static STATIC ${MEDIASTREAMER2_HEADER_FILES} ${BASE_SOURCE_FILES_C})
97
	set_target_properties(mediastreamer_base-static PROPERTIES OUTPUT_NAME mediastreamer_base)
98 99
	target_include_directories(mediastreamer_base-static PUBLIC ${MEDIASTREAMER2_INCLUDE_DIRS})
	target_link_libraries(mediastreamer_base-static INTERFACE ${BASE_LIBS})
100
	add_dependencies(mediastreamer_base-static ms2-git-version ms2-basedescs-header)
101 102 103 104 105 106
	install(TARGETS mediastreamer_base-static EXPORT ${EXPORT_TARGETS_NAME}Targets
		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
		PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
	)
endif()
if(ENABLE_SHARED)
107
	add_library(mediastreamer_base SHARED ${MEDIASTREAMER2_HEADER_FILES} ${BASE_SOURCE_FILES_C})
108
	set_target_properties(mediastreamer_base PROPERTIES LINKER_LANGUAGE CXX)
109
	#TODO: replace by if(APPLE) when we want to make apple framework on linphone-desktop too
110
	if(IOS)
111 112 113 114 115 116
		if(IOS)
			set(MIN_OS ${LINPHONE_IOS_DEPLOYMENT_TARGET})
		else()
			set(MIN_OS ${CMAKE_OSX_DEPLOYMENT_TARGET})
		endif()
		set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/build/osx/")
117 118
		set_target_properties(mediastreamer_base PROPERTIES
			FRAMEWORK TRUE
119 120
			MACOSX_FRAMEWORK_IDENTIFIER org.linphone.mediastreamerbase
  			MACOSX_FRAMEWORK_INFO_PLIST Info_base.plist.in
121
		)
122
	endif()
123
	if(NOT ANDROID)
124 125
		# Do not version shared library on Android
		set_target_properties(mediastreamer_base PROPERTIES SOVERSION ${MEDIASTREAMER_SO_VERSION})
126
	endif()
127
	target_include_directories(mediastreamer_base PUBLIC ${MEDIASTREAMER2_INCLUDE_DIRS})
128
	target_link_libraries(mediastreamer_base PRIVATE ${BASE_LIBS})
129
	add_dependencies(mediastreamer_base ms2-git-version ms2-basedescs-header)
130
	if(MSVC)
131 132
		if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
			install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/mediastreamer_base.pdb
133
				DESTINATION ${CMAKE_INSTALL_BINDIR}
134 135 136 137
				PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
			)
		endif()
	endif()
138 139 140 141
	install(TARGETS mediastreamer_base EXPORT ${EXPORT_TARGETS_NAME}Targets
		RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
		LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
142
		FRAMEWORK DESTINATION Frameworks
143 144
		PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
	)
145
endif()
146 147 148



149
set(VOIP_SOURCE_FILES_C
150 151 152
	audiofilters/alaw.c
	audiofilters/audiomixer.c
	audiofilters/chanadapt.c
153
	audiofilters/devices.c
154 155
	audiofilters/dtmfgen.c
	audiofilters/equalizer.c
156
	audiofilters/flowcontrol.c
157 158
	audiofilters/g711.c
	audiofilters/g711.h
johan's avatar
johan committed
159
	audiofilters/genericplc.h
160
	audiofilters/genericplc.c
johan's avatar
johan committed
161
	audiofilters/msgenericplc.c
162 163 164
	audiofilters/l16.c
	audiofilters/msfileplayer.c
	audiofilters/msfilerec.c
165 166
	audiofilters/asyncrw.c
	audiofilters/asyncrw.h
167
	audiofilters/msg722.c
168
	audiofilters/msvaddtx.c
169 170 171 172
	audiofilters/msvolume.c
	audiofilters/tonedetector.c
	audiofilters/ulaw.c
	audiofilters/waveheader.h
173
	crypto/dtls_srtp.c
174
	crypto/ms_srtp.c
175
	crypto/zrtp.c
176 177
	otherfilters/msrtp.c
	utils/_kiss_fft_guts.h
178
	utils/audiodiff.c
179 180 181 182 183 184 185 186
	utils/dsptools.c
	utils/g722.h
	utils/g722_decode.c
	utils/g722_encode.c
	utils/kiss_fft.c
	utils/kiss_fft.h
	utils/kiss_fftr.c
	utils/kiss_fftr.h
187 188
	utils/pcap_sender.c
	utils/pcap_sender.h
189
	utils/stream_regulator.c
DanmeiChen's avatar
DanmeiChen committed
190
	utils/srtp_prefix.h
191 192
	voip/audioconference.c
	voip/audiostream.c
193
	voip/bandwidthcontroller.c
194 195 196 197
	voip/bitratecontrol.c
	voip/bitratedriver.c
	voip/ice.c
	voip/mediastream.c
198
	voip/msiframerequestslimiter.c
199
	voip/msmediaplayer.c
200 201 202
	voip/msvoip.c
	voip/private.h
	voip/qosanalyzer.c
203
	voip/qosanalyzer.h
204
	voip/qualityindicator.c
205 206
	otherfilters/rfc4103_source.c
	otherfilters/rfc4103_sink.c
207
	otherfilters/msudp.c
208
	voip/rfc4103_textstream.c
209
	voip/ringstream.c
210
	voip/stun.c
211
)
212
set(VOIP_SOURCE_FILES_CXX
213 214
	utils/filter-wrapper/decoding-filter-wrapper.cpp
	utils/filter-wrapper/encoding-filter-wrapper.cpp
215
)
216
set(VOIP_SOURCE_FILES_OBJC )
217
set(VOIP_SOURCE_FILES_ASM )
218

219
if(ENABLE_ALSA)
220
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/alsa.c)
221
endif()
Ghislain MARY's avatar
Ghislain MARY committed
222 223 224
if(ANDROID)
	list(APPEND VOIP_SOURCE_FILES_CXX voip/msvoip_jni.cc)
endif()
225 226 227 228 229 230 231 232 233 234 235
if(ENABLE_ANDROIDSND)
	list(APPEND VOIP_SOURCE_FILES_CXX
		android/androidsound.cpp
		android/androidsound_depr.cpp
		android/androidsound_opensles.cpp
		android/AudioRecord.cpp
		android/AudioSystem.cpp
		android/AudioTrack.cpp
		android/hardware_echo_canceller.cpp
		android/loader.cpp
		android/String8.cpp
Erwan Croze's avatar
Erwan Croze committed
236 237
		#audiofilters/aac-eld-android.cpp
		#Not working on Android, to be fix
238 239
	)
endif()
240
if(ENABLE_ARTSC)
241
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/arts.c)
242 243
endif()
if(ENABLE_MACSND)
244
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/macsnd.c)
245 246
endif()
if(ENABLE_MACAQSND)
247
	list(APPEND VOIP_SOURCE_FILES_OBJC audiofilters/aqsnd.m)
248 249
endif()
if(ENABLE_OSS)
250
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/oss.c)
251 252
endif()
if(ENABLE_PORTAUDIO)
253
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/pasnd.c)
254 255
endif()
if(ENABLE_PULSEAUDIO)
256
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/pulseaudio.c)
257 258
endif()
if(ENABLE_QSA)
259
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/qsa.c)
260
endif()
261
if(APPLE)
262
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/aac-eld.c)
263 264
endif()
if(IOS)
265
	list(APPEND VOIP_SOURCE_FILES_OBJC audiofilters/msiounit.m)
266
endif()
267

268 269 270
if(ENABLE_G726)
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/g726.c)
endif()
271 272 273
if(BCG729_FOUND AND ENABLE_G729)
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/g729.c)
endif()
274
if(GSM_FOUND)
275
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/gsm.c)
276
endif()
277 278 279
if(BV16_FOUND)
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/bv16.c)
endif()
280
if(OPUS_FOUND)
281
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/msopus.c)
282 283
endif()
if(ENABLE_RESAMPLE)
284
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/msresample.c)
285 286
endif()
if(SPEEX_FOUND)
287 288 289 290
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/msspeex.c)
endif()
if(SPEEXDSP_FOUND)
	list(APPEND VOIP_SOURCE_FILES_C audiofilters/speexec.c)
291
endif()
292

293
if(ENABLE_VIDEO)
294
	list(APPEND VOIP_SOURCE_FILES_C
295
		utils/bits_rw.c
296 297
		videofilters/extdisplay.c
		videofilters/mire.c
298
		videofilters/nowebcam.c
299 300 301 302 303 304
		videofilters/pixconv.c
		videofilters/sizeconv.c
		voip/layouts.c
		voip/layouts.h
		voip/msvideo_neon.c
		voip/msvideo_neon.h
305
		voip/msvideo.c
306
		voip/nowebcam.h
307
		voip/rfc2429.h
308
		voip/video_preset_high_fps.c
Ghislain MARY's avatar
Ghislain MARY committed
309
		voip/videostarter.c
310 311
		voip/videostream.c
	)
312 313 314 315 316 317 318 319 320
	if(FFMPEG_FOUND AND NOT TURBOJPEG_FOUND)
		list(APPEND VOIP_SOURCE_FILES_C
			videofilters/ffmpegnowebcam.c
		)
	elseif(TURBOJPEG_FOUND)
		list(APPEND VOIP_SOURCE_FILES_C
			videofilters/turbojpegnowebcam.c
		)
	endif()
321
	if(WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone" AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
322
		add_definitions(-DHAVE_DIRECTSHOW)
323
		list(APPEND VOIP_SOURCE_FILES_C
324 325
			videofilters/drawdib-display.c
		)
326
		list(APPEND VOIP_SOURCE_FILES_CXX
327
			videofilters/msdscap.cc
328
		)
329
	endif()
330
	if(APPLE)
331
		if(IOS)
332
			list(APPEND VOIP_SOURCE_FILES_C
Ronan's avatar
Ronan committed
333 334
				utils/opengl_functions.c
				utils/opengl_functions.h
335 336
				utils/opengles_display.c
				utils/opengles_display.h
Ronan's avatar
Ronan committed
337 338
				utils/shader_util.c
				utils/shader_util.h
339 340 341
				voip/scaler.c
			)
			list(APPEND VOIP_SOURCE_FILES_OBJC
342 343 344 345 346
				videofilters/iosdisplay.m
				videofilters/ioscapture.m
				voip/ioshardware.m
			)
		else()
347
			list(APPEND VOIP_SOURCE_FILES_OBJC
348
				videofilters/msosxdisplay.m
349
				videofilters/avfound-capture.m
350
			)
351

352
			list(APPEND VOIP_SOURCE_FILES_C
Ronan's avatar
Ronan committed
353 354
				utils/opengl_functions.c
				utils/opengl_functions.h
355 356
				utils/opengles_display.c
				utils/opengles_display.h
Ronan's avatar
Ronan committed
357 358
				utils/shader_util.c
				utils/shader_util.h
359 360
			)
		endif()
361
	endif()
362 363 364 365
	if(ANDROID)
		list(APPEND VOIP_SOURCE_FILES_C
			android/android-display.c
			android/android-opengl-display.c
Ronan's avatar
Ronan committed
366 367
			utils/opengl_functions.c
			utils/opengl_functions.h
368 369
			utils/opengles_display.c
			utils/opengles_display.h
Ronan's avatar
Ronan committed
370 371
			utils/shader_util.c
			utils/shader_util.h
372 373
			voip/scaler.c
		)
374
		if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a")
375 376 377 378 379 380 381 382 383 384
			list(APPEND VOIP_SOURCE_FILES_ASM
				voip/scaler_arm.S
			)
		endif()
		list(APPEND VOIP_SOURCE_FILES_CXX
			android/android_mediacodec.cpp
			android/android-display-bad.cpp
			android/androidvideo.cpp
		)
	endif()
385
	if (ENABLE_QNX)
386 387 388 389 390
		list(APPEND VOIP_SOURCE_FILES_CXX
			videofilters/bb10_display.cpp
			videofilters/bb10_capture.cpp
		)
	endif()
391
	if(FFMPEG_FOUND)
392
		list(APPEND VOIP_SOURCE_FILES_C
393
			utils/ffmpeg-priv.c
394
			utils/ffmpeg-priv.h
395 396 397 398
			utils/swscale.h
			videofilters/videodec.c
			videofilters/videoenc.c
		)
399 400 401
		list(APPEND VOIP_SOURCE_FILES_CXX
			videofilters/h264dec.cpp
		)
402 403 404 405 406 407 408 409 410 411
		if(NOT TURBOJPEG_FOUND)
			list(APPEND VOIP_SOURCE_FILES_C
				videofilters/ffmpegjpegwriter.c
			)
		endif()
	endif()
	if(TURBOJPEG_FOUND)
		list(APPEND VOIP_SOURCE_FILES_C
			videofilters/turbojpegwriter.c
		)
412 413 414
		if(TURBOJPEG_USE_CONST_BUFFERS)
			set_source_files_properties(videofilters/turbojpegwriter.c PROPERTIES COMPILE_DEFINITIONS "TURBOJPEG_USE_CONST_BUFFERS")
		endif()
415
	endif()
Erwan Croze's avatar
Erwan Croze committed
416 417
	if(ZXING_FOUND)
		list(APPEND VOIP_SOURCE_FILES_CXX
418
			videofilters/zxing_qrcode.cpp
Erwan Croze's avatar
Erwan Croze committed
419 420 421
			utils/qrcode_image.cpp
		)
	endif()
422
	if(OPENGL_FOUND OR QTANGLE_FOUND)
423
		list(APPEND VOIP_SOURCE_FILES_C
Ronan's avatar
Ronan committed
424
			utils/opengl_functions.c
425
			utils/opengles_display.c
Ronan's avatar
Ronan committed
426
			utils/shader_util.c
427
			videofilters/generic_opengl_display.c
428
		)
429
	endif()
430
	if(GLX_FOUND)
431 432 433 434 435 436
		list(APPEND VOIP_SOURCE_FILES_C
			utils/opengl_functions.c
			utils/opengles_display.c
			utils/shader_util.c
			videofilters/glxvideo.c
		)
437
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
438
	if(NOT APPLE AND NOT ANDROID AND OPENGL_FOUND OR GLX_FOUND)
jehan's avatar
jehan committed
439 440
		find_package(Glew REQUIRED)
	endif()
441
	if(SDL_FOUND)
442
		list(APPEND VOIP_SOURCE_FILES_C videofilters/videoout.c)
443 444
	endif()
	if(THEORA_FOUND)
445
		list(APPEND VOIP_SOURCE_FILES_C videofilters/theora.c)
446
	endif()
447 448
	if(V4L_FOUND)
		if(HAVE_LINUX_VIDEODEV_H)
449
			list(APPEND VOIP_SOURCE_FILES_C videofilters/msv4l.c)
450 451
		endif()
		if(HAVE_LINUX_VIDEODEV2_H)
452
			list(APPEND VOIP_SOURCE_FILES_C videofilters/msv4l2.c)
453 454
		endif()
	endif()
455
	if(VPX_FOUND)
456
		list(APPEND VOIP_SOURCE_FILES_C
457 458 459 460 461 462
			videofilters/vp8.c
			voip/vp8rtpfmt.c
			voip/vp8rtpfmt.h
		)
	endif()
	if(X11_FOUND)
463
		list(APPEND VOIP_SOURCE_FILES_C utils/x11_helper.c)
464 465
	endif()
	if(XV_FOUND)
466
		list(APPEND VOIP_SOURCE_FILES_C videofilters/x11video.c)
467 468
	endif()
endif()
469
if(BCMATROSKA2_FOUND)
470 471 472
	list(APPEND VOIP_SOURCE_FILES_C
		utils/mkv_reader.c
		voip/rfc2429.h
473 474 475
	)
	list(APPEND VOIP_SOURCE_FILES_CXX
		videofilters/mkv.cpp
476 477
	)
endif()
478

479
if(PCAP_FOUND)
jehan's avatar
jehan committed
480
	list(APPEND VOIP_SOURCE_FILES_C otherfilters/mspcapfileplayer.c)
481
endif()
482
set(VOIP_SOURCE_FILES_ALL ${VOIP_SOURCE_FILES_C} ${VOIP_SOURCE_FILES_CXX} ${VOIP_SOURCE_FILES_OBJC})
483 484 485

add_custom_target(ms2-voipdescs-header
	COMMAND ${CMAKE_COMMAND} -DAWK_PROGRAM=${AWK_PROGRAM} -DAWK_SCRIPTS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../"
486
		-DINPUT_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR}
487
		-DTYPE=voip -DSOURCE_FILES="${VOIP_SOURCE_FILES_ALL}"
488 489
		-P "${CMAKE_CURRENT_SOURCE_DIR}/generate_descs_header.cmake"
	BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/voipdescs.h"
490
)
491

492
if(APPLE OR ANDROID OR OPENGL_FOUND OR GLX_FOUND OR QTANGLE_FOUND)
493
	find_package(PythonInterp REQUIRED)
494 495 496 497 498
	find_program(SED_PROGRAM sed)
	if(NOT SED_PROGRAM)
		message(FATAL_ERROR "You need the sed program to build mediastreamer2.")
	endif()
	add_custom_target(ms2-yuv2rgb-fs-header
499
		COMMAND ${CMAKE_COMMAND} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -DSED_PROGRAM=${SED_PROGRAM}
500 501 502 503 504 505
			-DINPUT_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR}
			-DSOURCE_FILE="yuv2rgb.fs"
			-P "${CMAKE_CURRENT_SOURCE_DIR}/generate_yuv2rgb_header.cmake"
		BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/yuv2rgb.fs.h"
	)
	add_custom_target(ms2-yuv2rgb-vs-header
506
		COMMAND ${CMAKE_COMMAND} -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} -DSED_PROGRAM=${SED_PROGRAM}
507 508 509 510 511
			-DINPUT_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR}
			-DSOURCE_FILE="yuv2rgb.vs"
			-P "${CMAKE_CURRENT_SOURCE_DIR}/generate_yuv2rgb_header.cmake"
		BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/yuv2rgb.vs.h"
	)
512
endif()
513

514
if(ENABLE_VIDEO)
515 516 517
	add_subdirectory(voip/h26x)
endif()

518 519
bc_apply_compile_flags(VOIP_SOURCE_FILES_C STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
bc_apply_compile_flags(VOIP_SOURCE_FILES_OBJC STRICT_OPTIONS_CPP STRICT_OPTIONS_OBJC)
520 521
if(VOIP_SOURCE_FILES_CXX)
	set_source_files_properties(${VOIP_SOURCE_FILES_CXX} PROPERTIES LANGUAGE CXX)
522
	bc_apply_compile_flags(VOIP_SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
523
endif()
524

525

526
if(ENABLE_VIDEO AND ANDROID AND CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a")
527 528 529 530
	set(NEON_SOURCE_FILES
		voip/msvideo_neon.c
		voip/scaler.c
	)
531 532 533 534 535 536
endif()


if(VOIP_SOURCE_FILES_ASM)
	get_directory_property(DIRECTORY_PROPERTY_COMPILE_OPTIONS "COMPILE_OPTIONS")
	string(REPLACE ";" " " DIRECTORY_PROPERTY_COMPILE_OPTIONS "${DIRECTORY_PROPERTY_COMPILE_OPTIONS}")
Ghislain MARY's avatar
Ghislain MARY committed
537 538 539 540 541
	set(CMAKE_ASM_TARGET_FLAG "")
	if(CMAKE_C_COMPILER_TARGET)
		set(CMAKE_ASM_TARGET_FLAG "--target=${CMAKE_C_COMPILER_TARGET}")
	endif()
	set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> ${CMAKE_ASM_TARGET_FLAG} ${CMAKE_CPP_FLAGS} ${CMAKE_C_FLAGS} ${DIRECTORY_PROPERTY_COMPILE_OPTIONS} ${ARCH_OPTIONS} -o <OBJECT> -c <SOURCE>")
542 543 544 545
	enable_language(ASM)
endif()


546
set(VOIP_LIBS
547
	${BCTOOLBOX_CORE_LIBRARIES}
548
	${ORTP_LIBRARIES}
549
)
550
if(WIN32)
551
	if(NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone" AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
Ghislain MARY's avatar
Ghislain MARY committed
552
		list(APPEND VOIP_LIBS ${LIBGCC} ${LIBMINGWEX} ole32 oleaut32 uuid Winmm Ws2_32)
553
		if(ENABLE_VIDEO)
554
			list(APPEND VOIP_LIBS gdi32 strmiids user32 vfw32)
555
		endif()
556
	endif()
557
endif()
558 559 560
if(LIBM)
	list(APPEND VOIP_LIBS ${LIBM})
endif()
Ghislain MARY's avatar
Ghislain MARY committed
561 562 563
if(ANDROID_CPU_FEATURES_LIBRARY)
	list(APPEND VOIP_LIBS ${ANDROID_CPU_FEATURES_LIBRARY})
endif()
564 565 566
if(ANDROID_SUPPORT_LIBRARY)
	list(APPEND VOIP_LIBS ${ANDROID_SUPPORT_LIBRARY})
endif()
567 568 569
if(ANDROID AND ENABLE_VIDEO)
	list(APPEND VOIP_LIBS GLESv2)
endif()
570 571 572
if(HAVE_DLOPEN)
	list(APPEND VOIP_LIBS dl)
endif()
573 574 575
if(PCAP_FOUND)
	list(APPEND VOIP_LIBS ${PCAP_LIBRARIES})
endif()
576 577 578
if(BZRTP_FOUND)
	list(APPEND VOIP_LIBS ${BZRTP_LIBRARIES})
endif()
johan's avatar
johan committed
579 580 581
if(SRTP_FOUND)
	list(APPEND VOIP_LIBS ${SRTP_LIBRARIES})
endif()
582 583 584
if(SPANDSP_FOUND)
	list(APPEND VOIP_LIBS ${SPANDSP_LIBRARIES})
endif()
585 586 587 588 589 590 591 592 593
if(GSM_FOUND)
	list(APPEND VOIP_LIBS ${GSM_LIBRARIES})
endif()
if(OPUS_FOUND)
	list(APPEND VOIP_LIBS ${OPUS_LIBRARIES})
endif()
if(SPEEX_FOUND)
	list(APPEND VOIP_LIBS ${SPEEX_LIBRARIES})
endif()
594 595 596
if(SPEEXDSP_FOUND)
	list(APPEND VOIP_LIBS ${SPEEXDSP_LIBRARIES})
endif()
597 598 599
if(BV16_FOUND)
	list(APPEND VOIP_LIBS ${BV16_LIBRARIES})
endif()
600 601 602 603 604 605 606 607 608 609 610 611 612 613
if(ALSA_FOUND)
	list(APPEND VOIP_LIBS ${ALSA_LIBRARIES})
endif()
if(ARTS_FOUND)
	list(APPEND VOIP_LIBS ${ARTS_LIBRARIES})
endif()
if(PORTAUDIO_FOUND)
	list(APPEND VOIP_LIBS ${PORTAUDIO_LIBRARIES})
endif()
if(PULSEAUDIO_FOUND)
	list(APPEND VOIP_LIBS ${PULSEAUDIO_LIBRARIES})
endif()
if(QSA_FOUND)
	list(APPEND VOIP_LIBS ${QSA_LIBRARIES})
614
	list(APPEND VOIP_LIBS ${QNXAUDIOMANAGER_LIBRARIES})
615 616 617 618 619 620 621
endif()
if(FFMPEG_FOUND)
	list(APPEND VOIP_LIBS ${FFMPEG_LIBRARIES})
	if(MSVC)
		add_definitions(-Dinline=__inline)
	endif()
endif()
622 623 624
if(V4L_FOUND)
	list(APPEND VOIP_LIBS ${V4L_LIBRARIES})
endif()
625 626 627 628 629 630 631 632 633
if(X11_FOUND)
	list(APPEND VOIP_LIBS ${X11_LIBRARIES})
endif()
if(XV_FOUND)
	list(APPEND VOIP_LIBS ${XV_LIBRARIES})
endif()
if(GLX_FOUND)
	list(APPEND VOIP_LIBS ${GLX_LIBRARIES})
endif()
jehan's avatar
jehan committed
634 635 636
if(GLEW_FOUND)
	list(APPEND VOIP_LIBS ${GLEW_LIBRARIES})
endif()
Ghislain MARY's avatar
Ghislain MARY committed
637 638 639
if(THEORA_FOUND)
	list(APPEND VOIP_LIBS ${THEORA_LIBRARIES})
endif()
640 641 642
if(VPX_FOUND)
	list(APPEND VOIP_LIBS ${VPX_LIBRARIES})
endif()
643 644
if(BCMATROSKA2_FOUND)
	list(APPEND VOIP_LIBS ${BCMATROSKA2_LIBRARIES})
645
endif()
646 647 648 649 650
if (SCREEN_FOUND)
	list(APPEND VOIP_LIBS ${SCREEN_LIBRARIES})
endif()
if (CAMAPI_FOUND)
	list(APPEND VOIP_LIBS ${CAMAPI_LIBRARIES})
651
endif()
652 653 654
if(TURBOJPEG_FOUND)
	list(APPEND VOIP_LIBS ${TURBOJPEG_LIBRARIES})
endif()
Erwan Croze's avatar
Erwan Croze committed
655 656 657
if(ZXING_FOUND)
	list(APPEND VOIP_LIBS ${ZXING_LIBRARIES})
endif()
658 659 660 661
if(BCG729_FOUND)
	if(ENABLE_G729_CNG)
		add_definitions("-DHAVE_G729B=1")
	endif()
jehan's avatar
jehan committed
662 663
	list(APPEND VOIP_LIBS ${BCG729_LIBRARIES})
endif()
664
set(MS2_VOIP_DEPENDENCIES ms2-git-version ms2-voipdescs-header)
665
if(APPLE OR ANDROID OR OPENGL_FOUND OR GLX_FOUND OR QTANGLE_FOUND)
666
	list(APPEND MS2_VOIP_DEPENDENCIES ms2-yuv2rgb-fs-header ms2-yuv2rgb-vs-header)
667 668 669
endif()

string(REPLACE ";" " " LINK_FLAGS_STR "${LINK_FLAGS}")
670
if(ENABLE_STATIC)
671
	add_library(mediastreamer_voip-static STATIC ${MEDIASTREAMER2_HEADER_FILES} ${VOIP_SOURCE_FILES_C} ${VOIP_SOURCE_FILES_CXX} ${VOIP_SOURCE_FILES_OBJC} ${VOIP_SOURCE_FILES_ASM})
672 673 674 675
	set_target_properties(mediastreamer_voip-static PROPERTIES OUTPUT_NAME mediastreamer_voip)
	if(LINK_FLAGS_STR)
		set_target_properties(mediastreamer_voip-static PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
	endif()
676
	add_dependencies(mediastreamer_voip-static ${MS2_VOIP_DEPENDENCIES})
677 678
	target_include_directories(mediastreamer_voip-static PUBLIC ${MEDIASTREAMER2_INCLUDE_DIRS})
	target_link_libraries(mediastreamer_voip-static INTERFACE mediastreamer_base-static ${VOIP_LIBS})
679 680 681 682 683 684
	install(TARGETS mediastreamer_voip-static EXPORT ${EXPORT_TARGETS_NAME}Targets
		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
		PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
	)
endif()
if(ENABLE_SHARED)
685
	add_library(mediastreamer_voip SHARED ${MEDIASTREAMER2_HEADER_FILES} ${VOIP_SOURCE_FILES_C} ${VOIP_SOURCE_FILES_CXX} ${VOIP_SOURCE_FILES_OBJC} ${VOIP_SOURCE_FILES_ASM})
686
	set_target_properties(mediastreamer_voip PROPERTIES LINKER_LANGUAGE CXX)
687 688 689
	if(LINK_FLAGS_STR)
		set_target_properties(mediastreamer_voip PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
	endif()
690
	add_dependencies(mediastreamer_voip ${MS2_VOIP_DEPENDENCIES})
691
	#TODO: replace by if(APPLE) when we want to make apple framework on linphone-desktop too
692
	if(IOS)
693 694 695 696 697 698
		if(IOS)
			set(MIN_OS ${LINPHONE_IOS_DEPLOYMENT_TARGET})
		else()
			set(MIN_OS ${CMAKE_OSX_DEPLOYMENT_TARGET})
		endif()
		set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/build/osx/")
699 700
		set_target_properties(mediastreamer_voip PROPERTIES
			FRAMEWORK TRUE
701 702
			MACOSX_FRAMEWORK_IDENTIFIER org.linphone.mediastreamervoip
  			MACOSX_FRAMEWORK_INFO_PLIST Info_voip.plist.in
703
		)
704
	endif()
Sylvain Berfini's avatar
Sylvain Berfini committed
705
	if(ANDROID)
706 707 708 709
		if(ENABLE_VPX)
			set_target_properties(mediastreamer_voip PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,libvpx.a")
		endif()
	else()
710 711
		# Do not version shared library on Android
		set_target_properties(mediastreamer_voip PROPERTIES SOVERSION ${MEDIASTREAMER_SO_VERSION})
712
	endif()
713
	target_include_directories(mediastreamer_voip PUBLIC ${MEDIASTREAMER2_INCLUDE_DIRS})
714
	target_link_libraries(mediastreamer_voip PRIVATE mediastreamer_base ${VOIP_LIBS})
715 716 717
	if(IOS)
		target_link_libraries(mediastreamer_voip INTERFACE "-framework Foundation" "-framework AVFoundation")
	endif()
718
	if(MSVC)
719 720
		if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
			install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/mediastreamer_voip.pdb
721
				DESTINATION ${CMAKE_INSTALL_BINDIR}
722 723 724 725
				PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
			)
		endif()
	endif()
726 727 728 729
	install(TARGETS mediastreamer_voip EXPORT ${EXPORT_TARGETS_NAME}Targets
		RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
		LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
730
		FRAMEWORK DESTINATION Frameworks
731 732
		PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
	)
733
endif()
734 735
if (ENABLE_SHARED AND IOS) 
	
jehan's avatar
jehan committed
736 737 738
	#According to Apple documentation (https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/IncludingFrameworks.html)
	#Framework header files must be included in application code using the #include directive using the followin patern: #include <Framework_name/Header_filename.h>. Consequece for medistreamer2 is that the framework must be named mediastreamer2. The final solution is to replace both mediastreamer_voip and mediastreamer_base by mediastreamer2. To preserve backward compatibility, both mediastreamer_voip and mediastreamer_base are kept for now (2018-05-06)
	add_library(mediastreamer2 SHARED ${MEDIASTREAMER2_HEADER_FILES})
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755
        set_target_properties(mediastreamer2 PROPERTIES LINKER_LANGUAGE CXX)
        add_dependencies(mediastreamer2 mediastreamer_voip)
	target_link_libraries(mediastreamer2 INTERFACE "-framework mediastreamer_base" "-framework mediastreamer_voip" "-framework Foundation" "-framework Foundation" "-framework AVFoundation")
	set_target_properties(mediastreamer2 PROPERTIES
                FRAMEWORK TRUE
                MACOSX_FRAMEWORK_IDENTIFIER org.linphone.mediastreamer
                MACOSX_FRAMEWORK_INFO_PLIST Info.plist.in
                PUBLIC_HEADER "${MEDIASTREAMER2_HEADER_FILES}"
        )
        install(TARGETS mediastreamer2 EXPORT ${EXPORT_TARGETS_NAME}Targets
                RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
                LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
                ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
                FRAMEWORK DESTINATION Frameworks
                PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
        )

jehan's avatar
jehan committed
756
endif()
757

758
if(FFMPEG_FOUND AND NOT WIN32)
759
	set(NO_DEPRECATED_DECLARATIONS_SOURCE_FILES
760
		videofilters/videoenc.c
761
		videofilters/videodec.c
762
		videofilters/h264dec.cpp
763
	)
764 765 766 767 768 769 770
	if(NOT TURBOJPEG_FOUND)
		set(NO_DEPRECATED_DECLARATIONS_SOURCE_FILES
			${NO_DEPRECATED_DECLARATIONS_SOURCE_FILES}
			videofilters/ffmpegjpegwriter.c
			videofilters/nowebcam.c
		)
	endif()
771 772 773 774
	foreach(file ${NO_DEPRECATED_DECLARATIONS_SOURCE_FILES})
		get_source_file_property(NO_DEPRECATED_DECLARATIONS_COMPILE_FLAGS ${file} COMPILE_FLAGS)
		set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "${NO_DEPRECATED_DECLARATIONS_COMPILE_FLAGS} -Wno-error=deprecated-declarations")
	endforeach()
775 776
endif()

777 778 779 780 781
if(ENABLE_VIDEO)
	install(FILES voip/nowebcamCIF.jpg
		DESTINATION ${PACKAGE_DATA_DIR}/images
        PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
	)
782
endif()