cmake/Source/cmGlobalVisualStudioGenerator.cxx

998 lines
34 KiB
C++
Raw Normal View History

2015-04-27 22:25:09 +02:00
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. */
#include "cmGlobalVisualStudioGenerator.h"
2022-03-29 21:10:50 +02:00
#include <cassert>
2018-04-23 21:13:27 +02:00
#include <future>
2017-04-14 19:02:05 +02:00
#include <iostream>
2022-03-29 21:10:50 +02:00
#include <sstream>
#include <system_error>
#include <utility>
2020-02-01 23:06:01 +01:00
#include <cm/iterator>
2020-08-30 11:54:41 +02:00
#include <cm/memory>
2020-02-01 23:06:01 +01:00
#include <windows.h>
2018-04-23 21:13:27 +02:00
#include <objbase.h>
#include <shellapi.h>
2017-04-14 19:02:05 +02:00
#include "cmCallVisualStudioMacro.h"
2019-11-11 23:01:05 +01:00
#include "cmCustomCommand.h"
2020-02-01 23:06:01 +01:00
#include "cmCustomCommandLines.h"
2015-11-17 17:22:37 +01:00
#include "cmGeneratedFileStream.h"
2012-04-19 19:04:21 +03:00
#include "cmGeneratorTarget.h"
2022-03-29 21:10:50 +02:00
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
2022-03-29 21:10:50 +02:00
#include "cmMessageType.h"
#include "cmPolicies.h"
2012-04-19 19:04:21 +03:00
#include "cmSourceFile.h"
2017-04-14 19:02:05 +02:00
#include "cmState.h"
2022-03-29 21:10:50 +02:00
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
2019-11-11 23:01:05 +01:00
#include "cmake.h"
2019-11-11 23:01:05 +01:00
cmGlobalVisualStudioGenerator::cmGlobalVisualStudioGenerator(
cmake* cm, std::string const& platformInGeneratorName)
2015-08-17 11:37:30 +02:00
: cmGlobalGenerator(cm)
{
2017-07-20 19:35:53 +02:00
cm->GetState()->SetIsGeneratorMultiConfig(true);
2015-08-17 11:37:30 +02:00
cm->GetState()->SetWindowsShell(true);
cm->GetState()->SetWindowsVSIDE(true);
2019-11-11 23:01:05 +01:00
if (platformInGeneratorName.empty()) {
this->DefaultPlatformName = "Win32";
} else {
this->DefaultPlatformName = platformInGeneratorName;
this->PlatformInGeneratorName = true;
}
}
2023-05-23 16:38:00 +02:00
cmGlobalVisualStudioGenerator::~cmGlobalVisualStudioGenerator() = default;
2015-08-17 11:37:30 +02:00
cmGlobalVisualStudioGenerator::VSVersion
cmGlobalVisualStudioGenerator::GetVersion() const
{
return this->Version;
}
void cmGlobalVisualStudioGenerator::SetVersion(VSVersion v)
{
this->Version = v;
}
2019-11-11 23:01:05 +01:00
void cmGlobalVisualStudioGenerator::EnableLanguage(
std::vector<std::string> const& lang, cmMakefile* mf, bool optional)
{
mf->AddDefinition("CMAKE_VS_PLATFORM_NAME_DEFAULT",
2020-02-01 23:06:01 +01:00
this->DefaultPlatformName);
2019-11-11 23:01:05 +01:00
this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
}
bool cmGlobalVisualStudioGenerator::SetGeneratorPlatform(std::string const& p,
cmMakefile* mf)
{
2023-07-02 19:51:09 +02:00
if (!this->InitializePlatform(mf)) {
return false;
}
2019-11-11 23:01:05 +01:00
if (this->GetPlatformName() == "x64") {
mf->AddDefinition("CMAKE_FORCE_WIN64", "TRUE");
} else if (this->GetPlatformName() == "Itanium") {
mf->AddDefinition("CMAKE_FORCE_IA64", "TRUE");
}
2020-02-01 23:06:01 +01:00
mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName());
2019-11-11 23:01:05 +01:00
return this->cmGlobalGenerator::SetGeneratorPlatform(p, mf);
}
2023-07-02 19:51:09 +02:00
bool cmGlobalVisualStudioGenerator::InitializePlatform(cmMakefile*)
{
return true;
}
2019-11-11 23:01:05 +01:00
std::string const& cmGlobalVisualStudioGenerator::GetPlatformName() const
{
if (!this->GeneratorPlatform.empty()) {
return this->GeneratorPlatform;
}
return this->DefaultPlatformName;
}
const char* cmGlobalVisualStudioGenerator::GetIDEVersion() const
{
switch (this->Version) {
2022-03-29 21:10:50 +02:00
case cmGlobalVisualStudioGenerator::VSVersion::VS9:
2019-11-11 23:01:05 +01:00
return "9.0";
2022-03-29 21:10:50 +02:00
case cmGlobalVisualStudioGenerator::VSVersion::VS11:
2019-11-11 23:01:05 +01:00
return "11.0";
2022-03-29 21:10:50 +02:00
case cmGlobalVisualStudioGenerator::VSVersion::VS12:
2019-11-11 23:01:05 +01:00
return "12.0";
2022-03-29 21:10:50 +02:00
case cmGlobalVisualStudioGenerator::VSVersion::VS14:
2019-11-11 23:01:05 +01:00
return "14.0";
2022-03-29 21:10:50 +02:00
case cmGlobalVisualStudioGenerator::VSVersion::VS15:
2019-11-11 23:01:05 +01:00
return "15.0";
2022-03-29 21:10:50 +02:00
case cmGlobalVisualStudioGenerator::VSVersion::VS16:
2019-11-11 23:01:05 +01:00
return "16.0";
2022-03-29 21:10:50 +02:00
case cmGlobalVisualStudioGenerator::VSVersion::VS17:
2021-09-14 00:13:48 +02:00
return "17.0";
2019-11-11 23:01:05 +01:00
}
return "";
}
void cmGlobalVisualStudioGenerator::WriteSLNHeader(std::ostream& fout)
{
2020-02-01 23:06:01 +01:00
char utf8bom[] = { char(0xEF), char(0xBB), char(0xBF) };
fout.write(utf8bom, 3);
2020-08-30 11:54:41 +02:00
fout << '\n';
2020-02-01 23:06:01 +01:00
2019-11-11 23:01:05 +01:00
switch (this->Version) {
2022-03-29 21:10:50 +02:00
case cmGlobalVisualStudioGenerator::VSVersion::VS9:
2019-11-11 23:01:05 +01:00
fout << "Microsoft Visual Studio Solution File, Format Version 10.00\n";
fout << "# Visual Studio 2008\n";
break;
2022-03-29 21:10:50 +02:00
case cmGlobalVisualStudioGenerator::VSVersion::VS11:
2019-11-11 23:01:05 +01:00
fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
if (this->ExpressEdition) {
fout << "# Visual Studio Express 2012 for Windows Desktop\n";
} else {
fout << "# Visual Studio 2012\n";
}
break;
2022-03-29 21:10:50 +02:00
case cmGlobalVisualStudioGenerator::VSVersion::VS12:
2019-11-11 23:01:05 +01:00
fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
if (this->ExpressEdition) {
fout << "# Visual Studio Express 2013 for Windows Desktop\n";
} else {
fout << "# Visual Studio 2013\n";
}
break;
2022-03-29 21:10:50 +02:00
case cmGlobalVisualStudioGenerator::VSVersion::VS14:
2019-11-11 23:01:05 +01:00
// Visual Studio 14 writes .sln format 12.00
fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
if (this->ExpressEdition) {
fout << "# Visual Studio Express 14 for Windows Desktop\n";
} else {
fout << "# Visual Studio 14\n";
}
break;
2022-03-29 21:10:50 +02:00
case cmGlobalVisualStudioGenerator::VSVersion::VS15:
2019-11-11 23:01:05 +01:00
// Visual Studio 15 writes .sln format 12.00
fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
if (this->ExpressEdition) {
fout << "# Visual Studio Express 15 for Windows Desktop\n";
} else {
fout << "# Visual Studio 15\n";
}
break;
2022-03-29 21:10:50 +02:00
case cmGlobalVisualStudioGenerator::VSVersion::VS16:
2019-11-11 23:01:05 +01:00
// Visual Studio 16 writes .sln format 12.00
fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
if (this->ExpressEdition) {
fout << "# Visual Studio Express 16 for Windows Desktop\n";
} else {
2020-08-30 11:54:41 +02:00
fout << "# Visual Studio Version 16\n";
2019-11-11 23:01:05 +01:00
}
break;
2022-03-29 21:10:50 +02:00
case cmGlobalVisualStudioGenerator::VSVersion::VS17:
2021-09-14 00:13:48 +02:00
// Visual Studio 17 writes .sln format 12.00
fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
if (this->ExpressEdition) {
fout << "# Visual Studio Express 17 for Windows Desktop\n";
} else {
fout << "# Visual Studio Version 17\n";
}
break;
2019-11-11 23:01:05 +01:00
}
}
2009-10-04 10:30:41 +03:00
std::string cmGlobalVisualStudioGenerator::GetRegistryBase()
2013-03-16 19:13:01 +02:00
{
2016-07-09 11:21:54 +02:00
return cmGlobalVisualStudioGenerator::GetRegistryBase(this->GetIDEVersion());
2013-03-16 19:13:01 +02:00
}
2016-07-09 11:21:54 +02:00
std::string cmGlobalVisualStudioGenerator::GetRegistryBase(const char* version)
2009-10-04 10:30:41 +03:00
{
2023-05-23 16:38:00 +02:00
std::string key = R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\)";
2013-03-16 19:13:01 +02:00
return key + version;
2009-10-04 10:30:41 +03:00
}
2016-03-13 13:35:51 +01:00
void cmGlobalVisualStudioGenerator::AddExtraIDETargets()
{
// Add a special target that depends on ALL projects for easy build
// of one configuration only.
2018-04-23 21:13:27 +02:00
for (auto const& it : this->ProjectMap) {
std::vector<cmLocalGenerator*> const& gen = it.second;
// add the ALL_BUILD to the first local generator of each project
2016-07-09 11:21:54 +02:00
if (!gen.empty()) {
// Use no actual command lines so that the target itself is not
// considered always out of date.
2022-03-29 21:10:50 +02:00
auto cc = cm::make_unique<cmCustomCommand>();
cc->SetEscapeOldStyle(false);
cc->SetComment("Build all projects");
cmTarget* allBuild =
gen[0]->AddUtilityCommand("ALL_BUILD", true, std::move(cc));
2010-11-13 01:00:53 +02:00
2020-08-30 11:54:41 +02:00
gen[0]->AddGeneratorTarget(
cm::make_unique<cmGeneratorTarget>(allBuild, gen[0]));
2015-11-17 17:22:37 +01:00
2010-11-13 01:00:53 +02:00
//
// Organize in the "predefined targets" folder:
//
2016-07-09 11:21:54 +02:00
if (this->UseFolderProperty()) {
2010-11-13 01:00:53 +02:00
allBuild->SetProperty("FOLDER", this->GetPredefinedTargetsFolder());
2016-07-09 11:21:54 +02:00
}
2010-11-13 01:00:53 +02:00
2009-10-04 10:30:41 +03:00
// Now make all targets depend on the ALL_BUILD target
2018-04-23 21:13:27 +02:00
for (cmLocalGenerator const* i : gen) {
2020-08-30 11:54:41 +02:00
for (const auto& tgt : i->GetGeneratorTargets()) {
2017-04-14 19:02:05 +02:00
if (tgt->GetType() == cmStateEnums::GLOBAL_TARGET ||
tgt->IsImported()) {
2015-11-17 17:22:37 +01:00
continue;
2016-07-09 11:21:54 +02:00
}
2020-08-30 11:54:41 +02:00
if (!this->IsExcluded(gen[0], tgt.get())) {
allBuild->AddUtility(tgt->GetName(), false);
2009-10-04 10:30:41 +03:00
}
}
}
}
2016-07-09 11:21:54 +02:00
}
// Configure CMake Visual Studio macros, for this user on this version
// of Visual Studio.
this->ConfigureCMakeVisualStudioMacros();
}
2016-07-09 11:21:54 +02:00
void cmGlobalVisualStudioGenerator::ComputeTargetObjectDirectory(
cmGeneratorTarget* gt) const
2012-04-19 19:04:21 +03:00
{
2020-02-01 23:06:01 +01:00
std::string dir =
cmStrCat(gt->LocalGenerator->GetCurrentBinaryDirectory(), '/');
2016-03-13 13:35:51 +01:00
std::string tgtDir = gt->LocalGenerator->GetTargetDirectory(gt);
2016-07-09 11:21:54 +02:00
if (!tgtDir.empty()) {
2012-04-19 19:04:21 +03:00
dir += tgtDir;
dir += "/";
2016-07-09 11:21:54 +02:00
}
2012-04-19 19:04:21 +03:00
const char* cd = this->GetCMakeCFGIntDir();
2016-07-09 11:21:54 +02:00
if (cd && *cd) {
2012-04-19 19:04:21 +03:00
dir += cd;
dir += "/";
2016-07-09 11:21:54 +02:00
}
2012-04-19 19:04:21 +03:00
gt->ObjectDirectory = dir;
}
bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
2016-07-09 11:21:54 +02:00
const std::string& regKeyBase,
std::string& nextAvailableSubKeyName);
void RegisterVisualStudioMacros(const std::string& macrosFile,
2016-07-09 11:21:54 +02:00
const std::string& regKeyBase);
2016-07-09 11:21:54 +02:00
#define CMAKE_VSMACROS_FILENAME "CMakeVSMacros2.vsmacros"
2016-07-09 11:21:54 +02:00
#define CMAKE_VSMACROS_RELOAD_MACRONAME \
"Macros.CMakeVSMacros2.Macros.ReloadProjects"
2016-07-09 11:21:54 +02:00
#define CMAKE_VSMACROS_STOP_MACRONAME "Macros.CMakeVSMacros2.Macros.StopBuild"
void cmGlobalVisualStudioGenerator::ConfigureCMakeVisualStudioMacros()
{
std::string dir = this->GetUserMacrosDirectory();
2018-01-26 17:06:56 +01:00
if (!dir.empty()) {
2020-02-01 23:06:01 +01:00
std::string src = cmStrCat(cmSystemTools::GetCMakeRoot(),
"/Templates/" CMAKE_VSMACROS_FILENAME);
std::string dst = dir + "/CMakeMacros/" CMAKE_VSMACROS_FILENAME;
// Copy the macros file to the user directory only if the
// destination does not exist or the source location is newer.
// This will allow the user to edit the macros for development
// purposes but newer versions distributed with CMake will replace
// older versions in user directories.
int res;
2019-11-11 23:01:05 +01:00
if (!cmSystemTools::FileTimeCompare(src, dst, &res) || res > 0) {
if (!cmSystemTools::CopyFileAlways(src, dst)) {
std::ostringstream oss;
oss << "Could not copy from: " << src << std::endl;
oss << " to: " << dst << std::endl;
2019-11-11 23:01:05 +01:00
cmSystemTools::Message(oss.str(), "Warning");
}
2016-07-09 11:21:54 +02:00
}
RegisterVisualStudioMacros(dst, this->GetUserMacrosRegKeyBase());
2016-07-09 11:21:54 +02:00
}
}
2016-07-09 11:21:54 +02:00
void cmGlobalVisualStudioGenerator::CallVisualStudioMacro(
2020-02-01 23:06:01 +01:00
MacroName m, const std::string& vsSolutionFile)
{
// If any solution or project files changed during the generation,
// tell Visual Studio to reload them...
std::string dir = this->GetUserMacrosDirectory();
// Only really try to call the macro if:
// - there is a UserMacrosDirectory
// - the CMake vsmacros file exists
// - the CMake vsmacros file is registered
// - there were .sln/.vcproj files changed during generation
//
2018-01-26 17:06:56 +01:00
if (!dir.empty()) {
std::string macrosFile = dir + "/CMakeMacros/" CMAKE_VSMACROS_FILENAME;
std::string nextSubkeyName;
2020-08-30 11:54:41 +02:00
if (cmSystemTools::FileExists(macrosFile) &&
2016-07-09 11:21:54 +02:00
IsVisualStudioMacrosFileRegistered(
macrosFile, this->GetUserMacrosRegKeyBase(), nextSubkeyName)) {
if (m == MacroReload) {
std::vector<std::string> filenames;
this->GetFilesReplacedDuringGenerate(filenames);
2016-07-09 11:21:54 +02:00
if (!filenames.empty()) {
2019-11-11 23:01:05 +01:00
std::string projects = cmJoin(filenames, ";");
2016-07-09 11:21:54 +02:00
cmCallVisualStudioMacro::CallMacro(
2020-02-01 23:06:01 +01:00
vsSolutionFile, CMAKE_VSMACROS_RELOAD_MACRONAME, projects,
2016-07-09 11:21:54 +02:00
this->GetCMakeInstance()->GetDebugOutput());
}
2016-07-09 11:21:54 +02:00
} else if (m == MacroStop) {
cmCallVisualStudioMacro::CallMacro(
2020-02-01 23:06:01 +01:00
vsSolutionFile, CMAKE_VSMACROS_STOP_MACRONAME, "",
this->GetCMakeInstance()->GetDebugOutput());
}
}
2016-07-09 11:21:54 +02:00
}
}
std::string cmGlobalVisualStudioGenerator::GetUserMacrosDirectory()
{
return "";
}
std::string cmGlobalVisualStudioGenerator::GetUserMacrosRegKeyBase()
{
return "";
}
2016-03-13 13:35:51 +01:00
void cmGlobalVisualStudioGenerator::FillLinkClosure(
2016-07-09 11:21:54 +02:00
const cmGeneratorTarget* target, TargetSet& linked)
2011-01-16 11:35:12 +01:00
{
2016-07-09 11:21:54 +02:00
if (linked.insert(target).second) {
TargetDependSet const& depends = this->GetTargetDirectDepends(target);
2018-04-23 21:13:27 +02:00
for (cmTargetDepend const& di : depends) {
if (di.IsLink()) {
this->FillLinkClosure(di, linked);
2011-01-16 11:35:12 +01:00
}
}
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
}
cmGlobalVisualStudioGenerator::TargetSet const&
2016-03-13 13:35:51 +01:00
cmGlobalVisualStudioGenerator::GetTargetLinkClosure(cmGeneratorTarget* target)
2011-01-16 11:35:12 +01:00
{
2019-11-11 23:01:05 +01:00
auto i = this->TargetLinkClosure.find(target);
2016-07-09 11:21:54 +02:00
if (i == this->TargetLinkClosure.end()) {
2011-01-16 11:35:12 +01:00
TargetSetMap::value_type entry(target, TargetSet());
i = this->TargetLinkClosure.insert(entry).first;
this->FillLinkClosure(target, i->second);
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
return i->second;
}
void cmGlobalVisualStudioGenerator::FollowLinkDepends(
2016-07-09 11:21:54 +02:00
const cmGeneratorTarget* target, std::set<const cmGeneratorTarget*>& linked)
2011-01-16 11:35:12 +01:00
{
2021-09-14 00:13:48 +02:00
if (!target->IsInBuildSystem()) {
2014-08-03 19:52:23 +02:00
return;
2016-07-09 11:21:54 +02:00
}
if (linked.insert(target).second &&
2017-04-14 19:02:05 +02:00
target->GetType() == cmStateEnums::STATIC_LIBRARY) {
2011-01-16 11:35:12 +01:00
// Static library targets do not list their link dependencies so
// we must follow them transitively now.
2016-03-13 13:35:51 +01:00
TargetDependSet const& depends = this->GetTargetDirectDepends(target);
2018-04-23 21:13:27 +02:00
for (cmTargetDepend const& di : depends) {
if (di.IsLink()) {
this->FollowLinkDepends(di, linked);
2011-01-16 11:35:12 +01:00
}
}
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
}
2010-11-13 01:00:53 +02:00
bool cmGlobalVisualStudioGenerator::ComputeTargetDepends()
{
2016-07-09 11:21:54 +02:00
if (!this->cmGlobalGenerator::ComputeTargetDepends()) {
2010-11-13 01:00:53 +02:00
return false;
2016-07-09 11:21:54 +02:00
}
2018-04-23 21:13:27 +02:00
for (auto const& it : this->ProjectMap) {
2019-11-11 23:01:05 +01:00
for (const cmLocalGenerator* i : it.second) {
2020-08-30 11:54:41 +02:00
for (const auto& ti : i->GetGeneratorTargets()) {
this->ComputeVSTargetDepends(ti.get());
}
}
2016-07-09 11:21:54 +02:00
}
2010-11-13 01:00:53 +02:00
return true;
}
2016-03-13 13:35:51 +01:00
static bool VSLinkable(cmGeneratorTarget const* t)
2012-04-19 19:04:21 +03:00
{
2017-04-14 19:02:05 +02:00
return t->IsLinkable() || t->GetType() == cmStateEnums::OBJECT_LIBRARY;
2012-04-19 19:04:21 +03:00
}
2016-03-13 13:35:51 +01:00
void cmGlobalVisualStudioGenerator::ComputeVSTargetDepends(
2016-07-09 11:21:54 +02:00
cmGeneratorTarget* target)
{
2016-07-09 11:21:54 +02:00
if (this->VSTargetDepends.find(target) != this->VSTargetDepends.end()) {
return;
2016-07-09 11:21:54 +02:00
}
2016-03-13 13:35:51 +01:00
VSDependSet& vsTargetDepend = this->VSTargetDepends[target];
2011-01-16 11:35:12 +01:00
// VS <= 7.1 has two behaviors that affect solution dependencies.
//
// (1) Solution-level dependencies between a linkable target and a
// library cause that library to be linked. We use an intermedite
// empty utility target to express the dependency. (VS 8 and above
// provide a project file "LinkLibraryDependencies" setting to
// choose whether to activate this behavior. We disable it except
// when linking external project files.)
//
// (2) We cannot let static libraries depend directly on targets to
// which they "link" because the librarian tool will copy the
// targets into the static library. While the work-around for
// behavior (1) would also avoid this, it would create a large
// number of extra utility targets for little gain. Instead, use
// the above work-around only for dependencies explicitly added by
// the add_dependencies() command. Approximate link dependencies by
// leaving them out for the static library itself but following them
// transitively for other targets.
2017-04-14 19:02:05 +02:00
bool allowLinkable = (target->GetType() != cmStateEnums::STATIC_LIBRARY &&
target->GetType() != cmStateEnums::SHARED_LIBRARY &&
target->GetType() != cmStateEnums::MODULE_LIBRARY &&
target->GetType() != cmStateEnums::EXECUTABLE);
2011-01-16 11:35:12 +01:00
2016-03-13 13:35:51 +01:00
TargetDependSet const& depends = this->GetTargetDirectDepends(target);
2011-01-16 11:35:12 +01:00
// Collect implicit link dependencies (target_link_libraries).
// Static libraries cannot depend on their link implementation
// due to behavior (2), but they do not really need to.
2016-03-13 13:35:51 +01:00
std::set<cmGeneratorTarget const*> linkDepends;
2017-04-14 19:02:05 +02:00
if (target->GetType() != cmStateEnums::STATIC_LIBRARY) {
2018-04-23 21:13:27 +02:00
for (cmTargetDepend const& di : depends) {
2019-11-11 23:01:05 +01:00
if (di.IsLink()) {
2018-04-23 21:13:27 +02:00
this->FollowLinkDepends(di, linkDepends);
}
}
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
2013-11-03 12:27:13 +02:00
// Collect explicit util dependencies (add_dependencies).
2016-03-13 13:35:51 +01:00
std::set<cmGeneratorTarget const*> utilDepends;
2018-04-23 21:13:27 +02:00
for (cmTargetDepend const& di : depends) {
2019-11-11 23:01:05 +01:00
if (di.IsUtil()) {
2018-04-23 21:13:27 +02:00
this->FollowLinkDepends(di, utilDepends);
}
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
// Collect all targets linked by this target so we can avoid
// intermediate targets below.
TargetSet linked;
2017-04-14 19:02:05 +02:00
if (target->GetType() != cmStateEnums::STATIC_LIBRARY) {
2016-03-13 13:35:51 +01:00
linked = this->GetTargetLinkClosure(target);
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
// Emit link dependencies.
2018-04-23 21:13:27 +02:00
for (cmGeneratorTarget const* dep : linkDepends) {
2011-01-16 11:35:12 +01:00
vsTargetDepend.insert(dep->GetName());
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
// Emit util dependencies. Possibly use intermediate targets.
2018-04-23 21:13:27 +02:00
for (cmGeneratorTarget const* dgt : utilDepends) {
2016-07-09 11:21:54 +02:00
if (allowLinkable || !VSLinkable(dgt) || linked.count(dgt)) {
2011-01-16 11:35:12 +01:00
// Direct dependency allowed.
2016-03-13 13:35:51 +01:00
vsTargetDepend.insert(dgt->GetName());
2016-07-09 11:21:54 +02:00
} else {
2011-01-16 11:35:12 +01:00
// Direct dependency on linkable target not allowed.
// Use an intermediate utility target.
2016-03-13 13:35:51 +01:00
vsTargetDepend.insert(this->GetUtilityDepend(dgt));
}
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
}
2017-04-14 19:02:05 +02:00
bool cmGlobalVisualStudioGenerator::FindMakeProgram(cmMakefile* mf)
2014-08-03 19:52:23 +02:00
{
// Visual Studio generators know how to lookup their build tool
// directly instead of needing a helper module to do it, so we
// do not actually need to put CMAKE_MAKE_PROGRAM into the cache.
2020-02-01 23:06:01 +01:00
if (cmIsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM"))) {
mf->AddDefinition("CMAKE_MAKE_PROGRAM", this->GetVSMakeProgram());
2016-07-09 11:21:54 +02:00
}
2017-04-14 19:02:05 +02:00
return true;
2014-08-03 19:52:23 +02:00
}
2016-07-09 11:21:54 +02:00
std::string cmGlobalVisualStudioGenerator::GetUtilityDepend(
cmGeneratorTarget const* target)
2010-11-13 01:00:53 +02:00
{
2019-11-11 23:01:05 +01:00
auto i = this->UtilityDepends.find(target);
2016-07-09 11:21:54 +02:00
if (i == this->UtilityDepends.end()) {
2010-11-13 01:00:53 +02:00
std::string name = this->WriteUtilityDepend(target);
UtilityDependsMap::value_type entry(target, name);
i = this->UtilityDepends.insert(entry).first;
2016-07-09 11:21:54 +02:00
}
2010-11-13 01:00:53 +02:00
return i->second;
}
2016-07-09 11:21:54 +02:00
std::string cmGlobalVisualStudioGenerator::GetStartupProjectName(
cmLocalGenerator const* root) const
{
2021-11-20 13:41:27 +01:00
cmValue n = root->GetMakefile()->GetProperty("VS_STARTUP_PROJECT");
2021-09-14 00:13:48 +02:00
if (cmNonempty(n)) {
2020-08-30 11:54:41 +02:00
std::string startup = *n;
2016-07-09 11:21:54 +02:00
if (this->FindTarget(startup)) {
return startup;
}
2023-05-23 16:38:00 +02:00
root->GetMakefile()->IssueMessage(
MessageType::AUTHOR_WARNING,
"Directory property VS_STARTUP_PROJECT specifies target "
"'" +
startup + "' that does not exist. Ignoring.");
2016-07-09 11:21:54 +02:00
}
// default, if not specified
return this->GetAllTargetName();
}
bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
2016-07-09 11:21:54 +02:00
const std::string& regKeyBase,
std::string& nextAvailableSubKeyName)
{
bool macrosRegistered = false;
std::string s1;
std::string s2;
// Make lowercase local copies, convert to Unix slashes, and
// see if the resulting strings are the same:
s1 = cmSystemTools::LowerCase(macrosFile);
cmSystemTools::ConvertToUnixSlashes(s1);
std::string keyname;
2023-07-02 19:51:09 +02:00
HKEY hkey = nullptr;
LONG result = ERROR_SUCCESS;
DWORD index = 0;
keyname = regKeyBase + "\\OtherProjects7";
2023-07-02 19:51:09 +02:00
hkey = nullptr;
2016-07-09 11:21:54 +02:00
result =
RegOpenKeyExW(HKEY_CURRENT_USER, cmsys::Encoding::ToWide(keyname).c_str(),
0, KEY_READ, &hkey);
if (ERROR_SUCCESS == result) {
// Iterate the subkeys and look for the values of interest in each subkey:
2014-08-03 19:52:23 +02:00
wchar_t subkeyname[256];
2020-02-01 23:06:01 +01:00
DWORD cch_subkeyname = cm::size(subkeyname);
2014-08-03 19:52:23 +02:00
wchar_t keyclass[256];
2020-02-01 23:06:01 +01:00
DWORD cch_keyclass = cm::size(keyclass);
FILETIME lastWriteTime;
lastWriteTime.dwHighDateTime = 0;
lastWriteTime.dwLowDateTime = 0;
2018-08-09 18:06:22 +02:00
while (ERROR_SUCCESS ==
RegEnumKeyExW(hkey, index, subkeyname, &cch_subkeyname, 0, keyclass,
&cch_keyclass, &lastWriteTime)) {
// Open the subkey and query the values of interest:
2023-07-02 19:51:09 +02:00
HKEY hsubkey = nullptr;
2014-08-03 19:52:23 +02:00
result = RegOpenKeyExW(hkey, subkeyname, 0, KEY_READ, &hsubkey);
2016-07-09 11:21:54 +02:00
if (ERROR_SUCCESS == result) {
DWORD valueType = REG_SZ;
2014-08-03 19:52:23 +02:00
wchar_t data1[256];
2020-02-01 23:06:01 +01:00
DWORD cch_data1 = sizeof(data1);
RegQueryValueExW(hsubkey, L"Path", 0, &valueType, (LPBYTE)data1,
2016-07-09 11:21:54 +02:00
&cch_data1);
DWORD data2 = 0;
DWORD cch_data2 = sizeof(data2);
2016-07-09 11:21:54 +02:00
RegQueryValueExW(hsubkey, L"Security", 0, &valueType, (LPBYTE)&data2,
&cch_data2);
DWORD data3 = 0;
DWORD cch_data3 = sizeof(data3);
2014-08-03 19:52:23 +02:00
RegQueryValueExW(hsubkey, L"StorageFormat", 0, &valueType,
2016-07-09 11:21:54 +02:00
(LPBYTE)&data3, &cch_data3);
2014-08-03 19:52:23 +02:00
s2 = cmSystemTools::LowerCase(cmsys::Encoding::ToNarrow(data1));
cmSystemTools::ConvertToUnixSlashes(s2);
2016-07-09 11:21:54 +02:00
if (s2 == s1) {
macrosRegistered = true;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
std::string fullname = cmsys::Encoding::ToNarrow(data1);
std::string filename;
std::string filepath;
std::string filepathname;
std::string filepathpath;
2020-08-30 11:54:41 +02:00
if (cmSystemTools::FileExists(fullname)) {
filename = cmSystemTools::GetFilenameName(fullname);
filepath = cmSystemTools::GetFilenamePath(fullname);
filepathname = cmSystemTools::GetFilenameName(filepath);
filepathpath = cmSystemTools::GetFilenamePath(filepath);
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
// std::cout << keyname << "\\" << subkeyname << ":" << std::endl;
// std::cout << " Path: " << data1 << std::endl;
// std::cout << " Security: " << data2 << std::endl;
// std::cout << " StorageFormat: " << data3 << std::endl;
// std::cout << " filename: " << filename << std::endl;
// std::cout << " filepath: " << filepath << std::endl;
// std::cout << " filepathname: " << filepathname << std::endl;
// std::cout << " filepathpath: " << filepathpath << std::endl;
// std::cout << std::endl;
RegCloseKey(hsubkey);
2016-07-09 11:21:54 +02:00
} else {
2022-11-16 20:14:03 +01:00
std::cout << "error opening subkey: "
<< cmsys::Encoding::ToNarrow(subkeyname) << std::endl;
std::cout << std::endl;
2016-07-09 11:21:54 +02:00
}
++index;
2020-02-01 23:06:01 +01:00
cch_subkeyname = cm::size(subkeyname);
cch_keyclass = cm::size(keyclass);
lastWriteTime.dwHighDateTime = 0;
lastWriteTime.dwLowDateTime = 0;
2016-07-09 11:21:54 +02:00
}
RegCloseKey(hkey);
2016-07-09 11:21:54 +02:00
} else {
std::cout << "error opening key: " << keyname << std::endl;
std::cout << std::endl;
2016-07-09 11:21:54 +02:00
}
// Pass back next available sub key name, assuming sub keys always
// follow the expected naming scheme. Expected naming scheme is that
// the subkeys of OtherProjects7 is 0 to n-1, so it's ok to use "n"
// as the name of the next subkey.
2020-02-01 23:06:01 +01:00
nextAvailableSubKeyName = std::to_string(index);
keyname = regKeyBase + "\\RecordingProject7";
2023-07-02 19:51:09 +02:00
hkey = nullptr;
2016-07-09 11:21:54 +02:00
result =
RegOpenKeyExW(HKEY_CURRENT_USER, cmsys::Encoding::ToWide(keyname).c_str(),
0, KEY_READ, &hkey);
if (ERROR_SUCCESS == result) {
DWORD valueType = REG_SZ;
2014-08-03 19:52:23 +02:00
wchar_t data1[256];
2020-02-01 23:06:01 +01:00
DWORD cch_data1 = sizeof(data1);
RegQueryValueExW(hkey, L"Path", 0, &valueType, (LPBYTE)data1, &cch_data1);
DWORD data2 = 0;
DWORD cch_data2 = sizeof(data2);
2016-07-09 11:21:54 +02:00
RegQueryValueExW(hkey, L"Security", 0, &valueType, (LPBYTE)&data2,
&cch_data2);
DWORD data3 = 0;
DWORD cch_data3 = sizeof(data3);
2016-07-09 11:21:54 +02:00
RegQueryValueExW(hkey, L"StorageFormat", 0, &valueType, (LPBYTE)&data3,
&cch_data3);
2014-08-03 19:52:23 +02:00
s2 = cmSystemTools::LowerCase(cmsys::Encoding::ToNarrow(data1));
cmSystemTools::ConvertToUnixSlashes(s2);
2016-07-09 11:21:54 +02:00
if (s2 == s1) {
macrosRegistered = true;
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
// std::cout << keyname << ":" << std::endl;
// std::cout << " Path: " << data1 << std::endl;
// std::cout << " Security: " << data2 << std::endl;
// std::cout << " StorageFormat: " << data3 << std::endl;
// std::cout << std::endl;
RegCloseKey(hkey);
2016-07-09 11:21:54 +02:00
} else {
std::cout << "error opening key: " << keyname << std::endl;
std::cout << std::endl;
2016-07-09 11:21:54 +02:00
}
return macrosRegistered;
}
2016-07-09 11:21:54 +02:00
void WriteVSMacrosFileRegistryEntry(const std::string& nextAvailableSubKeyName,
const std::string& macrosFile,
const std::string& regKeyBase)
{
std::string keyname = regKeyBase + "\\OtherProjects7";
2023-07-02 19:51:09 +02:00
HKEY hkey = nullptr;
2016-07-09 11:21:54 +02:00
LONG result =
RegOpenKeyExW(HKEY_CURRENT_USER, cmsys::Encoding::ToWide(keyname).c_str(),
0, KEY_READ | KEY_WRITE, &hkey);
if (ERROR_SUCCESS == result) {
// Create the subkey and set the values of interest:
2023-07-02 19:51:09 +02:00
HKEY hsubkey = nullptr;
2014-08-03 19:52:23 +02:00
wchar_t lpClass[] = L"";
2016-07-09 11:21:54 +02:00
result = RegCreateKeyExW(
hkey, cmsys::Encoding::ToWide(nextAvailableSubKeyName).c_str(), 0,
lpClass, 0, KEY_READ | KEY_WRITE, 0, &hsubkey, 0);
if (ERROR_SUCCESS == result) {
DWORD dw = 0;
std::string s(macrosFile);
2016-07-09 11:21:54 +02:00
std::replace(s.begin(), s.end(), '/', '\\');
2014-08-03 19:52:23 +02:00
std::wstring ws = cmsys::Encoding::ToWide(s);
2016-07-09 11:21:54 +02:00
result =
RegSetValueExW(hsubkey, L"Path", 0, REG_SZ, (LPBYTE)ws.c_str(),
static_cast<DWORD>(ws.size() + 1) * sizeof(wchar_t));
if (ERROR_SUCCESS != result) {
std::cout << "error result 1: " << result << std::endl;
std::cout << std::endl;
2016-07-09 11:21:54 +02:00
}
// Security value is always "1" for sample macros files (seems to be "2"
// if you put the file somewhere outside the standard VSMacros folder)
dw = 1;
2016-07-09 11:21:54 +02:00
result = RegSetValueExW(hsubkey, L"Security", 0, REG_DWORD, (LPBYTE)&dw,
sizeof(DWORD));
if (ERROR_SUCCESS != result) {
std::cout << "error result 2: " << result << std::endl;
std::cout << std::endl;
2016-07-09 11:21:54 +02:00
}
// StorageFormat value is always "0" for sample macros files
dw = 0;
2016-07-09 11:21:54 +02:00
result = RegSetValueExW(hsubkey, L"StorageFormat", 0, REG_DWORD,
(LPBYTE)&dw, sizeof(DWORD));
if (ERROR_SUCCESS != result) {
std::cout << "error result 3: " << result << std::endl;
std::cout << std::endl;
2016-07-09 11:21:54 +02:00
}
RegCloseKey(hsubkey);
2016-07-09 11:21:54 +02:00
} else {
std::cout << "error creating subkey: " << nextAvailableSubKeyName
<< std::endl;
std::cout << std::endl;
}
2016-07-09 11:21:54 +02:00
RegCloseKey(hkey);
} else {
std::cout << "error opening key: " << keyname << std::endl;
std::cout << std::endl;
2016-07-09 11:21:54 +02:00
}
}
void RegisterVisualStudioMacros(const std::string& macrosFile,
2016-07-09 11:21:54 +02:00
const std::string& regKeyBase)
{
bool macrosRegistered;
std::string nextAvailableSubKeyName;
2016-07-09 11:21:54 +02:00
macrosRegistered = IsVisualStudioMacrosFileRegistered(
macrosFile, regKeyBase, nextAvailableSubKeyName);
2016-07-09 11:21:54 +02:00
if (!macrosRegistered) {
int count =
cmCallVisualStudioMacro::GetNumberOfRunningVisualStudioInstances("ALL");
// Only register the macros file if there are *no* instances of Visual
// Studio running. If we register it while one is running, first, it has
// no effect on the running instance; second, and worse, Visual Studio
// removes our newly added registration entry when it quits. Instead,
// emit a warning asking the user to exit all running Visual Studio
// instances...
//
2016-07-09 11:21:54 +02:00
if (0 != count) {
std::ostringstream oss;
oss << "Could not register CMake's Visual Studio macros file '"
2016-07-09 11:21:54 +02:00
<< CMAKE_VSMACROS_FILENAME "' while Visual Studio is running."
<< " Please exit all running instances of Visual Studio before"
<< " continuing." << std::endl
<< std::endl
<< "CMake needs to register Visual Studio macros when its macros"
<< " file is updated or when it detects that its current macros file"
<< " is no longer registered with Visual Studio." << std::endl;
2019-11-11 23:01:05 +01:00
cmSystemTools::Message(oss.str(), "Warning");
// Count them again now that the warning is over. In the case of a GUI
// warning, the user may have gone to close Visual Studio and then come
// back to the CMake GUI and clicked ok on the above warning. If so,
// then register the macros *now* if the count is *now* 0...
//
2016-07-09 11:21:54 +02:00
count = cmCallVisualStudioMacro::GetNumberOfRunningVisualStudioInstances(
"ALL");
// Also re-get the nextAvailableSubKeyName in case Visual Studio
// wrote out new registered macros information as it was exiting:
//
2016-07-09 11:21:54 +02:00
if (0 == count) {
IsVisualStudioMacrosFileRegistered(macrosFile, regKeyBase,
2016-07-09 11:21:54 +02:00
nextAvailableSubKeyName);
}
2016-07-09 11:21:54 +02:00
}
// Do another if check - 'count' may have changed inside the above if:
//
2016-07-09 11:21:54 +02:00
if (0 == count) {
WriteVSMacrosFileRegistryEntry(nextAvailableSubKeyName, macrosFile,
2016-07-09 11:21:54 +02:00
regKeyBase);
}
2016-07-09 11:21:54 +02:00
}
}
2016-07-09 11:21:54 +02:00
bool cmGlobalVisualStudioGenerator::TargetIsFortranOnly(
cmGeneratorTarget const* gt)
{
2017-07-20 19:35:53 +02:00
// If there's only one source language, Fortran has to be used
// in order for the sources to compile.
2020-08-30 11:54:41 +02:00
std::set<std::string> languages = gt->GetAllConfigCompileLanguages();
2019-11-11 23:01:05 +01:00
// Consider an explicit linker language property, but *not* the
// computed linker language that may depend on linked targets.
// This allows the project to control the language choice in
// a target with none of its own sources, e.g. when also using
// object libraries.
2021-11-20 13:41:27 +01:00
cmValue linkLang = gt->GetProperty("LINKER_LANGUAGE");
2021-09-14 00:13:48 +02:00
if (cmNonempty(linkLang)) {
2020-08-30 11:54:41 +02:00
languages.insert(*linkLang);
2016-07-09 11:21:54 +02:00
}
2017-07-20 19:35:53 +02:00
2019-11-11 23:01:05 +01:00
// Intel Fortran .vfproj files do support the resource compiler.
languages.erase("RC");
2017-07-20 19:35:53 +02:00
2019-11-11 23:01:05 +01:00
return languages.size() == 1 && *languages.begin() == "Fortran";
}
2009-10-04 10:30:41 +03:00
2022-08-04 22:12:04 +02:00
bool cmGlobalVisualStudioGenerator::IsInSolution(
const cmGeneratorTarget* gt) const
{
return gt->IsInBuildSystem();
}
bool cmGlobalVisualStudioGenerator::IsDepInSolution(
const std::string& targetName) const
{
return !targetName.empty();
}
2016-07-09 11:21:54 +02:00
bool cmGlobalVisualStudioGenerator::TargetCompare::operator()(
cmGeneratorTarget const* l, cmGeneratorTarget const* r) const
2009-10-04 10:30:41 +03:00
{
2015-11-17 17:22:37 +01:00
// Make sure a given named target is ordered first,
// e.g. to set ALL_BUILD as the default active project.
// When the empty string is named this is a no-op.
2016-07-09 11:21:54 +02:00
if (r->GetName() == this->First) {
2009-10-04 10:30:41 +03:00
return false;
2016-07-09 11:21:54 +02:00
}
if (l->GetName() == this->First) {
2009-10-04 10:30:41 +03:00
return true;
2016-07-09 11:21:54 +02:00
}
2015-11-17 17:22:37 +01:00
return l->GetName() < r->GetName();
2009-10-04 10:30:41 +03:00
}
2016-07-09 11:21:54 +02:00
cmGlobalVisualStudioGenerator::OrderedTargetDependSet::OrderedTargetDependSet(
TargetDependSet const& targets, std::string const& first)
: derived(TargetCompare(first))
2009-10-04 10:30:41 +03:00
{
2015-04-27 22:25:09 +02:00
this->insert(targets.begin(), targets.end());
2009-10-04 10:30:41 +03:00
}
2011-01-16 11:35:12 +01:00
2016-07-09 11:21:54 +02:00
cmGlobalVisualStudioGenerator::OrderedTargetDependSet::OrderedTargetDependSet(
TargetSet const& targets, std::string const& first)
: derived(TargetCompare(first))
2011-01-16 11:35:12 +01:00
{
2018-04-23 21:13:27 +02:00
for (cmGeneratorTarget const* it : targets) {
this->insert(it);
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
}
2014-08-03 19:52:23 +02:00
std::string cmGlobalVisualStudioGenerator::ExpandCFGIntDir(
2016-07-09 11:21:54 +02:00
const std::string& str, const std::string& config) const
2014-08-03 19:52:23 +02:00
{
std::string replace = GetCMakeCFGIntDir();
std::string tmp = str;
2016-07-09 11:21:54 +02:00
for (std::string::size_type i = tmp.find(replace); i != std::string::npos;
i = tmp.find(replace, i)) {
2014-08-03 19:52:23 +02:00
tmp.replace(i, replace.size(), config);
i += config.size();
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
return tmp;
}
2015-11-17 17:22:37 +01:00
void cmGlobalVisualStudioGenerator::AddSymbolExportCommand(
cmGeneratorTarget* gt, std::vector<cmCustomCommand>& commands,
std::string const& configName)
{
2017-07-20 19:35:53 +02:00
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
gt->GetModuleDefinitionInfo(configName);
if (!mdi || !mdi->DefFileGenerated) {
return;
}
2015-11-17 17:22:37 +01:00
std::vector<std::string> outputs;
2017-07-20 19:35:53 +02:00
outputs.push_back(mdi->DefFile);
2015-11-17 17:22:37 +01:00
std::vector<std::string> empty;
std::vector<cmSourceFile const*> objectSources;
gt->GetObjectSources(objectSources, configName);
std::map<cmSourceFile const*, std::string> mapping;
2018-04-23 21:13:27 +02:00
for (cmSourceFile const* it : objectSources) {
mapping[it];
2016-07-09 11:21:54 +02:00
}
gt->LocalGenerator->ComputeObjectFilenames(mapping, gt);
2015-11-17 17:22:37 +01:00
std::string obj_dir = gt->ObjectDirectory;
std::string cmakeCommand = cmSystemTools::GetCMakeCommand();
std::string obj_dir_expanded = obj_dir;
2016-07-09 11:21:54 +02:00
cmSystemTools::ReplaceString(obj_dir_expanded, this->GetCMakeCFGIntDir(),
2015-11-17 17:22:37 +01:00
configName.c_str());
2017-07-20 19:35:53 +02:00
cmSystemTools::MakeDirectory(obj_dir_expanded);
std::string const objs_file = obj_dir_expanded + "/objects.txt";
2015-11-17 17:22:37 +01:00
cmGeneratedFileStream fout(objs_file.c_str());
2016-07-09 11:21:54 +02:00
if (!fout) {
2019-11-11 23:01:05 +01:00
cmSystemTools::Error("could not open " + objs_file);
2015-11-17 17:22:37 +01:00
return;
2016-07-09 11:21:54 +02:00
}
2017-04-14 19:02:05 +02:00
2017-07-20 19:35:53 +02:00
if (mdi->WindowsExportAllSymbols) {
std::vector<std::string> objs;
2018-04-23 21:13:27 +02:00
for (cmSourceFile const* it : objectSources) {
2017-07-20 19:35:53 +02:00
// Find the object file name corresponding to this source file.
// It must exist because we populated the mapping just above.
2019-11-11 23:01:05 +01:00
const auto& v = mapping[it];
assert(!v.empty());
std::string objFile = obj_dir + v;
2017-07-20 19:35:53 +02:00
objs.push_back(objFile);
}
std::vector<cmSourceFile const*> externalObjectSources;
gt->GetExternalObjects(externalObjectSources, configName);
2018-04-23 21:13:27 +02:00
for (cmSourceFile const* it : externalObjectSources) {
objs.push_back(it->GetFullPath());
2017-07-20 19:35:53 +02:00
}
2018-04-23 21:13:27 +02:00
for (std::string const& it : objs) {
std::string objFile = it;
2017-07-20 19:35:53 +02:00
// replace $(ConfigurationName) in the object names
cmSystemTools::ReplaceString(objFile, this->GetCMakeCFGIntDir(),
2020-08-30 11:54:41 +02:00
configName);
2017-07-20 19:35:53 +02:00
if (cmHasLiteralSuffix(objFile, ".obj")) {
fout << objFile << "\n";
}
2015-11-17 17:22:37 +01:00
}
2016-07-09 11:21:54 +02:00
}
2017-07-20 19:35:53 +02:00
2018-04-23 21:13:27 +02:00
for (cmSourceFile const* i : mdi->Sources) {
fout << i->GetFullPath() << "\n";
2017-07-20 19:35:53 +02:00
}
2020-02-01 23:06:01 +01:00
cmCustomCommandLines commandLines = cmMakeSingleCommandLine(
{ cmakeCommand, "-E", "__create_def", mdi->DefFile, objs_file });
2022-03-29 21:10:50 +02:00
cmCustomCommand command;
command.SetOutputs(outputs);
command.SetCommandLines(commandLines);
command.SetComment("Auto build dll exports");
command.SetBacktrace(gt->Target->GetMakefile()->GetBacktrace());
command.SetWorkingDirectory(".");
command.SetStdPipesUTF8(true);
2020-08-30 11:54:41 +02:00
commands.push_back(std::move(command));
2015-11-17 17:22:37 +01:00
}
2018-04-23 21:13:27 +02:00
2023-05-23 16:38:00 +02:00
static bool OpenSolution(std::string const& sln)
2018-04-23 21:13:27 +02:00
{
HRESULT comInitialized =
2023-07-02 19:51:09 +02:00
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
2018-04-23 21:13:27 +02:00
if (FAILED(comInitialized)) {
return false;
}
2023-07-02 19:51:09 +02:00
HINSTANCE hi = ShellExecuteA(nullptr, "open", sln.c_str(), nullptr, nullptr,
SW_SHOWNORMAL);
2018-04-23 21:13:27 +02:00
CoUninitialize();
return reinterpret_cast<intptr_t>(hi) > 32;
}
bool cmGlobalVisualStudioGenerator::Open(const std::string& bindir,
const std::string& projectName,
bool dryRun)
{
2018-10-28 12:09:07 +01:00
std::string sln = bindir + "/" + projectName + ".sln";
2018-04-23 21:13:27 +02:00
if (dryRun) {
return cmSystemTools::FileExists(sln, true);
}
2018-10-28 12:09:07 +01:00
sln = cmSystemTools::ConvertToOutputPath(sln);
2018-04-23 21:13:27 +02:00
return std::async(std::launch::async, OpenSolution, sln).get();
}