cmUnixMakefileGenerator.cxx 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  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. #include "cmGeneratedFileStream.h"
  40. cmUnixMakefileGenerator::cmUnixMakefileGenerator()
  41. {
  42. m_CacheOnly = false;
  43. m_Recurse = false;
  44. }
  45. void cmUnixMakefileGenerator::GenerateMakefile()
  46. {
  47. // suppoirt override in output directories
  48. if (m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
  49. {
  50. m_LibraryOutputPath = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  51. if(m_LibraryOutputPath.size() &&
  52. m_LibraryOutputPath[m_LibraryOutputPath.size() -1] != '/')
  53. {
  54. m_LibraryOutputPath += "/";
  55. }
  56. cmSystemTools::MakeDirectory(m_LibraryOutputPath.c_str());
  57. m_Makefile->GetLinkDirectories().push_back(m_LibraryOutputPath);
  58. }
  59. if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
  60. {
  61. m_ExecutableOutputPath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
  62. if(m_ExecutableOutputPath.size() &&
  63. m_ExecutableOutputPath[m_ExecutableOutputPath.size() -1] != '/')
  64. {
  65. m_ExecutableOutputPath += "/";
  66. }
  67. cmSystemTools::MakeDirectory(m_ExecutableOutputPath.c_str());
  68. m_Makefile->GetLinkDirectories().push_back(m_ExecutableOutputPath);
  69. }
  70. if(m_CacheOnly)
  71. {
  72. // Generate the cache only stuff
  73. this->GenerateCacheOnly();
  74. // if recurse then generate for all sub- makefiles
  75. if(m_Recurse)
  76. {
  77. this->RecursiveGenerateCacheOnly();
  78. }
  79. }
  80. // normal makefile output
  81. else
  82. {
  83. // Generate depends
  84. cmMakeDepend md;
  85. md.SetMakefile(m_Makefile);
  86. md.GenerateDependInformation();
  87. this->ProcessDepends(md);
  88. // output the makefile fragment
  89. this->OutputMakefile("Makefile");
  90. }
  91. }
  92. void cmUnixMakefileGenerator::ProcessDepends(const cmMakeDepend &md)
  93. {
  94. // Now create cmDependInformation objects for files in the directory
  95. cmTargets &tgts = m_Makefile->GetTargets();
  96. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
  97. {
  98. std::vector<cmSourceFile> &classes = l->second.GetSourceFiles();
  99. for(std::vector<cmSourceFile>::iterator i = classes.begin();
  100. i != classes.end(); ++i)
  101. {
  102. if(!i->GetIsAHeaderFileOnly())
  103. {
  104. // get the depends
  105. const cmDependInformation *info =
  106. md.GetDependInformationForSourceFile(*i);
  107. // Delete any hints from the source file's dependencies.
  108. i->GetDepends().erase(i->GetDepends().begin(), i->GetDepends().end());
  109. // Now add the real dependencies for the file.
  110. if (info)
  111. {
  112. for( cmDependInformation::IndexSet::const_iterator indx =
  113. info->m_IndexSet.begin();
  114. indx != info->m_IndexSet.end(); ++indx)
  115. {
  116. // Make sure the full path is given. If not, the dependency was
  117. // not found.
  118. if(md.GetDependInformation()[*indx]->m_FullPath != "")
  119. {
  120. i->GetDepends().push_back(md.GetDependInformation()[*indx]->m_FullPath);
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }
  128. // This is where CMakeTargets.make is generated
  129. void cmUnixMakefileGenerator::OutputMakefile(const char* file)
  130. {
  131. // Create sub directories fro aux source directories
  132. std::vector<std::string>& auxSourceDirs =
  133. m_Makefile->GetAuxSourceDirectories();
  134. if( auxSourceDirs.size() )
  135. {
  136. // For the case when this is running as a remote build
  137. // on unix, make the directory
  138. for(std::vector<std::string>::iterator i = auxSourceDirs.begin();
  139. i != auxSourceDirs.end(); ++i)
  140. {
  141. if(i->c_str()[0] != '/')
  142. {
  143. std::string dir = m_Makefile->GetCurrentOutputDirectory();
  144. if(dir.size() && dir[dir.size()-1] != '/')
  145. {
  146. dir += "/";
  147. }
  148. dir += *i;
  149. cmSystemTools::MakeDirectory(dir.c_str());
  150. }
  151. else
  152. {
  153. cmSystemTools::MakeDirectory(i->c_str());
  154. }
  155. }
  156. }
  157. // Create a stream that writes to a temporary file
  158. // then does a copy at the end. This is to allow users
  159. // to hit control-c during the make of the makefile
  160. cmGeneratedFileStream tempFile(file);
  161. tempFile.SetAlwaysCopy(true);
  162. std::ostream& fout = tempFile.GetStream();
  163. if(!fout)
  164. {
  165. cmSystemTools::Error("Error can not open for write: ", file);
  166. return;
  167. }
  168. fout << "# CMAKE generated Makefile, DO NOT EDIT!\n"
  169. << "# Generated from the following files:\n# "
  170. << m_Makefile->GetHomeOutputDirectory() << "/CMakeCache.txt\n";
  171. std::vector<std::string> lfiles = m_Makefile->GetListFiles();
  172. // sort the array
  173. std::sort(lfiles.begin(), lfiles.end(), std::less<std::string>());
  174. // remove duplicates
  175. std::vector<std::string>::iterator new_end =
  176. std::unique(lfiles.begin(), lfiles.end());
  177. lfiles.erase(new_end, lfiles.end());
  178. for(std::vector<std::string>::const_iterator i = lfiles.begin();
  179. i != lfiles.end(); ++i)
  180. {
  181. fout << "# " << i->c_str() << "\n";
  182. }
  183. fout << "\n\n";
  184. // create a make variable with all of the sources for this Makefile
  185. // for depend purposes.
  186. fout << "CMAKE_MAKEFILE_SOURCES = ";
  187. for(std::vector<std::string>::const_iterator i = lfiles.begin();
  188. i != lfiles.end(); ++i)
  189. {
  190. fout << " " << i->c_str();
  191. }
  192. // Add the cache to the list
  193. fout << " " << m_Makefile->GetHomeOutputDirectory() << "/CMakeCache.txt\n";
  194. fout << "\n\n";
  195. this->OutputMakeVariables(fout);
  196. this->OutputMakeFlags(fout);
  197. this->OutputTargetRules(fout);
  198. this->OutputDependencies(fout);
  199. this->OutputTargets(fout);
  200. this->OutputSubDirectoryRules(fout);
  201. std::string dependName = m_Makefile->GetStartOutputDirectory();
  202. dependName += "/cmake.depends";
  203. if(!this->m_CacheOnly)
  204. {
  205. std::ofstream dependout(dependName.c_str());
  206. if(!dependout)
  207. {
  208. cmSystemTools::Error("Error can not open for write: ", dependName.c_str());
  209. return;
  210. }
  211. this->OutputObjectDepends(dependout);
  212. }
  213. this->OutputCustomRules(fout);
  214. this->OutputMakeRules(fout);
  215. this->OutputInstallRules(fout);
  216. // only add the depend include if the depend file exists
  217. if(cmSystemTools::FileExists(dependName.c_str()))
  218. {
  219. fout << "include cmake.depends\n";
  220. }
  221. }
  222. // Output the rules for any targets
  223. void cmUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
  224. {
  225. // for each target add to the list of targets
  226. fout << "TARGETS = ";
  227. const cmTargets &tgts = m_Makefile->GetTargets();
  228. // list libraries first
  229. bool dll = cmCacheManager::GetInstance()->IsOn("BUILD_SHARED_LIBS");
  230. for(cmTargets::const_iterator l = tgts.begin();
  231. l != tgts.end(); l++)
  232. {
  233. if (l->second.GetType() == cmTarget::LIBRARY &&
  234. l->second.IsInAll())
  235. {
  236. fout << " \\\n" << m_LibraryOutputPath << "lib" << l->first.c_str();
  237. if(dll)
  238. {
  239. fout << m_Makefile->GetDefinition("CMAKE_SHLIB_SUFFIX");
  240. }
  241. else
  242. {
  243. fout << ".a";
  244. }
  245. }
  246. }
  247. // executables
  248. for(cmTargets::const_iterator l = tgts.begin();
  249. l != tgts.end(); l++)
  250. {
  251. if ((l->second.GetType() == cmTarget::EXECUTABLE ||
  252. l->second.GetType() == cmTarget::WIN32_EXECUTABLE) &&
  253. l->second.IsInAll())
  254. {
  255. fout << " \\\n" << m_ExecutableOutputPath << l->first.c_str();
  256. }
  257. }
  258. // list utilities last
  259. for(cmTargets::const_iterator l = tgts.begin();
  260. l != tgts.end(); l++)
  261. {
  262. if (l->second.GetType() == cmTarget::UTILITY &&
  263. l->second.IsInAll())
  264. {
  265. fout << " \\\n" << l->first.c_str();
  266. }
  267. }
  268. fout << "\n\n";
  269. // get the classes from the source lists then add them to the groups
  270. for(cmTargets::const_iterator l = tgts.begin();
  271. l != tgts.end(); l++)
  272. {
  273. std::vector<cmSourceFile> classes = l->second.GetSourceFiles();
  274. if (classes.begin() != classes.end())
  275. {
  276. fout << l->first << "_SRC_OBJS = ";
  277. for(std::vector<cmSourceFile>::iterator i = classes.begin();
  278. i != classes.end(); i++)
  279. {
  280. if(!i->IsAHeaderFileOnly())
  281. {
  282. fout << "\\\n" << i->GetSourceName() << ".o ";
  283. }
  284. }
  285. fout << "\n\n";
  286. }
  287. }
  288. fout << "CLEAN_OBJECT_FILES = ";
  289. for(cmTargets::const_iterator l = tgts.begin();
  290. l != tgts.end(); l++)
  291. {
  292. std::vector<cmSourceFile> classes = l->second.GetSourceFiles();
  293. if (classes.begin() != classes.end())
  294. {
  295. fout << "${" << l->first << "_SRC_OBJS} ";
  296. }
  297. }
  298. fout << "\n";
  299. }
  300. /**
  301. * Output the linking rules on a command line. For executables,
  302. * targetLibrary should be a NULL pointer. For libraries, it should point
  303. * to the name of the library. This will not link a library against itself.
  304. */
  305. void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
  306. const char* targetLibrary,
  307. const cmTarget &tgt)
  308. {
  309. // Try to emit each search path once
  310. std::set<std::string> emitted;
  311. // Embed runtime search paths if possible and if required.
  312. bool outputRuntime = cmCacheManager::GetInstance()->IsOn("BUILD_SHARED_LIBS");
  313. std::string runtimeFlag;
  314. std::string runtimeSep;
  315. std::vector<std::string> runtimeDirs;
  316. if(m_Makefile->GetDefinition("CMAKE_SHLIB_RUNTIME_FLAG"))
  317. {
  318. runtimeFlag = m_Makefile->GetDefinition("CMAKE_SHLIB_RUNTIME_FLAG");
  319. }
  320. if(m_Makefile->GetDefinition("CMAKE_SHLIB_RUNTIME_SEP"))
  321. {
  322. runtimeSep = m_Makefile->GetDefinition("CMAKE_SHLIB_RUNTIME_SEP");
  323. }
  324. // concatenate all paths or no?
  325. bool runtimeConcatenate = ( runtimeSep!="" );
  326. if(runtimeFlag == "")
  327. {
  328. outputRuntime = false;
  329. }
  330. // Some search paths should never be emitted
  331. emitted.insert("");
  332. emitted.insert("/usr/lib");
  333. // collect all the flags needed for linking libraries
  334. std::string linkLibs;
  335. std::vector<std::string>& libdirs = m_Makefile->GetLinkDirectories();
  336. for(std::vector<std::string>::iterator libDir = libdirs.begin();
  337. libDir != libdirs.end(); ++libDir)
  338. {
  339. std::string libpath = cmSystemTools::EscapeSpaces(libDir->c_str());
  340. if (m_LibraryOutputPath.size())
  341. {
  342. if(m_LibraryOutputPath != libpath
  343. && (libpath.find(m_Makefile->GetHomeOutputDirectory())
  344. != std::string::npos))
  345. {
  346. emitted.insert(libpath);
  347. }
  348. }
  349. if(emitted.insert(libpath).second)
  350. {
  351. std::string::size_type pos = libDir->find("-L");
  352. if((pos == std::string::npos || pos > 0)
  353. && libDir->find("${") == std::string::npos)
  354. {
  355. linkLibs += "-L";
  356. if(outputRuntime)
  357. {
  358. runtimeDirs.push_back( libpath );
  359. }
  360. }
  361. linkLibs += libpath;
  362. linkLibs += " ";
  363. }
  364. }
  365. std::string librariesLinked;
  366. const cmTarget::LinkLibraries& libs = tgt.GetLinkLibraries();
  367. cmRegularExpression reg("lib(.*)(\\.so$|\\.a|\\.sl$)");
  368. for(cmTarget::LinkLibraries::const_iterator lib = libs.begin();
  369. lib != libs.end(); ++lib)
  370. {
  371. // Don't link the library against itself!
  372. if(targetLibrary && (lib->first == targetLibrary)) continue;
  373. // don't look at debug libraries
  374. if (lib->second == cmTarget::DEBUG) continue;
  375. // skip zero size library entries, this may happen
  376. // if a variable expands to nothing.
  377. if (lib->first.size() == 0) continue;
  378. // if it is a full path break it into -L and -l
  379. cmRegularExpression reg("(^[ \t]*\\-l)|(\\${)");
  380. if(lib->first.find('/') != std::string::npos
  381. && !reg.find(lib->first))
  382. {
  383. std::string dir, file;
  384. cmSystemTools::SplitProgramPath(lib->first.c_str(),
  385. dir, file);
  386. std::string libpath = cmSystemTools::EscapeSpaces(dir.c_str());
  387. if(emitted.insert(libpath).second)
  388. {
  389. linkLibs += "-L";
  390. linkLibs += libpath;
  391. linkLibs += " ";
  392. if(outputRuntime)
  393. {
  394. runtimeDirs.push_back( libpath );
  395. }
  396. }
  397. cmRegularExpression libname("lib(.*)\\.(.*)");
  398. if(libname.find(file))
  399. {
  400. librariesLinked += "-l";
  401. file = libname.match(1);
  402. librariesLinked += file;
  403. librariesLinked += " ";
  404. }
  405. }
  406. // not a full path, so add -l name
  407. else
  408. {
  409. if(!reg.find(lib->first))
  410. {
  411. librariesLinked += "-l";
  412. }
  413. librariesLinked += lib->first;
  414. librariesLinked += " ";
  415. }
  416. }
  417. linkLibs += librariesLinked;
  418. if(!targetLibrary)
  419. {
  420. // For executables, add these a second time so order does not matter
  421. linkLibs += librariesLinked;
  422. }
  423. fout << linkLibs;
  424. if(outputRuntime && runtimeDirs.size()>0)
  425. {
  426. // For the runtime search directories, do a "-Wl,-rpath,a:b:c" or
  427. // a "-R a -R b -R c" type link line
  428. fout << runtimeFlag;
  429. std::vector<std::string>::iterator itr = runtimeDirs.begin();
  430. fout << *itr;
  431. ++itr;
  432. for( ; itr != runtimeDirs.end(); ++itr )
  433. {
  434. if(runtimeConcatenate)
  435. {
  436. fout << runtimeSep << *itr;
  437. }
  438. else
  439. {
  440. fout << " " << runtimeFlag << *itr;
  441. }
  442. }
  443. fout << " ";
  444. }
  445. }
  446. void cmUnixMakefileGenerator::OutputTargets(std::ostream& fout)
  447. {
  448. bool dll = cmCacheManager::GetInstance()->IsOn("BUILD_SHARED_LIBS");
  449. // for each target
  450. const cmTargets &tgts = m_Makefile->GetTargets();
  451. for(cmTargets::const_iterator l = tgts.begin();
  452. l != tgts.end(); l++)
  453. {
  454. if (l->second.GetType() == cmTarget::LIBRARY)
  455. {
  456. fout << "#---------------------------------------------------------\n";
  457. fout << "# rules for a library\n";
  458. fout << "#\n";
  459. fout << m_LibraryOutputPath << "lib" << l->first << ".a: ${" <<
  460. l->first << "_SRC_OBJS} \n";
  461. fout << "\t${CMAKE_AR} cr "
  462. << m_LibraryOutputPath << "lib" << l->first << ".a ${" <<
  463. l->first << "_SRC_OBJS} \n";
  464. fout << "\t${CMAKE_RANLIB} "
  465. << m_LibraryOutputPath << "lib" << l->first << ".a\n";
  466. fout << std::endl;
  467. fout << m_LibraryOutputPath << "lib" << l->first << "$(SHLIB_SUFFIX): ${" <<
  468. l->first << "_SRC_OBJS} \n";
  469. fout << "\trm -f lib" << l->first << "$(SHLIB_SUFFIX)\n";
  470. fout << "\t$(CMAKE_CXX_COMPILER) ${CMAKE_SHLIB_LINK_FLAGS} "
  471. "${CMAKE_SHLIB_BUILD_FLAGS} ${CMAKE_CXX_FLAGS} -o \\\n";
  472. fout << "\t " << m_LibraryOutputPath << "lib" << l->first << "$(SHLIB_SUFFIX) \\\n";
  473. fout << "\t ${" << l->first <<
  474. "_SRC_OBJS} ";
  475. this->OutputLinkLibraries(fout, l->first.c_str(), l->second);
  476. fout << "\n\n";
  477. }
  478. else if ((l->second.GetType() == cmTarget::EXECUTABLE)
  479. || (l->second.GetType() == cmTarget::WIN32_EXECUTABLE))
  480. {
  481. fout << m_ExecutableOutputPath << l->first << ": ${" <<
  482. l->first << "_SRC_OBJS} ${CMAKE_DEPEND_LIBS}\n";
  483. fout << "\t${CMAKE_CXX_COMPILER} ";
  484. if (dll)
  485. {
  486. fout << "${CMAKE_SHLIB_LINK_FLAGS} ";
  487. }
  488. fout << "${CMAKE_CXXFLAGS} ${" << l->first << "_SRC_OBJS} ";
  489. this->OutputLinkLibraries(fout, NULL,l->second);
  490. fout << " -o " << m_ExecutableOutputPath << l->first << "\n\n";
  491. }
  492. }
  493. }
  494. // output the list of libraries that the executables
  495. // in this makefile will depend on.
  496. void cmUnixMakefileGenerator::OutputDependencies(std::ostream& fout)
  497. {
  498. // Each dependency should only be emitted once.
  499. std::set<std::string> emitted;
  500. fout << "CMAKE_DEPEND_LIBS = ";
  501. cmTarget::LinkLibraries& libs = m_Makefile->GetLinkLibraries();
  502. cmTarget::LinkLibraries::const_iterator lib2;
  503. // Search the list of libraries that will be linked into
  504. // the executable
  505. emitted.clear();
  506. for(lib2 = libs.begin(); lib2 != libs.end(); ++lib2)
  507. {
  508. if( ! emitted.insert(lib2->first).second ) continue;
  509. const char* cacheValue
  510. = cmCacheManager::GetInstance()->GetCacheValue(lib2->first.c_str());
  511. if(cacheValue
  512. && (strcmp(m_Makefile->GetCurrentOutputDirectory(), cacheValue) != 0))
  513. {
  514. std::string libpath = cacheValue;
  515. if(m_LibraryOutputPath.size())
  516. {
  517. libpath = m_LibraryOutputPath;
  518. libpath += "lib";
  519. }
  520. else
  521. {
  522. libpath += "/lib";
  523. }
  524. libpath += lib2->first;
  525. bool dll = cmCacheManager::GetInstance()->IsOn("BUILD_SHARED_LIBS");
  526. if(dll)
  527. {
  528. libpath += m_Makefile->GetDefinition("CMAKE_SHLIB_SUFFIX");
  529. }
  530. else
  531. {
  532. libpath += ".a";
  533. }
  534. fout << libpath << " ";
  535. }
  536. }
  537. fout << "\n\n";
  538. emitted.clear();
  539. for(lib2 = libs.begin(); lib2 != libs.end(); ++lib2)
  540. {
  541. // loop over the list of directories that the libraries might
  542. // be in, looking for an ADD_LIBRARY(lib...) line. This would
  543. // be stored in the cache
  544. if( ! emitted.insert(lib2->first).second ) continue;
  545. const char* cacheValue
  546. = cmCacheManager::GetInstance()->GetCacheValue(lib2->first.c_str());
  547. // if cache and not the current directory add a rule, to
  548. // jump into the directory and build for the first time
  549. if(cacheValue
  550. && (strcmp(m_Makefile->GetCurrentOutputDirectory(), cacheValue) != 0))
  551. {
  552. std::string library = "lib";
  553. library += lib2->first;
  554. bool dll = cmCacheManager::GetInstance()->IsOn("BUILD_SHARED_LIBS");
  555. if(dll)
  556. {
  557. library += m_Makefile->GetDefinition("CMAKE_SHLIB_SUFFIX");
  558. }
  559. else
  560. {
  561. library += ".a";
  562. }
  563. std::string libpath = cacheValue;
  564. if(m_LibraryOutputPath.size())
  565. {
  566. libpath = m_LibraryOutputPath;
  567. }
  568. else
  569. {
  570. libpath += "/";
  571. }
  572. libpath += library;
  573. // put out a rule to build the library if it does not exist
  574. fout << libpath.c_str()
  575. << ":\n\tcd " << cacheValue
  576. << "; make " << m_LibraryOutputPath << library.c_str() << "\n\n";
  577. }
  578. }
  579. }
  580. // output make include flags
  581. void cmUnixMakefileGenerator::OutputMakeFlags(std::ostream& fout)
  582. {
  583. // Output Include paths
  584. fout << "INCLUDE_FLAGS = ";
  585. std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
  586. std::vector<std::string>::iterator i;
  587. fout << "-I" << m_Makefile->GetStartDirectory() << " ";
  588. for(i = includes.begin(); i != includes.end(); ++i)
  589. {
  590. std::string include = *i;
  591. fout << "-I" << cmSystemTools::EscapeSpaces(i->c_str()).c_str() << " ";
  592. }
  593. fout << m_Makefile->GetDefineFlags();
  594. fout << "\n\n";
  595. fout << "default_target: all\n\n";
  596. // see if there are files to compile in this makefile
  597. // These are used for both libraries and executables
  598. }
  599. // fix up names of directories so they can be used
  600. // as targets in makefiles.
  601. inline std::string FixDirectoryName(const char* dir)
  602. {
  603. std::string s = dir;
  604. // replace ../ with 3 under bars
  605. size_t pos = s.find("../");
  606. if(pos != std::string::npos)
  607. {
  608. s.replace(pos, 3, "___");
  609. }
  610. // replace / directory separators with a single under bar
  611. pos = s.find("/");
  612. while(pos != std::string::npos)
  613. {
  614. s.replace(pos, 1, "_");
  615. pos = s.find("/");
  616. }
  617. return s;
  618. }
  619. void
  620. cmUnixMakefileGenerator::
  621. OutputSubDirectoryVars(std::ostream& fout,
  622. const char* var,
  623. const char* target,
  624. const char* target1,
  625. const char* target2,
  626. const std::vector<std::string>& SubDirectories)
  627. {
  628. if( SubDirectories.size() == 0)
  629. {
  630. return;
  631. }
  632. fout << "# Variable for making " << target << " in subdirectories.\n";
  633. fout << var << " = \\\n";
  634. unsigned int i;
  635. for(i =0; i < SubDirectories.size(); i++)
  636. {
  637. std::string subdir = FixDirectoryName(SubDirectories[i].c_str());
  638. fout << target << "_" << subdir.c_str();
  639. if(i == SubDirectories.size()-1)
  640. {
  641. fout << " \n\n";
  642. }
  643. else
  644. {
  645. fout << " \\\n";
  646. }
  647. }
  648. fout << "# Targets for making " << target << " in subdirectories.\n";
  649. for(unsigned int i =0; i < SubDirectories.size(); i++)
  650. {
  651. std::string subdir = FixDirectoryName(SubDirectories[i].c_str());
  652. fout << target << "_" << subdir.c_str() << ":\n";
  653. if(target1)
  654. {
  655. fout << "\t@if test ! -d " << SubDirectories[i].c_str() << "; then ${MAKE} rebuild_cache; fi\n"
  656. "\tcd " << SubDirectories[i].c_str()
  657. << "; ${MAKE} -${MAKEFLAGS} " << target1 << "\n";
  658. }
  659. if(target2)
  660. {
  661. fout << "\t@cd " << SubDirectories[i].c_str()
  662. << "; ${MAKE} -${MAKEFLAGS} " << target2 << "\n";
  663. }
  664. }
  665. fout << "\n\n";
  666. }
  667. // output rules for decending into sub directories
  668. void cmUnixMakefileGenerator::OutputSubDirectoryRules(std::ostream& fout)
  669. {
  670. // Output Sub directory build rules
  671. const std::vector<std::string>& SubDirectories
  672. = m_Makefile->GetSubDirectories();
  673. if( SubDirectories.size() == 0)
  674. {
  675. return;
  676. }
  677. this->OutputSubDirectoryVars(fout, "SUBDIR_BUILD", "build",
  678. "cmake.depends",
  679. "all",
  680. SubDirectories);
  681. this->OutputSubDirectoryVars(fout, "SUBDIR_CLEAN", "clean",
  682. "clean",
  683. 0,
  684. SubDirectories);
  685. this->OutputSubDirectoryVars(fout, "SUBDIR_DEPEND", "depend",
  686. "depend",
  687. 0,
  688. SubDirectories);
  689. this->OutputSubDirectoryVars(fout, "SUBDIR_INSTALL", "install",
  690. "install",
  691. 0,
  692. SubDirectories);
  693. }
  694. // Output the depend information for all the classes
  695. // in the makefile. These would have been generated
  696. // by the class cmMakeDepend GenerateMakefile
  697. void cmUnixMakefileGenerator::OutputObjectDepends(std::ostream& fout)
  698. {
  699. // Iterate over every target.
  700. std::map<std::string, cmTarget>& targets = m_Makefile->GetTargets();
  701. for(std::map<std::string, cmTarget>::const_iterator target = targets.begin();
  702. target != targets.end(); ++target)
  703. {
  704. // Iterate over every source for this target.
  705. const std::vector<cmSourceFile>& sources = target->second.GetSourceFiles();
  706. for(std::vector<cmSourceFile>::const_iterator source = sources.begin();
  707. source != sources.end(); ++source)
  708. {
  709. if(!source->IsAHeaderFileOnly())
  710. {
  711. if(!source->GetDepends().empty())
  712. {
  713. fout << source->GetSourceName() << ".o :";
  714. // Iterate through all the dependencies for this source.
  715. for(std::vector<std::string>::const_iterator dep =
  716. source->GetDepends().begin();
  717. dep != source->GetDepends().end(); ++dep)
  718. {
  719. fout << " \\\n" << dep->c_str();
  720. }
  721. fout << "\n\n";
  722. }
  723. }
  724. }
  725. }
  726. }
  727. // Output each custom rule in the following format:
  728. // output: source depends...
  729. // (tab) command...
  730. void cmUnixMakefileGenerator::OutputCustomRules(std::ostream& fout)
  731. {
  732. // We may be modifying the source groups temporarily, so make a copy.
  733. std::vector<cmSourceGroup> sourceGroups = m_Makefile->GetSourceGroups();
  734. const cmTargets &tgts = m_Makefile->GetTargets();
  735. for(cmTargets::const_iterator tgt = tgts.begin();
  736. tgt != tgts.end(); ++tgt)
  737. {
  738. // add any custom rules to the source groups
  739. for (std::vector<cmCustomCommand>::const_iterator cr =
  740. tgt->second.GetCustomCommands().begin();
  741. cr != tgt->second.GetCustomCommands().end(); ++cr)
  742. {
  743. cmSourceGroup& sourceGroup =
  744. m_Makefile->FindSourceGroup(cr->GetSourceName().c_str(),
  745. sourceGroups);
  746. cmCustomCommand cc(*cr);
  747. cc.ExpandVariables(*m_Makefile);
  748. sourceGroup.AddCustomCommand(cc);
  749. }
  750. }
  751. // Loop through every source group.
  752. for(std::vector<cmSourceGroup>::const_iterator sg =
  753. sourceGroups.begin(); sg != sourceGroups.end(); ++sg)
  754. {
  755. const cmSourceGroup::BuildRules& buildRules = sg->GetBuildRules();
  756. if(buildRules.empty())
  757. { continue; }
  758. std::string name = sg->GetName();
  759. if(name != "")
  760. {
  761. fout << "# Start of source group \"" << name.c_str() << "\"\n";
  762. }
  763. // Loop through each source in the source group.
  764. for(cmSourceGroup::BuildRules::const_iterator cc =
  765. buildRules.begin(); cc != buildRules.end(); ++ cc)
  766. {
  767. std::string source = cc->first;
  768. const cmSourceGroup::Commands& commands = cc->second;
  769. // Loop through every command generating code from the current source.
  770. for(cmSourceGroup::Commands::const_iterator c = commands.begin();
  771. c != commands.end(); ++c)
  772. {
  773. std::string command = c->first;
  774. const cmSourceGroup::CommandFiles& commandFiles = c->second;
  775. // if the command has no outputs, then it is a utility command
  776. // with no outputs
  777. if(commandFiles.m_Outputs.size() == 0)
  778. {
  779. fout << source.c_str() << ": ";
  780. // Write out all the dependencies for this rule.
  781. for(std::set<std::string>::const_iterator d =
  782. commandFiles.m_Depends.begin();
  783. d != commandFiles.m_Depends.end(); ++d)
  784. {
  785. std::string dep = cmSystemTools::EscapeSpaces(d->c_str());
  786. fout << " " << dep.c_str();
  787. }
  788. fout << "\n\t" << command.c_str() << "\n\n";
  789. }
  790. // Write a rule for every output generated by this command.
  791. for(std::set<std::string>::const_iterator output =
  792. commandFiles.m_Outputs.begin();
  793. output != commandFiles.m_Outputs.end(); ++output)
  794. {
  795. std::string src = cmSystemTools::EscapeSpaces(source.c_str());
  796. fout << output->c_str() << ": " << src.c_str();
  797. // Write out all the dependencies for this rule.
  798. for(std::set<std::string>::const_iterator d =
  799. commandFiles.m_Depends.begin();
  800. d != commandFiles.m_Depends.end(); ++d)
  801. {
  802. std::string dep = cmSystemTools::EscapeSpaces(d->c_str());
  803. fout << " " << dep.c_str();
  804. }
  805. fout << "\n\t" << command.c_str() << "\n\n";
  806. }
  807. }
  808. }
  809. if(name != "")
  810. {
  811. fout << "# End of source group \"" << name.c_str() << "\"\n\n";
  812. }
  813. }
  814. }
  815. void cmUnixMakefileGenerator::GenerateCacheOnly()
  816. {
  817. cmSystemTools::MakeDirectory(m_Makefile->GetStartOutputDirectory());
  818. std::string dest = m_Makefile->GetStartOutputDirectory();
  819. dest += "/Makefile";
  820. std::cout << "cmake: creating : " << dest.c_str() << std::endl;
  821. this->OutputMakefile(dest.c_str());
  822. return;
  823. }
  824. void cmUnixMakefileGenerator::RecursiveGenerateCacheOnly()
  825. {
  826. std::vector<cmMakefile*> makefiles;
  827. m_Makefile->FindSubDirectoryCMakeListsFiles(makefiles);
  828. for(std::vector<cmMakefile*>::iterator i = makefiles.begin();
  829. i != makefiles.end(); ++i)
  830. {
  831. cmMakefile* mf = *i;
  832. if(m_Makefile->GetDefinition("RUN_CONFIGURE"))
  833. {
  834. mf->AddDefinition("RUN_CONFIGURE", true);
  835. }
  836. cmUnixMakefileGenerator* gen = new cmUnixMakefileGenerator;
  837. gen->SetCacheOnlyOn();
  838. gen->SetRecurseOff();
  839. mf->SetMakefileGenerator(gen);
  840. mf->GenerateMakefile();
  841. }
  842. // CLEAN up the makefiles created
  843. for(unsigned int i =0; i < makefiles.size(); ++i)
  844. {
  845. delete makefiles[i];
  846. }
  847. }
  848. void cmUnixMakefileGenerator::OutputMakeVariables(std::ostream& fout)
  849. {
  850. if(strcmp(m_Makefile->GetHomeDirectory(),
  851. m_Makefile->GetHomeOutputDirectory()) == 0)
  852. {
  853. fout << "srcdir = .\n\n";
  854. }
  855. else
  856. {
  857. fout << "srcdir = " << m_Makefile->GetStartDirectory() << "\n";
  858. fout << "VPATH = " << m_Makefile->GetStartDirectory() << "\n";
  859. }
  860. const char* variables =
  861. "# the standard shell for make\n"
  862. "SHELL = /bin/sh\n"
  863. "\n"
  864. "CMAKE_LIB_EXT = @CMAKE_LIB_EXT@\n"
  865. "CMAKE_RANLIB = @CMAKE_RANLIB@\n"
  866. "CMAKE_AR = @CMAKE_AR@\n"
  867. "CMAKE_C_COMPILER = @CMAKE_C_COMPILER@\n"
  868. "CMAKE_CFLAGS = @CMAKE_C_FLAGS@ @CMAKE_SHLIB_CFLAGS@ \n"
  869. "\n"
  870. "CMAKE_CXX_COMPILER = @CMAKE_CXX_COMPILER@\n"
  871. "CMAKE_CXXFLAGS = @CMAKE_CXX_FLAGS@ @CMAKE_SHLIB_CFLAGS@ @CMAKE_TEMPLATE_FLAGS@ \n"
  872. "\n"
  873. "CMAKE_SHLIB_BUILD_FLAGS = @CMAKE_SHLIB_BUILD_FLAGS@\n"
  874. "CMAKE_SHLIB_LINK_FLAGS = @CMAKE_SHLIB_LINK_FLAGS@\n"
  875. "DL_LIBS = @CMAKE_DL_LIBS@\n"
  876. "SHLIB_LD_LIBS = @CMAKE_SHLIB_LD_LIBS@\n"
  877. "SHLIB_SUFFIX = @CMAKE_SHLIB_SUFFIX@\n"
  878. "THREAD_LIBS = @CMAKE_THREAD_LIBS@\n"
  879. "\n"
  880. "# set up the path to the rulesgen program\n"
  881. "CMAKE_COMMAND = ${CMAKE_COMMAND}\n"
  882. "\n"
  883. "\n"
  884. "\n";
  885. std::string replaceVars = variables;
  886. bool dll = cmCacheManager::GetInstance()->IsOn("BUILD_SHARED_LIBS");
  887. if(!dll)
  888. {
  889. // if not a dll then remove the shlib -fpic flag
  890. m_Makefile->AddDefinition("CMAKE_SHLIB_CFLAGS", "");
  891. }
  892. m_Makefile->ExpandVariablesInString(replaceVars);
  893. fout << replaceVars.c_str();
  894. fout << "CMAKE_CURRENT_SOURCE = " << m_Makefile->GetStartDirectory() << "\n";
  895. fout << "CMAKE_CURRENT_BINARY = " << m_Makefile->GetStartOutputDirectory() << "\n";
  896. }
  897. void cmUnixMakefileGenerator::OutputInstallRules(std::ostream& fout)
  898. {
  899. bool dll = cmCacheManager::GetInstance()->IsOn("BUILD_SHARED_LIBS");
  900. const char* root
  901. = cmCacheManager::GetInstance()->GetCacheValue("CMAKE_ROOT");
  902. fout << "INSTALL = " << root << "/Templates/install-sh -c\n";
  903. fout << "INSTALL_PROGRAM = ${INSTALL}\n";
  904. fout << "INSTALL_DATA = ${INSTALL} -m 644\n";
  905. const cmTargets &tgts = m_Makefile->GetTargets();
  906. fout << "install: ${SUBDIR_INSTALL}\n";
  907. fout << "\t@echo \"Installing ...\"\n";
  908. const char* prefix
  909. = cmCacheManager::GetInstance()->GetCacheValue("CMAKE_INSTALL_PREFIX");
  910. if (!prefix)
  911. {
  912. prefix = "/usr/local";
  913. }
  914. for(cmTargets::const_iterator l = tgts.begin();
  915. l != tgts.end(); l++)
  916. {
  917. if (l->second.GetInstallPath() != "")
  918. {
  919. // first make the directories for each target
  920. fout << "\t@if [ ! -d " << prefix << l->second.GetInstallPath() <<
  921. " ] ; then \\\n";
  922. fout << "\t echo \"Making directory " << prefix
  923. << l->second.GetInstallPath() << " \"; \\\n";
  924. fout << "\t mkdir -p " << prefix << l->second.GetInstallPath()
  925. << "; \\\n";
  926. fout << "\t chmod 755 " << prefix << l->second.GetInstallPath()
  927. << "; \\\n";
  928. fout << "\t else true; \\\n";
  929. fout << "\t fi\n";
  930. // now install the target
  931. switch (l->second.GetType())
  932. {
  933. case cmTarget::LIBRARY:
  934. fout << "\t$(INSTALL_DATA) lib" << l->first;
  935. if(dll)
  936. {
  937. fout << m_Makefile->GetDefinition("CMAKE_SHLIB_SUFFIX");
  938. }
  939. else
  940. {
  941. fout << ".a";
  942. }
  943. fout << " " << prefix << l->second.GetInstallPath() << "\n";
  944. break;
  945. case cmTarget::WIN32_EXECUTABLE:
  946. case cmTarget::EXECUTABLE:
  947. fout << "\t$(INSTALL_PROGRAM) " << l->first
  948. << " " << prefix << l->second.GetInstallPath() << "\n";
  949. break;
  950. case cmTarget::INSTALL:
  951. {
  952. const std::vector<std::string> &sf = l->second.GetSourceLists();
  953. std::vector<std::string>::const_iterator i;
  954. for (i = sf.begin(); i != sf.end(); ++i)
  955. {
  956. fout << "\t@ echo \"Installing " << *i << " \"\n";
  957. fout << "\t@if [ -e " << *i << " ] ; then \\\n";
  958. fout << "\t $(INSTALL) " << *i
  959. << " " << prefix << l->second.GetInstallPath() << "; \\\n";
  960. fout << "\t elif [ -e ${srcdir}/" << *i << " ] ; then \\\n";
  961. fout << "\t $(INSTALL) ${srcdir}/" << *i
  962. << " " << prefix << l->second.GetInstallPath() << "; \\\n";
  963. fout << "\telse \\\n";
  964. fout << "\t echo \" ERROR!!! Unable to find: " << *i
  965. << " \"; \\\n";
  966. fout << "\t fi\n";
  967. }
  968. }
  969. break;
  970. case cmTarget::UTILITY:
  971. default:
  972. break;
  973. }
  974. }
  975. }
  976. }
  977. void cmUnixMakefileGenerator::OutputMakeRules(std::ostream& fout)
  978. {
  979. this->OutputMakeRule(fout,
  980. "# tell make about .cxx and .java",
  981. ".SUFFIXES", ".cxx .java .class", 0);
  982. this->OutputMakeRule(fout,
  983. "# build c file",
  984. ".c.o",
  985. 0,
  986. "${CMAKE_C_COMPILER} ${CMAKE_CFLAGS} ${INCLUDE_FLAGS} -c $< -o $@");
  987. this->OutputMakeRule(fout,
  988. "# build cplusplus file",
  989. ".cxx.o",
  990. 0,
  991. "${CMAKE_CXX_COMPILER} ${CMAKE_CXXFLAGS} ${INCLUDE_FLAGS} -c $< -o $@");
  992. // only include the cmake.depends and not the Makefile, as
  993. // building one will cause the other to be built
  994. this->OutputMakeRule(fout,
  995. "Default build rule",
  996. "all",
  997. "cmake.depends ${TARGETS} ${SUBDIR_BUILD} ${CMAKE_COMMAND}",
  998. 0);
  999. this->OutputMakeRule(fout,
  1000. "remove generated files",
  1001. "clean",
  1002. "${SUBDIR_CLEAN}",
  1003. "rm -f ${CLEAN_OBJECT_FILES} ${EXECUTABLES} ${TARGETS}");
  1004. this->OutputMakeRule(fout,
  1005. "Rule to build the cmake.depends and Makefile as side effect",
  1006. "cmake.depends",
  1007. "${CMAKE_COMMAND} ${CMAKE_MAKEFILE_SOURCES} ",
  1008. "${CMAKE_COMMAND} "
  1009. "-S${CMAKE_CURRENT_SOURCE} -O${CMAKE_CURRENT_BINARY} "
  1010. "-H${CMAKE_SOURCE_DIR} -B${CMAKE_BINARY_DIR}");
  1011. this->OutputMakeRule(fout,
  1012. "Rule to force the build of cmake.depends",
  1013. "depend",
  1014. "${SUBDIR_DEPEND}",
  1015. "${CMAKE_COMMAND} "
  1016. "-S${CMAKE_CURRENT_SOURCE} -O${CMAKE_CURRENT_BINARY} "
  1017. "-H${CMAKE_SOURCE_DIR} -B${CMAKE_BINARY_DIR}");
  1018. this->OutputMakeRule(fout,
  1019. "Rebuild the cache",
  1020. "rebuild_cache",
  1021. "${CMAKE_BINARY_DIR}/CMakeCache.txt",
  1022. "${CMAKE_COMMAND} "
  1023. "-H${CMAKE_SOURCE_DIR} -B${CMAKE_BINARY_DIR}");
  1024. this->OutputMakeRule(fout,
  1025. "Rebuild the cache",
  1026. "${CMAKE_BINARY_DIR}/CMakeCache.txt",
  1027. 0,
  1028. "${CMAKE_COMMAND} "
  1029. "-H${CMAKE_SOURCE_DIR} -B${CMAKE_BINARY_DIR}");
  1030. this->OutputMakeRule(fout,
  1031. "Rebuild cmake dummy rule",
  1032. "${CMAKE_COMMAND}",
  1033. 0,
  1034. "echo \"cmake might be out of date\"");
  1035. this->OutputMakeRule(fout,
  1036. "Rule to keep make from removing Makefiles "
  1037. "if control-C is hit during a run of cmake.",
  1038. ".PRECIOUS",
  1039. "Makefile cmake.depends",
  1040. 0);
  1041. }
  1042. void cmUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
  1043. const char* comment,
  1044. const char* target,
  1045. const char* depends,
  1046. const char* command)
  1047. {
  1048. if(!target)
  1049. {
  1050. cmSystemTools::Error("no target for OutputMakeRule");
  1051. return;
  1052. }
  1053. std::string replace;
  1054. if(comment)
  1055. {
  1056. replace = comment;
  1057. m_Makefile->ExpandVariablesInString(replace);
  1058. fout << "# " << comment;
  1059. }
  1060. fout << "\n";
  1061. replace = target;
  1062. m_Makefile->ExpandVariablesInString(replace);
  1063. fout << replace.c_str() << ": ";
  1064. if(depends)
  1065. {
  1066. replace = depends;
  1067. m_Makefile->ExpandVariablesInString(replace);
  1068. fout << replace.c_str();
  1069. }
  1070. fout << "\n";
  1071. if(command)
  1072. {
  1073. replace = command;
  1074. m_Makefile->ExpandVariablesInString(replace);
  1075. fout << "\t" << replace.c_str() << "\n\n";
  1076. }
  1077. fout << "\n\n\n";
  1078. }
  1079. void cmUnixMakefileGenerator::SetLocal (bool local)
  1080. {
  1081. if (local)
  1082. {
  1083. m_CacheOnly = false;
  1084. m_Recurse = false;
  1085. }
  1086. else
  1087. {
  1088. m_CacheOnly = true;
  1089. m_Recurse = true;
  1090. }
  1091. }
  1092. void cmUnixMakefileGenerator::ComputeSystemInfo()
  1093. {
  1094. if (m_CacheOnly)
  1095. {
  1096. // currently we run configure shell script here to determine the info
  1097. std::string output;
  1098. std::string cmd = "cd ";
  1099. cmd += m_Makefile->GetHomeOutputDirectory();
  1100. cmd += "; ";
  1101. const char* root
  1102. = cmCacheManager::GetInstance()->GetCacheValue("CMAKE_ROOT");
  1103. cmd += root;
  1104. cmd += "/Templates/configure";
  1105. cmSystemTools::RunCommand(cmd.c_str(), output);
  1106. m_Makefile->AddDefinition("RUN_CONFIGURE", true);
  1107. }
  1108. // now load the settings
  1109. std::string fpath = m_Makefile->GetHomeOutputDirectory();
  1110. fpath += "/CMakeSystemConfig.cmake";
  1111. m_Makefile->ReadListFile(NULL,fpath.c_str());
  1112. }