-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeConfigurationTests.cpp
More file actions
173 lines (150 loc) · 5.4 KB
/
Copy pathCMakeConfigurationTests.cpp
File metadata and controls
173 lines (150 loc) · 5.4 KB
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
168
169
170
171
172
173
#include <vix/engine/CMakeConfiguration.hpp>
#include "EnvGuard.hpp"
#include <algorithm>
#include <cassert>
#include <filesystem>
#include <string>
#include <utility>
#include <vector>
namespace
{
using namespace vix::engine;
bool has_system_ar()
{
#ifdef _WIN32
return false;
#else
std::error_code ec;
return std::filesystem::exists("/usr/bin/ar", ec) && !ec;
#endif
}
bool has_system_ranlib()
{
#ifdef _WIN32
return false;
#else
std::error_code ec;
return std::filesystem::exists("/usr/bin/ranlib", ec) && !ec;
#endif
}
std::vector<CMakeVariable> base_debug()
{
std::vector<CMakeVariable> vars;
if (has_system_ar())
vars.emplace_back("CMAKE_AR", "/usr/bin/ar");
vars.emplace_back("CMAKE_BUILD_TYPE", "Debug");
vars.emplace_back("CMAKE_EXPORT_COMPILE_COMMANDS", "ON");
if (has_system_ranlib())
vars.emplace_back("CMAKE_RANLIB", "/usr/bin/ranlib");
return vars;
}
}
int main()
{
using vix::engine::tests::EnvGuard;
EnvGuard path("PATH");
EnvGuard cxx("CXX");
EnvGuard cc("CC");
path.set("");
cxx.unset();
cc.unset();
{
CMakeConfigurationOptions options;
options.buildType = "Debug";
assert(make_cmake_variables(options) == base_debug());
assert(make_cmake_variables(options) == make_cmake_variables(options));
}
{
CMakeConfigurationOptions options;
options.buildType = "Release";
std::vector<CMakeVariable> expected;
if (has_system_ar())
expected.emplace_back("CMAKE_AR", "/usr/bin/ar");
expected.emplace_back("CMAKE_BUILD_TYPE", "Release");
expected.emplace_back("CMAKE_EXPORT_COMPILE_COMMANDS", "ON");
if (has_system_ranlib())
expected.emplace_back("CMAKE_RANLIB", "/usr/bin/ranlib");
assert(make_cmake_variables(options) == expected);
}
{
CMakeConfigurationOptions options;
options.buildType = "Debug";
options.linkStatic = true;
options.withSqlite = true;
options.withMySql = true;
options.warningCheck = true;
options.targetTriple = "aarch64-linux-gnu";
options.toolchainFile = "/tmp/toolchain.cmake";
options.sdkConfigDir = "/tmp/sdk/lib/cmake/Vix";
options.globalPackagesFile = "/tmp/global packages.cmake";
options.launcher = "ccache";
options.fastLinkerFlag = "-fuse-ld=mold";
std::vector<CMakeVariable> expected;
if (has_system_ar())
expected.emplace_back("CMAKE_AR", "/usr/bin/ar");
expected.emplace_back("CMAKE_BUILD_TYPE", "Debug");
expected.emplace_back("CMAKE_CXX_COMPILER", "c++");
expected.emplace_back("CMAKE_CXX_COMPILER_LAUNCHER", "ccache");
expected.emplace_back(
"CMAKE_CXX_FLAGS",
"-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wsign-conversion -Wformat=2 -Wold-style-cast -Woverloaded-virtual");
expected.emplace_back("CMAKE_C_COMPILER_LAUNCHER", "ccache");
expected.emplace_back("CMAKE_EXE_LINKER_FLAGS", "-fuse-ld=mold");
expected.emplace_back("CMAKE_EXPORT_COMPILE_COMMANDS", "ON");
expected.emplace_back("CMAKE_MODULE_LINKER_FLAGS", "-fuse-ld=mold");
if (has_system_ranlib())
expected.emplace_back("CMAKE_RANLIB", "/usr/bin/ranlib");
expected.emplace_back("CMAKE_SHARED_LINKER_FLAGS", "-fuse-ld=mold");
expected.emplace_back("CMAKE_TOOLCHAIN_FILE", "/tmp/toolchain.cmake");
expected.emplace_back("VIX_DB_REQUIRE_MYSQL", "ON");
expected.emplace_back("VIX_DB_REQUIRE_SQLITE", "ON");
expected.emplace_back("VIX_DB_USE_MYSQL", "ON");
expected.emplace_back("VIX_DB_USE_SQLITE", "ON");
expected.emplace_back("VIX_ENABLE_DB", "ON");
expected.emplace_back("VIX_ENABLE_DB", "ON");
expected.emplace_back("VIX_ENABLE_WARNINGS", "ON");
expected.emplace_back("VIX_LINK_STATIC", "ON");
expected.emplace_back("VIX_TARGET_TRIPLE", "aarch64-linux-gnu");
assert(make_cmake_variables(options) == expected);
for (const auto &var : make_cmake_variables(options))
assert(var.first != "globalPackagesFile");
}
{
CMakeConfigurationOptions options;
options.buildType = "Debug";
options.dependencyEnvironmentMode = DependencyEnvironmentMode::ManagedSdk;
options.sdkConfigDir = "/tmp/sdk/lib/cmake/Vix";
std::vector<CMakeVariable> expected = base_debug();
expected.emplace_back("Vix_DIR", "/tmp/sdk/lib/cmake/Vix");
expected.emplace_back("vix_DIR", "/tmp/sdk/lib/cmake/Vix");
std::sort(expected.begin(), expected.end());
assert(make_cmake_variables(options) == expected);
}
{
CMakeConfigurationOptions options;
options.buildType = "Debug";
options.launcher = "";
options.fastLinkerFlag = "";
assert(make_cmake_variables(options) == base_debug());
}
{
CMakeConfigurationOptions options;
options.buildType = "Debug";
cxx.set("my-clang++");
cc.set("my-clang");
options.warningCheck = true;
std::vector<CMakeVariable> expected;
if (has_system_ar())
expected.emplace_back("CMAKE_AR", "/usr/bin/ar");
expected.emplace_back("CMAKE_BUILD_TYPE", "Debug");
expected.emplace_back(
"CMAKE_CXX_FLAGS",
"-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wsign-conversion -Wformat=2 -Wold-style-cast -Woverloaded-virtual -Wlogical-op-parentheses -Wunreachable-code");
expected.emplace_back("CMAKE_EXPORT_COMPILE_COMMANDS", "ON");
if (has_system_ranlib())
expected.emplace_back("CMAKE_RANLIB", "/usr/bin/ranlib");
expected.emplace_back("VIX_ENABLE_WARNINGS", "ON");
assert(make_cmake_variables(options) == expected);
}
return 0;
}