File: StaticLinkSupport.cmake

package info (click to toggle)
ccache 4.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,188 kB
  • sloc: cpp: 47,282; asm: 28,570; sh: 8,674; ansic: 5,357; python: 685; perl: 68; makefile: 23
file content (35 lines) | stat: -rw-r--r-- 1,008 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# This sets up support for maximum static linking of dependent libraries on
# supported platforms.

set(STATIC_LINK_DEFAULT OFF)
if(WIN32)
  set(STATIC_LINK_DEFAULT ON)
endif()

option(STATIC_LINK "Link most libraries statically" ${STATIC_LINK_DEFAULT})

if(NOT STATIC_LINK)
  return()
endif()

set(CMAKE_LINK_SEARCH_START_STATIC ON)
set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_STATIC_LIBRARY_SUFFIX}")

if(WIN32)
  # Link MSVC runtime statically.
  if(MSVC)
    set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  # Link MINGW runtime statically.
  else()
    if(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang)\$")
      list(APPEND CCACHE_EXTRA_LIBS -static-libgcc -static-libstdc++ -static -lwinpthread -dynamic)
    endif()
    if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
      list(APPEND CCACHE_EXTRA_LIBS -fuse-ld=lld)
    endif()
  endif()
else()
  if(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang)\$")
    list(APPEND CCACHE_EXTRA_LIBS -static-libgcc -static-libstdc++)
  endif()
endif()