CMakeLists.txt 11.5 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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
############################################################################
# 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
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
############################################################################

cmake_minimum_required(VERSION 3.0)
project(LINPHONE_PACKAGE) # Dummy project

find_package(Linphone REQUIRED)
find_package(Git)

if(GIT_EXECUTABLE)
	execute_process(
		COMMAND ${GIT_EXECUTABLE} describe --always
		OUTPUT_VARIABLE LINPHONE_GIT_REVISION
		OUTPUT_STRIP_TRAILING_WHITESPACE
		WORKING_DIRECTORY ${LINPHONE_SOURCE_DIR}
	)
else()
	set(LINPHONE_GIT_REVISION "0.0.0")
endif()
string(REGEX REPLACE "([0-9.]+)-?.*" "\\1" LINPHONE_VERSION "${LINPHONE_GIT_REVISION}")
string(REPLACE "." ";" SPLITTED_LINPHONE_VERSION ${LINPHONE_VERSION})
list(GET SPLITTED_LINPHONE_VERSION 0 LINPHONE_MAJOR_VERSION)
list(GET SPLITTED_LINPHONE_VERSION 1 LINPHONE_MINOR_VERSION)
list(GET SPLITTED_LINPHONE_VERSION 2 LINPHONE_MICRO_VERSION)
44
set(PACKAGE_VERSION "${LINPHONE_VERSION}")
45

46 47
# Translates absolute internal dependency path of FFMepeg libraries into relative path on MacOSX
if(APPLE)
48 49 50 51
	set(LINPHONE_SDK_TMP ${CMAKE_CURRENT_BINARY_DIR}/linphone-sdk-tmp)
	file(REMOVE_RECURSE ${LINPHONE_SDK_TMP})
	file(COPY ${LINPHONE_OUTPUT_DIR} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
	file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/OUTPUT ${LINPHONE_SDK_TMP})
52
	set(RPATH_CHANGE_CMDS
53 54 55 56
		-change ${LINPHONE_OUTPUT_DIR}/lib/libavcodec.53.61.100.dylib @rpath/libavcodec.53.61.100.dylib
		-change ${LINPHONE_OUTPUT_DIR}/lib/libavutil.51.35.100.dylib @rpath/libavutil.51.35.100.dylib
		-change ${LINPHONE_OUTPUT_DIR}/lib/libswscale.2.1.100.dylib @rpath/libswscale.2.1.100.dylib
		-change ${LINPHONE_OUTPUT_DIR}/lib/libswresample.0.6.100.dylib @rpath/libswresample.0.6.100.dylib
57
		-change ${LINPHONE_OUTPUT_DIR}/lib/libopenh264.0.dylib @rpath/libopenh264.0.dylib
58
		-change /opt/local/lib/libintl.8.dylib @rpath/libintl.8.dylib
59
		-change /opt/local/lib/libiconv.2.dylib @rpath/libiconv.2.dylib
60
		-change /lib/libopenh264.0.dylib @rpath/libopenh264.0.dylib
61 62 63 64 65 66 67 68
	)
	set(RPATH_LIBS_TO_MODIFY
		libavcodec.53.61.100.dylib
		libavutil.51.35.100.dylib
		liblinphone.7.dylib
		libmediastreamer_voip.5.dylib
		libswresample.0.6.100.dylib
		libswscale.2.1.100.dylib
69 70 71 72 73 74
		mediastreamer/plugins/libmsamr.dylib
		mediastreamer/plugins/libmsbcg729.dylib
		mediastreamer/plugins/libmsilbc.dylib
		mediastreamer/plugins/libmsopenh264.dylib
		mediastreamer/plugins/libmssilk.dylib
		mediastreamer/plugins/libmswebrtc.dylib
75 76 77
	)
	foreach(LIB_TO_CHANGE ${RPATH_LIBS_TO_MODIFY})
		execute_process(
78 79 80
			COMMAND install_name_tool ${RPATH_CHANGE_CMDS} ${LINPHONE_SDK_TMP}/lib/${LIB_TO_CHANGE}
			COMMAND install_name_tool -id @rpath/${LIB_TO_CHANGE} ${LINPHONE_SDK_TMP}/lib/${LIB_TO_CHANGE}
			COMMAND install_name_tool -delete_rpath ${LINPHONE_OUTPUT_DIR}/lib ${LINPHONE_SDK_TMP}/lib/${LIB_TO_CHANGE}
81 82
		)
	endforeach()
