summaryrefslogtreecommitdiffstats
path: root/Source/CPack/cmCPackExternalGenerator.h
blob: 176d6a9d9f7ae1dcc289aef67c7eb2dba77e5b7c (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
#ifndef cmCPackExternalGenerator_h
#define cmCPackExternalGenerator_h

#include "cmCPackGenerator.h"
#include "cm_sys_stat.h"

#include <memory>
#include <string>

class cmGlobalGenerator;
namespace Json {
class Value;
}

/** \class cmCPackExternalGenerator
 * \brief A generator for CPack External packaging tools
 */
class cmCPackExternalGenerator : public cmCPackGenerator
{
public:
  cmCPackTypeMacro(cmCPackExternalGenerator, cmCPackGenerator);

  const char* GetOutputExtension() override { return ".json"; }

protected:
  int InitializeInternal() override;

  int PackageFiles() override;

  bool SupportsComponentInstallation() const override;

  int InstallProjectViaInstallCommands(
    bool setDestDir, const std::string& tempInstallDirectory) override;
  int InstallProjectViaInstallScript(
    bool setDestDir, const std::string& tempInstallDirectory) override;
  int InstallProjectViaInstalledDirectories(
    bool setDestDir, const std::string& tempInstallDirectory,
    const mode_t* default_dir_mode) override;

  int RunPreinstallTarget(const std::string& installProjectName,
                          const std::string& installDirectory,
                          cmGlobalGenerator* globalGenerator,
                          const std::string& buildConfig) override;
  int InstallCMakeProject(bool setDestDir, const std::string& installDirectory,
                          const std::string& baseTempInstallDirectory,
                          const mode_t* default_dir_mode,
                          const std::string& component, bool componentInstall,
                          const std::string& installSubDirectory,
                          const std::string& buildConfig,
                          std::string& absoluteDestFiles) override;

private:
  bool StagingEnabled() const;

  class cmCPackExternalVersionGenerator
  {
  public:
    cmCPackExternalVersionGenerator(cmCPackExternalGenerator* parent);

    virtual ~cmCPackExternalVersionGenerator() = default;

    virtual int WriteToJSON(Json::Value& root);

  protected:
    virtual int GetVersionMajor() = 0;
    virtual int GetVersionMinor() = 0;

    int WriteVersion(Json::Value& root);

    cmCPackExternalGenerator* Parent;
  };

  class cmCPackExternalVersion1Generator
    : public cmCPackExternalVersionGenerator
  {
  public:
    using cmCPackExternalVersionGenerator::cmCPackExternalVersionGenerator;

  protected:
    int GetVersionMajor() override { return 1; }
    int GetVersionMinor() override { return 0; }
  };

  std::unique_ptr<cmCPackExternalVersionGenerator> Generator;
};

#endif