CMakeLists.txt 11.8 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
############################################################################
# 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 2.8.12)
24
project(PYLINPHONE C CXX) # Dummy project
25

26 27
if(APPLE)
	set(PLATFORM_ARCH_NAME "${CMAKE_OSX_ARCHITECTURES}")
28
else()
29
	set(PLATFORM_ARCH_NAME "${CMAKE_HOST_SYSTEM_PROCESSOR}")
30 31
endif()

32
set(Python_ADDITIONAL_VERSIONS 2.7)
33
find_package(PythonInterp REQUIRED)
34
find_package(PythonLibs 2.7 REQUIRED)
35
find_package(Git)
36

37
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
38
find_package(Linphone REQUIRED)
39
find_package(XML2 REQUIRED)
40 41 42

set(LINPHONE_SOURCE_DIR "${CMAKE_SOURCE_DIR}/../EP_linphone")

43 44 45 46 47 48 49 50 51 52 53 54
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}")

55 56 57 58 59
execute_process(
	COMMAND ${CMAKE_COMMAND} -E echo "#define LINPHONE_GIT_REVISION \"${LINPHONE_GIT_REVISION}\""
	OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/gitversion.h
)

60 61 62 63
# Find the doxygen XML directory
file(GLOB XML_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/linphone-*/xml")

# Generate the API in XML format from the doxygen XML files
64 65
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/api.xml"
	COMMAND ${PYTHON_EXECUTABLE} "${LINPHONE_SOURCE_DIR}/tools/genapixml.py" "--pretty" "--outputfile" "${CMAKE_CURRENT_BINARY_DIR}/api.xml" "${XML_DIR}"
66
	DEPENDS ${XML_FILES} "${LINPHONE_SOURCE_DIR}/tools/genapixml.py"
67
)
68
add_custom_target(api_xml DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/api.xml")
69 70

# Generate the Python wrapper source code for the API in XML format
71
set(SOURCE_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/linphone.c")
72 73
add_custom_command(OUTPUT "${SOURCE_FILENAME}"
	COMMAND ${PYTHON_EXECUTABLE} "${LINPHONE_SOURCE_DIR}/tools/python/apixml2python.py" "--outputfile" "${SOURCE_FILENAME}" "${CMAKE_CURRENT_BINARY_DIR}/api.xml"
74
	DEPENDS api_xml "${LINPHONE_SOURCE_DIR}/tools/python/apixml2python.py" "${LINPHONE_SOURCE_DIR}/tools/python/apixml2python/linphone.py"
75 76
	WORKING_DIRECTORY "${LINPHONE_SOURCE_DIR}/tools/python"
)
77
add_custom_target(pylinphone_source DEPENDS "${SOURCE_FILENAME}")
78 79

if(WIN32)
80 81 82 83 84 85
	set(PACKAGES_TO_BUILD "exe" "msi" "zip" "wheel")
	set(PY_MODULE_EXT ".pyd")
	file(GLOB LINPHONE_DYNAMIC_LIBRARIES_TO_INSTALL "${CMAKE_INSTALL_PREFIX}/bin/*.dll")
else()
	set(PACKAGES_TO_BUILD "zip" "wheel")
	set(PY_MODULE_EXT ".so")
86
	set(LINPHONE_DYNAMIC_LIBRARIES_TO_INSTALL )
87
	if(APPLE)
88 89 90 91 92 93 94
		if(ENABLE_FFMPEG)
			list(APPEND LINPHONE_DYNAMIC_LIBRARIES_TO_INSTALL
				"${CMAKE_INSTALL_PREFIX}/lib/libavcodec.53.61.100.dylib"
				"${CMAKE_INSTALL_PREFIX}/lib/libavutil.51.35.100.dylib"
				"${CMAKE_INSTALL_PREFIX}/lib/libswscale.2.1.100.dylib"
			)
		endif()
95
	else()
96 97 98 99 100 101 102
		if(ENABLE_FFMPEG)
			list(APPEND LINPHONE_DYNAMIC_LIBRARIES_TO_INSTALL
				"${CMAKE_INSTALL_PREFIX}/lib/libavcodec.so.53.61.100"
				"${CMAKE_INSTALL_PREFIX}/lib/libavutil.so.51.35.100"
				"${CMAKE_INSTALL_PREFIX}/lib/libswscale.so.2.1.100"
			)
		endif()
103
	endif()
104
endif()
105 106

if(UNIX)
107
	find_program(LORDER_EXECUTABLE lorder HINTS "${CMAKE_CURRENT_SOURCE_DIR}")
108 109
	if(NOT LORDER_EXECUTABLE)
		message(FATAL_ERROR "lorder executable is needed.")
110
	endif()
111 112 113
	find_program(TSORT_EXECUTABLE tsort)
	if(NOT TSORT_EXECUTABLE)
		message(FATAL_ERROR "tsort executable is needed.")
114
	endif()
115 116 117 118 119 120
	execute_process(COMMAND ${LORDER_EXECUTABLE} ${LINPHONE_LIBRARIES} OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/lorder.out")
	execute_process(COMMAND ${TSORT_EXECUTABLE} OUTPUT_VARIABLE LINPHONE_LIBRARIES INPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/lorder.out")
	separate_arguments(LINPHONE_LIBRARIES UNIX_COMMAND "${LINPHONE_LIBRARIES}")
endif()

add_library(pylinphone MODULE "${SOURCE_FILENAME}")
121 122 123 124 125 126
if(ENABLE_OPENH264)
	find_library(MSOPENH264_LIBRARY msopenh264 HINTS "${CMAKE_INSTALL_PREFIX}/lib/mediastreamer/plugins")
	find_library(OPENH264_LIBRARY openh264)
	target_compile_definitions(pylinphone PRIVATE "ENABLE_OPENH264=1")
	target_link_libraries(pylinphone ${MSOPENH264_LIBRARY} ${OPENH264_LIBRARY})
endif()
127 128 129 130 131
if(ENABLE_WASAPI)
	find_library(MSWASAPI_LIBRARY mswasapi HINTS "${CMAKE_INSTALL_PREFIX}/lib/mediastreamer/plugins")
	target_compile_definitions(pylinphone PRIVATE "ENABLE_WASAPI=1")
	target_link_libraries(pylinphone ${MSWASAPI_LIBRARY})
endif()
132
target_compile_options(pylinphone PUBLIC ${LINPHONE_CPPFLAGS})
133
target_include_directories(pylinphone PUBLIC ${LINPHONE_INCLUDE_DIRS} ${XML2_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} PRIVATE "${LINPHONE_SOURCE_DIR}/coreapi" "${LINPHONE_SOURCE_DIR}/include")
134
set_target_properties(pylinphone PROPERTIES LINKER_LANGUAGE CXX)
135
set(PYLINPHONE_LINK_LIBRARIES ${LINPHONE_LIBRARIES} ${XML2_LIBRARIES})
136 137 138
if(WIN32)
	find_library(GCC_LIBRARIES gcc)
	find_library(MINGWEX_LIBRARIES mingwex)
139
	list(APPEND PYLINPHONE_LINK_LIBRARIES ${PYTHON_LIBRARIES} ${GCC_LIBRARIES} ${MINGWEX_LIBRARIES})
140 141
endif()
target_link_libraries(pylinphone ${PYLINPHONE_LINK_LIBRARIES})
142
string(REPLACE ";" " " LINPHONE_LDFLAGS_STR "${LINPHONE_LDFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
143 144 145 146 147 148
set(PYLINPHONE_LDFLAGS "")
if(APPLE)
	set(PYLINPHONE_LDFLAGS "${LINPHONE_LDFLAGS_STR} -undefined dynamic_lookup")
endif()
if(NOT "${PYLINPHONE_LDFLAGS}" STREQUAL "")
	set_target_properties(pylinphone PROPERTIES LINK_FLAGS "${PYLINPHONE_LDFLAGS}")
149 150 151 152 153
endif()
set_target_properties(pylinphone PROPERTIES OUTPUT_NAME linphone PREFIX "" SUFFIX "${PY_MODULE_EXT}")
if(UNIX)
	if(APPLE)
		set_target_properties(pylinphone PROPERTIES INSTALL_NAME_DIR "@executable_path")
154
	else()
155
		set_target_properties(pylinphone PROPERTIES INSTALL_RPATH "$ORIGIN" BUILD_WITH_INSTALL_RPATH TRUE)
156
	endif()
157 158 159
endif()
foreach(PACKAGE_TO_BUILD ${PACKAGES_TO_BUILD})
	add_custom_command(TARGET pylinphone POST_BUILD
160
		COMMAND "${CMAKE_COMMAND}" "-DPACKAGE_NAME=${PACKAGE_NAME}" "-DLINPHONE_VERSION=${LINPHONE_VERSION}" "-DLINPHONE_GIT_REVISION=${LINPHONE_GIT_REVISION}"
161 162
			"-DLINPHONE_PYTHON_MODULE=$<TARGET_FILE:pylinphone>" "-DLINPHONE_RESOURCES_PREFIX=${CMAKE_INSTALL_PREFIX}"
			"-DLINPHONE_DYNAMIC_LIBRARIES_TO_INSTALL=\"${LINPHONE_DYNAMIC_LIBRARIES_TO_INSTALL}\"" "-DPACKAGE_TYPE=${PACKAGE_TO_BUILD}"
163
			"-DINPUT_DIR=${CMAKE_CURRENT_SOURCE_DIR}" "-DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR}" "-DLINPHONE_SOURCE_DIR=${LINPHONE_SOURCE_DIR}"
164 165
			"-P" "${CMAKE_CURRENT_SOURCE_DIR}/prepare_packaging.cmake"
	)
Ghislain MARY's avatar
Ghislain MARY committed
166 167 168 169 170
	if(APPLE)
		add_custom_command(TARGET pylinphone POST_BUILD
			COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/mac_rpath.py" "${CMAKE_CURRENT_BINARY_DIR}/build_${PACKAGE_TO_BUILD}/linphone/linphone"
		)
	endif()
171
endforeach()
172

173 174
if(WIN32)

175
# Generate the installer
176
set(EXE_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/build_exe/linphone/dist/${PACKAGE_NAME}-${LINPHONE_GIT_REVISION}.win32.exe")
177 178
add_custom_command(OUTPUT "${EXE_FILENAME}"
	COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/build_exe/linphone/setup.py" "bdist_wininst"
179
	DEPENDS pylinphone
180
	WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_exe/linphone"
181
)
182
add_custom_target(pylinphone_exe ALL DEPENDS "${EXE_FILENAME}")
183
install(FILES ${EXE_FILENAME} DESTINATION "." RENAME "${PACKAGE_NAME}-${LINPHONE_GIT_REVISION}.win32-py${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.exe")
184 185

# Generate the msi
186
set(MSI_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/build_msi/linphone/dist/${PACKAGE_NAME}-${LINPHONE_VERSION}.win32.msi")
187 188
add_custom_command(OUTPUT "${MSI_FILENAME}"
	COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/build_msi/linphone/setup.py" "bdist_msi"
189
	DEPENDS pylinphone
190
	WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_msi/linphone"
191
)
192
add_custom_target(pylinphone_msi ALL DEPENDS "${MSI_FILENAME}")
193
install(FILES ${MSI_FILENAME} DESTINATION "." RENAME "${PACKAGE_NAME}-${LINPHONE_GIT_REVISION}.win32-py${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.msi")
194

195
# Generate the zip
196
set(ZIP_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/build_zip/linphone/dist/${PACKAGE_NAME}-${LINPHONE_GIT_REVISION}.win32.zip")
197 198
add_custom_command(OUTPUT "${ZIP_FILENAME}"
	COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/build_zip/linphone/setup.py" "bdist" "--format=zip"
199
	DEPENDS pylinphone
200
	WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_zip/linphone"
201
)
202
add_custom_target(pylinphone_zip ALL DEPENDS "${ZIP_FILENAME}")
203
install(FILES ${ZIP_FILENAME} DESTINATION "." RENAME "${PACKAGE_NAME}-${LINPHONE_GIT_REVISION}.win32-py${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.zip")
204 205 206

# Generate the wheel package
string(REPLACE "-" "_" LINPHONE_UNDERSCORE_GIT_REVISION ${LINPHONE_GIT_REVISION})
207
set(WHEEL_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/build_wheel/linphone/dist/${PACKAGE_NAME}-${LINPHONE_UNDERSCORE_GIT_REVISION}-py2-none-any.whl")
208 209
add_custom_command(OUTPUT "${WHEEL_FILENAME}"
	COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/build_wheel/linphone/setup.py" "bdist_wheel"
210
	DEPENDS pylinphone
211 212
	WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_wheel/linphone"
)
213
add_custom_target(pylinphone_wheel ALL DEPENDS "${WHEEL_FILENAME}")
214
install(FILES ${WHEEL_FILENAME} DESTINATION "." RENAME "${PACKAGE_NAME}-${LINPHONE_UNDERSCORE_GIT_REVISION}-cp27-none-win32.whl")
215 216 217 218 219

endif()

if(UNIX)

220 221 222 223
if(CMAKE_CROSSCOMPILING)
	string(TOLOWER "${CMAKE_SYSTEM_NAME}" PLATFORM_OS)
	set(PLATFORM_TAG "${PLATFORM_OS}-${CMAKE_SYSTEM_PROCESSOR}")
	set(UNDERSCORE_PLATFORM_TAG "any")
224
else()
225
	if(APPLE)
226 227 228
		if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
			set(CMAKE_OSX_DEPLOYMENT_TARGET "x86_64")
		endif()
229 230 231 232 233 234 235
		set(PLATFORM_OS "macosx-${CMAKE_OSX_DEPLOYMENT_TARGET}")
	else()
		set(PLATFORM_OS "linux")
	endif()
	string(REPLACE "-" "_" UNDERSCORE_PLATFORM_OS ${PLATFORM_OS})
	string(REPLACE "." "_" UNDERSCORE_PLATFORM_OS ${UNDERSCORE_PLATFORM_OS})
	set(PLATFORM_TAG "${PLATFORM_OS}-${PLATFORM_ARCH_NAME}")
236
	set(UNDERSCORE_PLATFORM_TAG "${UNDERSCORE_PLATFORM_OS}_${PLATFORM_ARCH_NAME}")
237 238
endif()

239
# Generate the zip
240
set(ZIP_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/build_zip/linphone/dist/${PACKAGE_NAME}-${LINPHONE_GIT_REVISION}.${PLATFORM_OS}-${PLATFORM_ARCH_NAME}.zip")
241 242
add_custom_command(OUTPUT "${ZIP_FILENAME}"
	COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/build_zip/linphone/setup.py" "bdist" "--format=zip"
243
	DEPENDS pylinphone
244 245
	WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_zip/linphone"
)
246
add_custom_target(pylinphone_zip ALL DEPENDS "${ZIP_FILENAME}")
247
install(FILES ${ZIP_FILENAME} DESTINATION "." RENAME "${PACKAGE_NAME}-${LINPHONE_GIT_REVISION}.${PLATFORM_TAG}-py${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.zip")
248 249 250

# Generate the wheel package
string(REPLACE "-" "_" LINPHONE_UNDERSCORE_GIT_REVISION ${LINPHONE_GIT_REVISION})
251
set(WHEEL_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/build_wheel/linphone/dist/${PACKAGE_NAME}-${LINPHONE_UNDERSCORE_GIT_REVISION}-py2-none-any.whl")
252 253
add_custom_command(OUTPUT "${WHEEL_FILENAME}"
	COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/build_wheel/linphone/setup.py" "bdist_wheel"
254
	DEPENDS pylinphone
255 256
	WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_wheel/linphone"
)
257
add_custom_target(pylinphone_wheel ALL DEPENDS "${WHEEL_FILENAME}")
258
install(FILES ${WHEEL_FILENAME} DESTINATION "." RENAME "${PACKAGE_NAME}-${LINPHONE_UNDERSCORE_GIT_REVISION}-cp27-none-${UNDERSCORE_PLATFORM_TAG}.whl")
259

260
endif()