83 84 85 86 87
	file(COPY /opt/local/lib/libintl.8.dylib /opt/local/lib/libintl.dylib /opt/local/lib/libiconv.dylib /opt/local/lib/libiconv.2.dylib DESTINATION ${LINPHONE_SDK_TMP}/lib)
	execute_process(
		COMMAND install_name_tool -id @rpath/libintl.8.dylib -change /opt/local/lib/libiconv.2.dylib @rpath/libiconv.2.dylib ${LINPHONE_SDK_TMP}/lib/libintl.8.dylib
		COMMAND install_name_tool -id @rpath/libiconv.2.dylib ${LINPHONE_SDK_TMP}/lib/libiconv.2.dylib
	)
88
	file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/README.openh264.txt DESTINATION ${LINPHONE_SDK_TMP})
89 90
endif()

91
# Generates a zip archive containing the development files of liblinphone
92
if(WIN32)
93
	find_program(7Z_PROGRAM 7z.exe)
94 95 96 97 98 99 100 101 102 103 104
	if(7Z_PROGRAM)
		execute_process(
			COMMAND ${7Z_PROGRAM} a -tzip ${CMAKE_BINARY_DIR}/linphone-sdk-${LINPHONE_GIT_REVISION}-win32.zip @${CMAKE_SOURCE_DIR}/linphone-sdk.list
			WORKING_DIRECTORY ${LINPHONE_OUTPUT_DIR}
		)
		execute_process(
			COMMAND ${7Z_PROGRAM} a -tzip ${CMAKE_BINARY_DIR}/linphone-sdk-${LINPHONE_GIT_REVISION}-win32.zip ${CMAKE_SOURCE_DIR}/README.openh264.txt
		)
	else()
		message(WARNING "7z has not been found, cannot generate the SDK!")
	endif()
105 106 107 108
elseif(APPLE)
	execute_process(
		COMMAND rm -rf ${CMAKE_BINARY_DIR}/linphone-sdk-${LINPHONE_GIT_REVISION}-mac.zip
		COMMAND zip -ry ${CMAKE_BINARY_DIR}/linphone-sdk-${LINPHONE_GIT_REVISION}-mac.zip . -i @${CMAKE_SOURCE_DIR}/linphone-sdk-mac.list
109
		WORKING_DIRECTORY ${LINPHONE_SDK_TMP}
110
	)
111
endif()
112

113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 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
if(WIN32)
	install(DIRECTORY "${LINPHONE_OUTPUT_DIR}/"
		DESTINATION "."
		COMPONENT "linphone_base"
		PATTERN "doc" EXCLUDE
		PATTERN "etc" EXCLUDE
		PATTERN "include" EXCLUDE
		PATTERN "lib/cmake" EXCLUDE
		PATTERN "lib/gdk-pixbuf-2.0" EXCLUDE
		PATTERN "lib/glib-2.0" EXCLUDE
		PATTERN "lib/mediastreamer" EXCLUDE
		PATTERN "lib/pkgconfig" EXCLUDE
		PATTERN "lib/*.a" EXCLUDE
		PATTERN "lib/*.def" EXCLUDE
		PATTERN "lib/*.exp" EXCLUDE
		PATTERN "lib/*.la" EXCLUDE
		PATTERN "lib/*.lib" EXCLUDE
		PATTERN "man" EXCLUDE
		PATTERN "manifest" EXCLUDE
		PATTERN "share/aclocal" EXCLUDE
		PATTERN "share/CUnit" EXCLUDE
		PATTERN "share/glib-2.0" EXCLUDE
		PATTERN "share/gtk-2.0" EXCLUDE
		PATTERN "share/gtk-doc" EXCLUDE
		PATTERN "share/intltool" EXCLUDE
		PATTERN "share/java" EXCLUDE
		PATTERN "src" EXCLUDE
		PATTERN "gtk+-bundle_*" EXCLUDE
		PATTERN "linphone.lnk" EXCLUDE
		PATTERN "bin/envsubst.exe" EXCLUDE
		PATTERN "bin/fc-*" EXCLUDE
		PATTERN "bin/freetype-config" EXCLUDE
		PATTERN "bin/g*.exe" EXCLUDE
		PATTERN "bin/gettext.sh" EXCLUDE
		PATTERN "bin/glib*" EXCLUDE
		PATTERN "bin/gtk-*" EXCLUDE
		PATTERN "bin/intltool*" EXCLUDE
		PATTERN "bin/ngettext.exe" EXCLUDE
		PATTERN "bin/pango*.exe" EXCLUDE
		PATTERN "bin/pkg-config.exe" EXCLUDE
		PATTERN "bin/xmlwf.exe" EXCLUDE
		PATTERN "bin/openh264.dll" EXCLUDE
	)
