cmake/Source/cmGlobalVisualStudioGenerator.h

236 lines
7.0 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2021-09-14 00:13:48 +02:00
#pragma once
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2017-04-14 19:02:05 +02:00
#include <iosfwd>
#include <map>
#include <set>
#include <string>
#include <vector>
2022-03-29 21:10:50 +02:00
#include "cm_codecvt.hxx"
#include "cmGlobalGenerator.h"
2017-04-14 19:02:05 +02:00
#include "cmTargetDepend.h"
2022-03-29 21:10:50 +02:00
#include "cmValue.h"
2017-04-14 19:02:05 +02:00
class cmCustomCommand;
class cmGeneratorTarget;
class cmLocalGenerator;
class cmMakefile;
class cmake;
/** \class cmGlobalVisualStudioGenerator
* \brief Base class for global Visual Studio generators.
*
* cmGlobalVisualStudioGenerator provides functionality common to all
* global Visual Studio generators.
*/
class cmGlobalVisualStudioGenerator : public cmGlobalGenerator
{
public:
2015-08-17 11:37:30 +02:00
/** Known versions of Visual Studio. */
2022-03-29 21:10:50 +02:00
enum class VSVersion : uint16_t
2015-08-17 11:37:30 +02:00
{
VS9 = 90,
VS11 = 110,
VS12 = 120,
/* VS13 = 130 was skipped */
2016-10-30 18:24:19 +01:00
VS14 = 140,
2019-11-11 23:01:05 +01:00
VS15 = 150,
2021-09-14 00:13:48 +02:00
VS16 = 160,
VS17 = 170
2015-08-17 11:37:30 +02:00
};
2023-05-23 16:38:00 +02:00
~cmGlobalVisualStudioGenerator() override;
2015-08-17 11:37:30 +02:00
VSVersion GetVersion() const;
void SetVersion(VSVersion v);
2019-11-11 23:01:05 +01:00
/** Is the installed VS an Express edition? */
bool IsExpressEdition() const { return this->ExpressEdition; }
void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
bool optional) override;
bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override;
/**
* Get the name of the target platform (architecture) for which we generate.
* The names are as defined by VS, e.g. "Win32", "x64", "Itanium", "ARM".
*/
std::string const& GetPlatformName() const;
/**
* Configure CMake's Visual Studio macros file into the user's Visual
* Studio macros directory.
*/
virtual void ConfigureCMakeVisualStudioMacros();
/**
* Where does this version of Visual Studio look for macros for the
* current user? Returns the empty string if this version of Visual
* Studio does not implement support for VB macros.
*/
virtual std::string GetUserMacrosDirectory();
/**
* What is the reg key path to "vsmacros" for this version of Visual
* Studio?
*/
virtual std::string GetUserMacrosRegKeyBase();
2016-07-09 11:21:54 +02:00
enum MacroName
{
MacroReload,
MacroStop
};
/**
* Call the ReloadProjects macro if necessary based on
* GetFilesReplacedDuringGenerate results.
*/
2020-02-01 23:06:01 +01:00
void CallVisualStudioMacro(MacroName m, const std::string& vsSolutionFile);
2013-03-16 19:13:01 +02:00
// return true if target is fortran only
2016-07-09 11:21:54 +02:00
bool TargetIsFortranOnly(const cmGeneratorTarget* gt);
2022-08-04 22:12:04 +02:00
// return true if target should be included in solution.
virtual bool IsInSolution(const cmGeneratorTarget* gt) const;
// return true if project dependency should be included in solution.
virtual bool IsDepInSolution(const std::string& targetName) const;
2009-10-04 10:30:41 +03:00
/** Get the top-level registry key for this VS version. */
std::string GetRegistryBase();
2010-03-17 14:00:29 +02:00
2013-03-16 19:13:01 +02:00
/** Get the top-level registry key for the given VS version. */
static std::string GetRegistryBase(const char* version);
2010-03-17 14:00:29 +02:00
/** Return true if the generated build tree may contain multiple builds.
i.e. "Can I build Debug and Release in the same tree?" */
2018-04-23 21:13:27 +02:00
bool IsMultiConfig() const override { return true; }
2010-03-17 14:00:29 +02:00
2013-03-16 19:13:01 +02:00
/** Return true if building for Windows CE */
virtual bool TargetsWindowsCE() const { return false; }
2018-04-23 21:13:27 +02:00
bool IsIncludeExternalMSProjectSupported() const override { return true; }
2020-02-01 23:06:01 +01:00
/** Get encoding used by generator for generated source files
*/
codecvt::Encoding GetMakefileEncoding() const override
{
return codecvt::ANSI;
}
2016-07-09 11:21:54 +02:00
class TargetSet : public std::set<cmGeneratorTarget const*>
{
};
2015-11-17 17:22:37 +01:00
class TargetCompare
2009-10-04 10:30:41 +03:00
{
2015-11-17 17:22:37 +01:00
std::string First;
2016-07-09 11:21:54 +02:00
2015-11-17 17:22:37 +01:00
public:
2023-05-23 16:38:00 +02:00
TargetCompare(std::string first)
: First(std::move(first))
2016-07-09 11:21:54 +02:00
{
}
2015-11-17 17:22:37 +01:00
bool operator()(cmGeneratorTarget const* l,
cmGeneratorTarget const* r) const;
2009-10-04 10:30:41 +03:00
};
2011-01-16 11:35:12 +01:00
class OrderedTargetDependSet;
2009-10-04 10:30:41 +03:00
2018-01-26 17:06:56 +01:00
bool FindMakeProgram(cmMakefile*) override;
2014-08-03 19:52:23 +02:00
2018-04-23 21:13:27 +02:00
std::string ExpandCFGIntDir(const std::string& str,
const std::string& config) const override;
2014-08-03 19:52:23 +02:00
2019-11-11 23:01:05 +01:00
void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override;
2015-11-17 17:22:37 +01:00
2016-07-09 11:21:54 +02:00
std::string GetStartupProjectName(cmLocalGenerator const* root) const;
void AddSymbolExportCommand(cmGeneratorTarget*,
std::vector<cmCustomCommand>& commands,
std::string const& configName);
2018-04-23 21:13:27 +02:00
bool Open(const std::string& bindir, const std::string& projectName,
bool dryRun) override;
2020-08-30 11:54:41 +02:00
bool IsVisualStudio() const override { return true; }
2010-11-13 01:00:53 +02:00
protected:
2019-11-11 23:01:05 +01:00
cmGlobalVisualStudioGenerator(cmake* cm,
std::string const& platformInGeneratorName);
2023-07-02 19:51:09 +02:00
virtual bool InitializePlatform(cmMakefile* mf);
2018-04-23 21:13:27 +02:00
void AddExtraIDETargets() override;
2015-04-27 22:25:09 +02:00
2010-11-13 01:00:53 +02:00
// Does this VS version link targets to each other if there are
// dependencies in the SLN file? This was done for VS versions
// below 8.
virtual bool VSLinksDependencies() const { return true; }
2019-11-11 23:01:05 +01:00
const char* GetIDEVersion() const;
void WriteSLNHeader(std::ostream& fout);
2010-11-13 01:00:53 +02:00
2018-04-23 21:13:27 +02:00
bool ComputeTargetDepends() override;
2016-07-09 11:21:54 +02:00
class VSDependSet : public std::set<std::string>
{
};
class VSDependMap : public std::map<cmGeneratorTarget const*, VSDependSet>
{
};
2010-11-13 01:00:53 +02:00
VSDependMap VSTargetDepends;
2016-07-09 11:21:54 +02:00
void ComputeVSTargetDepends(cmGeneratorTarget*);
2016-03-13 13:35:51 +01:00
bool CheckTargetLinks(cmGeneratorTarget& target, const std::string& name);
std::string GetUtilityForTarget(cmGeneratorTarget& target,
const std::string&);
virtual std::string WriteUtilityDepend(cmGeneratorTarget const*) = 0;
2016-07-09 11:21:54 +02:00
std::string GetUtilityDepend(const cmGeneratorTarget* target);
2020-02-01 23:06:01 +01:00
using UtilityDependsMap = std::map<cmGeneratorTarget const*, std::string>;
2010-11-13 01:00:53 +02:00
UtilityDependsMap UtilityDepends;
2013-03-16 19:13:01 +02:00
2015-08-17 11:37:30 +02:00
VSVersion Version;
2019-11-11 23:01:05 +01:00
bool ExpressEdition;
std::string GeneratorPlatform;
std::string DefaultPlatformName;
bool PlatformInGeneratorName = false;
2015-08-17 11:37:30 +02:00
2011-01-16 11:35:12 +01:00
private:
2014-08-03 19:52:23 +02:00
virtual std::string GetVSMakeProgram() = 0;
2015-04-27 22:25:09 +02:00
void PrintCompilerAdvice(std::ostream&, std::string const&,
2021-11-20 13:41:27 +01:00
cmValue) const override
2016-07-09 11:21:54 +02:00
{
}
2012-04-19 19:04:21 +03:00
2016-03-13 13:35:51 +01:00
void FollowLinkDepends(cmGeneratorTarget const* target,
std::set<cmGeneratorTarget const*>& linked);
2011-01-16 11:35:12 +01:00
2016-07-09 11:21:54 +02:00
class TargetSetMap : public std::map<cmGeneratorTarget*, TargetSet>
{
};
2011-01-16 11:35:12 +01:00
TargetSetMap TargetLinkClosure;
2016-07-09 11:21:54 +02:00
void FillLinkClosure(const cmGeneratorTarget* target, TargetSet& linked);
2016-03-13 13:35:51 +01:00
TargetSet const& GetTargetLinkClosure(cmGeneratorTarget* target);
2011-01-16 11:35:12 +01:00
};
2016-07-09 11:21:54 +02:00
class cmGlobalVisualStudioGenerator::OrderedTargetDependSet
: public std::multiset<cmTargetDepend,
cmGlobalVisualStudioGenerator::TargetCompare>
2011-01-16 11:35:12 +01:00
{
2020-02-01 23:06:01 +01:00
using derived = std::multiset<cmTargetDepend,
cmGlobalVisualStudioGenerator::TargetCompare>;
2016-07-09 11:21:54 +02:00
2011-01-16 11:35:12 +01:00
public:
2020-02-01 23:06:01 +01:00
using TargetDependSet = cmGlobalGenerator::TargetDependSet;
using TargetSet = cmGlobalVisualStudioGenerator::TargetSet;
2015-11-17 17:22:37 +01:00
OrderedTargetDependSet(TargetDependSet const&, std::string const& first);
OrderedTargetDependSet(TargetSet const&, std::string const& first);
};