diff options
author | iphydf <iphydf@users.noreply.github.com> | 2017-06-04 12:20:35 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2017-06-04 12:20:35 +0000 |
commit | 41850deb43082533a55e127f9a7cb673f25add92 (patch) | |
tree | d57c1b6b1841c9d94ce4c80d87984b367fb1d2d4 /cmake | |
parent | b782ef5d8e2da0443f90edf3f14649402bb4a6fa (diff) |
Factor out strict_abi cmake code into a separate module.
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/StrictAbi.cmake | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/cmake/StrictAbi.cmake b/cmake/StrictAbi.cmake new file mode 100644 index 00000000..fdf3664b --- /dev/null +++ b/cmake/StrictAbi.cmake | |||
@@ -0,0 +1,38 @@ | |||
1 | ################################################################################ | ||
2 | # | ||
3 | # :: Strict ABI | ||
4 | # | ||
5 | # Enabling the STRICT_ABI flag will generate and use an LD version script. | ||
6 | # It ensures that the dynamic libraries (libtoxcore.so, libtoxav.so) only | ||
7 | # export the symbols that are defined in their public API (tox.h and toxav.h, | ||
8 | # respectively). | ||
9 | # | ||
10 | ################################################################################ | ||
11 | |||
12 | function(make_version_script header ns lib) | ||
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 | |||
19 | set(${lib}_VERSION_SCRIPT "${CMAKE_BINARY_DIR}/${lib}.ld") | ||
20 | |||
21 | file(WRITE ${${lib}_VERSION_SCRIPT} | ||
22 | "{ global:\n") | ||
23 | foreach(sym ${${lib}_SYMS}) | ||
24 | file(APPEND ${${lib}_VERSION_SCRIPT} | ||
25 | "${sym};\n") | ||
26 | endforeach(sym) | ||
27 | file(APPEND ${${lib}_VERSION_SCRIPT} | ||
28 | "local: *; };\n") | ||
29 | |||
30 | set_target_properties(${lib}_shared PROPERTIES | ||
31 | LINK_FLAGS -Wl,--version-script,${${lib}_VERSION_SCRIPT}) | ||
32 | endfunction() | ||
33 | |||
34 | option(STRICT_ABI "Enforce strict ABI export in dynamic libraries" OFF) | ||
35 | if(WIN32 OR APPLE) | ||
36 | # Windows and OSX don't have this linker functionality. | ||
37 | set(STRICT_ABI OFF) | ||
38 | endif() | ||