156

157 158 159 160 161 162 163 164 165 166 167 168
	install(DIRECTORY "${LINPHONE_OUTPUT_DIR}/lib/mediastreamer/plugins/"
		DESTINATION "lib/mediastreamer/plugins"
		COMPONENT "msopenh264"
		FILES_MATCHING PATTERN "libmsopenh264.*"
	)
	
	install(DIRECTORY "${LINPHONE_OUTPUT_DIR}/lib/mediastreamer/plugins/"
		DESTINATION "lib/mediastreamer/plugins"
		FILES_MATCHING PATTERN "libmssilk.*" PATTERN "libmsilbc.*"
	)
elseif(APPLE)
	find_program(MAC_BUNDLER gtk-mac-bundler)
169
	find_program(PATCH_PROGRAM patch)
170 171 172 173 174 175 176
	configure_file("${LINPHONE_SOURCE_DIR}/build/macos/Info-linphone.plist.in" "mac-bundler/Info-linphone.plist" @ONLY)
	configure_file("${LINPHONE_SOURCE_DIR}/build/macos/environment.sh" "mac-bundler/environment.sh" COPYONLY)
	configure_file("${LINPHONE_SOURCE_DIR}/gtk/gtkrc.mac" "mac-bundler/gtkrc" COPYONLY)
	configure_file("${LINPHONE_SOURCE_DIR}/pixmaps/linphone.icns" "mac-bundler/linphone.icns" COPYONLY)
	configure_file("mac-bundler/linphone.bundle" "mac-bundler/linphone.bundle" COPYONLY)	# This file has to be different than the one in the linphone source code because of different file access paths
	configure_file("mac-bundler/call-bundler.cmake.in" "mac-bundler/call-bundler.cmake")
	install(SCRIPT "${CMAKE_BINARY_DIR}/mac-bundler/call-bundler.cmake")
177
endif()
178

179
if(MSVC)
180 181
	install(DIRECTORY "${LINPHONE_OUTPUT_DIR}/lib/mediastreamer/plugins/"
		DESTINATION "lib/mediastreamer/plugins"
182
		FILES_MATCHING PATTERN "libmswasapi.dll"
183
	)
184
	string(REGEX REPLACE "Visual Studio ([0-9]+).*" "\\1" MSVC_VERSION "${CMAKE_GENERATOR}")
Ghislain MARY's avatar
Ghislain MARY committed
185
	if(CMAKE_BUILD_TYPE STREQUAL "Debug")
186 187 188 189 190
		set(MSVC_DEBUG_SYSTEM_LIBRARIES "d")
	endif()
	find_file(MSVCP_LIB "msvcp${MSVC_VERSION}0${MSVC_DEBUG_SYSTEM_LIBRARIES}.dll" PATHS "C:/Windows/System32")
	find_file(MSVCR_LIB "msvcr${MSVC_VERSION}0${MSVC_DEBUG_SYSTEM_LIBRARIES}.dll" PATHS "C:/Windows/System32")
	install(FILES ${MSVCP_LIB} ${MSVCR_LIB} DESTINATION "bin")
191 192 193 194 195 196 197 198
endif()

set(CPACK_PACKAGE_NAME "Linphone")
set(CPACK_PACKAGE_VENDOR "Belledonne communications")
set(CPACK_PACKAGE_VERSION_MAJOR ${LINPHONE_MAJOR_VERSION})
set(CPACK_PACKAGE_VERSION_MINOR ${LINPHONE_MINOR_VERSION})
set(CPACK_PACKAGE_VERSION_PATCH ${LINPHONE_MICRO_VERSION})
set(CPACK_PACKAGE_EXECUTABLES "linphone;Linphone")
199
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Linphone")
200
set(CPACK_RESOURCE_FILE_LICENSE "${LINPHONE_SOURCE_DIR}/COPYING")
201

