cmUnixMakefileGenerator.cxx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2001 Insight Consortium
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. * Redistributions of source code must retain the above copyright notice,
  12. this list of conditions and the following disclaimer.
  13. * Redistributions in binary form must reproduce the above copyright notice,
  14. this list of conditions and the following disclaimer in the documentation
  15. and/or other materials provided with the distribution.
  16. * The name of the Insight Consortium, nor the names of any consortium members,
  17. nor of any contributors, may be used to endorse or promote products derived
  18. from this software without specific prior written permission.
  19. * Modified source versions must be plainly marked as such, and must not be
  20. misrepresented as being the original software.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
  25. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. =========================================================================*/
  32. #include "cmUnixMakefileGenerator.h"
  33. #include "cmMakefile.h"
  34. #include "cmStandardIncludes.h"
  35. #include "cmSystemTools.h"
  36. #include "cmSourceFile.h"
  37. #include "cmMakeDepend.h"
  38. #include "cmCacheManager.h"
  39. cmUnixMakefileGenerator::cmUnixMakefileGenerator()
  40. {
  41. m_CacheOnly = false;
  42. m_Recurse = false;
  43. }
  44. void cmUnixMakefileGenerator::GenerateMakefile()
  45. {
  46. if(m_CacheOnly)
  47. {
  48. // Generate the cache only stuff
  49. this->GenerateCacheOnly();
  50. // if recurse then generate for all sub- makefiles
  51. if(m_Recurse)
  52. {
  53. this->RecursiveGenerateCacheOnly();
  54. }
  55. }
  56. // normal makefile output
  57. else
  58. {
  59. // Generate depends
  60. cmMakeDepend md;
  61. md.SetMakefile(m_Makefile);
  62. md.DoDepends();
  63. // output the makefile fragment
  64. this->OutputMakefile("CMakeTargets.make");
  65. }
  66. }
  67. // This is where CMakeTargets.make is generated
  68. void cmUnixMakefileGenerator::OutputMakefile(const char* file)
  69. {
  70. // Create sub directories fro aux source directories
  71. std::vector<std::string>& auxSourceDirs =
  72. m_Makefile->GetAuxSourceDirectories();
  73. if( auxSourceDirs.size() )
  74. {
  75. // For the case when this is running as a remote build
  76. // on unix, make the directory
  77. for(std::vector<std::string>::iterator i = auxSourceDirs.begin();
  78. i != auxSourceDirs.end(); ++i)
  79. {
  80. cmSystemTools::MakeDirectory(i->c_str());
  81. }
  82. }
  83. std::ofstream fout(file);
  84. if(!fout)
  85. {
  86. cmSystemTools::Error("Error can not open for write: ", file);
  87. return;
  88. }
  89. this->OutputMakeFlags(fout);
  90. this->OutputVerbatim(fout);
  91. this->OutputTargetRules(fout);
  92. this->OutputDependencies(fout);
  93. this->OutputTargets(fout);
  94. this->OutputSubDirectoryRules(fout);
  95. this->OutputObjectDepends(fout);
  96. this->OutputCustomRules(fout);
  97. }
  98. // Output the rules for any targets
  99. void cmUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
  100. {
  101. // for each target add to the list of targets
  102. fout << "TARGETS = ";
  103. const cmTargets &tgts = m_Makefile->GetTargets();
  104. // list libraries first
  105. for(cmTargets::const_iterator l = tgts.begin();
  106. l != tgts.end(); l++)
  107. {
  108. if (l->second.GetType() == cmTarget::LIBRARY &&
  109. l->second.IsInAll())
  110. {
  111. fout << " \\\nlib" << l->first.c_str() << "${CMAKE_LIB_EXT}";
  112. }
  113. }
  114. // executables
  115. for(cmTargets::const_iterator l = tgts.begin();
  116. l != tgts.end(); l++)
  117. {
  118. if (l->second.GetType() == cmTarget::EXECUTABLE &&
  119. l->second.IsInAll())
  120. {
  121. fout << " \\\n" << l->first.c_str();
  122. }
  123. }
  124. // list utilities last
  125. for(cmTargets::const_iterator l = tgts.begin();
  126. l != tgts.end(); l++)
  127. {
  128. if (l->second.GetType() == cmTarget::UTILITY &&
  129. l->second.IsInAll())
  130. {
  131. fout << " \\\n" << l->first.c_str();
  132. }
  133. }
  134. fout << "\n\n";
  135. // get the classes from the source lists then add them to the groups
  136. for(cmTargets::const_iterator l = tgts.begin();
  137. l != tgts.end(); l++)
  138. {
  139. std::vector<cmSourceFile> classes = l->second.GetSourceFiles();
  140. fout << l->first << "_SRC_OBJS = ";
  141. for(std::vector<cmSourceFile>::iterator i = classes.begin();
  142. i != classes.end(); i++)
  143. {
  144. if(!i->IsAHeaderFileOnly())
  145. {
  146. fout << "\\\n" << i->GetSourceName() << ".o ";
  147. }
  148. }
  149. fout << "\n\n";
  150. }
  151. }
  152. /**
  153. * Output the linking rules on a command line. For executables,
  154. * targetLibrary should be a NULL pointer. For libraries, it should point
  155. * to the name of the library. This will not link a library against itself.
  156. */
  157. void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
  158. const char* targetLibrary,
  159. const cmTarget &tgt)
  160. {
  161. // collect all the flags needed for linking libraries
  162. std::string linkLibs;
  163. std::vector<std::string>::iterator j;
  164. std::vector<std::string>& libdirs = m_Makefile->GetLinkDirectories();
  165. for(j = libdirs.begin(); j != libdirs.end(); ++j)
  166. {
  167. std::string::size_type pos = (*j).find("-L");
  168. if((pos == std::string::npos || pos > 0)
  169. && (*j).find("${") == std::string::npos)
  170. {
  171. linkLibs += "-L";
  172. }
  173. linkLibs += *j;
  174. linkLibs += " ";
  175. }
  176. std::string librariesLinked;
  177. const cmTarget::LinkLibraries& libs = tgt.GetLinkLibraries();
  178. cmTarget::LinkLibraries::const_iterator j2;
  179. for(j2 = libs.begin(); j2 != libs.end(); ++j2)
  180. {
  181. // Don't link the library against itself!
  182. if(targetLibrary && (j2->first == targetLibrary)) continue;
  183. // don't look at debug libraries
  184. if (j2->second == cmTarget::DEBUG) continue;
  185. std::string::size_type pos = j2->first.find("-l");
  186. if((pos == std::string::npos || pos > 0)
  187. && j2->first.find("${") == std::string::npos)
  188. {
  189. librariesLinked += "-l";
  190. }
  191. librariesLinked += j2->first;
  192. librariesLinked += " ";
  193. }
  194. linkLibs += librariesLinked;
  195. if(!targetLibrary)
  196. {
  197. // For executables, add these a second time so order does not matter
  198. linkLibs += librariesLinked;
  199. }
  200. linkLibs += " ${LOCAL_LINK_FLAGS} ";
  201. fout << linkLibs;
  202. }
  203. void cmUnixMakefileGenerator::OutputTargets(std::ostream& fout)
  204. {
  205. // for each target
  206. const cmTargets &tgts = m_Makefile->GetTargets();
  207. for(cmTargets::const_iterator l = tgts.begin();
  208. l != tgts.end(); l++)
  209. {
  210. if (l->second.GetType() == cmTarget::LIBRARY)
  211. {
  212. fout << "#---------------------------------------------------------\n";
  213. fout << "# rules for a library\n";
  214. fout << "#\n";
  215. fout << "lib" << l->first << ".a: ${KIT_OBJ} ${" <<
  216. l->first << "_SRC_OBJS} \n";
  217. fout << "\t${AR} cr lib" << l->first << ".a ${KIT_OBJ} ${" <<
  218. l->first << "_SRC_OBJS} \n";
  219. fout << "\t${RANLIB} lib" << l->first << ".a\n";
  220. fout << std::endl;
  221. fout << "lib" << l->first << "$(SHLIB_SUFFIX): ${KIT_OBJ} ${" <<
  222. l->first << "_SRC_OBJS} \n";
  223. fout << "\trm -f lib" << l->first << "$(SHLIB_SUFFIX)\n";
  224. fout << "\t$(CXX) ${CXX_FLAGS} ${CMAKE_SHLIB_BUILD_FLAGS} -o \\\n";
  225. fout << "\t lib" << l->first << "$(SHLIB_SUFFIX) \\\n";
  226. fout << "\t ${KIT_OBJ} ${" << l->first <<
  227. "_SRC_OBJS} ";
  228. this->OutputLinkLibraries(fout, l->first.c_str(), l->second);
  229. fout << "\n\n";
  230. }
  231. else if (l->second.GetType() == cmTarget::EXECUTABLE)
  232. {
  233. fout << l->first << ": ${" <<
  234. l->first << "_SRC_OBJS} ${CMAKE_DEPEND_LIBS}\n";
  235. fout << "\t${CXX} ${CXX_FLAGS} ${" <<
  236. l->first << "_SRC_OBJS} ";
  237. this->OutputLinkLibraries(fout, NULL,l->second);
  238. fout << " -o " << l->first << "\n\n";
  239. }
  240. }
  241. }
  242. // output the list of libraries that the executables
  243. // in this makefile will depend on.
  244. void cmUnixMakefileGenerator::OutputDependencies(std::ostream& fout)
  245. {
  246. fout << "CMAKE_DEPEND_LIBS = ";
  247. cmTarget::LinkLibraries& libs = m_Makefile->GetLinkLibraries();
  248. cmTarget::LinkLibraries::const_iterator lib2;
  249. // Search the list of libraries that will be linked into
  250. // the executable
  251. for(lib2 = libs.begin(); lib2 != libs.end(); ++lib2)
  252. {
  253. // loop over the list of directories that the libraries might
  254. // be in, looking for an ADD_LIBRARY(lib...) line. This would
  255. // be stored in the cache
  256. const char* cacheValue
  257. = cmCacheManager::GetInstance()->GetCacheValue(lib2->first.c_str());
  258. if(cacheValue)
  259. {
  260. std::string libpath = cacheValue;
  261. libpath += "/lib";
  262. libpath += lib2->first;
  263. libpath += "${CMAKE_LIB_EXT}";
  264. fout << libpath << " ";
  265. }
  266. }
  267. std::vector<std::string>& utils = m_Makefile->GetUtilities();
  268. std::vector<std::string>& utildirs = m_Makefile->GetUtilityDirectories();
  269. std::vector<std::string>::iterator dir, util;
  270. // Search the list of utilities that may be used to generate code for
  271. // this project.
  272. for(util = utils.begin(); util != utils.end(); ++util)
  273. {
  274. bool found = false;
  275. // loop over the list of directories that the utilities might
  276. // be in, looking for an ADD_EXECUTABLE(util ...) line.
  277. for(dir = utildirs.begin(); dir != utildirs.end() && !found; ++dir)
  278. {
  279. std::string expression = "TARGETS =.*";
  280. expression += util->c_str();
  281. if(cmSystemTools::Grep(dir->c_str(), "CMakeTargets.make",
  282. expression.c_str()))
  283. {
  284. fout << *util << " ";
  285. found = true;
  286. }
  287. }
  288. }
  289. fout << "\n";
  290. }
  291. // output make include flags
  292. void cmUnixMakefileGenerator::OutputMakeFlags(std::ostream& fout)
  293. {
  294. // Output Include paths
  295. fout << "INCLUDE_FLAGS = ";
  296. std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
  297. std::vector<std::string>::iterator i;
  298. fout << "-I" << m_Makefile->GetStartDirectory() << " ";
  299. for(i = includes.begin(); i != includes.end(); ++i)
  300. {
  301. std::string include = *i;
  302. fout << "-I" << i->c_str() << " ";
  303. }
  304. fout << m_Makefile->GetDefineFlags();
  305. fout << " ${LOCAL_INCLUDE_FLAGS} ";
  306. fout << "\n\n";
  307. fout << "default_target: all\n\n";
  308. // see if there are files to compile in this makefile
  309. // These are used for both libraries and executables
  310. }
  311. // output verbatim section
  312. void cmUnixMakefileGenerator::OutputVerbatim(std::ostream& fout)
  313. {
  314. std::vector<std::string>& MakeVerbatim = m_Makefile->GetMakeVerbatim();
  315. // Ouput user make text embeded in the input file
  316. for(unsigned int i =0; i < MakeVerbatim.size(); i++)
  317. {
  318. fout << MakeVerbatim[i] << "\n";
  319. }
  320. fout << "\n\n";
  321. }
  322. // fix up names of directories so they can be used
  323. // as targets in makefiles.
  324. inline std::string FixDirectoryName(const char* dir)
  325. {
  326. std::string s = dir;
  327. // replace ../ with 3 under bars
  328. size_t pos = s.find("../");
  329. if(pos != std::string::npos)
  330. {
  331. s.replace(pos, 3, "___");
  332. }
  333. // replace / directory separators with a single under bar
  334. pos = s.find("/");
  335. while(pos != std::string::npos)
  336. {
  337. s.replace(pos, 1, "_");
  338. pos = s.find("/");
  339. }
  340. return s;
  341. }
  342. // output rules for decending into sub directories
  343. void cmUnixMakefileGenerator::OutputSubDirectoryRules(std::ostream& fout)
  344. {
  345. // Output Sub directory build rules
  346. const std::vector<std::string>& SubDirectories
  347. = m_Makefile->GetSubDirectories();
  348. if( SubDirectories.size() == 0)
  349. {
  350. return;
  351. }
  352. fout << "SUBDIR_BUILD = \\\n";
  353. unsigned int i;
  354. for(i =0; i < SubDirectories.size(); i++)
  355. {
  356. std::string subdir = FixDirectoryName(SubDirectories[i].c_str());
  357. fout << "build_" << subdir.c_str();
  358. if(i == SubDirectories.size()-1)
  359. {
  360. fout << " \n\n";
  361. }
  362. else
  363. {
  364. fout << " \\\n";
  365. }
  366. }
  367. fout << std::endl;
  368. fout << "SUBDIR_CLEAN = \\\n";
  369. for(i =0; i < SubDirectories.size(); i++)
  370. {
  371. std::string subdir = FixDirectoryName(SubDirectories[i].c_str());
  372. fout << "clean_" << subdir.c_str();
  373. if(i == SubDirectories.size()-1)
  374. {
  375. fout << " \n\n";
  376. }
  377. else
  378. {
  379. fout << " \\\n";
  380. }
  381. }
  382. fout << std::endl;
  383. fout << "alldirs : ${SUBDIR_BUILD}\n\n";
  384. for(i =0; i < SubDirectories.size(); i++)
  385. {
  386. std::string subdir = FixDirectoryName(SubDirectories[i].c_str());
  387. fout << "build_" << subdir.c_str() << ":\n";
  388. fout << "\tcd " << SubDirectories[i].c_str()
  389. << "; ${MAKE} -${MAKEFLAGS} CMakeTargets.make\n";
  390. fout << "\tcd " << SubDirectories[i].c_str()
  391. << "; ${MAKE} -${MAKEFLAGS} all\n\n";
  392. fout << "clean_" << subdir.c_str() << ": \n";
  393. fout << "\tcd " << SubDirectories[i].c_str()
  394. << "; ${MAKE} -${MAKEFLAGS} clean\n\n";
  395. }
  396. }
  397. // Output the depend information for all the classes
  398. // in the makefile. These would have been generated
  399. // by the class cmMakeDepend GenerateMakefile
  400. void cmUnixMakefileGenerator::OutputObjectDepends(std::ostream& fout)
  401. {
  402. // Iterate over every target.
  403. std::map<std::string, cmTarget>& targets = m_Makefile->GetTargets();
  404. for(std::map<std::string, cmTarget>::const_iterator target = targets.begin();
  405. target != targets.end(); ++target)
  406. {
  407. // Iterate over every source for this target.
  408. const std::vector<cmSourceFile>& sources = target->second.GetSourceFiles();
  409. for(std::vector<cmSourceFile>::const_iterator source = sources.begin();
  410. source != sources.end(); ++source)
  411. {
  412. if(!source->IsAHeaderFileOnly())
  413. {
  414. if(!source->GetDepends().empty())
  415. {
  416. fout << source->GetSourceName() << ".o :";
  417. // Iterate through all the dependencies for this source.
  418. for(std::vector<std::string>::const_iterator dep =
  419. source->GetDepends().begin();
  420. dep != source->GetDepends().end(); ++dep)
  421. {
  422. fout << " \\\n" << dep->c_str();
  423. }
  424. fout << "\n\n";
  425. }
  426. }
  427. }
  428. }
  429. }
  430. // Output each custom rule in the following format:
  431. // output: source depends...
  432. // (tab) command...
  433. void cmUnixMakefileGenerator::OutputCustomRules(std::ostream& fout)
  434. {
  435. // We may be modifying the source groups temporarily, so make a copy.
  436. std::vector<cmSourceGroup> sourceGroups = m_Makefile->GetSourceGroups();
  437. const cmTargets &tgts = m_Makefile->GetTargets();
  438. for(cmTargets::const_iterator tgt = tgts.begin();
  439. tgt != tgts.end(); ++tgt)
  440. {
  441. // add any custom rules to the source groups
  442. for (std::vector<cmCustomCommand>::const_iterator cr =
  443. tgt->second.GetCustomCommands().begin();
  444. cr != tgt->second.GetCustomCommands().end(); ++cr)
  445. {
  446. cmSourceGroup& sourceGroup =
  447. m_Makefile->FindSourceGroup(cr->GetSourceName().c_str(),
  448. sourceGroups);
  449. cmCustomCommand cc(*cr);
  450. cc.ExpandVariables(*m_Makefile);
  451. sourceGroup.AddCustomCommand(cc);
  452. }
  453. }
  454. // Loop through every source group.
  455. for(std::vector<cmSourceGroup>::const_iterator sg =
  456. sourceGroups.begin(); sg != sourceGroups.end(); ++sg)
  457. {
  458. const cmSourceGroup::BuildRules& buildRules = sg->GetBuildRules();
  459. if(buildRules.empty())
  460. { continue; }
  461. std::string name = sg->GetName();
  462. if(name != "")
  463. {
  464. fout << "# Start of source group \"" << name.c_str() << "\"\n";
  465. }
  466. // Loop through each source in the source group.
  467. for(cmSourceGroup::BuildRules::const_iterator cc =
  468. buildRules.begin(); cc != buildRules.end(); ++ cc)
  469. {
  470. std::string source = cc->first;
  471. const cmSourceGroup::Commands& commands = cc->second;
  472. // Loop through every command generating code from the current source.
  473. for(cmSourceGroup::Commands::const_iterator c = commands.begin();
  474. c != commands.end(); ++c)
  475. {
  476. std::string command = c->first;
  477. const cmSourceGroup::CommandFiles& commandFiles = c->second;
  478. // if the command has no outputs, then it is a utility command
  479. // with no outputs
  480. if(commandFiles.m_Outputs.size() == 0)
  481. {
  482. fout << source.c_str() << ": ";
  483. // Write out all the dependencies for this rule.
  484. for(std::set<std::string>::const_iterator d =
  485. commandFiles.m_Depends.begin();
  486. d != commandFiles.m_Depends.end(); ++d)
  487. {
  488. std::string dep = cmSystemTools::EscapeSpaces(d->c_str());
  489. fout << " " << dep.c_str();
  490. }
  491. fout << "\n\t" << command.c_str() << "\n\n";
  492. }
  493. // Write a rule for every output generated by this command.
  494. for(std::set<std::string>::const_iterator output =
  495. commandFiles.m_Outputs.begin();
  496. output != commandFiles.m_Outputs.end(); ++output)
  497. {
  498. std::string src = cmSystemTools::EscapeSpaces(source.c_str());
  499. fout << output->c_str() << ": " << src.c_str();
  500. // Write out all the dependencies for this rule.
  501. for(std::set<std::string>::const_iterator d =
  502. commandFiles.m_Depends.begin();
  503. d != commandFiles.m_Depends.end(); ++d)
  504. {
  505. std::string dep = cmSystemTools::EscapeSpaces(d->c_str());
  506. fout << " " << dep.c_str();
  507. }
  508. fout << "\n\t" << command.c_str() << "\n\n";
  509. }
  510. }
  511. }
  512. if(name != "")
  513. {
  514. fout << "# End of source group \"" << name.c_str() << "\"\n\n";
  515. }
  516. }
  517. }
  518. void cmUnixMakefileGenerator::GenerateCacheOnly()
  519. {
  520. std::string source = m_Makefile->GetHomeDirectory();
  521. source += "/CMake/CMakeMakefileTemplate.in";
  522. cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory());
  523. std::string dest = m_Makefile->GetStartOutputDirectory();
  524. dest += "/Makefile";
  525. std::ofstream fout(dest.c_str());
  526. std::cout << "cmake: creating : " << dest.c_str() << "\n";
  527. if(!fout)
  528. {
  529. cmSystemTools::Error("Failed to open file for write " , dest.c_str());
  530. }
  531. else
  532. {
  533. if(strcmp(m_Makefile->GetHomeDirectory(),
  534. m_Makefile->GetHomeOutputDirectory()) == 0)
  535. {
  536. fout << "srcdir = .\n\n";
  537. }
  538. else
  539. {
  540. fout << "srcdir = " << m_Makefile->GetStartDirectory() << "\n";
  541. fout << "VPATH = " << m_Makefile->GetStartDirectory() << "\n";
  542. }
  543. }
  544. fout << "include "
  545. << m_Makefile->GetHomeOutputDirectory() << "/CMake/CMakeMaster.make\n";
  546. dest = m_Makefile->GetStartOutputDirectory();
  547. dest += "/CMakeTargets.make";
  548. // make sure there is a CMakeTargets.make file as some
  549. // makes require it to exist
  550. if(!cmSystemTools::FileExists(dest.c_str()))
  551. {
  552. std::cout << "cmake: creating : " << dest.c_str() << "\n";
  553. std::ofstream fout(dest.c_str());
  554. if(!fout)
  555. {
  556. cmSystemTools::Error("Failed to open file for write " , dest.c_str());
  557. }
  558. fout << "#Initial CMakeTargets.make file created only to keep \n";
  559. fout << "#certain makes happy that don't like to include makefiles\n";
  560. fout << "#that do not exist\n";
  561. }
  562. }
  563. void cmUnixMakefileGenerator::RecursiveGenerateCacheOnly()
  564. {
  565. std::vector<cmMakefile*> makefiles;
  566. m_Makefile->FindSubDirectoryCMakeListsFiles(makefiles);
  567. for(std::vector<cmMakefile*>::iterator i = makefiles.begin();
  568. i != makefiles.end(); ++i)
  569. {
  570. cmMakefile* mf = *i;
  571. if(m_Makefile->GetDefinition("RUN_CONFIGURE"))
  572. {
  573. mf->AddDefinition("RUN_CONFIGURE", true);
  574. }
  575. cmUnixMakefileGenerator* gen = new cmUnixMakefileGenerator;
  576. gen->SetCacheOnlyOn();
  577. gen->SetRecurseOff();
  578. mf->SetMakefileGenerator(gen);
  579. mf->GenerateMakefile();
  580. }
  581. // CLEAN up the makefiles created
  582. for(unsigned int i =0; i < makefiles.size(); ++i)
  583. {
  584. delete makefiles[i];
  585. }
  586. }