blob: 8b2949bd9691d7191df7e6f5f18c4ec7f60d4ca1 (
plain) (
blame)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# Copyright (c) 2020 Egor Tensin <egor@tensin.name>
# This file is part of the "cmake-common" project.
# For details, see https://github.com/egor-tensin/cmake-common.
# Distributed under the MIT License.
import argparse
from enum import Enum
import logging
from project.os import on_linux_like
class Linkage(Enum):
STATIC = 'static'
SHARED = 'shared'
def __str__(self):
return str(self.value)
@staticmethod
def all():
return tuple(Linkage)
@staticmethod
def parse(s):
try:
return Linkage(s)
except ValueError as e:
raise argparse.ArgumentTypeError(f'invalid linkage: {s}') from e
# For my development, I link everything statically (to be able to pull the
# binaries from a CI, etc. and run them everywhere):
@staticmethod
def default_link():
return Linkage.STATIC
@staticmethod
def default_runtime_link():
return Linkage.STATIC
@staticmethod
def validate_linkage(link, runtime_link):
if runtime_link is Linkage.STATIC:
if link is Linkage.SHARED:
logging.warning(
"Cannot link the runtime statically to a dynamic library, going to link dynamically"
)
runtime_link = Linkage.SHARED
elif on_linux_like():
logging.warning(
"Cannot link to the GNU C Library or BSD libc (which are assumed) statically, going to link dynamically"
)
runtime_link = Linkage.SHARED
return link, runtime_link
def b2_args_link(self):
return [f'link={self}']
def b2_args_runtime_link(self):
return [f'runtime-link={self}']
def cmake_args_link(self):
if self is Linkage.STATIC:
return ['-DBoost_USE_STATIC_LIBS=ON']
return []
def cmake_args_runtime_link(self):
if self is Linkage.STATIC:
return [
'-DBoost_USE_STATIC_RUNTIME=ON',
'-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug>',
]
return []
|