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 |
| 11 | "Link statically against most libraries, if possible" ON) |
| 12 | |
| 13 | if(BUILD_STATIC) |
| 14 | message(STATUS "Attempting to link static binaries...") |
| 15 | |
| 16 | set(JPEG_LIBRARIES "-Wl,-Bstatic -ljpeg -Wl,-Bdynamic") |
| 17 | |
| 18 | if(WIN32 AND NOT USE_INCLUDED_ZLIB) |
| 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}) |
| 33 | |
| 34 | set(GNUTLS_LIBRARIES "-Wl,-Bstatic -lgnutls -ltasn1") |
| 35 | |
| 36 | if(NETTLE_LIBRARY) |
| 37 | set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -lnettle -lhogweed -lgmp") |
| 38 | endif() |
| 39 | if(GCRYPT_LIBRARY) |
| 40 | set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -lgcrypt -lgpg-error") |
| 41 | endif() |
| 42 | |
| 43 | set(GNUTLS_LIBRARIES "${GNUTLS_LIBRARIES} -Wl,-Bdynamic") |
| 44 | |
| 45 | # nanosleep() lives here on Solaris |
| 46 | if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") |
| 47 | set(GNUTLS_LIBRARIES ${GNUTLS_LIBRARIES} -lrt) |
| 48 | endif() |
| 49 | endif() |
| 50 | |
| 51 | if(FLTK_FOUND) |
| 52 | set(FLTK_LIBRARIES "-Wl,-Bstatic -lfltk_images -lpng -ljpeg -lfltk -Wl,-Bdynamic") |
| 53 | |
| 54 | if(WIN32) |
| 55 | set(FLTK_LIBRARIES ${FLTK_LIBRARIES} comctl32) |
| 56 | elseif(APPLE) |
| 57 | set(FLTK_LIBRARIES ${FLTK_LIBRARIES} "-framework Cocoa") |
| 58 | else() |
| 59 | set(FLTK_LIBRARIES ${FLTK_LIBRARIES} m) |
| 60 | endif() |
| 61 | |
| 62 | if(X11_FOUND AND NOT APPLE) |
| 63 | if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") |
| 64 | set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xcursor_LIB} ${X11_Xfixes_LIB} "-Wl,-Bstatic -lXft -Wl,-Bdynamic" fontconfig Xext -R/usr/sfw/lib) |
| 65 | else() |
| 66 | set(FLTK_LIBRARIES ${FLTK_LIBRARIES} "-Wl,-Bstatic -lXcursor -lXfixes -lXft -lfontconfig -lexpat -lfreetype -lbz2 -lXrender -lXext -lXinerama -Wl,-Bdynamic") |
| 67 | endif() |
| 68 | |
| 69 | set(FLTK_LIBRARIES ${FLTK_LIBRARIES} X11) |
| 70 | endif() |
| 71 | endif() |
| 72 | |
| 73 | # X11 libraries change constantly on Linux systems so we have to link |
| 74 | # them statically, even libXext. libX11 is somewhat stable, although |
| 75 | # even it has had an ABI change once or twice. |
| 76 | if(X11_FOUND AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") |
| 77 | set(X11_LIBRARIES "-Wl,-Bstatic -lXext -Wl,-Bdynamic" X11) |
| 78 | if(X11_XTest_LIB) |
| 79 | set(X11_XTest_LIB "-Wl,-Bstatic -lXtst -Wl,-Bdynamic") |
| 80 | endif() |
| 81 | if(X11_Xdamage_LIB) |
| 82 | set(X11_Xdamage_LIB "-Wl,-Bstatic -lXdamage -Wl,-Bdynamic") |
| 83 | endif() |
| 84 | endif() |
| 85 | |
| 86 | # This ensures that we don't depend on libstdc++ or libgcc_s |
| 87 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nodefaultlibs") |
| 88 | set(STATIC_BASE_LIBRARIES "-Wl,-Bstatic -lstdc++ -Wl,-Bdynamic") |
| 89 | if(WIN32) |
| 90 | set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -lmingw32 -lmoldname -lmingwex -lgcc -lgcc_eh -lmsvcrt -lkernel32") |
| 91 | else() |
| 92 | set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -lgcc -lgcc_eh -lc") |
| 93 | endif() |
| 94 | set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${STATIC_BASE_LIBRARIES}") |
| 95 | |
| 96 | endif() |