810
824
cmLocalNinjaGenerator *ng =
811
825
static_cast<cmLocalNinjaGenerator *>(this->LocalGenerators[0]);
827
// for frameworks, we want the real name, not smple name
828
// frameworks always appear versioned, and the build.ninja
829
// will always attempt to manage symbolic links instead
830
// of letting cmOSXBundleGenerator do it.
831
bool realname = target->IsFrameworkOnApple();
813
833
switch (target->GetType()) {
814
834
case cmTarget::EXECUTABLE:
815
835
case cmTarget::SHARED_LIBRARY:
816
836
case cmTarget::STATIC_LIBRARY:
817
837
case cmTarget::MODULE_LIBRARY:
818
838
outputs.push_back(ng->ConvertToNinjaPath(
819
target->GetFullPath(configName).c_str()));
839
target->GetFullPath(configName, false, realname).c_str()));
822
842
case cmTarget::OBJECT_LIBRARY:
894
914
cmNinjaDeps deps;
895
915
this->AppendTargetOutputs(i->second, deps);
897
cmGlobalNinjaGenerator::WritePhonyBuild(os,
899
cmNinjaDeps(1, i->first),
917
this->WritePhonyBuild(os,
919
cmNinjaDeps(1, i->first),
924
void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
926
//now write out the unknown explicit dependencies.
928
//union the configured files, evaluations files and the CombinedBuildOutputs,
929
//and then difference with CombinedExplicitDependencies to find the explicit
930
//dependencies that we have no rule for
932
cmGlobalNinjaGenerator::WriteDivider(os);
933
os << "# Unknown Build Time Dependencies.\n"
934
<< "# Tell Ninja that they may appear as side effects of build rules\n"
935
<< "# otherwise ordered by order-only dependencies.\n\n";
937
//get the list of files that cmake itself has generated as a
938
//product of configuration.
939
cmLocalNinjaGenerator *ng =
940
static_cast<cmLocalNinjaGenerator *>(this->LocalGenerators[0]);
942
std::set<std::string> knownDependencies;
943
for (std::vector<cmLocalGenerator *>::const_iterator i =
944
this->LocalGenerators.begin(); i != this->LocalGenerators.end(); ++i)
946
//get the vector of files created by this makefile and convert them
947
//to ninja paths, which are all relative in respect to the build directory
948
const std::vector<std::string>& files =
949
(*i)->GetMakefile()->GetOutputFiles();
950
typedef std::vector<std::string>::const_iterator vect_it;
951
for(vect_it j = files.begin(); j != files.end(); ++j)
953
knownDependencies.insert( ng->ConvertToNinjaPath( j->c_str() ) );
957
for(std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator
958
li = this->EvaluationFiles.begin();
959
li != this->EvaluationFiles.end();
962
//get all the files created by generator expressions and convert them
964
std::vector<std::string> files = (*li)->GetFiles();
965
typedef std::vector<std::string>::const_iterator vect_it;
966
for(vect_it j = files.begin(); j != files.end(); ++j)
968
knownDependencies.insert( ng->ConvertToNinjaPath( j->c_str() ) );
972
for(TargetAliasMap::const_iterator i= this->TargetAliases.begin();
973
i != this->TargetAliases.end();
976
knownDependencies.insert( ng->ConvertToNinjaPath(i->first.c_str()) );
979
//remove all source files we know will exist.
980
typedef std::map<std::string, std::set<std::string> >::const_iterator map_it;
981
for(map_it i = this->AssumedSourceDependencies.begin();
982
i != this->AssumedSourceDependencies.end();
985
knownDependencies.insert( ng->ConvertToNinjaPath(i->first.c_str()) );
988
//insert outputs from all WirteBuild commands
989
for(std::set<std::string>::iterator i = this->CombinedBuildOutputs.begin();
990
i != this->CombinedBuildOutputs.end(); ++i)
992
//these paths have already be encoded when added to CombinedBuildOutputs
993
knownDependencies.insert(*i);
996
//after we have combined the data into knownDependencies we have no need
997
//to keep this data around
998
this->CombinedBuildOutputs.clear();
1000
//now we difference with CombinedBuildExplicitDependencies to find
1001
//the list of items we know nothing about.
1002
//We have encoded all the paths in CombinedBuildExplicitDependencies
1003
//and knownDependencies so no matter if unix or windows paths they
1004
//should all match now.
1006
std::vector<std::string> unkownExplicitDepends;
1007
this->CombinedBuildExplicitDependencies.erase("all");
1009
std::set_difference(this->CombinedBuildExplicitDependencies.begin(),
1010
this->CombinedBuildExplicitDependencies.end(),
1011
knownDependencies.begin(),
1012
knownDependencies.end(),
1013
std::back_inserter(unkownExplicitDepends));
1016
std::string const rootBuildDirectory =
1017
this->GetCMakeInstance()->GetHomeOutputDirectory();
1018
for (std::vector<std::string>::const_iterator
1019
i = unkownExplicitDepends.begin();
1020
i != unkownExplicitDepends.end();
1023
//verify the file is in the build directory
1024
std::string const absDepPath = cmSystemTools::CollapseFullPath(
1025
i->c_str(), rootBuildDirectory.c_str());
1026
bool const inBuildDir = cmSystemTools::IsSubDirectory(absDepPath.c_str(),
1027
rootBuildDirectory.c_str());
1030
cmNinjaDeps deps(1,*i);
1031
this->WritePhonyBuild(os,
904
1039
void cmGlobalNinjaGenerator::WriteBuiltinTargets(std::ostream& os)
906
1041
// Write headers.
959
1094
this->LocalGenerators.begin(); i != this->LocalGenerators.end(); ++i) {
960
1095
const std::vector<std::string>& lf = (*i)->GetMakefile()->GetListFiles();
961
1096
implicitDeps.insert(implicitDeps.end(), lf.begin(), lf.end());
1098
const std::vector<std::string>& of = (*i)->GetMakefile()->GetOutputFiles();
1099
implicitDeps.insert(implicitDeps.end(), of.begin(), of.end());
963
1101
std::sort(implicitDeps.begin(), implicitDeps.end());
964
1102
implicitDeps.erase(std::unique(implicitDeps.begin(), implicitDeps.end()),
965
1103
implicitDeps.end());
966
1104
implicitDeps.push_back("CMakeCache.txt");
969
"Re-run CMake if any of its inputs changed.",
971
/*outputs=*/ cmNinjaDeps(1, NINJA_BUILD_FILE),
972
/*explicitDeps=*/ cmNinjaDeps(),
974
/*orderOnlyDeps=*/ cmNinjaDeps(),
975
/*variables=*/ cmNinjaVars());
1106
this->WriteBuild(os,
1107
"Re-run CMake if any of its inputs changed.",
1109
/*outputs=*/ cmNinjaDeps(1, NINJA_BUILD_FILE),
1110
/*explicitDeps=*/ cmNinjaDeps(),
1112
/*orderOnlyDeps=*/ cmNinjaDeps(),
1113
/*variables=*/ cmNinjaVars());
978
"A missing CMake input file is not an error.",
1115
this->WritePhonyBuild(os,
1116
"A missing CMake input file is not an error.",
983
1121
std::string cmGlobalNinjaGenerator::ninjaCmd() const