CMakeLists.txt 9.17 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
set(Python_ADDITIONAL_VERSIONS 2.7)
27
find_package(PythonInterp REQUIRED)
28
find_package(PythonLibs 2.7 REQUIRED)
29
find_package(Git)
30

31
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
32
find_package(Linphone REQUIRED)
33
find_package(XML2 REQUIRED)
34 35 36

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

37 38 39 40 41 42 43 44 45 46 47 48
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}")

49 50 51 52 53
execute_process(
	COMMAND ${CMAKE_COMMAND} -E echo "#define LINPHONE_GIT_REVISION \"${LINPHONE_GIT_REVISION}\""
	OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/gitversion.h
)

54 55 56 57
# 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
58 59
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}"
60
	DEPENDS ${XML_FILES} "${LINPHONE_SOURCE_DIR}/tools/genapixml.py"
61
)
62
add_custom_target(api_xml DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/api.xml")
63 64

# Generate the Python wrapper source code for the API in XML format
65
set(SOURCE_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/linphone.c")
66 67
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"
68
	DEPENDS api_xml "${LINPHONE_SOURCE_DIR}/tools/python/apixml2python.py" "${LINPHONE_SOURCE_DIR}/tools/python/apixml2python/linphone.py"
69 70
	WORKING_DIRECTORY "${LINPHONE_SOURCE_DIR}/tools/python"
)
71
add_custom_target(pylinphone_source DEPENDS "${SOURCE_FILENAME}")
72 73

if(WIN32)
74 75 76 77 78 79
	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")
80
	set(LINPHONE_DYNAMIC_LIBRARIES_TO_INSTALL )
81
	if(APPLE)
82 83 84 85 86 87 88
		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()
89
	else()
90 91 92 93 94 95 96
		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()
97
	endif()
98
endif()
99 100

if(UNIX)
101
	find_program(LORDER_EXECUTABLE lorder HINTS "${CMAKE_CURRENT_SOURCE_DIR}")
102 103
	if(NOT LORDER_EXECUTABLE)
		message(FATAL_ERROR "lorder executable is needed.")
104
	endif()
105 106 107
	find_program(TSORT_EXECUTABLE tsort)
	if(NOT TSORT_EXECUTABLE)
		message(FATAL_ERROR "tsort executable is needed.")
108
	endif()
109 110 111 112 113 114
	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}")
115 116 117 118 119 120
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()
121 122 123 124 125
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()
126
target_compile_options(pylinphone PUBLIC ${LINPHONE_CPPFLAGS})
127
target_include_directories(pylinphone PUBLIC ${LINPHONE_INCLUDE_DIRS} ${XML2_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} PRIVATE "${LINPHONE_SOURCE_DIR}/coreapi" "${LINPHONE_SOURCE_DIR}/include")
128
set_target_properties(pylinphone PROPERTIES LINKER_LANGUAGE CXX)
129
set(PYLINPHONE_LINK_LIBRARIES ${LINPHONE_LIBRARIES} ${XML2_LIBRARIES})
130 131 132
if(WIN32)
	find_library(GCC_LIBRARIES gcc)
	find_library(MINGWEX_LIBRARIES mingwex)
133
	list(APPEND PYLINPHONE_LINK_LIBRARIES ${PYTHON_LIBRARIES} ${GCC_LIBRARIES} ${MINGWEX_LIBRARIES})
134 135
endif()
target_link_libraries(pylinphone ${PYLINPHONE_LINK_LIBRARIES})
136
string(REPLACE ";" " " LINPHONE_LDFLAGS_STR "${LINPHONE_LDFLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
137 138 139 140 141 142
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}")
143 144 145 146 147
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")
148
	else()
149
		set_target_properties(pylinphone PROPERTIES INSTALL_RPATH "$ORIGIN" BUILD_WITH_INSTALL_RPATH TRUE)
150
	endif()
151 152 153
endif()
foreach(PACKAGE_TO_BUILD ${PACKAGES_TO_BUILD})
	add_custom_command(TARGET pylinphone POST_BUILD
154
		COMMAND "${CMAKE_COMMAND}" "-DPACKAGE_NAME=${PACKAGE_NAME}" "-DLINPHONE_VERSION=${LINPHONE_VERSION}" "-DLINPHONE_GIT_REVISION=${LINPHONE_GIT_REVISION}"
155 156
			"-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}"
157
			"-DINPUT_DIR=${CMAKE_CURRENT_SOURCE_DIR}" "-DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR}" "-DLINPHONE_SOURCE_DIR=${LINPHONE_SOURCE_DIR}"
158 159
			"-P" "${CMAKE_CURRENT_SOURCE_DIR}/prepare_packaging.cmake"
	)
Ghislain MARY's avatar
Ghislain MARY committed
160 161 162 163 164
	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()
165
endforeach()
166

167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184

if(WIN32)
	set(PLATFORM_TAG "win32")
else()
	if(CMAKE_CROSSCOMPILING)
		string(TOLOWER "${CMAKE_SYSTEM_NAME}" PLATFORM_OS)
	else()
		if(APPLE)
			set(PLATFORM_OS "macosx")
		else()
			set(PLATFORM_OS "linux")
		endif()
	endif()
	set(PLATFORM_TAG "${PLATFORM_OS}-${CMAKE_SYSTEM_PROCESSOR}")
endif()

set(PYLINPHONE_INSTALL_DEPS )

185 186
if(WIN32)

187
# Generate the installer
188
add_custom_target(pylinphone_exe ALL
189
	COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/build_exe/linphone/setup.py" "bdist_wininst"
190
	DEPENDS pylinphone
191
	WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_exe/linphone"
192
)
193
list(APPEND PYLINPHONE_INSTALL_DEPS pylinphone_exe)
194 195

# Generate the msi
196
add_custom_target(pylinphone_msi ALL
197
	COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/build_msi/linphone/setup.py" "bdist_msi"
198
	DEPENDS pylinphone
199
	WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_msi/linphone"
200
)
201
list(APPEND PYLINPHONE_INSTALL_DEPS pylinphone_msi)
202 203 204 205

endif()

# Generate the zip
206
add_custom_target(pylinphone_zip ALL
207
	COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/build_zip/linphone/setup.py" "bdist" "--format=zip"
208
	DEPENDS pylinphone
209 210
	WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_zip/linphone"
)
211
list(APPEND PYLINPHONE_INSTALL_DEPS pylinphone_zip)
212 213

# Generate the wheel package
214
add_custom_target(pylinphone_wheel
215
	COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_BINARY_DIR}/build_wheel/linphone/setup.py" "bdist_wheel"
216
	DEPENDS pylinphone
217 218
	WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build_wheel/linphone"
)
219
list(APPEND PYLINPHONE_INSTALL_DEPS pylinphone_wheel)
220

221 222 223 224 225 226 227 228

add_custom_target(pylinphone_install ALL
	COMMAND "${CMAKE_COMMAND}" "-DPACKAGE_NAME=${PACKAGE_NAME}" "-DLINPHONE_GIT_REVISION=${LINPHONE_GIT_REVISION}"
		"-DPLATFORM_TAG=${PLATFORM_TAG}" "-DPYTHON_VERSION=${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}"
		"-DBINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}" "-DINSTALL_DIR=${CMAKE_INSTALL_PREFIX}"
		"-P" "${CMAKE_CURRENT_SOURCE_DIR}/install.cmake"
	DEPENDS ${PYLINPHONE_INSTALL_DEPS}
)