cmUnixMakefileGenerator.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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.GetType() == cmTarget::WIN32_EXECUTABLE) &&
  120. l->second.IsInAll())
  121. {
  122. fout << " \\\n" << l->first.c_str();
  123. }
  124. }
  125. // list utilities last
  126. for(cmTargets::const_iterator l = tgts.begin();
  127. l != tgts.end(); l++)
  128. {
  129. if (l->second.GetType() == cmTarget::UTILITY &&
  130. l->second.IsInAll())
  131. {
  132. fout << " \\\n" << l->first.c_str();
  133. }
  134. }
  135. fout << "\n\n";
  136. // get the classes from the source lists then add them to the groups
  137. for(cmTargets::const_iterator l = tgts.begin();
  138. l != tgts.end(); l++)
  139. {
  140. std::vector<cmSourceFile> classes = l->second.GetSourceFiles();
  141. fout << l->first << "_SRC_OBJS = ";
  142. for(std::vector<cmSourceFile>::iterator i = classes.begin();
  143. i != classes.end(); i++)
  144. {
  145. if(!i->IsAHeaderFileOnly())
  146. {
  147. fout << "\\\n" << i->GetSourceName() << ".o ";
  148. }
  149. }
  150. fout << "\n\n";
  151. }
  152. }
  153. /**
  154. * Output the linking rules on a command line. For executables,
  155. * targetLibrary should be a NULL pointer. For libraries, it should point
  156. * to the name of the library. This will not link a library against itself.
  157. */
  158. void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
  159. const char* targetLibrary,
  160. const cmTarget &tgt)
  161. {
  162. // collect all the flags needed for linking libraries
  163. std::string linkLibs;
  164. std::vector<std::string>& libdirs = m_Makefile->GetLinkDirectories();
  165. for(std::vector<std::string>::iterator libDir = libdirs.begin();
  166. libDir != libdirs.end(); ++libDir)
  167. {
  168. std::string::size_type pos = libDir->find("-L");
  169. if((pos == std::string::npos || pos > 0)
  170. && libDir->find("${") == std::string::npos)
  171. {
  172. linkLibs += "-L";
  173. }
  174. linkLibs += cmSystemTools::EscapeSpaces(libDir->c_str());
  175. linkLibs += " ";
  176. }
  177. std::string librariesLinked;
  178. const cmTarget::LinkLibraries& libs = tgt.GetLinkLibraries();
  179. for(cmTarget::LinkLibraries::const_iterator lib = libs.begin();
  180. lib != libs.end(); ++lib)
  181. {
  182. // Don't link the library against itself!
  183. if(targetLibrary && (lib->first == targetLibrary)) continue;
  184. // don't look at debug libraries
  185. if (lib->second == cmTarget::DEBUG) continue;
  186. if(lib->first.find('/') != std::string::npos)
  187. {
  188. std::string dir, file;
  189. cmSystemTools::SplitProgramPath(lib->first.c_str(),
  190. dir, file);
  191. linkLibs += "-L";
  192. linkLibs += cmSystemTools::EscapeSpaces(dir.c_str());
  193. linkLibs += " ";
  194. librariesLinked += "-l";
  195. librariesLinked += file;
  196. librariesLinked += " ";
  197. }
  198. else
  199. {
  200. std::string::size_type pos = lib->first.find("-l");
  201. if((pos == std::string::npos || pos > 0)
  202. && lib->first.find("${") == std::string::npos)
  203. {
  204. librariesLinked += "-l";
  205. }
  206. librariesLinked += lib->first;
  207. librariesLinked += " ";
  208. }
  209. }
  210. linkLibs += librariesLinked;
  211. if(!targetLibrary)
  212. {
  213. // For executables, add these a second time so order does not matter
  214. linkLibs += librariesLinked;
  215. }
  216. linkLibs += " ${LOCAL_LINK_FLAGS} ";
  217. fout << linkLibs;
  218. }
  219. void cmUnixMakefileGenerator::OutputTargets(std::ostream& fout)
  220. {
  221. // for each target
  222. const cmTargets &tgts = m_Makefile->GetTargets();
  223. for(cmTargets::const_iterator l = tgts.begin();
  224. l != tgts.end(); l++)
  225. {
  226. if (l->second.GetType() == cmTarget::LIBRARY)
  227. {
  228. fout << "#---------------------------------------------------------\n";
  229. fout << "# rules for a library\n";
  230. fout << "#\n";
  231. fout << "lib" << l->first << ".a: ${KIT_OBJ} ${" <<
  232. l->first << "_SRC_OBJS} \n";
  233. fout << "\t${AR} cr lib" << l->first << ".a ${KIT_OBJ} ${" <<
  234. l->first << "_SRC_OBJS} \n";
  235. fout << "\t${RANLIB} lib" << l->first << ".a\n";
  236. fout << std::endl;
  237. fout << "lib" << l->first << "$(SHLIB_SUFFIX): ${KIT_OBJ} ${" <<
  238. l->first << "_SRC_OBJS} \n";
  239. fout << "\trm -f lib" << l->first << "$(SHLIB_SUFFIX)\n";
  240. fout << "\t$(CXX) ${CXX_FLAGS} ${CMAKE_SHLIB_BUILD_FLAGS} -o \\\n";
  241. fout << "\t lib" << l->first << "$(SHLIB_SUFFIX) \\\n";
  242. fout << "\t ${KIT_OBJ} ${" << l->first <<
  243. "_SRC_OBJS} ";
  244. this->OutputLinkLibraries(fout, l->first.c_str(), l->second);
  245. fout << "\n\n";
  246. }
  247. else if (l->second.GetType() == cmTarget::EXECUTABLE)
  248. {
  249. fout << l->first << ": ${" <<
  250. l->first << "_SRC_OBJS} ${CMAKE_DEPEND_LIBS}\n";
  251. fout << "\t${CXX} ${CXX_FLAGS} ${" <<
  252. l->first << "_SRC_OBJS} ";
  253. this->OutputLinkLibraries(fout, NULL,l->second);
  254. fout << " -o " << l->first << "\n\n";
  255. }
  256. }
  257. }
  258. // output the list of libraries that the executables
  259. // in this makefile will depend on.
  260. void cmUnixMakefileGenerator::OutputDependencies(std::ostream& fout)
  261. {
  262. fout << "CMAKE_DEPEND_LIBS = ";
  263. cmTarget::LinkLibraries& libs = m_Makefile->GetLinkLibraries();
  264. cmTarget::LinkLibraries::const_iterator lib2;
  265. // Search the list of libraries that will be linked into
  266. // the executable
  267. for(lib2 = libs.begin(); lib2 != libs.end(); ++lib2)
  268. {
  269. // loop over the list of directories that the libraries might
  270. // be in, looking for an ADD_LIBRARY(lib...) line. This would
  271. // be stored in the cache
  272. const char* cacheValue
  273. = cmCacheManager::GetInstance()->GetCacheValue(lib2->first.c_str());
  274. if(cacheValue)
  275. {
  276. std::string libpath = cacheValue;
  277. libpath += "/lib";
  278. libpath += lib2->first;
  279. libpath += "${CMAKE_LIB_EXT}";
  280. fout << libpath << " ";
  281. }
  282. }
  283. std::vector<std::string>& utils = m_Makefile->GetUtilities();
  284. std::vector<std::string>& utildirs = m_Makefile->GetUtilityDirectories();
  285. std::vector<std::string>::iterator dir, util;
  286. // Search the list of utilities that may be used to generate code for
  287. // this project.
  288. for(util = utils.begin(); util != utils.end(); ++util)
  289. {
  290. bool found = false;
  291. // loop over the list of directories that the utilities might
  292. // be in, looking for an ADD_EXECUTABLE(util ...) line.
  293. for(dir = utildirs.begin(); dir != utildirs.end() && !found; ++dir)
  294. {
  295. std::string expression = "TARGETS =.*";
  296. expression += util->c_str();
  297. if(cmSystemTools::Grep(dir->c_str(), "CMakeTargets.make",
  298. expression.c_str()))
  299. {
  300. fout << *util << " ";
  301. found = true;
  302. }
  303. }
  304. }
  305. fout << "\n";
  306. }
  307. // output make include flags
  308. void cmUnixMakefileGenerator::OutputMakeFlags(std::ostream& fout)
  309. {
  310. // Output Include paths
  311. fout << "INCLUDE_FLAGS = ";
  312. std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
  313. std::vector<std::string>::iterator i;
  314. fout << "-I" << m_Makefile->GetStartDirectory() << " ";
  315. for(i = includes.begin(); i != includes.end(); ++i)
  316. {
  317. std::string include = *i;
  318. fout << "-I" << cmSystemTools::EscapeSpaces(i->c_str()).c_str() << " ";
  319. }
  320. fout << m_Makefile->GetDefineFlags();
  321. fout << " ${LOCAL_INCLUDE_FLAGS} ";
  322. fout << "\n\n";
  323. fout << "default_target: all\n\n";
  324. // see if there are files to compile in this makefile
  325. // These are used for both libraries and executables
  326. }
  327. // output verbatim section
  328. void cmUnixMakefileGenerator::OutputVerbatim(std::ostream& fout)
  329. {
  330. std::vector<std::string>& MakeVerbatim = m_Makefile->GetMakeVerbatim();
  331. // Ouput user make text embeded in the input file
  332. for(unsigned int i =0; i < MakeVerbatim.size(); i++)
  333. {
  334. fout << MakeVerbatim[i] << "\n";
  335. }
  336. fout << "\n\n";
  337. }
  338. // fix up names of directories so they can be used
  339. // as targets in makefiles.
  340. inline std::string FixDirectoryName(const char* dir)
  341. {
  342. std::string s = dir;
  343. // replace ../ with 3 under bars
  344. size_t pos = s.find("../");
  345. if(pos != std::string::npos)
  346. {
  347. s.replace(pos, 3, "___");
  348. }
  349. // replace / directory separators with a single under bar
  350. pos = s.find("/");
  351. while(pos != std::string::npos)
  352. {
  353. s.replace(pos, 1, "_");
  354. pos = s.find("/");
  355. }
  356. return s;
  357. }
  358. // output rules for decending into sub directories
  359. void cmUnixMakefileGenerator::OutputSubDirectoryRules(std::ostream& fout)
  360. {
  361. // Output Sub directory build rules
  362. const std::vector<std::string>& SubDirectories
  363. = m_Makefile->GetSubDirectories();
  364. if( SubDirectories.size() == 0)
  365. {
  366. return;
  367. }
  368. fout << "SUBDIR_BUILD = \\\n";
  369. unsigned int i;
  370. for(i =0; i < SubDirectories.size(); i++)
  371. {
  372. std::string subdir = FixDirectoryName(SubDirectories[i].c_str());
  373. fout << "build_" << subdir.c_str();
  374. if(i == SubDirectories.size()-1)
  375. {
  376. fout << " \n\n";
  377. }
  378. else
  379. {
  380. fout << " \\\n";
  381. }
  382. }
  383. fout << std::endl;
  384. fout << "SUBDIR_CLEAN = \\\n";
  385. for(i =0; i < SubDirectories.size(); i++)
  386. {
  387. std::string subdir = FixDirectoryName(SubDirectories[i].c_str());
  388. fout << "clean_" << subdir.c_str();
  389. if(i == SubDirectories.size()-1)
  390. {
  391. fout << " \n\n";
  392. }
  393. else
  394. {
  395. fout << " \\\n";
  396. }
  397. }
  398. fout << std::endl;
  399. fout << "alldirs : ${SUBDIR_BUILD}\n\n";
  400. for(i =0; i < SubDirectories.size(); i++)
  401. {
  402. std::string subdir = FixDirectoryName(SubDirectories[i].c_str());
  403. fout << "build_" << subdir.c_str() << ":\n";
  404. fout << "\tcd " << SubDirectories[i].c_str()
  405. << "; ${MAKE} -${MAKEFLAGS} CMakeTargets.make\n";
  406. fout << "\tcd " << SubDirectories[i].c_str()
  407. << "; ${MAKE} -${MAKEFLAGS} all\n\n";
  408. fout << "clean_" << subdir.c_str() << ": \n";
  409. fout << "\tcd " << SubDirectories[i].c_str()
  410. << "; ${MAKE} -${MAKEFLAGS} clean\n\n";
  411. }
  412. }
  413. // Output the depend information for all the classes
  414. // in the makefile. These would have been generated
  415. // by the class cmMakeDepend GenerateMakefile
  416. void cmUnixMakefileGenerator::OutputObjectDepends(std::ostream& fout)
  417. {
  418. // Iterate over every target.
  419. std::map<std::string, cmTarget>& targets = m_Makefile->GetTargets();
  420. for(std::map<std::string, cmTarget>::const_iterator target = targets.begin();
  421. target != targets.end(); ++target)
  422. {
  423. // Iterate over every source for this target.
  424. const std::vector<cmSourceFile>& sources = target->second.GetSourceFiles();
  425. for(std::vector<cmSourceFile>::const_iterator source = sources.begin();
  426. source != sources.end(); ++source)
  427. {
  428. if(!source->IsAHeaderFileOnly())
  429. {
  430. if(!source->GetDepends().empty())
  431. {
  432. fout << source->GetSourceName() << ".o :";
  433. // Iterate through all the dependencies for this source.
  434. for(std::vector<std::string>::const_iterator dep =
  435. source->GetDepends().begin();
  436. dep != source->GetDepends().end(); ++dep)
  437. {
  438. fout << " \\\n" << dep->c_str();
  439. }
  440. fout << "\n\n";
  441. }
  442. }
  443. }
  444. }
  445. }
  446. // Output each custom rule in the following format:
  447. // output: source depends...
  448. // (tab) command...
  449. void cmUnixMakefileGenerator::OutputCustomRules(std::ostream& fout)
  450. {
  451. // We may be modifying the source groups temporarily, so make a copy.
  452. std::vector<cmSourceGroup> sourceGroups = m_Makefile->GetSourceGroups();
  453. const cmTargets &tgts = m_Makefile->GetTargets();
  454. for(cmTargets::const_iterator tgt = tgts.begin();
  455. tgt != tgts.end(); ++tgt)
  456. {
  457. // add any custom rules to the source groups
  458. for (std::vector<cmCustomCommand>::const_iterator cr =
  459. tgt->second.GetCustomCommands().begin();
  460. cr != tgt->second.GetCustomCommands().end(); ++cr)
  461. {
  462. cmSourceGroup& sourceGroup =
  463. m_Makefile->FindSourceGroup(cr->GetSourceName().c_str(),
  464. sourceGroups);
  465. cmCustomCommand cc(*cr);
  466. cc.ExpandVariables(*m_Makefile);
  467. sourceGroup.AddCustomCommand(cc);
  468. }
  469. }
  470. // Loop through every source group.
  471. for(std::vector<cmSourceGroup>::const_iterator sg =
  472. sourceGroups.begin(); sg != sourceGroups.end(); ++sg)
  473. {
  474. const cmSourceGroup::BuildRules& buildRules = sg->GetBuildRules();
  475. if(buildRules.empty())
  476. { continue; }
  477. std::string name = sg->GetName();
  478. if(name != "")
  479. {
  480. fout << "# Start of source group \"" << name.c_str() << "\"\n";
  481. }
  482. // Loop through each source in the source group.
  483. for(cmSourceGroup::BuildRules::const_iterator cc =
  484. buildRules.begin(); cc != buildRules.end(); ++ cc)
  485. {
  486. std::string source = cc->first;
  487. const cmSourceGroup::Commands& commands = cc->second;
  488. // Loop through every command generating code from the current source.
  489. for(cmSourceGroup::Commands::const_iterator c = commands.begin();
  490. c != commands.end(); ++c)
  491. {
  492. std::string command = c->first;
  493. const cmSourceGroup::CommandFiles& commandFiles = c->second;
  494. // if the command has no outputs, then it is a utility command
  495. // with no outputs
  496. if(commandFiles.m_Outputs.size() == 0)
  497. {
  498. fout << source.c_str() << ": ";
  499. // Write out all the dependencies for this rule.
  500. for(std::set<std::string>::const_iterator d =
  501. commandFiles.m_Depends.begin();
  502. d != commandFiles.m_Depends.end(); ++d)
  503. {
  504. std::string dep = cmSystemTools::EscapeSpaces(d->c_str());
  505. fout << " " << dep.c_str();
  506. }
  507. fout << "\n\t" << command.c_str() << "\n\n";
  508. }
  509. // Write a rule for every output generated by this command.
  510. for(std::set<std::string>::const_iterator output =
  511. commandFiles.m_Outputs.begin();
  512. output != commandFiles.m_Outputs.end(); ++output)
  513. {
  514. std::string src = cmSystemTools::EscapeSpaces(source.c_str());
  515. fout << output->c_str() << ": " << src.c_str();
  516. // Write out all the dependencies for this rule.
  517. for(std::set<std::string>::const_iterator d =
  518. commandFiles.m_Depends.begin();
  519. d != commandFiles.m_Depends.end(); ++d)
  520. {
  521. std::string dep = cmSystemTools::EscapeSpaces(d->c_str());
  522. fout << " " << dep.c_str();
  523. }
  524. fout << "\n\t" << command.c_str() << "\n\n";
  525. }
  526. }
  527. }
  528. if(name != "")
  529. {
  530. fout << "# End of source group \"" << name.c_str() << "\"\n\n";
  531. }
  532. }
  533. }
  534. void cmUnixMakefileGenerator::GenerateCacheOnly()
  535. {
  536. std::string source = m_Makefile->GetHomeDirectory();
  537. source += "/CMake/CMakeMakefileTemplate.in";
  538. cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory());
  539. std::string dest = m_Makefile->GetStartOutputDirectory();
  540. dest += "/Makefile";
  541. std::ofstream fout(dest.c_str());
  542. std::cout << "cmake: creating : " << dest.c_str() << "\n";
  543. if(!fout)
  544. {
  545. cmSystemTools::Error("Failed to open file for write " , dest.c_str());
  546. }
  547. else
  548. {
  549. if(strcmp(m_Makefile->GetHomeDirectory(),
  550. m_Makefile->GetHomeOutputDirectory()) == 0)
  551. {
  552. fout << "srcdir = .\n\n";
  553. }
  554. else
  555. {
  556. fout << "srcdir = " << m_Makefile->GetStartDirectory() << "\n";
  557. fout << "VPATH = " << m_Makefile->GetStartDirectory() << "\n";
  558. }
  559. }
  560. fout << "include "
  561. << m_Makefile->GetHomeOutputDirectory() << "/CMake/CMakeMaster.make\n";
  562. dest = m_Makefile->GetStartOutputDirectory();
  563. dest += "/CMakeTargets.make";
  564. // make sure there is a CMakeTargets.make file as some
  565. // makes require it to exist
  566. if(!cmSystemTools::FileExists(dest.c_str()))
  567. {
  568. std::cout << "cmake: creating : " << dest.c_str() << "\n";
  569. std::ofstream fout(dest.c_str());
  570. if(!fout)
  571. {
  572. cmSystemTools::Error("Failed to open file for write " , dest.c_str());
  573. }
  574. fout << "#Initial CMakeTargets.make file created only to keep \n";
  575. fout << "#certain makes happy that don't like to include makefiles\n";
  576. fout << "#that do not exist\n";
  577. }
  578. }
  579. void cmUnixMakefileGenerator::RecursiveGenerateCacheOnly()
  580. {
  581. std::vector<cmMakefile*> makefiles;
  582. m_Makefile->FindSubDirectoryCMakeListsFiles(makefiles);
  583. for(std::vector<cmMakefile*>::iterator i = makefiles.begin();
  584. i != makefiles.end(); ++i)
  585. {
  586. cmMakefile* mf = *i;
  587. if(m_Makefile->GetDefinition("RUN_CONFIGURE"))
  588. {
  589. mf->AddDefinition("RUN_CONFIGURE", true);
  590. }
  591. cmUnixMakefileGenerator* gen = new cmUnixMakefileGenerator;
  592. gen->SetCacheOnlyOn();
  593. gen->SetRecurseOff();
  594. mf->SetMakefileGenerator(gen);
  595. mf->GenerateMakefile();
  596. }
  597. // CLEAN up the makefiles created
  598. for(unsigned int i =0; i < makefiles.size(); ++i)
  599. {
  600. delete makefiles[i];
  601. }
  602. }