CMakeLists.txt 8.58 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
#
############################################################################

Ghislain MARY's avatar
Ghislain MARY committed
23 24 25 26
function(require_c99 target)
	if(CMAKE_C_COMPILER_ID STREQUAL "QCC")
		target_compile_options(${target} PRIVATE "-std=gnu99")
	else()
27 28 29 30 31 32 33 34
		if (CMAKE_VERSION VERSION_LESS "3.1")
			if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
				target_compile_options(${target} PRIVATE "-std=gnu99")
			endif()
		else()
			set_property(TARGET ${target} PROPERTY C_STANDARD 99)
			set_property(TARGET ${target} PROPERTY C_STANDARD_REQUIRED TRUE)
		endif()
Ghislain MARY's avatar
Ghislain MARY committed
35 36 37
	endif()
endfunction()

38 39 40 41 42
set(PUBLIC_INCLUDE_DIRS
	${BCTOOLBOX_CORE_INCLUDE_DIR}
	$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
	$<INSTALL_INTERFACE:include>
)
Ghislain MARY's avatar
Ghislain MARY committed
43 44 45 46
set(PRIVATE_INCLUDE_DIRS
	${CMAKE_CURRENT_SOURCE_DIR}/antlr3c/include
	${CMAKE_CURRENT_BINARY_DIR}/antlr3c
)
47
set(LIBS ${BCTOOLBOX_CORE_LIBRARIES})
48

49
if(Threads_FOUND)
50 51
	if(CMAKE_USE_PTHREADS_INIT AND NOT CMAKE_SYSTEM_NAME MATCHES "QNX" AND NOT ANDROID)
		list(APPEND LIBS ${CMAKE_THREAD_LIBS_INIT})
52 53
	endif()
endif()
54
if(HAVE_LIBDL)
55
	list(APPEND LIBS dl)
56
endif()
57
if(HAVE_LIBRT)
58 59
	list(APPEND LIBS rt)
endif()
60
if(HAVE_RESINIT)
61
	list(APPEND LIBS resolv)
62
endif()
Ghislain MARY's avatar
Ghislain MARY committed
63 64 65
if(ZLIB_FOUND)
	list(APPEND LIBS ${ZLIB_LIBRARIES})
endif()
66 67 68
if(DNSSD_FOUND)
	list(APPEND LIBS ${DNSSD_LIBRARIES})
endif()
69 70
if(WIN32)
	list(APPEND LIBS ws2_32)
71
endif()
Ghislain MARY's avatar
Ghislain MARY committed
72

73
set(SDP_GENERATED_SOURCE_FILES_C
74 75 76 77
	grammars/belle_sdpLexer.c
	grammars/belle_sdpLexer.h
	grammars/belle_sdpParser.c
	grammars/belle_sdpParser.h
78
)
79
set(SIP_MESSAGE_GENERATED_SOURCE_FILES_C
80 81 82 83
	grammars/belle_sip_messageLexer.c
	grammars/belle_sip_messageLexer.h
	grammars/belle_sip_messageParser.c
	grammars/belle_sip_messageParser.h
84
)
85

86
if(ENABLE_TUNNEL)
87
	set(TUNNEL_SOURCE_FILES_C
88 89
		transports/tunnel_listeningpoint.c
		transports/tunnel_channel.c
90 91
	)
	set(TUNNEL_SOURCE_FILES_CXX
92 93 94
		transports/tunnel_wrapper.cc
	)
	list(APPEND LIBS ${TUNNEL_LIBRARIES})
95
endif()
96

97 98
add_subdirectory(antlr3c)

