summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2017-01-15 16:16:16 +0000
committeriphydf <iphydf@users.noreply.github.com>2017-12-28 23:01:41 +0000
commitf2b6090eca42f4a364ef7517c5eec6d472e9b5f6 (patch)
tree3e83bf92287d822fef55f44e2ed3b9e1157c061e
parent83377e6865dcf8aaf3652fde3d70d73c2a48b2cb (diff)
Generate only one large library "libtoxcore".
This library contains all the code for the old libtoxcore, libtoxav, libtoxdns, and libtoxencryptsave. The build for toxav is still optional, and disabling it causes libtoxcore to simply not contain those symbols and the pkg-config file to not include opus and vpx as dependencies.
-rw-r--r--CMakeLists.txt209
-rw-r--r--cmake/ModulePackage.cmake98
-rw-r--r--cmake/StrictAbi.cmake46
-rw-r--r--other/pkgconfig/libtoxav.pc.in8
-rw-r--r--other/pkgconfig/libtoxcore.pc.in8
-rw-r--r--other/pkgconfig/toxav.pc.in10
-rw-r--r--other/pkgconfig/toxcore.pc.in4
-rw-r--r--other/pkgconfig/toxdns.pc.in10
-rw-r--r--other/pkgconfig/toxencryptsave.pc.in10
-rw-r--r--testing/hstox/binary_decode.c2
-rw-r--r--testing/hstox/binary_encode.c2
11 files changed, 216 insertions, 191 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 41b89597..f794982f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,3 +1,19 @@
1################################################################################
2#
3# The main toxcore CMake build file.
4#
5# This file when processed with cmake produces:
6# - A number of small libraries (.a/.so/...) containing independent components
7# of toxcore. E.g. the DHT has its own library, and the system/network
8# abstractions are in their own library as well. These libraries are not
9# installed on `make install`. The toxdns, toxav, and toxencryptsave
10# libraries are also not installed.
11# - A number of small programs, statically linked if possible.
12# - One big library containing all of the toxcore, toxav, toxdns, and
13# toxencryptsave code.
14#
15################################################################################
16
1cmake_minimum_required(VERSION 2.8.6) 17cmake_minimum_required(VERSION 2.8.6)
2cmake_policy(VERSION 2.8.6) 18cmake_policy(VERSION 2.8.6)
3project(toxcore) 19project(toxcore)
@@ -30,7 +46,6 @@ math(EXPR SOVERSION_MAJOR ${SOVERSION_CURRENT}-${SOVERSION_AGE})
30set(SOVERSION "${SOVERSION_MAJOR}.${SOVERSION_AGE}.${SOVERSION_REVISION}") 46set(SOVERSION "${SOVERSION_MAJOR}.${SOVERSION_AGE}.${SOVERSION_REVISION}")
31message("SOVERSION: ${SOVERSION}") 47message("SOVERSION: ${SOVERSION}")
32 48
33
34################################################################################ 49################################################################################
35# 50#
36# :: Dependencies and configuration 51# :: Dependencies and configuration
@@ -39,9 +54,8 @@ message("SOVERSION: ${SOVERSION}")
39 54
40include(AddCompilerFlag) 55include(AddCompilerFlag)
41include(ApiDsl) 56include(ApiDsl)
42include(CheckCCompilerFlag)
43include(CheckCXXCompilerFlag)
44include(MacRpath) 57include(MacRpath)
58include(ModulePackage)
45include(StrictAbi) 59include(StrictAbi)
46 60
47enable_testing() 61enable_testing()
@@ -172,20 +186,10 @@ endif()
172# 186#
173################################################################################ 187################################################################################
174 188
175# toxcore_PKGCONFIG_LIBS is what's added to the Libs: line in toxcore.pc. It
176# needs to contain all the libraries a program using toxcore should link against
177# if it's statically linked. If it's dynamically linked, there is no need to
178# explicitly link against all the dependencies, but it doesn't harm much(*)
179# either.
180#
181# (*) It allows client code to use symbols from our dependencies without
182# explicitly linking against them.
183set(toxcore_PKGCONFIG_LIBS)
184
185# LAYER 1: Crypto core 189# LAYER 1: Crypto core
186# -------------------- 190# --------------------
187apidsl(toxcore/crypto_core.api.h) 191apidsl(toxcore/crypto_core.api.h)
188add_module(toxcrypto 192add_submodule(toxcore toxcrypto
189 toxcore/ccompat.h 193 toxcore/ccompat.h
190 toxcore/crypto_core.c 194 toxcore/crypto_core.c
191 toxcore/crypto_core.h 195 toxcore/crypto_core.h
@@ -194,10 +198,11 @@ include(CheckFunctionExists)
194check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO) 198check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO)
195check_function_exists(memset_s HAVE_MEMSET_S) 199check_function_exists(memset_s HAVE_MEMSET_S)
196target_link_modules(toxcrypto ${LIBSODIUM_LIBRARIES}) 200target_link_modules(toxcrypto ${LIBSODIUM_LIBRARIES})
201set(toxcrypto_PKGCONFIG_REQUIRES ${toxcrypto_PKGCONFIG_REQUIRES} libsodium)
197 202
198# LAYER 2: Basic networking 203# LAYER 2: Basic networking
199# ------------------------- 204# -------------------------
200add_module(toxnetwork 205add_submodule(toxcore toxnetwork
201 toxcore/logger.c 206 toxcore/logger.c
202 toxcore/logger.h 207 toxcore/logger.h
203 toxcore/network.c 208 toxcore/network.c
@@ -208,22 +213,22 @@ target_link_modules(toxnetwork toxcrypto)
208 213
209if(CMAKE_THREAD_LIBS_INIT) 214if(CMAKE_THREAD_LIBS_INIT)
210 target_link_modules(toxnetwork ${CMAKE_THREAD_LIBS_INIT}) 215 target_link_modules(toxnetwork ${CMAKE_THREAD_LIBS_INIT})
211 set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} ${CMAKE_THREAD_LIBS_INIT}) 216 set(toxnetwork_PKGCONFIG_LIBS ${toxnetwork_PKGCONFIG_LIBS} ${CMAKE_THREAD_LIBS_INIT})
212endif() 217endif()
213 218
214if(RT_LIBRARIES) 219if(RT_LIBRARIES)
215 target_link_modules(toxnetwork ${RT_LIBRARIES}) 220 target_link_modules(toxnetwork ${RT_LIBRARIES})
216 set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lrt") 221 set(toxnetwork_PKGCONFIG_LIBS ${toxnetwork_PKGCONFIG_LIBS} "-lrt")
217endif() 222endif()
218 223
219if(WIN32) 224if(WIN32)
220 target_link_modules(toxnetwork ws2_32 iphlpapi) 225 target_link_modules(toxnetwork ws2_32 iphlpapi)
221 set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} "-lws2_32 -liphlpapi") 226 set(toxnetwork_PKGCONFIG_LIBS ${toxnetwork_PKGCONFIG_LIBS} "-lws2_32 -liphlpapi")
222endif() 227endif()
223 228
224# LAYER 3: Distributed Hash Table 229# LAYER 3: Distributed Hash Table
225# ------------------------------- 230# -------------------------------
226add_module(toxdht 231add_submodule(toxcore toxdht
227 toxcore/DHT.c 232 toxcore/DHT.c
228 toxcore/DHT.h 233 toxcore/DHT.h
229 toxcore/LAN_discovery.c 234 toxcore/LAN_discovery.c
@@ -236,7 +241,7 @@ target_link_modules(toxdht toxnetwork)
236 241
237# LAYER 4: Onion routing, TCP connections, crypto connections 242# LAYER 4: Onion routing, TCP connections, crypto connections
238# ----------------------------------------------------------- 243# -----------------------------------------------------------
239add_module(toxnetcrypto 244add_submodule(toxcore toxnetcrypto
240 toxcore/TCP_client.c 245 toxcore/TCP_client.c
241 toxcore/TCP_client.h 246 toxcore/TCP_client.h
242 toxcore/TCP_connection.c 247 toxcore/TCP_connection.c
@@ -257,7 +262,7 @@ target_link_modules(toxnetcrypto toxdht)
257 262
258# LAYER 5: Friend requests and connections 263# LAYER 5: Friend requests and connections
259# ---------------------------------------- 264# ----------------------------------------
260add_module(toxfriends 265add_submodule(toxcore toxfriends
261 toxcore/friend_connection.c 266 toxcore/friend_connection.c
262 toxcore/friend_connection.h 267 toxcore/friend_connection.h
263 toxcore/friend_requests.c 268 toxcore/friend_requests.c
@@ -266,14 +271,14 @@ target_link_modules(toxfriends toxnetcrypto)
266 271
267# LAYER 6: Tox messenger 272# LAYER 6: Tox messenger
268# ---------------------- 273# ----------------------
269add_module(toxmessenger 274add_submodule(toxcore toxmessenger
270 toxcore/Messenger.c 275 toxcore/Messenger.c
271 toxcore/Messenger.h) 276 toxcore/Messenger.h)
272target_link_modules(toxmessenger toxfriends) 277target_link_modules(toxmessenger toxfriends)
273 278
274# LAYER 7: Group chats 279# LAYER 7: Group chats
275# -------------------- 280# --------------------
276add_module(toxgroup 281add_submodule(toxcore toxgroup
277 toxcore/group.c 282 toxcore/group.c
278 toxcore/group.h) 283 toxcore/group.h)
279target_link_modules(toxgroup toxmessenger) 284target_link_modules(toxgroup toxmessenger)
@@ -281,11 +286,12 @@ target_link_modules(toxgroup toxmessenger)
281# LAYER 8: Public API 286# LAYER 8: Public API
282# ------------------- 287# -------------------
283apidsl(toxcore/tox.api.h) 288apidsl(toxcore/tox.api.h)
284add_module(toxcore 289add_submodule(toxcore toxapi
285 toxcore/tox_api.c 290 toxcore/tox_api.c
286 toxcore/tox.c 291 toxcore/tox.c
287 toxcore/tox.h) 292 toxcore/tox.h)
288target_link_modules(toxcore toxgroup) 293target_link_modules(toxapi toxgroup)
294set(toxapi_API_HEADERS ${toxcore_SOURCE_DIR}/toxcore/tox.h^tox)
289 295
290################################################################################ 296################################################################################
291# 297#
@@ -295,7 +301,7 @@ target_link_modules(toxcore toxgroup)
295 301
296if(BUILD_TOXAV) 302if(BUILD_TOXAV)
297 apidsl(toxav/toxav.api.h) 303 apidsl(toxav/toxav.api.h)
298 add_module(toxav 304 add_submodule(toxcore toxav
299 toxav/audio.c 305 toxav/audio.c
300 toxav/audio.h 306 toxav/audio.h
301 toxav/bwcontroller.c 307 toxav/bwcontroller.c
@@ -313,7 +319,11 @@ if(BUILD_TOXAV)
313 toxav/toxav_old.c 319 toxav/toxav_old.c
314 toxav/video.c 320 toxav/video.c
315 toxav/video.h) 321 toxav/video.h)
316 target_link_modules(toxav toxcore ${OPUS_LIBRARIES} ${VPX_LIBRARIES}) 322 target_link_modules(toxav toxgroup ${OPUS_LIBRARIES} ${VPX_LIBRARIES})
323 set(toxav_PKGCONFIG_REQUIRES ${toxav_PKGCONFIG_REQUIRES} opus vpx)
324
325 set(toxav_API_HEADERS ${toxcore_SOURCE_DIR}/toxav/toxav.h^toxav)
326 make_version_script(toxav ${toxav_API_HEADERS})
317endif() 327endif()
318 328
319################################################################################ 329################################################################################
@@ -322,15 +332,54 @@ endif()
322# 332#
323################################################################################ 333################################################################################
324 334
325add_module(toxdns 335add_submodule(toxcore toxdns
326 toxdns/toxdns.c) 336 toxdns/toxdns.c)
327target_link_modules(toxdns toxcore) 337target_link_modules(toxdns toxnetwork)
338set(toxdns_API_HEADERS ${toxcore_SOURCE_DIR}/toxdns/toxdns.h^tox)
328 339
329apidsl(toxencryptsave/toxencryptsave.api.h) 340apidsl(toxencryptsave/toxencryptsave.api.h)
330add_module(toxencryptsave 341add_submodule(toxcore toxencryptsave
331 toxencryptsave/toxencryptsave.c 342 toxencryptsave/toxencryptsave.c
332 toxencryptsave/toxencryptsave.h) 343 toxencryptsave/toxencryptsave.h)
333target_link_modules(toxencryptsave toxcore) 344target_link_modules(toxencryptsave toxcrypto)
345set(toxencryptsave_API_HEADERS ${toxcore_SOURCE_DIR}/toxencryptsave/toxencryptsave.h^tox)
346
347################################################################################
348#
349# :: All layers together in one library for ease of use
350#
351################################################################################
352
353# Create combined library from all the sources.
354add_module(toxcore ${toxcore_SOURCES})
355
356# Link it to all dependencies.
357foreach(sublib ${toxcore_SUBLIBS})
358 set(toxcore_LINK_MODULES ${toxcore_LINK_MODULES} ${${sublib}_LINK_MODULES})
359endforeach()
360target_link_modules(toxcore ${toxcore_LINK_MODULES})
361
362# Concatenate all the pkg-config Libs: lines.
363foreach(sublib ${toxcore_SUBLIBS})
364 set(toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} ${${sublib}_PKGCONFIG_LIBS})
365endforeach()
366
367# Concatenate all the pkg-config Requires: lines.
368foreach(sublib ${toxcore_SUBLIBS})
369 set(toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} ${${sublib}_PKGCONFIG_REQUIRES})
370endforeach()
371
372# Collect all API headers.
373foreach(sublib ${toxcore_SUBLIBS})
374 set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${${sublib}_API_HEADERS})
375endforeach()
376
377# Make version script (on systems that support it) to limit symbol visibility.
378make_version_script(toxcore ${toxcore_API_HEADERS})
379
380# Generate pkg-config file, install library to "lib" and install headers to
381# "include/tox".
382install_module(toxcore DESTINATION "include/tox")
334 383
335################################################################################ 384################################################################################
336# 385#
@@ -338,7 +387,9 @@ target_link_modules(toxencryptsave toxcore)
338# 387#
339################################################################################ 388################################################################################
340 389
341find_program(SPECTEST NAMES tox-spectest) 390find_program(SPECTEST NAMES
391 tox-spectest
392 ../.stack-work/install/x86_64-linux/lts-2.22/7.8.4/bin/tox-spectest)
342 393
343if(NOT SPECTEST) 394if(NOT SPECTEST)
344 find_program(STACK NAMES stack) 395 find_program(STACK NAMES stack)
@@ -360,6 +411,8 @@ if(MSGPACK_FOUND)
360 testing/hstox/util.c) 411 testing/hstox/util.c)
361 target_link_modules(toxcore-sut 412 target_link_modules(toxcore-sut
362 toxcore 413 toxcore
414 toxdht
415 toxnetcrypto
363 ${MSGPACK_LIBRARIES}) 416 ${MSGPACK_LIBRARIES})
364 if(SPECTEST) 417 if(SPECTEST)
365 add_test(NAME spectest COMMAND ${SPECTEST} $<TARGET_FILE:toxcore-sut>) 418 add_test(NAME spectest COMMAND ${SPECTEST} $<TARGET_FILE:toxcore-sut>)
@@ -393,11 +446,10 @@ function(auto_test target)
393 add_c_executable(auto_${target}_test auto_tests/${target}_test.c) 446 add_c_executable(auto_${target}_test auto_tests/${target}_test.c)
394 target_link_modules(auto_${target}_test 447 target_link_modules(auto_${target}_test
395 toxcore 448 toxcore
396 toxencryptsave 449 toxcrypto
450 toxmessenger
451 toxnetcrypto
397 ${CHECK_LIBRARIES}) 452 ${CHECK_LIBRARIES})
398 if(BUILD_TOXAV)
399 target_link_modules(auto_${target}_test toxav)
400 endif()
401 if(NOT ARGV1 STREQUAL "DONT_RUN") 453 if(NOT ARGV1 STREQUAL "DONT_RUN")
402 add_test(NAME ${target} COMMAND auto_${target}_test) 454 add_test(NAME ${target} COMMAND auto_${target}_test)
403 set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}") 455 set_tests_properties(${target} PROPERTIES TIMEOUT "${TEST_TIMEOUT_SECONDS}")
@@ -478,7 +530,7 @@ if(BOOTSTRAP_DAEMON)
478 other/bootstrap_daemon/src/tox-bootstrapd.c 530 other/bootstrap_daemon/src/tox-bootstrapd.c
479 other/bootstrap_node_packets.c 531 other/bootstrap_node_packets.c
480 other/bootstrap_node_packets.h) 532 other/bootstrap_node_packets.h)
481 target_link_modules(tox-bootstrapd toxnetcrypto ${LIBCONFIG_LIBRARIES}) 533 target_link_modules(tox-bootstrapd toxfriends ${LIBCONFIG_LIBRARIES})
482 install(TARGETS tox-bootstrapd RUNTIME DESTINATION bin) 534 install(TARGETS tox-bootstrapd RUNTIME DESTINATION bin)
483 endif() 535 endif()
484endif() 536endif()
@@ -491,11 +543,11 @@ endif()
491 543
492option(BUILD_AV_TEST "Build toxav test" ON) 544option(BUILD_AV_TEST "Build toxav test" ON)
493if(NOT WIN32 545if(NOT WIN32
494 AND BUILD_AV_TEST AND BUILD_TOXAV 546 AND BUILD_AV_TEST AND BUILD_TOXAV
495 AND SNDFILE_FOUND AND PORTAUDIO_FOUND AND OPENCV_FOUND) 547 AND SNDFILE_FOUND AND PORTAUDIO_FOUND AND OPENCV_FOUND)
496 add_c_executable(av_test testing/av_test.c) 548 add_c_executable(av_test testing/av_test.c)
497 target_link_modules(av_test 549 target_link_modules(av_test
498 toxav 550 toxcore
499 ${OPENCV_LIBRARIES} 551 ${OPENCV_LIBRARIES}
500 ${PORTAUDIO_LIBRARIES} 552 ${PORTAUDIO_LIBRARIES}
501 ${SNDFILE_LIBRARIES}) 553 ${SNDFILE_LIBRARIES})
@@ -533,80 +585,5 @@ endif()
533 585
534if(NOT WIN32) 586if(NOT WIN32)
535 add_c_executable(irc_syncbot testing/irc_syncbot.c) 587 add_c_executable(irc_syncbot testing/irc_syncbot.c)
536 target_link_modules(irc_syncbot toxcore) 588 target_link_modules(irc_syncbot toxcore toxnetwork)
537endif()
538
539################################################################################
540#
541# :: Installation and pkg-config
542#
543################################################################################
544
545string(REPLACE ";" " " toxcore_PKGCONFIG_LIBS "${toxcore_PKGCONFIG_LIBS}")
546
547if(BUILD_TOXAV)
548 configure_file(
549 "${toxcore_SOURCE_DIR}/other/pkgconfig/toxav.pc.in"
550 "${CMAKE_BINARY_DIR}/toxav.pc"
551 @ONLY
552 )
553endif()
554
555configure_file(
556 "${toxcore_SOURCE_DIR}/other/pkgconfig/toxcore.pc.in"
557 "${CMAKE_BINARY_DIR}/toxcore.pc"
558 @ONLY
559)
560
561configure_file(
562 "${toxcore_SOURCE_DIR}/other/pkgconfig/toxdns.pc.in"
563 "${CMAKE_BINARY_DIR}/toxdns.pc"
564 @ONLY
565)
566
567configure_file(
568 "${toxcore_SOURCE_DIR}/other/pkgconfig/toxencryptsave.pc.in"
569 "${CMAKE_BINARY_DIR}/toxencryptsave.pc"
570 @ONLY
571)
572
573configure_file(
574 "${toxcore_SOURCE_DIR}/other/pkgconfig/libtoxcore.pc.in"
575 "${CMAKE_BINARY_DIR}/libtoxcore.pc"
576 @ONLY
577)
578
579configure_file(
580 "${toxcore_SOURCE_DIR}/other/pkgconfig/libtoxav.pc.in"
581 "${CMAKE_BINARY_DIR}/libtoxav.pc"
582 @ONLY
583)
584
585install(FILES
586 ${CMAKE_BINARY_DIR}/libtoxcore.pc
587 ${CMAKE_BINARY_DIR}/toxcore.pc
588 ${CMAKE_BINARY_DIR}/toxdns.pc
589 ${CMAKE_BINARY_DIR}/toxencryptsave.pc
590 DESTINATION "lib/pkgconfig")
591install(FILES
592 toxcore/tox.h
593 toxdns/toxdns.h
594 toxencryptsave/toxencryptsave.h
595 DESTINATION "include/tox")
596
597if(BUILD_TOXAV)
598 install(FILES
599 ${CMAKE_BINARY_DIR}/libtoxav.pc
600 ${CMAKE_BINARY_DIR}/toxav.pc
601 DESTINATION "lib/pkgconfig")
602 install(FILES
603 toxav/toxav.h
604 DESTINATION "include/tox")
605endif()
606
607if(STRICT_ABI AND SHELL AND ENABLE_SHARED)
608 if(BUILD_TOXAV)
609 make_version_script(${toxcore_SOURCE_DIR}/toxav/toxav.h toxav toxav)
610 endif()
611 make_version_script(${toxcore_SOURCE_DIR}/toxcore/tox.h tox toxcore)
612endif() 589endif()
diff --git a/cmake/ModulePackage.cmake b/cmake/ModulePackage.cmake
index 3a4eb9b9..d51607df 100644
--- a/cmake/ModulePackage.cmake
+++ b/cmake/ModulePackage.cmake
@@ -51,45 +51,123 @@ function(pkg_use_module mod pkg)
51 endif() 51 endif()
52endfunction() 52endfunction()
53 53
54macro(add_submodule super lib)
55 add_module(${lib} ${ARGN})
56 set(${super}_SUBLIBS ${${super}_SUBLIBS} ${lib})
57 set(${super}_SOURCES ${${super}_SOURCES} ${${lib}_SOURCES})
58endmacro()
59
54function(add_module lib) 60function(add_module lib)
55 set_source_language(${ARGN}) 61 set_source_language(${ARGN})
62 set(${lib}_SOURCES ${ARGN} PARENT_SCOPE)
56 63
57 if(ENABLE_SHARED) 64 if(ENABLE_SHARED)
58 add_library(${lib}_shared SHARED ${ARGN}) 65 add_library(${lib}_shared SHARED ${ARGN})
66 set_target_properties(${lib}_shared PROPERTIES OUTPUT_NAME ${lib})
67 endif()
68 if(ENABLE_STATIC)
69 add_library(${lib}_static STATIC ${ARGN})
70 set_target_properties(${lib}_static PROPERTIES OUTPUT_NAME ${lib})
71 endif()
72
73 # ${lib}_PKGCONFIG_LIBS is what's added to the Libs: line in ${lib}.pc. It
74 # needs to contain all the libraries a program using ${lib} should link against
75 # if it's statically linked. If it's dynamically linked, there is no need to
76 # explicitly link against all the dependencies, but it doesn't harm much(*)
77 # either.
78 #
79 # (*) It allows client code to use symbols from our dependencies without
80 # explicitly linking against them.
81 set(${lib}_PKGCONFIG_LIBS PARENT_SCOPE)
82 # Requires: in pkg-config file.
83 set(${lib}_PKGCONFIG_REQUIRES PARENT_SCOPE)
84endfunction()
85
86function(install_module lib)
87 if(ENABLE_SHARED)
59 set_target_properties(${lib}_shared PROPERTIES 88 set_target_properties(${lib}_shared PROPERTIES
60 OUTPUT_NAME ${lib}
61 VERSION ${SOVERSION} 89 VERSION ${SOVERSION}
62 SOVERSION ${SOVERSION_MAJOR} 90 SOVERSION ${SOVERSION_MAJOR}
63 ) 91 )
64 install(TARGETS ${lib}_shared DESTINATION "lib") 92 install(TARGETS ${lib}_shared DESTINATION "lib")
65 endif() 93 endif()
66 if(ENABLE_STATIC) 94 if(ENABLE_STATIC)
67 add_library(${lib}_static STATIC ${ARGN})
68 set_target_properties(${lib}_static PROPERTIES OUTPUT_NAME ${lib})
69 install(TARGETS ${lib}_static DESTINATION "lib") 95 install(TARGETS ${lib}_static DESTINATION "lib")
70 endif() 96 endif()
97
98 string(REPLACE ";" " " ${lib}_PKGCONFIG_LIBS "${${lib}_PKGCONFIG_LIBS}")
99 string(REPLACE ";" " " ${lib}_PKGCONFIG_REQUIRES "${${lib}_PKGCONFIG_REQUIRES}")
100
101 configure_file(
102 "${${lib}_SOURCE_DIR}/other/pkgconfig/${lib}.pc.in"
103 "${CMAKE_BINARY_DIR}/${lib}.pc"
104 @ONLY
105 )
106
107 install(FILES
108 ${CMAKE_BINARY_DIR}/${lib}.pc
109 DESTINATION "lib/pkgconfig")
110
111 foreach(sublib ${${lib}_API_HEADERS})
112 string(REPLACE "^" ";" sublib ${sublib})
113 list(GET sublib 0 header)
114
115 install(FILES ${header} ${ARGN})
116 endforeach()
71endfunction() 117endfunction()
72 118
73function(target_link_modules target) 119function(target_link_modules target)
120 # If the target we're adding dependencies to is a shared library, add it to
121 # the set of targets.
74 if(TARGET ${target}_shared) 122 if(TARGET ${target}_shared)
75 set(_targets ${_targets} ${target}_shared) 123 set(_targets ${_targets} ${target}_shared)
124 # Shared libraries should first try to link against other shared libraries.
125 set(${target}_shared_primary shared)
126 # If that fails (because the shared target doesn't exist), try linking
127 # against the static library. This requires the static library's objects to
128 # be PIC.
129 set(${target}_shared_secondary static)
76 endif() 130 endif()
131 # It can also be a static library at the same time.
77 if(TARGET ${target}_static) 132 if(TARGET ${target}_static)
78 set(_targets ${_targets} ${target}_static) 133 set(_targets ${_targets} ${target}_static)
134 # Static libraries aren't actually linked, but their dependencies are
135 # recorded by "linking" them. If we link an executable to a static library,
136 # we want to also link statically against its transitive dependencies.
137 set(${target}_static_primary static)
138 # If a dependency doesn't exist as static library, we link against the
139 # shared one.
140 set(${target}_static_secondary shared)
79 endif() 141 endif()
142 # If it's neither, then it's an executable.
80 if(NOT _targets) 143 if(NOT _targets)
81 set(_targets ${_targets} ${target}) 144 set(_targets ${_targets} ${target})
145 # Executables preferrably link against static libraries, so they are
146 # standalone and can be shipped without any external dependencies. As a
147 # frame of reference: nTox becomes an 1.3M binary instead of 139K on x86_64
148 # Linux.
149 set(${target}_primary static)
150 set(${target}_secondary shared)
82 endif() 151 endif()
83 152
84 foreach(target ${_targets}) 153 foreach(dep ${ARGN})
85 foreach(dep ${ARGN}) 154 foreach(_target ${_targets})
86 if(TARGET ${dep}_shared) 155 if(TARGET ${dep}_${${_target}_primary})
87 target_link_libraries(${target} ${dep}_shared) 156 target_link_libraries(${_target} ${dep}_${${_target}_primary})
88 elseif(TARGET ${dep}_static) 157 elseif(TARGET ${dep}_${${_target}_secondary})
89 target_link_libraries(${target} ${dep}_static) 158 target_link_libraries(${_target} ${dep}_${${_target}_secondary})
90 else() 159 else()
91 target_link_libraries(${target} ${dep}) 160 # We record the modules linked to this target, so that we can collect
161 # them later when linking a composed module.
162 list(FIND LINK_MODULES ${dep} _index)
163 if(_index EQUAL -1)
164 set(LINK_MODULES ${LINK_MODULES} ${dep})
165 endif()
166
167 target_link_libraries(${_target} ${dep})
92 endif() 168 endif()
93 endforeach() 169 endforeach()
94 endforeach() 170 endforeach()
171
172 set(${target}_LINK_MODULES ${${target}_LINK_MODULES} ${LINK_MODULES} PARENT_SCOPE)
95endfunction() 173endfunction()
diff --git a/cmake/StrictAbi.cmake b/cmake/StrictAbi.cmake
index fdf3664b..5a646d77 100644
--- a/cmake/StrictAbi.cmake
+++ b/cmake/StrictAbi.cmake
@@ -9,26 +9,42 @@
9# 9#
10################################################################################ 10################################################################################
11 11
12function(make_version_script header ns lib) 12find_program(SHELL NAMES sh dash bash zsh fish)
13 execute_process(
14 COMMAND ${SHELL} -c "egrep '^\\w' ${header} | grep '${ns}_[a-z0-9_]*(' | grep -v '^typedef' | grep -o '${ns}_[a-z0-9_]*(' | egrep -o '\\w+' | sort -u"
15 OUTPUT_VARIABLE ${lib}_SYMS
16 OUTPUT_STRIP_TRAILING_WHITESPACE)
17 string(REPLACE "\n" ";" ${lib}_SYMS ${${lib}_SYMS})
18 13
19 set(${lib}_VERSION_SCRIPT "${CMAKE_BINARY_DIR}/${lib}.ld") 14macro(make_version_script)
15 if(STRICT_ABI AND SHELL AND ENABLE_SHARED)
16 _make_version_script(${ARGN})
17 endif()
18endmacro()
20 19
21 file(WRITE ${${lib}_VERSION_SCRIPT} 20function(_make_version_script target)
21 set(${target}_VERSION_SCRIPT "${CMAKE_BINARY_DIR}/${target}.ld")
22
23 file(WRITE ${${target}_VERSION_SCRIPT}
22 "{ global:\n") 24 "{ global:\n")
23 foreach(sym ${${lib}_SYMS}) 25
24 file(APPEND ${${lib}_VERSION_SCRIPT} 26 foreach(sublib ${ARGN})
25 "${sym};\n") 27 string(REPLACE "^" ";" sublib ${sublib})
26 endforeach(sym) 28 list(GET sublib 0 header)
27 file(APPEND ${${lib}_VERSION_SCRIPT} 29 list(GET sublib 1 ns)
30
31 execute_process(
32 COMMAND ${SHELL} -c "egrep '^\\w' ${header} | grep '${ns}_[a-z0-9_]*(' | grep -v '^typedef' | grep -o '${ns}_[a-z0-9_]*(' | egrep -o '\\w+' | sort -u"
33 OUTPUT_VARIABLE sublib_SYMS
34 OUTPUT_STRIP_TRAILING_WHITESPACE)
35 string(REPLACE "\n" ";" sublib_SYMS ${sublib_SYMS})
36
37 foreach(sym ${sublib_SYMS})
38 file(APPEND ${${target}_VERSION_SCRIPT}
39 "${sym};\n")
40 endforeach(sym)
41 endforeach(sublib)
42
43 file(APPEND ${${target}_VERSION_SCRIPT}
28 "local: *; };\n") 44 "local: *; };\n")
29 45
30 set_target_properties(${lib}_shared PROPERTIES 46 set_target_properties(${target}_shared PROPERTIES
31 LINK_FLAGS -Wl,--version-script,${${lib}_VERSION_SCRIPT}) 47 LINK_FLAGS -Wl,--version-script,${${target}_VERSION_SCRIPT})
32endfunction() 48endfunction()
33 49
34option(STRICT_ABI "Enforce strict ABI export in dynamic libraries" OFF) 50option(STRICT_ABI "Enforce strict ABI export in dynamic libraries" OFF)
diff --git a/other/pkgconfig/libtoxav.pc.in b/other/pkgconfig/libtoxav.pc.in
deleted file mode 100644
index e0b95b48..00000000
--- a/other/pkgconfig/libtoxav.pc.in
+++ /dev/null
@@ -1,8 +0,0 @@
1prefix=@CMAKE_INSTALL_PREFIX@
2libdir=${prefix}/lib
3includedir=${prefix}/include
4
5Name: libtoxav
6Description: Tox A/V library - compatibility module (use toxav instead)
7Requires: toxav
8Version: @PROJECT_VERSION@
diff --git a/other/pkgconfig/libtoxcore.pc.in b/other/pkgconfig/libtoxcore.pc.in
deleted file mode 100644
index c5588bb4..00000000
--- a/other/pkgconfig/libtoxcore.pc.in
+++ /dev/null
@@ -1,8 +0,0 @@
1prefix=@CMAKE_INSTALL_PREFIX@
2libdir=${prefix}/lib
3includedir=${prefix}/include
4
5Name: libtoxcore
6Description: Tox protocol library - compatibility module (use toxcore, toxdns, and toxencryptsave instead)
7Requires: toxcore toxdns toxencryptsave
8Version: @PROJECT_VERSION@
diff --git a/other/pkgconfig/toxav.pc.in b/other/pkgconfig/toxav.pc.in
deleted file mode 100644
index 6b56500b..00000000
--- a/other/pkgconfig/toxav.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
1prefix=@CMAKE_INSTALL_PREFIX@
2libdir=${prefix}/lib
3includedir=${prefix}/include
4
5Name: toxav
6Description: Tox A/V library
7Requires: opus toxcore vpx
8Version: @PROJECT_VERSION@
9Libs: -L${libdir} @toxav_PKGCONFIG_LIBS@ -ltoxav
10Cflags: -I${includedir}
diff --git a/other/pkgconfig/toxcore.pc.in b/other/pkgconfig/toxcore.pc.in
index 48acc429..72fe00cf 100644
--- a/other/pkgconfig/toxcore.pc.in
+++ b/other/pkgconfig/toxcore.pc.in
@@ -4,7 +4,7 @@ includedir=${prefix}/include
4 4
5Name: toxcore 5Name: toxcore
6Description: Tox protocol library 6Description: Tox protocol library
7Requires: libsodium 7Requires: @toxcore_PKGCONFIG_REQUIRES@
8Version: @PROJECT_VERSION@ 8Version: @PROJECT_VERSION@
9Libs: -L${libdir} -ltoxcore @toxcore_PKGCONFIG_LIBS@ -ltoxcrypto -ltoxnetwork -ltoxdht -ltoxnetcrypto -ltoxfriends -ltoxmessenger -ltoxgroup 9Libs: -L${libdir} -ltoxcore @toxcore_PKGCONFIG_LIBS@
10Cflags: -I${includedir} 10Cflags: -I${includedir}
diff --git a/other/pkgconfig/toxdns.pc.in b/other/pkgconfig/toxdns.pc.in
deleted file mode 100644
index 0f69130c..00000000
--- a/other/pkgconfig/toxdns.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
1prefix=@CMAKE_INSTALL_PREFIX@
2libdir=${prefix}/lib
3includedir=${prefix}/include
4
5Name: toxdns
6Description: Tox DNS3 library
7Requires: toxcore
8Version: @PROJECT_VERSION@
9Libs: -L${libdir} @toxdns_PKGCONFIG_LIBS@ -ltoxdns
10Cflags: -I${includedir}
diff --git a/other/pkgconfig/toxencryptsave.pc.in b/other/pkgconfig/toxencryptsave.pc.in
deleted file mode 100644
index bd717f53..00000000
--- a/other/pkgconfig/toxencryptsave.pc.in
+++ /dev/null
@@ -1,10 +0,0 @@
1prefix=@CMAKE_INSTALL_PREFIX@
2libdir=${prefix}/lib
3includedir=${prefix}/include
4
5Name: toxencryptsave
6Description: Tox block encryption library
7Requires: toxcore
8Version: @PROJECT_VERSION@
9Libs: -L${libdir} @toxencryptsave_PKGCONFIG_LIBS@ -ltoxencryptsave
10Cflags: -I${includedir}
diff --git a/testing/hstox/binary_decode.c b/testing/hstox/binary_decode.c
index 588b9a7c..5f66063b 100644
--- a/testing/hstox/binary_decode.c
+++ b/testing/hstox/binary_decode.c
@@ -1,4 +1,4 @@
1#define _BSD_SOURCE 1#define _DEFAULT_SOURCE
2#include "methods.h" 2#include "methods.h"
3 3
4#include "byteswap.h" 4#include "byteswap.h"
diff --git a/testing/hstox/binary_encode.c b/testing/hstox/binary_encode.c
index aad94f5f..ba412e13 100644
--- a/testing/hstox/binary_encode.c
+++ b/testing/hstox/binary_encode.c
@@ -1,4 +1,4 @@
1#define _BSD_SOURCE 1#define _DEFAULT_SOURCE
2#include "methods.h" 2#include "methods.h"
3 3
4#include "byteswap.h" 4#include "byteswap.h"