Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 1 | # |
| 2 | # Best-effort magic that tries to produce semi-static binaries |
| 3 | # (i.e. only depends on "safe" libraries like libc and libX11) |
| 4 | # |
| 5 | # Note that this often fails as there is no way to automatically |
| 6 | # determine the dependencies of the libraries we depend on, and |
| 7 | # a lot of details change with each different build environment. |
| 8 | # |
| 9 | |
| 10 | option(BUILD_STATIC |
Pierre Ossman | ced99a9 | 2014-10-28 17:01:08 +0100 | [diff] [blame] | 11 | "Link statically against most libraries, if possible" OFF) |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 12 | |
| 13 | if(BUILD_STATIC) |
| 14 | message(STATUS "Attempting to link static binaries...") |
| 15 | |
| 16 | set(JPEG_LIBRARIES "-Wl,-Bstatic -ljpeg -Wl,-Bdynamic") |
| 17 | |
Pierre Ossman | cc8c6a2 | 2015-02-03 09:54:49 +0100 | [diff] [blame] | 18 | if(WIN32) |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 19 | set(ZLIB_LIBRARIES "-Wl,-Bstatic -lz -Wl,-Bdynamic") |
| 20 | endif() |
| 21 | |
| 22 | # gettext is included in libc on many unix systems |
| 23 | if(NOT LIBC_HAS_DGETTEXT) |
| 24 | set(GETTEXT_LIBRARIES "-Wl,-Bstatic -lintl -liconv -Wl,-Bdynamic") |
| 25 | endif() |
| 26 | |
| 27 | if(GNUTLS_FOUND) |
| 28 | # GnuTLS has historically had different crypto backends |
| 29 | FIND_LIBRARY(GCRYPT_LIBRARY NAMES gcrypt libgcrypt |
| 30 | HINTS ${PC_GNUTLS_LIBDIR} ${PC_GNUTLS_LIBRARY_DIRS}) |
| 31 | FIND_LIBRARY(NETTLE_LIBRARY NAMES nettle libnettle |
| 32 | HINTS ${PC_GNUTLS_LIBDIR} ${PC_GNUTLS_LIBRARY_DIRS}) |
Brian P. Hinz | 4475976 | 2014-11-04 00:03:24 -0500 | [diff] [blame] | 33 | FIND_LIBRARY(TASN1_LIBRARY NAMES tasn1 libtasn1 |
| 34 | HINTS ${PC_GNUTLS_LIBDIR} ${PC_GNUTLS_LIBRARY_DIRS}) |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 35 | |
Brian P. Hinz | 4475976 | 2014-11-04 00:03:24 -0500 | [diff] [blame] | 36 | set(GNUTLS_LIBRARIES "-Wl,-Bstatic -lgnutls") |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 37 | |
Brian P. Hinz | 4475976 | 2014-11-04 00:03:24 -0500 | [diff] [blame] | 38 | if(TASN1_LIBRARY) |
| 39 | set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -ltasn1") |
| 40 | endif() |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 41 | if(NETTLE_LIBRARY) |
Pierre Ossman | 9549139 | 2014-10-28 16:58:14 +0100 | [diff] [blame] | 42 | set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -lnettle -lhogweed -lgmp") |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 43 | endif() |
| 44 | if(GCRYPT_LIBRARY) |
| 45 | set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -lgcrypt -lgpg-error") |
| 46 | endif() |
| 47 | |
| 48 | set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -Wl,-Bdynamic") |
| 49 | |
Pierre Ossman | 9549139 | 2014-10-28 16:58:14 +0100 | [diff] [blame] | 50 | if (WIN32) |
Pierre Ossman | 95763a6 | 2015-02-13 11:12:42 +0100 | [diff] [blame] | 51 | # GnuTLS uses various crypto-api stuff |
Pierre Ossman | 9549139 | 2014-10-28 16:58:14 +0100 | [diff] [blame] | 52 | set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -lcrypt32") |
Pierre Ossman | 95763a6 | 2015-02-13 11:12:42 +0100 | [diff] [blame] | 53 | # And sockets |
| 54 | set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -lws2_32") |
Pierre Ossman | 9549139 | 2014-10-28 16:58:14 +0100 | [diff] [blame] | 55 | endif() |
| 56 | |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 57 | if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") |
Pierre Ossman | 95763a6 | 2015-02-13 11:12:42 +0100 | [diff] [blame] | 58 | # nanosleep() lives here on Solaris |
Pierre Ossman | 4790e11 | 2014-10-28 16:57:05 +0100 | [diff] [blame] | 59 | set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -lrt") |
Pierre Ossman | 95763a6 | 2015-02-13 11:12:42 +0100 | [diff] [blame] | 60 | # and socket functions are hidden here |
| 61 | set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -lsocket") |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 62 | endif() |
Pierre Ossman | 5b9303a | 2014-10-28 16:59:02 +0100 | [diff] [blame] | 63 | |
| 64 | # GnuTLS uses gettext and zlib, so make sure those are always |
| 65 | # included and in the proper order |
| 66 | set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} ${ZLIB_LIBRARIES}") |
| 67 | set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} ${GETTEXT_LIBRARIES}") |
| 68 | |
| 69 | # The last variables might introduce whitespace, which CMake |
| 70 | # throws a hissy fit about |
| 71 | string(STRIP ${GNUTLS_LIBRARIES} GNUTLS_LIBRARIES) |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 72 | endif() |
| 73 | |
| 74 | if(FLTK_FOUND) |
| 75 | set(FLTK_LIBRARIES "-Wl,-Bstatic -lfltk_images -lpng -ljpeg -lfltk -Wl,-Bdynamic") |
| 76 | |
| 77 | if(WIN32) |
Pierre Ossman | 4790e11 | 2014-10-28 16:57:05 +0100 | [diff] [blame] | 78 | set(FLTK_LIBRARIES "${FLTK_LIBRARIES} -lcomctl32") |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 79 | elseif(APPLE) |
Pierre Ossman | 4790e11 | 2014-10-28 16:57:05 +0100 | [diff] [blame] | 80 | set(FLTK_LIBRARIES "${FLTK_LIBRARIES} -framework Cocoa") |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 81 | else() |
Peter Åstrand (astrand) | c4bc5a8 | 2015-02-10 12:21:05 +0100 | [diff] [blame] | 82 | set(FLTK_LIBRARIES "${FLTK_LIBRARIES} -lm -ldl") |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 83 | endif() |
| 84 | |
| 85 | if(X11_FOUND AND NOT APPLE) |
| 86 | if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") |
Peter Åstrand (astrand) | c4bc5a8 | 2015-02-10 12:21:05 +0100 | [diff] [blame] | 87 | set(FLTK_LIBRARIES "${FLTK_LIBRARIES} ${X11_Xcursor_LIB} ${X11_Xfixes_LIB} -Wl,-Bstatic -lXft -Wl,-Bdynamic -lfontconfig -lXrender -lXext -R/usr/sfw/lib -L=/usr/sfw/lib -lfreetype -lsocket -lnsl") |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 88 | else() |
Pierre Ossman | 4790e11 | 2014-10-28 16:57:05 +0100 | [diff] [blame] | 89 | set(FLTK_LIBRARIES "${FLTK_LIBRARIES} -Wl,-Bstatic -lXcursor -lXfixes -lXft -lfontconfig -lexpat -lfreetype -lbz2 -lXrender -lXext -lXinerama -Wl,-Bdynamic") |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 90 | endif() |
| 91 | |
Pierre Ossman | 4790e11 | 2014-10-28 16:57:05 +0100 | [diff] [blame] | 92 | set(FLTK_LIBRARIES "${FLTK_LIBRARIES} -lX11") |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 93 | endif() |
| 94 | endif() |
| 95 | |
| 96 | # X11 libraries change constantly on Linux systems so we have to link |
| 97 | # them statically, even libXext. libX11 is somewhat stable, although |
| 98 | # even it has had an ABI change once or twice. |
| 99 | if(X11_FOUND AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") |
Pierre Ossman | 4790e11 | 2014-10-28 16:57:05 +0100 | [diff] [blame] | 100 | set(X11_LIBRARIES "-Wl,-Bstatic -lXext -Wl,-Bdynamic -lX11") |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 101 | if(X11_XTest_LIB) |
| 102 | set(X11_XTest_LIB "-Wl,-Bstatic -lXtst -Wl,-Bdynamic") |
| 103 | endif() |
| 104 | if(X11_Xdamage_LIB) |
| 105 | set(X11_Xdamage_LIB "-Wl,-Bstatic -lXdamage -Wl,-Bdynamic") |
| 106 | endif() |
| 107 | endif() |
| 108 | |
| 109 | # This ensures that we don't depend on libstdc++ or libgcc_s |
| 110 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nodefaultlibs") |
| 111 | set(STATIC_BASE_LIBRARIES "-Wl,-Bstatic -lstdc++ -Wl,-Bdynamic") |
Pierre Ossman | 86640e8 | 2015-09-29 09:40:20 +0200 | [diff] [blame^] | 112 | if(ENABLE_ASAN AND NOT WIN32 AND NOT APPLE) |
| 113 | set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -Wl,-Bstatic -lasan -Wl,-Bdynamic -ldl -lm -lpthread") |
| 114 | endif() |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 115 | if(WIN32) |
Pierre Ossman | df3cc42 | 2014-11-03 14:36:23 +0100 | [diff] [blame] | 116 | set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt") |
| 117 | set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -luser32 -lkernel32 -ladvapi32 -lshell32") |
| 118 | # mingw has some fun circular dependencies that requires us to link |
| 119 | # these things again |
| 120 | set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -lmingw32 -lgcc_eh -lgcc -lmoldname -lmingwex -lmsvcrt") |
Pierre Ossman | f95272d | 2014-10-17 13:59:35 +0200 | [diff] [blame] | 121 | else() |
| 122 | set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -lgcc -lgcc_eh -lc") |
| 123 | endif() |
| 124 | set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${STATIC_BASE_LIBRARIES}") |
| 125 | |
| 126 | endif() |