202 203 204 205 206 207 208 209
if(WIN32)
	set(CPACK_COMPONENT_LINPHONE_BASE_DISPLAY_NAME "Linphone")
	set(CPACK_COMPONENT_LINPHONE_BASE_DESCRIPTION "Minimal installation of Linphone")
	set(CPACK_COMPONENT_LINPHONE_BASE_REQUIRED True)
	set(CPACK_COMPONENT_MSOPENH264_DISPLAY_NAME "Cisco's OpenH264 codec")
	set(CPACK_COMPONENT_MSOPENH264_DESCRIPTION "Download OpenH264 Video Codec provided by Cisco Systems, Inc.")
	set(CPACK_COMPONENT_MSOPENH264_DISABLED True)
endif()
210

211 212
if(WIN32)
	set(CPACK_GENERATOR "NSIS")
213 214
	set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\linphone-banner.bmp")
	set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${LINPHONE_GIT_REVISION}-win32")
215 216
	set(CPACK_NSIS_MUI_ICON "${LINPHONE_SOURCE_DIR}/gtk/linphone.ico")
	set(CPACK_NSIS_MUI_UNIICON "${LINPHONE_SOURCE_DIR}/gtk/linphone.ico")
217
	set(CPACK_NSIS_DISPLAY_NAME "Linphone")
218 219
	set(CPACK_NSIS_PACKAGE_NAME "Linphone ${LINPHONE_MAJOR_VERSION}.${LINPHONE_MINOR_VERSION}.${LINPHONE_MICRO_VERSION}")
	set(CPACK_NSIS_URL_INFO_ABOUT "http://www.linphone.org/")
220
	set(CPACK_NSIS_MUI_FINISHPAGE_RUN "linphone")
221 222
	set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
	
François Grisez's avatar
François Grisez committed
223 224 225
	file(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" DOS_STYLE_SOURCE_DIR)
	string(REPLACE "\\" "\\\\" ESCAPED_DOS_STYLE_SOURCE_DIR "${DOS_STYLE_SOURCE_DIR}")
	
226
	# Add NSI instructions to download the openh264 codec from Cisco's servers whether msopenh264 has been installed
François Grisez's avatar
François Grisez committed
227
	set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "!include \\\"${ESCAPED_DOS_STYLE_SOURCE_DIR}\\\\openh264-install.nsi\\\"")
228 229
	
	# Add NSI instructions to delete the openh264 codecs while uninstalling Linphone
François Grisez's avatar
François Grisez committed
230
	set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "!include \\\"${ESCAPED_DOS_STYLE_SOURCE_DIR}\\\\openh264-uninstall.nsi\\\"")
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255

	# Sign the installer
	set(TIMESTAMP_URL "http://timestamp.verisign.com/scripts/timestamp.dll")
	set(PFX_FILE "${CMAKE_CURRENT_SOURCE_DIR}/sign/linphone.pfx")
	set(PASSPHRASE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/sign/passphrase.txt")
	get_filename_component(WINSDK_DIR "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]" REALPATH CACHE)
	find_package(PythonInterp)
	find_program(SIGNTOOL signtool PATHS ${WINSDK_DIR}/bin)
	set(SIGNTOOL_COMMAND "${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/signtool.py")
	set(PERFORM_SIGNING 0)
	if(EXISTS ${PFX_FILE})
		if(SIGNTOOL)
			set(SIGNTOOL_COMMAND "${SIGNTOOL_COMMAND} signtool sign /f ${PFX_FILE}")
			set(SIGNTOOL_COMMAND "${SIGNTOOL_COMMAND} /p ${PASSPHRASE_FILE}")
			set(SIGNTOOL_COMMAND "${SIGNTOOL_COMMAND} /t ${TIMESTAMP_URL}")
			message("Found signtool and certificate ${PFX_FILE}")
			set(PERFORM_SIGNING 1)
		else()
			message(STATUS "Could not find signtool! Code signing disabled (${SIGNTOOL})")
		endif()
	else()
		message(STATUS "No signtool certificate found; assuming development machine (${PFX_FILE})")
	endif()
	configure_file("${CMAKE_CURRENT_SOURCE_DIR}/WindowsPackaging.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/WindowsPackaging.cmake" @ONLY)
	install(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/WindowsPackaging.cmake")
256 257
endif()
include(CPack)