99
set(BELLE_SIP_SOURCE_FILES_C
100 101 102
	auth_event.c
	auth_helper.c
	belle_sdp_impl.c
103
	belle_sip_dict.c
104
	belle_sip_headers_impl.c
105
	belle_sip_internal.h
106
	belle_sip_loop.c
107
	belle_sip_mdns_register.c
108 109 110 111 112
	belle_sip_object.c
	belle_sip_parameters.c
	belle_sip_resolver.c
	belle_sip_uri_impl.c
	belle_sip_utils.c
Ghislain MARY's avatar
Ghislain MARY committed
113
	bodyhandler.c
114
	channel.c
115 116 117
	channel.h
	clock_gettime.c
	clock_gettime.h
118 119
	dialog.c
	dns.c
120 121 122 123 124
	dns.h
	generic-uri.c
	http-listener.c
	http-message.c
	http-provider.c
125 126 127
	ict.c
	ist.c
	listeningpoint.c
128
	listeningpoint_internal.h
129
	md5.c
130
	md5.h
131 132 133
	message.c
	nict.c
	nist.c
134
	parserutils.h
135
	port.c
136
	port.h
137 138 139 140 141 142
	provider.c
	refresher.c
	siplistener.c
	sipstack.c
	transaction.c
	transports/stream_channel.c
143
	transports/stream_channel.h
144 145 146
	transports/stream_listeningpoint.c
	transports/udp_channel.c
	transports/udp_listeningpoint.c
147 148
	transports/tls_listeningpoint.c
	transports/tls_channel.c
149 150 151 152
	${SDP_GENERATED_SOURCE_FILES_C}
	${SIP_MESSAGE_GENERATED_SOURCE_FILES_C}
	${TUNNEL_SOURCE_FILES_C}
)
Simon Morlat's avatar
Simon Morlat committed
153

Simon Morlat's avatar
Simon Morlat committed
154 155 156 157
add_definitions(
	-DBCTBX_LOG_DOMAIN="belle-sip"
)

158 159 160
if(ANDROID)
	list(APPEND BELLE_SIP_SOURCE_FILES_C wakelock.c)
endif()
161 162
set(BELLE_SIP_SOURCE_FILES_CXX
	${TUNNEL_SOURCE_FILES_CXX}
163
)
164
if(APPLE)
165 166 167 168 169
	set(BELLE_SIP_SOURCE_FILES_OBJC
		backgroundtask.m
	)
endif()

