2014-03-14 18:48:42 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2007-04-04 19:22:14 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2007-04-04 19:22:14 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2007-04-04 19:22:14 +04:00
|
|
|
#include "cmGlobalVisualStudioGenerator.h"
|
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmAlgorithms.h"
|
2007-11-16 15:01:58 +03:00
|
|
|
#include "cmCallVisualStudioMacro.h"
|
2015-06-19 23:12:43 +03:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2012-03-07 23:04:33 +04:00
|
|
|
#include "cmGeneratorTarget.h"
|
|
|
|
#include "cmLocalVisualStudioGenerator.h"
|
2007-04-04 22:50:35 +04:00
|
|
|
#include "cmMakefile.h"
|
2012-03-07 23:04:33 +04:00
|
|
|
#include "cmSourceFile.h"
|
2007-04-04 22:50:35 +04:00
|
|
|
#include "cmTarget.h"
|
2013-12-05 09:17:24 +04:00
|
|
|
#include <cmsys/Encoding.hxx>
|
2007-04-04 22:50:35 +04:00
|
|
|
|
2015-05-24 12:31:14 +03:00
|
|
|
cmGlobalVisualStudioGenerator::cmGlobalVisualStudioGenerator(cmake* cm)
|
|
|
|
: cmGlobalGenerator(cm)
|
2007-04-04 19:22:14 +04:00
|
|
|
{
|
2015-05-24 12:46:30 +03:00
|
|
|
cm->GetState()->SetWindowsShell(true);
|
|
|
|
cm->GetState()->SetWindowsVSIDE(true);
|
2007-04-04 19:22:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cmGlobalVisualStudioGenerator::~cmGlobalVisualStudioGenerator()
|
|
|
|
{
|
|
|
|
}
|
2007-04-04 22:50:35 +04:00
|
|
|
|
2015-05-17 12:33:09 +03:00
|
|
|
cmGlobalVisualStudioGenerator::VSVersion
|
|
|
|
cmGlobalVisualStudioGenerator::GetVersion() const
|
|
|
|
{
|
|
|
|
return this->Version;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalVisualStudioGenerator::SetVersion(VSVersion v)
|
|
|
|
{
|
|
|
|
this->Version = v;
|
|
|
|
}
|
|
|
|
|
2009-09-16 19:44:08 +04:00
|
|
|
std::string cmGlobalVisualStudioGenerator::GetRegistryBase()
|
2012-11-20 15:18:43 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
return cmGlobalVisualStudioGenerator::GetRegistryBase(this->GetIDEVersion());
|
2012-11-20 15:18:43 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmGlobalVisualStudioGenerator::GetRegistryBase(const char* version)
|
2009-09-16 19:44:08 +04:00
|
|
|
{
|
|
|
|
std::string key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\";
|
2012-11-20 15:18:43 +04:00
|
|
|
return key + version;
|
2009-09-16 19:44:08 +04:00
|
|
|
}
|
|
|
|
|
2015-09-15 21:47:35 +03:00
|
|
|
void cmGlobalVisualStudioGenerator::AddExtraIDETargets()
|
2007-04-10 21:09:03 +04:00
|
|
|
{
|
|
|
|
// Add a special target that depends on ALL projects for easy build
|
|
|
|
// of one configuration only.
|
|
|
|
const char* no_working_dir = 0;
|
|
|
|
std::vector<std::string> no_depends;
|
|
|
|
cmCustomCommandLines no_commands;
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, std::vector<cmLocalGenerator*> >::iterator it;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (it = this->ProjectMap.begin(); it != this->ProjectMap.end(); ++it) {
|
2007-04-10 21:09:03 +04:00
|
|
|
std::vector<cmLocalGenerator*>& gen = it->second;
|
|
|
|
// add the ALL_BUILD to the first local generator of each project
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!gen.empty()) {
|
2007-04-10 21:09:03 +04:00
|
|
|
// Use no actual command lines so that the target itself is not
|
|
|
|
// considered always out of date.
|
2016-05-16 17:34:04 +03:00
|
|
|
cmTarget* allBuild = gen[0]->GetMakefile()->AddUtilityCommand(
|
|
|
|
"ALL_BUILD", true, no_working_dir, no_depends, no_commands, false,
|
|
|
|
"Build all projects");
|
2015-08-05 01:00:53 +03:00
|
|
|
|
2015-07-28 19:57:29 +03:00
|
|
|
cmGeneratorTarget* gt = new cmGeneratorTarget(allBuild, gen[0]);
|
2015-10-18 17:53:00 +03:00
|
|
|
gen[0]->AddGeneratorTarget(gt);
|
2010-09-03 21:53:22 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Organize in the "predefined targets" folder:
|
|
|
|
//
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->UseFolderProperty()) {
|
2010-09-03 21:53:22 +04:00
|
|
|
allBuild->SetProperty("FOLDER", this->GetPredefinedTargetsFolder());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-09-03 21:53:22 +04:00
|
|
|
|
2009-07-10 17:12:39 +04:00
|
|
|
// Now make all targets depend on the ALL_BUILD target
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmLocalGenerator*>::iterator i = gen.begin();
|
|
|
|
i != gen.end(); ++i) {
|
|
|
|
std::vector<cmGeneratorTarget*> targets = (*i)->GetGeneratorTargets();
|
|
|
|
for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
|
|
|
|
t != targets.end(); ++t) {
|
2015-10-18 17:53:00 +03:00
|
|
|
cmGeneratorTarget* tgt = *t;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (tgt->GetType() == cmState::GLOBAL_TARGET || tgt->IsImported()) {
|
2015-07-28 19:48:40 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!this->IsExcluded(gen[0], tgt)) {
|
2015-10-18 17:53:00 +03:00
|
|
|
allBuild->AddUtility(tgt->GetName());
|
2009-07-10 17:12:39 +04:00
|
|
|
}
|
|
|
|
}
|
2007-04-10 21:09:03 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-04-10 21:09:03 +04:00
|
|
|
|
2007-11-16 15:01:58 +03:00
|
|
|
// Configure CMake Visual Studio macros, for this user on this version
|
|
|
|
// of Visual Studio.
|
|
|
|
this->ConfigureCMakeVisualStudioMacros();
|
|
|
|
|
2012-03-28 21:49:01 +04:00
|
|
|
// Add CMakeLists.txt with custom command to rerun CMake.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmLocalGenerator*>::const_iterator lgi =
|
|
|
|
this->LocalGenerators.begin();
|
|
|
|
lgi != this->LocalGenerators.end(); ++lgi) {
|
2012-03-28 21:49:01 +04:00
|
|
|
cmLocalVisualStudioGenerator* lg =
|
|
|
|
static_cast<cmLocalVisualStudioGenerator*>(*lgi);
|
|
|
|
lg->AddCMakeListsRules();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-04-10 21:09:03 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGlobalVisualStudioGenerator::ComputeTargetObjectDirectory(
|
|
|
|
cmGeneratorTarget* gt) const
|
2012-03-07 23:04:33 +04:00
|
|
|
{
|
2015-10-22 01:29:36 +03:00
|
|
|
std::string dir = gt->LocalGenerator->GetCurrentBinaryDirectory();
|
2012-03-09 01:32:03 +04:00
|
|
|
dir += "/";
|
2015-10-09 23:27:46 +03:00
|
|
|
std::string tgtDir = gt->LocalGenerator->GetTargetDirectory(gt);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!tgtDir.empty()) {
|
2012-03-09 01:32:03 +04:00
|
|
|
dir += tgtDir;
|
|
|
|
dir += "/";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-03-09 01:32:03 +04:00
|
|
|
const char* cd = this->GetCMakeCFGIntDir();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cd && *cd) {
|
2012-03-09 01:32:03 +04:00
|
|
|
dir += cd;
|
|
|
|
dir += "/";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-03-09 01:32:03 +04:00
|
|
|
gt->ObjectDirectory = dir;
|
2012-03-07 23:04:33 +04:00
|
|
|
}
|
|
|
|
|
2007-11-16 21:54:21 +03:00
|
|
|
bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& regKeyBase,
|
|
|
|
std::string& nextAvailableSubKeyName);
|
2007-11-16 21:54:21 +03:00
|
|
|
|
2008-02-15 19:49:58 +03:00
|
|
|
void RegisterVisualStudioMacros(const std::string& macrosFile,
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& regKeyBase);
|
2007-11-16 15:01:58 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
#define CMAKE_VSMACROS_FILENAME "CMakeVSMacros2.vsmacros"
|
2007-11-16 15:01:58 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
#define CMAKE_VSMACROS_RELOAD_MACRONAME \
|
2008-02-15 19:49:58 +03:00
|
|
|
"Macros.CMakeVSMacros2.Macros.ReloadProjects"
|
2007-11-16 15:01:58 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
#define CMAKE_VSMACROS_STOP_MACRONAME "Macros.CMakeVSMacros2.Macros.StopBuild"
|
2007-11-19 21:44:51 +03:00
|
|
|
|
2007-11-16 15:01:58 +03:00
|
|
|
void cmGlobalVisualStudioGenerator::ConfigureCMakeVisualStudioMacros()
|
|
|
|
{
|
|
|
|
std::string dir = this->GetUserMacrosDirectory();
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (dir != "") {
|
2016-03-14 17:38:19 +03:00
|
|
|
std::string src = cmSystemTools::GetCMakeRoot();
|
2007-11-16 15:01:58 +03:00
|
|
|
src += "/Templates/" CMAKE_VSMACROS_FILENAME;
|
|
|
|
|
|
|
|
std::string dst = dir + "/CMakeMacros/" CMAKE_VSMACROS_FILENAME;
|
|
|
|
|
2007-11-19 21:44:51 +03:00
|
|
|
// 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;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileTimeCompare(src.c_str(), dst.c_str(), &res) ||
|
|
|
|
res > 0) {
|
|
|
|
if (!cmSystemTools::CopyFileAlways(src.c_str(), dst.c_str())) {
|
2007-11-16 15:01:58 +03:00
|
|
|
std::ostringstream oss;
|
|
|
|
oss << "Could not copy from: " << src << std::endl;
|
|
|
|
oss << " to: " << dst << std::endl;
|
|
|
|
cmSystemTools::Message(oss.str().c_str(), "Warning");
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03:00
|
|
|
|
2008-02-15 19:49:58 +03:00
|
|
|
RegisterVisualStudioMacros(dst, this->GetUserMacrosRegKeyBase());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGlobalVisualStudioGenerator::CallVisualStudioMacro(
|
|
|
|
MacroName m, const char* vsSolutionFile)
|
2007-11-16 15:01:58 +03:00
|
|
|
{
|
|
|
|
// If any solution or project files changed during the generation,
|
|
|
|
// tell Visual Studio to reload them...
|
|
|
|
cmMakefile* mf = this->LocalGenerators[0]->GetMakefile();
|
|
|
|
std::string dir = this->GetUserMacrosDirectory();
|
|
|
|
|
2007-11-16 21:54:21 +03:00
|
|
|
// 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
|
|
|
|
//
|
2016-05-16 17:34:04 +03:00
|
|
|
if (dir != "") {
|
2007-11-16 21:54:21 +03:00
|
|
|
std::string macrosFile = dir + "/CMakeMacros/" CMAKE_VSMACROS_FILENAME;
|
|
|
|
std::string nextSubkeyName;
|
|
|
|
if (cmSystemTools::FileExists(macrosFile.c_str()) &&
|
2016-05-16 17:34:04 +03:00
|
|
|
IsVisualStudioMacrosFileRegistered(
|
|
|
|
macrosFile, this->GetUserMacrosRegKeyBase(), nextSubkeyName)) {
|
2007-11-19 21:44:51 +03:00
|
|
|
std::string topLevelSlnName;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (vsSolutionFile) {
|
2007-11-19 21:44:51 +03:00
|
|
|
topLevelSlnName = vsSolutionFile;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-04-16 21:06:54 +03:00
|
|
|
topLevelSlnName = mf->GetCurrentBinaryDirectory();
|
2007-11-16 21:54:21 +03:00
|
|
|
topLevelSlnName += "/";
|
2015-10-07 01:29:25 +03:00
|
|
|
topLevelSlnName += this->LocalGenerators[0]->GetProjectName();
|
2007-11-16 21:54:21 +03:00
|
|
|
topLevelSlnName += ".sln";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (m == MacroReload) {
|
2007-11-19 21:44:51 +03:00
|
|
|
std::vector<std::string> filenames;
|
|
|
|
this->GetFilesReplacedDuringGenerate(filenames);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!filenames.empty()) {
|
2007-11-19 21:44:51 +03:00
|
|
|
// Convert vector to semi-colon delimited string of filenames:
|
|
|
|
std::string projects;
|
|
|
|
std::vector<std::string>::iterator it = filenames.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (it != filenames.end()) {
|
2007-11-19 21:44:51 +03:00
|
|
|
projects = *it;
|
|
|
|
++it;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
for (; it != filenames.end(); ++it) {
|
2007-11-19 21:44:51 +03:00
|
|
|
projects += ";";
|
|
|
|
projects += *it;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCallVisualStudioMacro::CallMacro(
|
|
|
|
topLevelSlnName, CMAKE_VSMACROS_RELOAD_MACRONAME, projects,
|
|
|
|
this->GetCMakeInstance()->GetDebugOutput());
|
2007-11-19 21:44:51 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (m == MacroStop) {
|
|
|
|
cmCallVisualStudioMacro::CallMacro(
|
|
|
|
topLevelSlnName, CMAKE_VSMACROS_STOP_MACRONAME, "",
|
2008-07-30 23:26:34 +04:00
|
|
|
this->GetCMakeInstance()->GetDebugOutput());
|
2007-11-16 15:01:58 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmGlobalVisualStudioGenerator::GetUserMacrosDirectory()
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2008-02-15 19:49:58 +03:00
|
|
|
std::string cmGlobalVisualStudioGenerator::GetUserMacrosRegKeyBase()
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-10-23 19:26:39 +03:00
|
|
|
void cmGlobalVisualStudioGenerator::FillLinkClosure(
|
2016-05-16 17:34:04 +03:00
|
|
|
const cmGeneratorTarget* target, TargetSet& linked)
|
2010-08-25 18:26:25 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (linked.insert(target).second) {
|
|
|
|
TargetDependSet const& depends = this->GetTargetDirectDepends(target);
|
|
|
|
for (TargetDependSet::const_iterator di = depends.begin();
|
|
|
|
di != depends.end(); ++di) {
|
|
|
|
if (di->IsLink()) {
|
2015-10-23 19:26:39 +03:00
|
|
|
this->FillLinkClosure(*di, linked);
|
2010-08-25 18:26:25 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-08-25 18:26:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cmGlobalVisualStudioGenerator::TargetSet const&
|
2015-10-23 19:26:39 +03:00
|
|
|
cmGlobalVisualStudioGenerator::GetTargetLinkClosure(cmGeneratorTarget* target)
|
2010-08-25 18:26:25 +04:00
|
|
|
{
|
2015-10-23 19:26:48 +03:00
|
|
|
TargetSetMap::iterator i = this->TargetLinkClosure.find(target);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (i == this->TargetLinkClosure.end()) {
|
2015-10-23 19:26:48 +03:00
|
|
|
TargetSetMap::value_type entry(target, TargetSet());
|
2010-08-25 18:26:25 +04:00
|
|
|
i = this->TargetLinkClosure.insert(entry).first;
|
|
|
|
this->FillLinkClosure(target, i->second);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-08-25 18:26:25 +04:00
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmGlobalVisualStudioGenerator::FollowLinkDepends(
|
2016-05-16 17:34:04 +03:00
|
|
|
const cmGeneratorTarget* target, std::set<const cmGeneratorTarget*>& linked)
|
2010-08-25 18:26:25 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target->GetType() == cmState::INTERFACE_LIBRARY) {
|
2012-11-02 18:47:40 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (linked.insert(target).second &&
|
|
|
|
target->GetType() == cmState::STATIC_LIBRARY) {
|
2010-08-25 18:26:25 +04:00
|
|
|
// Static library targets do not list their link dependencies so
|
|
|
|
// we must follow them transitively now.
|
2015-10-23 19:26:48 +03:00
|
|
|
TargetDependSet const& depends = this->GetTargetDirectDepends(target);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (TargetDependSet::const_iterator di = depends.begin();
|
|
|
|
di != depends.end(); ++di) {
|
|
|
|
if (di->IsLink()) {
|
2015-10-23 19:26:48 +03:00
|
|
|
this->FollowLinkDepends(*di, linked);
|
2010-08-25 18:26:25 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-08-25 18:26:25 +04:00
|
|
|
}
|
|
|
|
|
2010-08-25 02:39:36 +04:00
|
|
|
bool cmGlobalVisualStudioGenerator::ComputeTargetDepends()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->cmGlobalGenerator::ComputeTargetDepends()) {
|
2010-08-25 02:39:36 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, std::vector<cmLocalGenerator*> >::iterator it;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (it = this->ProjectMap.begin(); it != this->ProjectMap.end(); ++it) {
|
2010-08-25 02:39:36 +04:00
|
|
|
std::vector<cmLocalGenerator*>& gen = it->second;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmLocalGenerator*>::iterator i = gen.begin();
|
|
|
|
i != gen.end(); ++i) {
|
2015-10-18 18:06:14 +03:00
|
|
|
std::vector<cmGeneratorTarget*> targets = (*i)->GetGeneratorTargets();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
|
|
|
|
ti != targets.end(); ++ti) {
|
2015-10-23 19:26:45 +03:00
|
|
|
this->ComputeVSTargetDepends(*ti);
|
2010-08-25 02:39:36 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-08-25 02:39:36 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-10 00:44:11 +03:00
|
|
|
static bool VSLinkable(cmGeneratorTarget const* t)
|
2012-03-12 18:47:40 +04:00
|
|
|
{
|
2015-10-08 01:21:51 +03:00
|
|
|
return t->IsLinkable() || t->GetType() == cmState::OBJECT_LIBRARY;
|
2012-03-12 18:47:40 +04:00
|
|
|
}
|
|
|
|
|
2015-10-23 19:26:45 +03:00
|
|
|
void cmGlobalVisualStudioGenerator::ComputeVSTargetDepends(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGeneratorTarget* target)
|
2010-08-25 02:39:36 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->VSTargetDepends.find(target) != this->VSTargetDepends.end()) {
|
2010-08-25 02:39:36 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-10-23 19:26:45 +03:00
|
|
|
VSDependSet& vsTargetDepend = this->VSTargetDepends[target];
|
2010-08-25 18:26:25 +04: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.
|
|
|
|
|
2015-10-23 19:26:45 +03:00
|
|
|
bool allowLinkable = (target->GetType() != cmState::STATIC_LIBRARY &&
|
|
|
|
target->GetType() != cmState::SHARED_LIBRARY &&
|
|
|
|
target->GetType() != cmState::MODULE_LIBRARY &&
|
|
|
|
target->GetType() != cmState::EXECUTABLE);
|
2010-08-25 18:26:25 +04:00
|
|
|
|
2015-10-23 19:26:45 +03:00
|
|
|
TargetDependSet const& depends = this->GetTargetDirectDepends(target);
|
2010-08-25 18:26:25 +04: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.
|
2015-10-23 19:26:48 +03:00
|
|
|
std::set<cmGeneratorTarget const*> linkDepends;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target->GetType() != cmState::STATIC_LIBRARY) {
|
|
|
|
for (TargetDependSet::const_iterator di = depends.begin();
|
|
|
|
di != depends.end(); ++di) {
|
2010-08-25 18:26:25 +04:00
|
|
|
cmTargetDepend dep = *di;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (dep.IsLink()) {
|
2015-10-23 19:26:48 +03:00
|
|
|
this->FollowLinkDepends(*di, linkDepends);
|
2010-08-25 02:39:36 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-08-25 18:26:25 +04:00
|
|
|
|
2012-11-07 20:13:09 +04:00
|
|
|
// Collect explicit util dependencies (add_dependencies).
|
2015-10-23 19:26:48 +03:00
|
|
|
std::set<cmGeneratorTarget const*> utilDepends;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (TargetDependSet::const_iterator di = depends.begin();
|
|
|
|
di != depends.end(); ++di) {
|
2010-08-25 18:26:25 +04:00
|
|
|
cmTargetDepend dep = *di;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (dep.IsUtil()) {
|
2015-10-23 19:26:48 +03:00
|
|
|
this->FollowLinkDepends(*di, utilDepends);
|
2010-08-25 02:39:36 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-08-25 02:39:36 +04:00
|
|
|
|
2010-08-25 18:26:25 +04:00
|
|
|
// Collect all targets linked by this target so we can avoid
|
|
|
|
// intermediate targets below.
|
|
|
|
TargetSet linked;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (target->GetType() != cmState::STATIC_LIBRARY) {
|
2015-10-23 19:26:45 +03:00
|
|
|
linked = this->GetTargetLinkClosure(target);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-08-25 18:26:25 +04:00
|
|
|
|
|
|
|
// Emit link dependencies.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<cmGeneratorTarget const*>::iterator di = linkDepends.begin();
|
|
|
|
di != linkDepends.end(); ++di) {
|
2015-10-23 19:26:48 +03:00
|
|
|
cmGeneratorTarget const* dep = *di;
|
2010-08-25 18:26:25 +04:00
|
|
|
vsTargetDepend.insert(dep->GetName());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-08-25 18:26:25 +04:00
|
|
|
|
|
|
|
// Emit util dependencies. Possibly use intermediate targets.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<cmGeneratorTarget const*>::iterator di = utilDepends.begin();
|
|
|
|
di != utilDepends.end(); ++di) {
|
2015-10-23 19:26:48 +03:00
|
|
|
cmGeneratorTarget const* dgt = *di;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (allowLinkable || !VSLinkable(dgt) || linked.count(dgt)) {
|
2010-08-25 18:26:25 +04:00
|
|
|
// Direct dependency allowed.
|
2015-10-23 19:26:48 +03:00
|
|
|
vsTargetDepend.insert(dgt->GetName());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2010-08-25 18:26:25 +04:00
|
|
|
// Direct dependency on linkable target not allowed.
|
|
|
|
// Use an intermediate utility target.
|
2015-10-23 19:26:46 +03:00
|
|
|
vsTargetDepend.insert(this->GetUtilityDepend(dgt));
|
2007-04-04 22:50:35 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-07-21 17:37:46 +04:00
|
|
|
}
|
|
|
|
|
2013-11-15 19:41:45 +04:00
|
|
|
void cmGlobalVisualStudioGenerator::FindMakeProgram(cmMakefile* mf)
|
|
|
|
{
|
|
|
|
// 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.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM"))) {
|
|
|
|
mf->AddDefinition("CMAKE_MAKE_PROGRAM", this->GetVSMakeProgram().c_str());
|
|
|
|
}
|
2013-11-15 19:41:45 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmGlobalVisualStudioGenerator::GetUtilityDepend(
|
|
|
|
cmGeneratorTarget const* target)
|
2010-08-25 02:47:56 +04:00
|
|
|
{
|
|
|
|
UtilityDependsMap::iterator i = this->UtilityDepends.find(target);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (i == this->UtilityDepends.end()) {
|
2015-10-23 19:26:47 +03:00
|
|
|
std::string name = this->WriteUtilityDepend(target);
|
2010-08-25 02:47:56 +04:00
|
|
|
UtilityDependsMap::value_type entry(target, name);
|
|
|
|
i = this->UtilityDepends.insert(entry).first;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-08-25 02:47:56 +04:00
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmGlobalVisualStudioGenerator::GetStartupProjectName(
|
2016-03-17 23:12:02 +03:00
|
|
|
cmLocalGenerator const* root) const
|
|
|
|
{
|
|
|
|
const char* n = root->GetMakefile()->GetProperty("VS_STARTUP_PROJECT");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (n && *n) {
|
2016-03-17 23:12:02 +03:00
|
|
|
std::string startup = n;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->FindTarget(startup)) {
|
2016-03-17 23:12:02 +03:00
|
|
|
return startup;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2016-03-17 23:12:02 +03:00
|
|
|
root->GetMakefile()->IssueMessage(
|
|
|
|
cmake::AUTHOR_WARNING,
|
|
|
|
"Directory property VS_STARTUP_PROJECT specifies target "
|
2016-05-16 17:34:04 +03:00
|
|
|
"'" +
|
|
|
|
startup + "' that does not exist. Ignoring.");
|
2016-03-17 23:12:02 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-03-17 23:12:02 +03:00
|
|
|
|
|
|
|
// default, if not specified
|
|
|
|
return this->GetAllTargetName();
|
|
|
|
}
|
|
|
|
|
2007-11-16 15:01:58 +03:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& regKeyBase,
|
|
|
|
std::string& nextAvailableSubKeyName)
|
2007-11-16 15:01:58 +03:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
HKEY hkey = NULL;
|
|
|
|
LONG result = ERROR_SUCCESS;
|
|
|
|
DWORD index = 0;
|
|
|
|
|
2008-02-15 19:49:58 +03:00
|
|
|
keyname = regKeyBase + "\\OtherProjects7";
|
2007-11-16 15:01:58 +03:00
|
|
|
hkey = NULL;
|
2016-05-16 17:34:04 +03:00
|
|
|
result =
|
|
|
|
RegOpenKeyExW(HKEY_CURRENT_USER, cmsys::Encoding::ToWide(keyname).c_str(),
|
|
|
|
0, KEY_READ, &hkey);
|
|
|
|
if (ERROR_SUCCESS == result) {
|
2007-11-16 15:01:58 +03:00
|
|
|
// Iterate the subkeys and look for the values of interest in each subkey:
|
2013-12-05 09:17:24 +04:00
|
|
|
wchar_t subkeyname[256];
|
2016-05-16 17:34:04 +03:00
|
|
|
DWORD cch_subkeyname = sizeof(subkeyname) * sizeof(subkeyname[0]);
|
2013-12-05 09:17:24 +04:00
|
|
|
wchar_t keyclass[256];
|
2016-05-16 17:34:04 +03:00
|
|
|
DWORD cch_keyclass = sizeof(keyclass) * sizeof(keyclass[0]);
|
2007-11-16 15:01:58 +03:00
|
|
|
FILETIME lastWriteTime;
|
|
|
|
lastWriteTime.dwHighDateTime = 0;
|
|
|
|
lastWriteTime.dwLowDateTime = 0;
|
|
|
|
|
2013-12-05 09:17:24 +04:00
|
|
|
while (ERROR_SUCCESS == RegEnumKeyExW(hkey, index, subkeyname,
|
2016-05-16 17:34:04 +03:00
|
|
|
&cch_subkeyname, 0, keyclass,
|
|
|
|
&cch_keyclass, &lastWriteTime)) {
|
2007-11-16 15:01:58 +03:00
|
|
|
// Open the subkey and query the values of interest:
|
|
|
|
HKEY hsubkey = NULL;
|
2013-12-05 09:17:24 +04:00
|
|
|
result = RegOpenKeyExW(hkey, subkeyname, 0, KEY_READ, &hsubkey);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (ERROR_SUCCESS == result) {
|
2007-11-16 15:01:58 +03:00
|
|
|
DWORD valueType = REG_SZ;
|
2013-12-05 09:17:24 +04:00
|
|
|
wchar_t data1[256];
|
2016-05-16 17:34:04 +03:00
|
|
|
DWORD cch_data1 = sizeof(data1) * sizeof(data1[0]);
|
|
|
|
RegQueryValueExW(hsubkey, L"Path", 0, &valueType, (LPBYTE)&data1[0],
|
|
|
|
&cch_data1);
|
2007-11-16 15:01:58 +03:00
|
|
|
|
|
|
|
DWORD data2 = 0;
|
|
|
|
DWORD cch_data2 = sizeof(data2);
|
2016-05-16 17:34:04 +03:00
|
|
|
RegQueryValueExW(hsubkey, L"Security", 0, &valueType, (LPBYTE)&data2,
|
|
|
|
&cch_data2);
|
2007-11-16 15:01:58 +03:00
|
|
|
|
|
|
|
DWORD data3 = 0;
|
|
|
|
DWORD cch_data3 = sizeof(data3);
|
2013-12-05 09:17:24 +04:00
|
|
|
RegQueryValueExW(hsubkey, L"StorageFormat", 0, &valueType,
|
2016-05-16 17:34:04 +03:00
|
|
|
(LPBYTE)&data3, &cch_data3);
|
2007-11-16 15:01:58 +03:00
|
|
|
|
2013-12-05 09:17:24 +04:00
|
|
|
s2 = cmSystemTools::LowerCase(cmsys::Encoding::ToNarrow(data1));
|
2007-11-16 15:01:58 +03:00
|
|
|
cmSystemTools::ConvertToUnixSlashes(s2);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (s2 == s1) {
|
2007-11-16 15:01:58 +03:00
|
|
|
macrosRegistered = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03:00
|
|
|
|
2013-12-05 09:17:24 +04:00
|
|
|
std::string fullname = cmsys::Encoding::ToNarrow(data1);
|
2007-11-16 15:01:58 +03:00
|
|
|
std::string filename;
|
|
|
|
std::string filepath;
|
|
|
|
std::string filepathname;
|
|
|
|
std::string filepathpath;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileExists(fullname.c_str())) {
|
2007-11-16 15:01:58 +03:00
|
|
|
filename = cmSystemTools::GetFilenameName(fullname);
|
|
|
|
filepath = cmSystemTools::GetFilenamePath(fullname);
|
|
|
|
filepathname = cmSystemTools::GetFilenameName(filepath);
|
|
|
|
filepathpath = cmSystemTools::GetFilenamePath(filepath);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03:00
|
|
|
|
2016-05-16 17:34:04 +03: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;
|
2007-11-16 15:01:58 +03:00
|
|
|
|
|
|
|
RegCloseKey(hsubkey);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2007-11-16 15:01:58 +03:00
|
|
|
std::cout << "error opening subkey: " << subkeyname << std::endl;
|
|
|
|
std::cout << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03:00
|
|
|
|
|
|
|
++index;
|
2016-05-16 17:34:04 +03:00
|
|
|
cch_subkeyname = sizeof(subkeyname) * sizeof(subkeyname[0]);
|
|
|
|
cch_keyclass = sizeof(keyclass) * sizeof(keyclass[0]);
|
2007-11-16 15:01:58 +03:00
|
|
|
lastWriteTime.dwHighDateTime = 0;
|
|
|
|
lastWriteTime.dwLowDateTime = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03:00
|
|
|
|
|
|
|
RegCloseKey(hkey);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2007-11-16 15:01:58 +03:00
|
|
|
std::cout << "error opening key: " << keyname << std::endl;
|
|
|
|
std::cout << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03: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.
|
|
|
|
std::ostringstream ossNext;
|
|
|
|
ossNext << index;
|
|
|
|
nextAvailableSubKeyName = ossNext.str();
|
|
|
|
|
2008-02-15 19:49:58 +03:00
|
|
|
keyname = regKeyBase + "\\RecordingProject7";
|
2007-11-16 15:01:58 +03:00
|
|
|
hkey = NULL;
|
2016-05-16 17:34:04 +03:00
|
|
|
result =
|
|
|
|
RegOpenKeyExW(HKEY_CURRENT_USER, cmsys::Encoding::ToWide(keyname).c_str(),
|
|
|
|
0, KEY_READ, &hkey);
|
|
|
|
if (ERROR_SUCCESS == result) {
|
2007-11-16 15:01:58 +03:00
|
|
|
DWORD valueType = REG_SZ;
|
2013-12-05 09:17:24 +04:00
|
|
|
wchar_t data1[256];
|
2016-05-16 17:34:04 +03:00
|
|
|
DWORD cch_data1 = sizeof(data1) * sizeof(data1[0]);
|
|
|
|
RegQueryValueExW(hkey, L"Path", 0, &valueType, (LPBYTE)&data1[0],
|
|
|
|
&cch_data1);
|
2007-11-16 15:01:58 +03:00
|
|
|
|
|
|
|
DWORD data2 = 0;
|
|
|
|
DWORD cch_data2 = sizeof(data2);
|
2016-05-16 17:34:04 +03:00
|
|
|
RegQueryValueExW(hkey, L"Security", 0, &valueType, (LPBYTE)&data2,
|
|
|
|
&cch_data2);
|
2007-11-16 15:01:58 +03:00
|
|
|
|
|
|
|
DWORD data3 = 0;
|
|
|
|
DWORD cch_data3 = sizeof(data3);
|
2016-05-16 17:34:04 +03:00
|
|
|
RegQueryValueExW(hkey, L"StorageFormat", 0, &valueType, (LPBYTE)&data3,
|
|
|
|
&cch_data3);
|
2007-11-16 15:01:58 +03:00
|
|
|
|
2013-12-05 09:17:24 +04:00
|
|
|
s2 = cmSystemTools::LowerCase(cmsys::Encoding::ToNarrow(data1));
|
2007-11-16 15:01:58 +03:00
|
|
|
cmSystemTools::ConvertToUnixSlashes(s2);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (s2 == s1) {
|
2007-11-16 15:01:58 +03:00
|
|
|
macrosRegistered = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03:00
|
|
|
|
2016-05-16 17:34:04 +03: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;
|
2007-11-16 15:01:58 +03:00
|
|
|
|
|
|
|
RegCloseKey(hkey);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2007-11-16 15:01:58 +03:00
|
|
|
std::cout << "error opening key: " << keyname << std::endl;
|
|
|
|
std::cout << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03:00
|
|
|
|
|
|
|
return macrosRegistered;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void WriteVSMacrosFileRegistryEntry(const std::string& nextAvailableSubKeyName,
|
|
|
|
const std::string& macrosFile,
|
|
|
|
const std::string& regKeyBase)
|
2007-11-16 15:01:58 +03:00
|
|
|
{
|
2008-02-15 19:49:58 +03:00
|
|
|
std::string keyname = regKeyBase + "\\OtherProjects7";
|
2007-11-16 15:01:58 +03:00
|
|
|
HKEY hkey = NULL;
|
2016-05-16 17:34:04 +03:00
|
|
|
LONG result =
|
|
|
|
RegOpenKeyExW(HKEY_CURRENT_USER, cmsys::Encoding::ToWide(keyname).c_str(),
|
|
|
|
0, KEY_READ | KEY_WRITE, &hkey);
|
|
|
|
if (ERROR_SUCCESS == result) {
|
2007-11-16 15:01:58 +03:00
|
|
|
// Create the subkey and set the values of interest:
|
|
|
|
HKEY hsubkey = NULL;
|
2013-12-05 09:17:24 +04:00
|
|
|
wchar_t lpClass[] = L"";
|
2016-05-16 17:34:04 +03:00
|
|
|
result = RegCreateKeyExW(
|
|
|
|
hkey, cmsys::Encoding::ToWide(nextAvailableSubKeyName).c_str(), 0,
|
|
|
|
lpClass, 0, KEY_READ | KEY_WRITE, 0, &hsubkey, 0);
|
|
|
|
if (ERROR_SUCCESS == result) {
|
2007-11-16 15:01:58 +03:00
|
|
|
DWORD dw = 0;
|
|
|
|
|
|
|
|
std::string s(macrosFile);
|
|
|
|
cmSystemTools::ReplaceString(s, "/", "\\");
|
2013-12-05 09:17:24 +04:00
|
|
|
std::wstring ws = cmsys::Encoding::ToWide(s);
|
2007-11-16 15:01:58 +03:00
|
|
|
|
2016-05-16 17:34:04 +03: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) {
|
2007-11-16 15:01:58 +03:00
|
|
|
std::cout << "error result 1: " << result << std::endl;
|
|
|
|
std::cout << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03: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-05-16 17:34:04 +03:00
|
|
|
result = RegSetValueExW(hsubkey, L"Security", 0, REG_DWORD, (LPBYTE)&dw,
|
|
|
|
sizeof(DWORD));
|
|
|
|
if (ERROR_SUCCESS != result) {
|
2007-11-16 15:01:58 +03:00
|
|
|
std::cout << "error result 2: " << result << std::endl;
|
|
|
|
std::cout << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03:00
|
|
|
|
|
|
|
// StorageFormat value is always "0" for sample macros files
|
|
|
|
dw = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
result = RegSetValueExW(hsubkey, L"StorageFormat", 0, REG_DWORD,
|
|
|
|
(LPBYTE)&dw, sizeof(DWORD));
|
|
|
|
if (ERROR_SUCCESS != result) {
|
2007-11-16 15:01:58 +03:00
|
|
|
std::cout << "error result 3: " << result << std::endl;
|
|
|
|
std::cout << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03:00
|
|
|
|
|
|
|
RegCloseKey(hsubkey);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
std::cout << "error creating subkey: " << nextAvailableSubKeyName
|
|
|
|
<< std::endl;
|
2007-11-16 15:01:58 +03:00
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
RegCloseKey(hkey);
|
|
|
|
} else {
|
2007-11-16 15:01:58 +03:00
|
|
|
std::cout << "error opening key: " << keyname << std::endl;
|
|
|
|
std::cout << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03:00
|
|
|
}
|
|
|
|
|
2008-02-15 19:49:58 +03:00
|
|
|
void RegisterVisualStudioMacros(const std::string& macrosFile,
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& regKeyBase)
|
2007-11-16 15:01:58 +03:00
|
|
|
{
|
|
|
|
bool macrosRegistered;
|
|
|
|
std::string nextAvailableSubKeyName;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
macrosRegistered = IsVisualStudioMacrosFileRegistered(
|
|
|
|
macrosFile, regKeyBase, nextAvailableSubKeyName);
|
2007-11-16 15:01:58 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!macrosRegistered) {
|
|
|
|
int count =
|
|
|
|
cmCallVisualStudioMacro::GetNumberOfRunningVisualStudioInstances("ALL");
|
2007-11-16 15:01:58 +03:00
|
|
|
|
|
|
|
// 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,
|
2007-11-16 21:54:21 +03:00
|
|
|
// emit a warning asking the user to exit all running Visual Studio
|
|
|
|
// instances...
|
2007-11-16 15:01:58 +03:00
|
|
|
//
|
2016-05-16 17:34:04 +03:00
|
|
|
if (0 != count) {
|
2007-11-16 15:01:58 +03:00
|
|
|
std::ostringstream oss;
|
2007-11-16 21:54:21 +03:00
|
|
|
oss << "Could not register CMake's Visual Studio macros file '"
|
2016-05-16 17:34:04 +03: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;
|
2007-11-16 15:01:58 +03:00
|
|
|
cmSystemTools::Message(oss.str().c_str(), "Warning");
|
2007-11-16 21:54:21 +03:00
|
|
|
|
|
|
|
// 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-05-16 17:34:04 +03:00
|
|
|
count = cmCallVisualStudioMacro::GetNumberOfRunningVisualStudioInstances(
|
|
|
|
"ALL");
|
2007-11-16 21:54:21 +03:00
|
|
|
|
|
|
|
// Also re-get the nextAvailableSubKeyName in case Visual Studio
|
|
|
|
// wrote out new registered macros information as it was exiting:
|
|
|
|
//
|
2016-05-16 17:34:04 +03:00
|
|
|
if (0 == count) {
|
2008-02-15 19:49:58 +03:00
|
|
|
IsVisualStudioMacrosFileRegistered(macrosFile, regKeyBase,
|
2016-05-16 17:34:04 +03:00
|
|
|
nextAvailableSubKeyName);
|
2007-11-16 21:54:21 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 21:54:21 +03:00
|
|
|
|
|
|
|
// Do another if check - 'count' may have changed inside the above if:
|
|
|
|
//
|
2016-05-16 17:34:04 +03:00
|
|
|
if (0 == count) {
|
2008-02-15 19:49:58 +03:00
|
|
|
WriteVSMacrosFileRegistryEntry(nextAvailableSubKeyName, macrosFile,
|
2016-05-16 17:34:04 +03:00
|
|
|
regKeyBase);
|
2007-11-16 15:01:58 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-11-16 15:01:58 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmGlobalVisualStudioGenerator::TargetIsFortranOnly(
|
|
|
|
cmGeneratorTarget const* gt)
|
2008-04-30 21:26:04 +04:00
|
|
|
{
|
|
|
|
// check to see if this is a fortran build
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> languages;
|
2014-02-13 20:25:00 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
// Issue diagnostic if the source files depend on the config.
|
|
|
|
std::vector<cmSourceFile*> sources;
|
|
|
|
if (!gt->GetConfigCommonSourceFiles(sources)) {
|
|
|
|
return false;
|
2014-02-13 20:25:00 +04:00
|
|
|
}
|
|
|
|
}
|
2015-08-05 18:37:50 +03:00
|
|
|
gt->GetLanguages(languages, "");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (languages.size() == 1) {
|
|
|
|
if (*languages.begin() == "Fortran") {
|
2008-04-30 21:26:04 +04:00
|
|
|
return true;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-04-30 21:26:04 +04:00
|
|
|
return false;
|
|
|
|
}
|
2009-10-01 00:02:58 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmGlobalVisualStudioGenerator::TargetCompare::operator()(
|
|
|
|
cmGeneratorTarget const* l, cmGeneratorTarget const* r) const
|
2009-10-01 00:02:58 +04:00
|
|
|
{
|
2015-09-22 17:14:49 +03: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-05-16 17:34:04 +03:00
|
|
|
if (r->GetName() == this->First) {
|
2009-10-01 00:02:58 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (l->GetName() == this->First) {
|
2009-10-01 00:02:58 +04:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-22 17:14:49 +03:00
|
|
|
return l->GetName() < r->GetName();
|
2009-10-01 00:02:58 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGlobalVisualStudioGenerator::OrderedTargetDependSet::OrderedTargetDependSet(
|
|
|
|
TargetDependSet const& targets, std::string const& first)
|
|
|
|
: derived(TargetCompare(first))
|
2009-10-01 00:02:58 +04:00
|
|
|
{
|
2014-11-25 18:33:00 +03:00
|
|
|
this->insert(targets.begin(), targets.end());
|
2009-10-01 00:02:58 +04:00
|
|
|
}
|
2010-08-25 18:26:25 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGlobalVisualStudioGenerator::OrderedTargetDependSet::OrderedTargetDependSet(
|
|
|
|
TargetSet const& targets, std::string const& first)
|
|
|
|
: derived(TargetCompare(first))
|
2010-08-25 18:26:25 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
for (TargetSet::const_iterator it = targets.begin(); it != targets.end();
|
|
|
|
++it) {
|
2015-10-23 19:26:48 +03:00
|
|
|
this->insert(*it);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-08-25 18:26:25 +04:00
|
|
|
}
|
2014-02-02 08:18:04 +04:00
|
|
|
|
|
|
|
std::string cmGlobalVisualStudioGenerator::ExpandCFGIntDir(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& str, const std::string& config) const
|
2014-02-02 08:18:04 +04:00
|
|
|
{
|
|
|
|
std::string replace = GetCMakeCFGIntDir();
|
|
|
|
|
|
|
|
std::string tmp = str;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::string::size_type i = tmp.find(replace); i != std::string::npos;
|
|
|
|
i = tmp.find(replace, i)) {
|
2014-02-02 08:18:04 +04:00
|
|
|
tmp.replace(i, replace.size(), config);
|
|
|
|
i += config.size();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-02-02 08:18:04 +04:00
|
|
|
return tmp;
|
|
|
|
}
|
2015-06-19 23:12:43 +03:00
|
|
|
|
|
|
|
void cmGlobalVisualStudioGenerator::AddSymbolExportCommand(
|
|
|
|
cmGeneratorTarget* gt, std::vector<cmCustomCommand>& commands,
|
|
|
|
std::string const& configName)
|
|
|
|
{
|
|
|
|
std::vector<std::string> outputs;
|
|
|
|
std::string deffile = gt->ObjectDirectory;
|
|
|
|
deffile += "/exportall.def";
|
|
|
|
outputs.push_back(deffile);
|
|
|
|
std::vector<std::string> empty;
|
|
|
|
std::vector<cmSourceFile const*> objectSources;
|
|
|
|
gt->GetObjectSources(objectSources, configName);
|
|
|
|
std::map<cmSourceFile const*, std::string> mapping;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<cmSourceFile const*>::const_iterator it =
|
|
|
|
objectSources.begin();
|
|
|
|
it != objectSources.end(); ++it) {
|
2015-06-19 23:12:43 +03:00
|
|
|
mapping[*it];
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
gt->LocalGenerator->ComputeObjectFilenames(mapping, gt);
|
2015-06-19 23:12:43 +03:00
|
|
|
std::string obj_dir = gt->ObjectDirectory;
|
|
|
|
std::string cmakeCommand = cmSystemTools::GetCMakeCommand();
|
|
|
|
cmSystemTools::ConvertToWindowsExtendedPath(cmakeCommand);
|
|
|
|
cmCustomCommandLine cmdl;
|
|
|
|
cmdl.push_back(cmakeCommand);
|
|
|
|
cmdl.push_back("-E");
|
|
|
|
cmdl.push_back("__create_def");
|
|
|
|
cmdl.push_back(deffile);
|
|
|
|
std::string obj_dir_expanded = obj_dir;
|
2016-05-16 17:34:04 +03:00
|
|
|
cmSystemTools::ReplaceString(obj_dir_expanded, this->GetCMakeCFGIntDir(),
|
2015-06-19 23:12:43 +03:00
|
|
|
configName.c_str());
|
|
|
|
std::string objs_file = obj_dir_expanded;
|
|
|
|
cmSystemTools::MakeDirectory(objs_file.c_str());
|
|
|
|
objs_file += "/objects.txt";
|
|
|
|
cmdl.push_back(objs_file);
|
|
|
|
cmGeneratedFileStream fout(objs_file.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!fout) {
|
2015-06-19 23:12:43 +03:00
|
|
|
cmSystemTools::Error("could not open ", objs_file.c_str());
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
for (std::vector<cmSourceFile const*>::const_iterator it =
|
|
|
|
objectSources.begin();
|
|
|
|
it != objectSources.end(); ++it) {
|
2015-06-19 23:12:43 +03:00
|
|
|
// Find the object file name corresponding to this source file.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::map<cmSourceFile const*, std::string>::const_iterator map_it =
|
|
|
|
mapping.find(*it);
|
2015-06-19 23:12:43 +03:00
|
|
|
// It must exist because we populated the mapping just above.
|
|
|
|
assert(!map_it->second.empty());
|
|
|
|
std::string objFile = obj_dir + map_it->second;
|
|
|
|
// replace $(ConfigurationName) in the object names
|
|
|
|
cmSystemTools::ReplaceString(objFile, this->GetCMakeCFGIntDir(),
|
|
|
|
configName.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmHasLiteralSuffix(objFile, ".obj")) {
|
2015-06-19 23:12:43 +03:00
|
|
|
fout << objFile << "\n";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-06-19 23:12:43 +03:00
|
|
|
cmCustomCommandLines commandLines;
|
|
|
|
commandLines.push_back(cmdl);
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCustomCommand command(gt->Target->GetMakefile(), outputs, empty, empty,
|
|
|
|
commandLines, "Auto build dll exports", ".");
|
2015-06-19 23:12:43 +03:00
|
|
|
commands.push_back(command);
|
|
|
|
}
|