LinphoneCMakeBuilder.cmake 10.4 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
############################################################################
# LinphoneCMakeBuilder.cmake
# 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.
#
############################################################################

include(ExternalProject)

25 26 27
set(ep_base ${CMAKE_CURRENT_SOURCE_DIR}/WORK)
set_property(DIRECTORY PROPERTY EP_BASE ${ep_base})

28

29
option(LINPHONE_BUILDER_AUTOTOOLS_ONCE "Run configure stage only once for subprojects built with the autotools." OFF)
30

31 32 33
if(${LINPHONE_BUILDER_AUTOTOOLS_ONCE})
	set(LINPHONE_BUILDER_AUTOTOOLS_ONCE "yes")
else(${LINPHONE_BUILDER_AUTOTOOLS_ONCE})
34
	set(LINPHONE_BUILDER_AUTOTOOLS_ONCE "no")
35 36 37 38 39 40 41 42 43 44 45
endif(${LINPHONE_BUILDER_AUTOTOOLS_ONCE})

if(${CMAKE_VERBOSE_MAKEFILE})
	set(AUTOTOOLS_VERBOSE_MAKEFILE 1)
else(${CMAKE_VERBOSE_MAKEFILE})
	set(AUTOTOOLS_VERBOSE_MAKEFILE 0)
endif(${CMAKE_VERBOSE_MAKEFILE})


set(LINPHONE_BUILDER_PKG_CONFIG_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)

46

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 156 157 158
set(LINPHONE_BUILDER_EP_VARS)

macro(linphone_builder_expand_external_project_vars)
  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()
endmacro(linphone_builder_expand_external_project_vars)

list(APPEND LINPHONE_BUILDER_EP_VARS
	CMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH
	CMAKE_BUILD_TYPE:STRING
	CMAKE_BUNDLE_OUTPUT_DIRECTORY:PATH
	CMAKE_C_COMPILER:PATH
	CMAKE_C_FLAGS_DEBUG:STRING
	CMAKE_C_FLAGS_MINSIZEREL:STRING
	CMAKE_C_FLAGS_RELEASE:STRING
	CMAKE_C_FLAGS_RELWITHDEBINFO:STRING
	CMAKE_C_FLAGS:STRING
	CMAKE_CROSSCOMPILING:BOOL
	CMAKE_CXX_COMPILER:PATH
	CMAKE_CXX_FLAGS_DEBUG:STRING
	CMAKE_CXX_FLAGS_MINSIZEREL:STRING
	CMAKE_CXX_FLAGS_RELEASE:STRING
	CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING
	CMAKE_CXX_FLAGS: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_EXE_LINKER_FLAGS:STRING
	CMAKE_EXTRA_GENERATOR:STRING
	CMAKE_FIND_ROOT_PATH:PATH
	CMAKE_FIND_ROOT_PATH_MODE_INCLUDE:STRING
	CMAKE_FIND_ROOT_PATH_MODE_LIBRARY:STRING
	CMAKE_FIND_ROOT_PATH_MODE_PROGRAM:STRING
	CMAKE_INSTALL_PREFIX:PATH
	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_LINKER_FLAGS:STRING
	CMAKE_MODULE_PATH:PATH
	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
	CMAKE_SHARED_LINKER_FLAGS:STRING
	CMAKE_SKIP_RPATH:BOOL
	CMAKE_SYSTEM_NAME:STRING
	CMAKE_SYSTEM_PROCESSOR:STRING
	CMAKE_VERBOSE_MAKEFILE:BOOL
	LINPHONE_BUILDER_TOOLCHAIN:STRING
)
if(APPLE)
	list(APPEND LINPHONE_BUILDER_EP_VARS
		CMAKE_OSX_ARCHITECTURES:STRING
		CMAKE_OSX_DEPLOYMENT_TARGET:STRING
	)
endif(APPLE)