170 171
bc_apply_compile_flags(BELLE_SIP_SOURCE_FILES_C STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
bc_apply_compile_flags(BELLE_SIP_SOURCE_FILES_OBJC STRICT_OPTIONS_CPP STRICT_OPTIONS_OBJC)
172 173
if(BELLE_SIP_SOURCE_FILES_CXX)
	set_source_files_properties(${BELLE_SIP_SOURCE_FILES_CXX} PROPERTIES LANGUAGE CXX)
174
	bc_apply_compile_flags(BELLE_SIP_SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
175
endif()
176
if(MSVC)
177 178
	get_source_file_property(DNS_C_COMPILE_FLAGS dns.c COMPILE_FLAGS)
	set(DNS_C_COMPILE_FLAGS "${DNS_C_COMPILE_FLAGS} /wd4267") # Disable "possible loss of data" warnings
179 180 181 182
	set(DNS_C_COMPILE_FLAGS "${DNS_C_COMPILE_FLAGS} /wd4804") # Disable "unsafe use of type 'bool' in operation" warnings
	set(DNS_C_COMPILE_FLAGS "${DNS_C_COMPILE_FLAGS} /wd4244") # Disable "conversion from 'intmax_t' to 'int', possible loss of data" warnings
	set(DNS_C_COMPILE_FLAGS "${DNS_C_COMPILE_FLAGS} /wd4305") # Disable "'initializing': truncation from 'unsigned int' to 'UCHAR'" warnings
	set(DNS_C_COMPILE_FLAGS "${DNS_C_COMPILE_FLAGS} /wd4018") # Disable "signed/unsigned mismatch" warnings
183
	set_source_files_properties(dns.c PROPERTIES COMPILE_FLAGS "${DNS_C_COMPILE_FLAGS}")
184 185 186 187 188 189
	get_source_file_property(SDP_PARSER_COMPILE_FLAGS grammars/belle_sdpParser.c COMPILE_FLAGS)
	set(SDP_PARSER_COMPILE_FLAGS "${SDP_PARSER_COMPILE_FLAGS} /wd4267") # Disable "possible loss of data" warnings
	set_source_files_properties(grammars/belle_sdpParser.c PROPERTIES COMPILE_FLAGS "${SDP_PARSER_COMPILE_FLAGS}")
	get_source_file_property(SIP_MESSAGE_PARSER_COMPILE_FLAGS grammars/belle_sip_messageParser.c COMPILE_FLAGS)
	set(SIP_MESSAGE_PARSER_COMPILE_FLAGS "${SIP_MESSAGE_PARSER_COMPILE_FLAGS} /wd4267") # Disable "possible loss of data" warnings
	set_source_files_properties(grammars/belle_sip_messageParser.c PROPERTIES COMPILE_FLAGS "${SIP_MESSAGE_PARSER_COMPILE_FLAGS}")
190
else()
191 192 193
	get_source_file_property(DNS_C_COMPILE_FLAGS dns.c COMPILE_FLAGS)
	set(DNS_C_COMPILE_FLAGS "${DNS_C_COMPILE_FLAGS} -Wno-error")
	set_source_files_properties(dns.c PROPERTIES COMPILE_FLAGS "${DNS_C_COMPILE_FLAGS}")
194 195 196
	get_source_file_property(SIP_MESSAGE_PARSER_COMPILE_FLAGS grammars/belle_sip_messageParser.c COMPILE_FLAGS)
	set(SIP_MESSAGE_PARSER_COMPILE_FLAGS "${SIP_MESSAGE_PARSER_COMPILE_FLAGS} -Wno-sign-compare")
	set_source_files_properties(grammars/belle_sip_messageParser.c PROPERTIES COMPILE_FLAGS "${SIP_MESSAGE_PARSER_COMPILE_FLAGS}")
197
endif()
198

199
string(REPLACE ";" " " LINK_FLAGS_STR "${LINK_FLAGS}")
200
if(ENABLE_STATIC)
201
	add_library(bellesip-static STATIC ${BELLE_SIP_HEADER_FILES} ${BELLE_SIP_SOURCE_FILES_C} ${BELLE_SIP_SOURCE_FILES_CXX} ${BELLE_SIP_SOURCE_FILES_OBJC} ${ANTLR3C_SOURCE_FILES})
202
	set_target_properties(bellesip-static PROPERTIES OUTPUT_NAME bellesip)
Ghislain MARY's avatar
Ghislain MARY committed
203
	target_include_directories(bellesip-static PUBLIC ${PUBLIC_INCLUDE_DIRS} PRIVATE ${PRIVATE_INCLUDE_DIRS})
204
	target_link_libraries(bellesip-static INTERFACE ${LIBS})
205
	if(NOT "${LINK_FLAGS_STR}" STREQUAL "")
206
		set_target_properties(bellesip-static PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
207
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
208
	require_c99(bellesip-static)
209 210 211 212 213 214
	install(TARGETS bellesip-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)
215
	add_library(bellesip SHARED ${BELLE_SIP_HEADER_FILES} ${BELLE_SIP_SOURCE_FILES_C} ${BELLE_SIP_SOURCE_FILES_CXX} ${BELLE_SIP_SOURCE_FILES_OBJC} ${ANTLR3C_SOURCE_FILES})
216
	set_target_properties(bellesip PROPERTIES SOVERSION 0)
217
	set_target_properties(bellesip PROPERTIES LINKER_LANGUAGE CXX)
Ghislain MARY's avatar
Ghislain MARY committed
218
	target_include_directories(bellesip PUBLIC ${PUBLIC_INCLUDE_DIRS} PRIVATE ${PRIVATE_INCLUDE_DIRS})
219
	target_link_libraries(bellesip PRIVATE ${LIBS})
220 221 222
	if(NOT "${LINK_FLAGS_STR}" STREQUAL "")
		set_target_properties(bellesip PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
223
	require_c99(bellesip)
224
	if(MSVC)
225 226
		if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
			install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bellesip.pdb
227
				DESTINATION ${CMAKE_INSTALL_BINDIR}
228 229 230
				PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
			)
		endif()
231
	endif()
232 233 234 235 236 237
	install(TARGETS bellesip EXPORT ${EXPORT_TARGETS_NAME}Targets
		RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
		LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
		PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
	)
238
endif()
239 240 241 242
#to avoid // build to generate code twice in // leading compilation issues. Might probably be done in a better way
if (ENABLE_SHARED AND ENABLE_STATIC)
	add_dependencies(bellesip-static bellesip)
endif()