forked from conan-io/conan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_cmaketoolchain.py
167 lines (128 loc) · 5.11 KB
/
test_cmaketoolchain.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import types
import pytest
from mock import Mock
from conan.tools.cmake import CMakeToolchain
from conan.tools.cmake.toolchain import Block, GenericSystemBlock
from conans import ConanFile, Settings
from conans.model.conf import Conf
from conans.model.env_info import EnvValues
@pytest.fixture
def conanfile():
c = ConanFile(Mock(), None)
c.settings = "os", "compiler", "build_type", "arch"
c.initialize(Settings({"os": ["Windows"],
"compiler": {"gcc": {"libcxx": ["libstdc++"]}},
"build_type": ["Release"],
"arch": ["x86"]}), EnvValues())
c.settings.build_type = "Release"
c.settings.arch = "x86"
c.settings.compiler = "gcc"
c.settings.compiler.libcxx = "libstdc++"
c.conf = Conf()
c.folders.set_base_generators(".")
c._conan_node = Mock()
c._conan_node.dependencies = []
return c
def test_cmake_toolchain(conanfile):
toolchain = CMakeToolchain(conanfile)
content = toolchain.content
assert 'set(CMAKE_BUILD_TYPE "Release"' in content
def test_remove(conanfile):
toolchain = CMakeToolchain(conanfile)
toolchain.blocks.remove("generic_system")
content = toolchain.content
assert 'CMAKE_BUILD_TYPE' not in content
def test_template_remove(conanfile):
toolchain = CMakeToolchain(conanfile)
toolchain.blocks["generic_system"].template = ""
content = toolchain.content
assert 'CMAKE_BUILD_TYPE' not in content
def test_template_change(conanfile):
toolchain = CMakeToolchain(conanfile)
tmp = toolchain.blocks["generic_system"].template
toolchain.blocks["generic_system"].template = tmp.replace("CMAKE_BUILD_TYPE", "OTHER_THING")
content = toolchain.content
assert 'set(OTHER_THING "Release"' in content
def test_context_change(conanfile):
toolchain = CMakeToolchain(conanfile)
tmp = toolchain.blocks["generic_system"]
def context(self):
assert self
return {"build_type": "SuperRelease"}
tmp.context = types.MethodType(context, tmp)
content = toolchain.content
assert 'set(CMAKE_BUILD_TYPE "SuperRelease"' in content
def test_context_update(conanfile):
toolchain = CMakeToolchain(conanfile)
build_type = toolchain.blocks["generic_system"].values["build_type"]
toolchain.blocks["generic_system"].values["build_type"] = "Super" + build_type
content = toolchain.content
assert 'set(CMAKE_BUILD_TYPE "SuperRelease"' in content
def test_context_replace(conanfile):
toolchain = CMakeToolchain(conanfile)
toolchain.blocks["generic_system"].values = {"build_type": "SuperRelease"}
content = toolchain.content
assert 'set(CMAKE_BUILD_TYPE "SuperRelease"' in content
def test_replace_block(conanfile):
toolchain = CMakeToolchain(conanfile)
class MyBlock(Block):
template = "HelloWorld"
def context(self):
return {}
toolchain.blocks["generic_system"] = MyBlock
content = toolchain.content
assert 'HelloWorld' in content
assert 'CMAKE_BUILD_TYPE' not in content
def test_add_new_block(conanfile):
toolchain = CMakeToolchain(conanfile)
class MyBlock(Block):
template = "Hello {{myvar}}!!!"
def context(self):
return {"myvar": "World"}
toolchain.blocks["mynewblock"] = MyBlock
content = toolchain.content
assert 'Hello World!!!' in content
assert 'CMAKE_BUILD_TYPE' in content
def test_extend_block(conanfile):
toolchain = CMakeToolchain(conanfile)
class MyBlock(GenericSystemBlock):
template = "Hello {{build_type}}!!"
def context(self):
c = super(MyBlock, self).context()
c["build_type"] = c["build_type"] + "Super"
return c
toolchain.blocks["generic_system"] = MyBlock
content = toolchain.content
assert 'Hello ReleaseSuper!!' in content
assert 'CMAKE_BUILD_TYPE' not in content
def test_user_toolchain(conanfile):
toolchain = CMakeToolchain(conanfile)
toolchain.blocks["user_toolchain"].user_toolchain = "myowntoolchain.cmake"
content = toolchain.content
assert 'include(myowntoolchain.cmake)' in content
toolchain = CMakeToolchain(conanfile)
content = toolchain.content
assert 'include(' not in content
@pytest.fixture
def conanfile_apple():
c = ConanFile(Mock(), None)
c.settings = "os", "compiler", "build_type", "arch"
c.initialize(Settings({"os": {"Macos": {"version": ["10.15"]}},
"compiler": {"apple-clang": {"libcxx": ["libc++"]}},
"build_type": ["Release"],
"arch": ["x86"]}), EnvValues())
c.settings.build_type = "Release"
c.settings.arch = "x86"
c.settings.compiler = "apple-clang"
c.settings.compiler.libcxx = "libc++"
c.settings.os = "Macos"
c.settings.os.version = "10.15"
c.conf = Conf()
c.folders.set_base_generators(".")
c._conan_node = Mock()
c._conan_node.dependencies = []
return c
def test_osx_deployment_target(conanfile_apple):
toolchain = CMakeToolchain(conanfile_apple)
content = toolchain.content
assert 'set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15)' in content