macro(linphone_builder_apply_toolchain_flags)
	foreach(BUILD_CONFIG "" "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
		if(NOT "${LINPHONE_BUILDER_TOOLCHAIN_CPPFLAGS}" STREQUAL "")
			set(CMAKE_C_FLAGS${BUILD_CONFIG} "${CMAKE_C_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_TOOLCHAIN_CPPFLAGS}")
			set(CMAKE_CXX_FLAGS${BUILD_CONFIG} "${CMAKE_CXX_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_TOOLCHAIN_CPPFLAGS}")
		endif(NOT "${LINPHONE_BUILDER_TOOLCHAIN_CPPFLAGS}" STREQUAL "")
		if(NOT "${LINPHONE_BUILDER_TOOLCHAIN_CFLAGS}" STREQUAL "")
			set(CMAKE_C_FLAGS${BUILD_CONFIG} "${CMAKE_C_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_TOOLCHAIN_CFLAGS}")
		endif(NOT "${LINPHONE_BUILDER_TOOLCHAIN_CFLAGS}" STREQUAL "")
		if(NOT "${LINPHONE_BUILDER_TOOLCHAIN_CXXFLAGS}" STREQUAL "")
			set(CMAKE_CXX_FLAGS${BUILD_CONFIG} "${CMAKE_CXX_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_TOOLCHAIN_CXXFLAGS}")
		endif(NOT "${LINPHONE_BUILDER_TOOLCHAIN_CXXFLAGS}" STREQUAL "")
		if(NOT "${LINPHONE_BUILDER_TOOLCHAIN_LDFLAGS}" STREQUAL "")
			# TODO: The two following lines should not be here
			set(CMAKE_C_FLAGS${BUILD_CONFIG} "${CMAKE_C_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_TOOLCHAIN_LDFLAGS}")
			set(CMAKE_CXX_FLAGS${BUILD_CONFIG} "${CMAKE_CXX_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_TOOLCHAIN_LDFLAGS}")

			set(CMAKE_EXE_LINKER_FLAGS${BUILD_CONFIG} "${CMAKE_EXE_LINKER_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_TOOLCHAIN_LDFLAGS}")
			set(CMAKE_MODULE_LINKER_FLAGS${BUILD_CONFIG} "${CMAKE_MODULE_LINKER_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_TOOLCHAIN_LDFLAGS}")
			set(CMAKE_SHARED_LINKER_FLAGS${BUILD_CONFIG} "${CMAKE_SHARED_LINKER_FLAGS${BUILD_CONFIG}} ${LINPHONE_BUILDER_TOOLCHAIN_LDFLAGS}")
		endif(NOT "${LINPHONE_BUILDER_TOOLCHAIN_LDFLAGS}" STREQUAL "")
	endforeach(BUILD_CONFIG)
endmacro(linphone_builder_apply_toolchain_flags)


macro(linphone_builder_apply_extra_flags EXTRA_CFLAGS EXTRA_CXXFLAGS EXTRA_LDFLAGS)
	foreach(BUILD_CONFIG "" "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
		if(NOT "${EXTRA_CFLAGS}" STREQUAL "")
			set(CMAKE_C_FLAGS${BUILD_CONFIG} "${CMAKE_C_FLAGS${BUILD_CONFIG}} ${EXTRA_CFLAGS}")
		endif(NOT "${EXTRA_CFLAGS}" STREQUAL "")
		if(NOT "${EXTRA_CXXFLAGS}" STREQUAL "")
			set(CMAKE_CXX_FLAGS${BUILD_CONFIG} "${CMAKE_CXX_FLAGS${BUILD_CONFIG}} ${EXTRA_CXXFLAGS}")
		endif(NOT "${EXTRA_CXXFLAGS}" STREQUAL "")
		if(NOT "${EXTRA_LDFLAGS}" STREQUAL "")
			set(CMAKE_EXE_LINKER_FLAGS${BUILD_CONFIG} "${CMAKE_EXE_LINKER_FLAGS${BUILD_CONFIG}} ${EXTRA_LDFLAGS}")
			set(CMAKE_MODULE_LINKER_FLAGS${BUILD_CONFIG} "${CMAKE_MODULE_LINKER_FLAGS${BUILD_CONFIG}} ${EXTRA_LDFLAGS}")
			set(CMAKE_SHARED_LINKER_FLAGS${BUILD_CONFIG} "${CMAKE_SHARED_LINKER_FLAGS${BUILD_CONFIG}} ${EXTRA_LDFLAGS}")
		endif(NOT "${EXTRA_LDFLAGS}" STREQUAL "")
	endforeach(BUILD_CONFIG)
endmacro(linphone_builder_apply_extra_flags)


159 160 161 162 163 164 165 166 167 168 169
macro(linphone_builder_set_ep_directories PROJNAME)
	set(ep_source "${ep_base}/Source/EP_${PROJNAME}")
	if(NOT "${LINPHONE_BUILDER_TOOLCHAIN}" STREQUAL "")
		set(ep_tmp "${ep_base}/tmp-${LINPHONE_BUILDER_TOOLCHAIN}/${PROJNAME}")
		set(ep_build "${ep_base}/Build-${LINPHONE_BUILDER_TOOLCHAIN}/${PROJNAME}")
	else()
		set(ep_tmp "${ep_base}/tmp/${PROJNAME}")
		set(ep_build "${ep_base}/Build/${PROJNAME}")
	endif()
endmacro(linphone_builder_set_ep_directories)

170 171 172
macro(linphone_builder_add_cmake_project PROJNAME)
	set(EP_${PROJNAME}_SOURCE_DIR "" CACHE PATH "Build ${PROJNAME} from a local source path instead of cloning a repository.")

173
	linphone_builder_set_ep_directories(${PROJNAME})
174 175 176 177 178 179
	linphone_builder_apply_extra_flags("${EP_${PROJNAME}_EXTRA_CFLAGS}" "${EP_${PROJNAME}_EXTRA_CXXFLAGS}" "${EP_${PROJNAME}_EXTRA_LDFLAGS}")
	linphone_builder_expand_external_project_vars()

	if(NOT "${EP_${PROJNAME}_SOURCE_DIR}" STREQUAL "")
		ExternalProject_Add(EP_${PROJNAME}
			DEPENDS ${EP_${PROJNAME}_DEPENDENCIES}
180 181
			TMP_DIR ${ep_tmp}
			BINARY_DIR ${ep_build}
182 183
			SOURCE_DIR ${EP_${PROJNAME}_SOURCE_DIR}
			PATCH_COMMAND ${EP_${PROJNAME}_PATCH_COMMAND}
184
			CMAKE_GENERATOR ${CMAKE_GENERATOR}
185 186
			CMAKE_ARGS ${EP_${PROJNAME}_CMAKE_OPTIONS}
			CMAKE_CACHE_ARGS ${LINPHONE_BUILDER_EP_ARGS}
187 188 189 190
		)
	else(NOT "${EP_${PROJNAME}_SOURCE_DIR}" STREQUAL "")
 		ExternalProject_Add(EP_${PROJNAME}
			DEPENDS ${EP_${PROJNAME}_DEPENDENCIES}
191 192 193 194 195 196 197
			TMP_DIR ${ep_tmp}
			BINARY_DIR ${ep_build}
			GIT_REPOSITORY ${EP_${PROJNAME}_GIT_REPOSITORY}
			GIT_TAG ${EP_${PROJNAME}_GIT_TAG}
			PATCH_COMMAND ${EP_${PROJNAME}_PATCH_COMMAND}
			CMAKE_GENERATOR ${CMAKE_GENERATOR}
			CMAKE_ARGS ${EP_${PROJNAME}_CMAKE_OPTIONS}
198
			CMAKE_CACHE_ARGS ${LINPHONE_BUILDER_EP_ARGS}
199 200
		)
	endif(NOT "${EP_${PROJNAME}_SOURCE_DIR}" STREQUAL "")
201 202 203
endmacro(linphone_builder_add_cmake_project)

macro(linphone_builder_add_autotools_project PROJNAME)
204
	linphone_builder_set_ep_directories(${PROJNAME})
205 206 207 208 209 210 211 212 213 214
	linphone_builder_apply_extra_flags("${EP_${PROJNAME}_EXTRA_CFLAGS}" "${EP_${PROJNAME}_EXTRA_CXXFLAGS}" "${EP_${PROJNAME}_EXTRA_LDFLAGS}")
	linphone_builder_expand_external_project_vars()

	configure_file(${CMAKE_CURRENT_SOURCE_DIR}/builders/${PROJNAME}/configure.sh.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_configure.sh)
	configure_file(${CMAKE_CURRENT_SOURCE_DIR}/builders/${PROJNAME}/build.sh.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_build.sh)
	configure_file(${CMAKE_CURRENT_SOURCE_DIR}/builders/${PROJNAME}/install.sh.cmake ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_install.sh)

	if(NOT "${EP_${PROJNAME}_SOURCE_DIR}" STREQUAL "")
		ExternalProject_Add(EP_${PROJNAME}
			DEPENDS ${EP_${PROJNAME}_DEPENDENCIES}
215 216
			TMP_DIR ${ep_tmp}
			BINARY_DIR ${ep_build}
217 218
			SOURCE_DIR ${EP_${PROJNAME}_SOURCE_DIR}
			PATCH_COMMAND ${EP_${PROJNAME}_PATCH_COMMAND}
219
			CMAKE_GENERATOR ${CMAKE_GENERATOR}
220 221 222 223 224 225 226
			CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_configure.sh
			BUILD_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_build.sh
			INSTALL_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_install.sh
		)
	else(NOT "${EP_${PROJNAME}_SOURCE_DIR}" STREQUAL "")
		ExternalProject_Add(EP_${PROJNAME}
			DEPENDS ${EP_${PROJNAME}_DEPENDENCIES}
227 228
			TMP_DIR ${ep_tmp}
			BINARY_DIR ${ep_build}
229 230 231
			GIT_REPOSITORY ${EP_${PROJNAME}_GIT_REPOSITORY}
			GIT_TAG ${EP_${PROJNAME}_GIT_TAG}
			PATCH_COMMAND ${EP_${PROJNAME}_PATCH_COMMAND}
232
			CMAKE_GENERATOR ${CMAKE_GENERATOR}
233 234 235 236 237 238
			CONFIGURE_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_configure.sh
			BUILD_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_build.sh
			INSTALL_COMMAND ${CMAKE_CURRENT_BINARY_DIR}/EP_${PROJNAME}_install.sh
		)
	endif(NOT "${EP_${PROJNAME}_SOURCE_DIR}" STREQUAL "")
endmacro(linphone_builder_add_autotools_project PROJNAME)