CMakeLists.txt 9.04 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
set(INCLUDES ${ANTLR3C_INCLUDE_DIRS})
39
set(LIBS ${ANTLR3C_LIBRARIES})
40

41 42
list(APPEND INCLUDES ${BCTOOLBOX_CORE_INCLUDE_DIR})
list(APPEND LIBS ${BCTOOLBOX_CORE_LIBRARIES})
43

44
if(Threads_FOUND)
45 46
	if(CMAKE_USE_PTHREADS_INIT AND NOT CMAKE_SYSTEM_NAME MATCHES "QNX" AND NOT ANDROID)
		list(APPEND LIBS ${CMAKE_THREAD_LIBS_INIT})
Ghislain MARY's avatar
Ghislain MARY committed
47 48
	endif()
endif()
49
if(HAVE_LIBDL)
50
	list(APPEND LIBS dl)
Ghislain MARY's avatar
Ghislain MARY committed
51
endif()
52
if(HAVE_LIBRT)
53 54
	list(APPEND LIBS rt)
endif()
55
if(HAVE_RESINIT)
56
	list(APPEND LIBS resolv)
Ghislain MARY's avatar
Ghislain MARY committed
57
endif()
Ghislain MARY's avatar
Ghislain MARY committed
58 59 60
if(ZLIB_FOUND)
	list(APPEND LIBS ${ZLIB_LIBRARIES})
endif()
61 62
if(WIN32)
	list(APPEND LIBS ws2_32)
Ghislain MARY's avatar
Ghislain MARY committed
63
endif()
Ghislain MARY's avatar
Ghislain MARY committed
64

65
set(SDP_GENERATED_SOURCE_FILES_C
66 67 68 69
	${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sdpLexer.c
	${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sdpLexer.h
	${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sdpParser.c
	${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sdpParser.h
70 71
)
add_custom_command(
72
	OUTPUT ${SDP_GENERATED_SOURCE_FILES_C}
73
	COMMAND ${ANTLR3_COMMAND} -make -Xmultithreaded -Xconversiontimeout 10000 -fo ${CMAKE_CURRENT_BINARY_DIR}/grammars ${CMAKE_CURRENT_SOURCE_DIR}/grammars/belle_sdp.g
74
	DEPENDS grammars/belle_sdp.g
75 76
)

77
set(SIP_MESSAGE_GENERATED_SOURCE_FILES_C
78 79 80 81
	${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sip_messageLexer.c
	${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sip_messageLexer.h
	${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sip_messageParser.c
	${CMAKE_CURRENT_BINARY_DIR}/grammars/belle_sip_messageParser.h
82 83
)
add_custom_command(
84
	OUTPUT ${SIP_MESSAGE_GENERATED_SOURCE_FILES_C}
85
	COMMAND ${ANTLR3_COMMAND} -make -Xmultithreaded -Xconversiontimeout 10000 -fo ${CMAKE_CURRENT_BINARY_DIR}/grammars ${CMAKE_CURRENT_SOURCE_DIR}/grammars/belle_sip_message.g
86
	DEPENDS grammars/belle_sip_message.g
87 88
)

89
set_source_files_properties(${SDP_GENERATED_SOURCE_FILES_C} ${SIP_MESSAGE_GENERATED_SOURCE_FILES_C} PROPERTIES GENERATED TRUE)
90

91
if(ENABLE_TUNNEL)
92
	set(TUNNEL_SOURCE_FILES_C
93 94
		transports/tunnel_listeningpoint.c
		transports/tunnel_channel.c
95 96
	)
	set(TUNNEL_SOURCE_FILES_CXX
97 98 99
		transports/tunnel_wrapper.cc
	)
	list(APPEND LIBS ${TUNNEL_LIBRARIES})
Ghislain MARY's avatar
Ghislain MARY committed
100
endif()
101

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

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

168 169
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)
170 171
if(BELLE_SIP_SOURCE_FILES_CXX)
	set_source_files_properties(${BELLE_SIP_SOURCE_FILES_CXX} PROPERTIES LANGUAGE CXX)
172
	bc_apply_compile_flags(BELLE_SIP_SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
173
endif()
174
if(MSVC)
175 176
	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
177 178 179 180
	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
181
	set_source_files_properties(dns.c PROPERTIES COMPILE_FLAGS "${DNS_C_COMPILE_FLAGS}")
Ghislain MARY's avatar
Ghislain MARY committed
182 183 184 185 186 187
	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}")
188
else()
189 190 191
	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}")
192 193 194
	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}")
195
endif()
196

197
string(REPLACE ";" " " LINK_FLAGS_STR "${LINK_FLAGS}")
198
if(ENABLE_STATIC)
199
	add_library(bellesip-static STATIC ${BELLE_SIP_HEADER_FILES} ${BELLE_SIP_SOURCE_FILES_C} ${BELLE_SIP_SOURCE_FILES_CXX} ${BELLE_SIP_SOURCE_FILES_OBJC})
200
	set_target_properties(bellesip-static PROPERTIES OUTPUT_NAME bellesip)
201
	target_include_directories(bellesip-static PUBLIC ${INCLUDES})
202
	target_link_libraries(bellesip-static INTERFACE ${LIBS})
203
	if(NOT "${LINK_FLAGS_STR}" STREQUAL "")
Ghislain MARY's avatar
Ghislain MARY committed
204
		set_target_properties(bellesip-static PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
205
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
206
	require_c99(bellesip-static)
207 208 209 210 211 212
	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)
213
	add_library(bellesip SHARED ${BELLE_SIP_HEADER_FILES} ${BELLE_SIP_SOURCE_FILES_C} ${BELLE_SIP_SOURCE_FILES_CXX} ${BELLE_SIP_SOURCE_FILES_OBJC})
214
	set_target_properties(bellesip PROPERTIES SOVERSION 0)
215
	set_target_properties(bellesip PROPERTIES LINKER_LANGUAGE CXX)
216
	target_include_directories(bellesip PUBLIC ${INCLUDES})
217
	target_link_libraries(bellesip PRIVATE ${LIBS})
218 219 220
	if(NOT "${LINK_FLAGS_STR}" STREQUAL "")
		set_target_properties(bellesip PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
221
	require_c99(bellesip)
222
	if(MSVC)
223 224
		if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
			install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bellesip.pdb
225
				DESTINATION ${CMAKE_INSTALL_BINDIR}
226 227 228
				PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
			)
		endif()
Ghislain MARY's avatar
Ghislain MARY committed
229
	endif()
230 231 232 233 234 235
	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
	)
Ghislain MARY's avatar
Ghislain MARY committed
236
endif()
237 238 239 240
#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()