aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/PostBuildLint_BuildPolicies.cpp
blob: f070a2a42907661e65d4fb41bc32776caa54c957 (plain)
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
#include "pch.h"
#include "PostBuildLint_BuildPolicies.h"
#include "vcpkg_Enums.h"

namespace vcpkg::PostBuildLint::BuildPolicies
{
    static const std::string NULLVALUE_STRING = Enums::nullvalue_toString(ENUM_NAME);

    static const std::string NAME_EMPTY_PACKAGE = "PolicyEmptyPackage";
    static const std::string NAME_DLLS_WITHOUT_LIBS = "PolicyDLLsWithoutLIBs";
    static const std::string NAME_ONLY_RELEASE_CRT = "PolicyOnlyReleaseCRT";

    const std::string& type::toString() const
    {
        switch (this->backing_enum)
        {
            case EMPTY_PACKAGE:
                return NAME_EMPTY_PACKAGE;
            case DLLS_WITHOUT_LIBS:
                return NAME_DLLS_WITHOUT_LIBS;
            case ONLY_RELEASE_CRT:
                return NAME_ONLY_RELEASE_CRT;
            case NULLVALUE:
                return NULLVALUE_STRING;
            default:
                Enums::unreachable(ENUM_NAME);
        }
    }

    const std::string& type::cmake_variable() const
    {
        static const std::string CMAKE_VARIABLE_EMPTY_PACKAGE = "VCPKG_POLICY_EMPTY_PACKAGE";
        static const std::string CMAKE_VARIABLE_DLLS_WITHOUT_LIBS = "VCPKG_POLICY_DLLS_WITHOUT_LIBS";
        static const std::string CMAKE_VARIABLE_ONLY_RELEASE_CRT = "VCPKG_POLICY_ONLY_RELEASE_CRT";

        switch (this->backing_enum)
        {
            case EMPTY_PACKAGE:
                return CMAKE_VARIABLE_EMPTY_PACKAGE;
            case DLLS_WITHOUT_LIBS:
                return CMAKE_VARIABLE_DLLS_WITHOUT_LIBS;
            case ONLY_RELEASE_CRT:
                return CMAKE_VARIABLE_ONLY_RELEASE_CRT;
            case NULLVALUE:
                Enums::nullvalue_used(ENUM_NAME);
            default:
                Enums::unreachable(ENUM_NAME);
        }
    }

    type parse(const std::string& s)
    {
        if (s == NAME_EMPTY_PACKAGE)
        {
            return BuildPolicies::EMPTY_PACKAGE;
        }

        if (s == NAME_DLLS_WITHOUT_LIBS)
        {
            return BuildPolicies::DLLS_WITHOUT_LIBS;
        }

        if (s == NAME_ONLY_RELEASE_CRT)
        {
            return BuildPolicies::ONLY_RELEASE_CRT;
        }

        return BuildPolicies::NULLVALUE;
    }
}