cmNMakeMakefileGenerator.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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 "cmNMakeMakefileGenerator.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. #include "windows.h"
  41. cmNMakeMakefileGenerator::cmNMakeMakefileGenerator()
  42. {
  43. m_LibraryPathOption = "$(CMAKE_C_LIBPATH_FLAG)";
  44. this->SetObjectFileExtension("$(CMAKE_OBJECT_FILE_SUFFIX)");
  45. this->SetExecutableExtension("$(CMAKE_EXECUTABLE_SUFFIX)");
  46. this->SetLibraryPrefix("");
  47. this->SetStaticLibraryExtension("$(CMAKE_STATICLIB_SUFFIX)");
  48. this->SetSharedLibraryExtension("$(CMAKE_SHLIB_SUFFIX)");
  49. m_QuoteNextCommand = true; // most of the time command should be quoted
  50. }
  51. cmNMakeMakefileGenerator::~cmNMakeMakefileGenerator()
  52. {
  53. }
  54. // convert to windows short paths if there are spaces
  55. // in path
  56. std::string cmNMakeMakefileGenerator::ShortPath(const char* path)
  57. {
  58. std::string ret = path;
  59. cmSystemTools::ConvertToWindowsSlashes(ret);
  60. // if there are no spaces in path, then just return path
  61. if(ret.find(' ') == std::string::npos)
  62. {
  63. return ret;
  64. }
  65. // if there are spaces then call GetShortPathName to get rid of them
  66. char *buffer = new char[strlen(path)+1];
  67. if(GetShortPathName(path, buffer,
  68. strlen(path)+1) != 0)
  69. {
  70. ret = buffer;
  71. }
  72. else
  73. {
  74. // if GetShortPathName failed for some reason use
  75. // EscapeSpaces instead
  76. ret = cmSystemTools::EscapeSpaces(path);
  77. }
  78. delete [] buffer;
  79. return ret;
  80. }
  81. // convert a command to a short path if it has spaces
  82. // this separates the arguments from the command and puts
  83. // them back together
  84. std::string cmNMakeMakefileGenerator::ShortPathCommand(const char* command)
  85. {
  86. if(!strchr(command, ' '))
  87. {
  88. return command;
  89. }
  90. cmRegularExpression reg("^\"([^\"]*)\"(.*)");
  91. if(reg.find(command))
  92. {
  93. std::string c = reg.match(1);
  94. cmRegularExpression removeIntDir("(.*)/\\$\\(IntDir\\)(.*)");
  95. if(removeIntDir.find(c))
  96. {
  97. c = removeIntDir.match(1) + removeIntDir.match(2);
  98. }
  99. c = ShortPath(c.c_str());
  100. std::string ret = c;
  101. std::string args = reg.match(2);
  102. ret += args;
  103. return ret;
  104. }
  105. return command;
  106. }
  107. void cmNMakeMakefileGenerator::ComputeSystemInfo()
  108. {
  109. // now load the settings
  110. if(!m_Makefile->GetDefinition("CMAKE_ROOT"))
  111. {
  112. cmSystemTools::Error(
  113. "CMAKE_ROOT has not been defined, bad GUI or driver program");
  114. return;
  115. }
  116. std::string fpath =
  117. m_Makefile->GetDefinition("CMAKE_ROOT");
  118. fpath += "/Templates/CMakeNMakeWindowsSystemConfig.cmake";
  119. m_Makefile->ReadListFile(NULL,fpath.c_str());
  120. }
  121. void cmNMakeMakefileGenerator::OutputMakeVariables(std::ostream& fout)
  122. {
  123. fout << "# NMake Makefile generated by cmake\n";
  124. const char* variables =
  125. "# general varibles used in the makefile\n"
  126. "\n"
  127. "# Path to cmake\n"
  128. "CMAKE_COMMAND = ${CMAKE_COMMAND}\n"
  129. "CMAKE_STANDARD_WINDOWS_LIBRARIES = @CMAKE_STANDARD_WINDOWS_LIBRARIES@\n"
  130. "CMAKE_C_COMPILER = @CMAKE_C_COMPILER@\n"
  131. "CMAKE_C_FLAGS = @CMAKE_C_FLAGS@ @BUILD_FLAGS@\n"
  132. "CMAKE_C_OUTPUT_OBJECT_FILE_FLAG = @CMAKE_C_OUTPUT_OBJECT_FILE_FLAG@\n"
  133. "CMAKE_C_OUTPUT_EXECUTABLE_FILE_FLAG = @CMAKE_C_OUTPUT_EXECUTABLE_FILE_FLAG@\n"
  134. "CMAKE_LINKER = @CMAKE_LINKER@\n"
  135. "CMAKE_C_LINK_EXECUTABLE_FLAG = @CMAKE_C_LINK_EXECUTABLE_FLAG@\n"
  136. "CMAKE_C_LIBPATH_FLAG = @CMAKE_C_LIBPATH_FLAG@\n"
  137. "CMAKE_LINKER_FLAGS = @CMAKE_LINKER_FLAGS@ @LINKER_BUILD_FLAGS@\n"
  138. "CMAKE_LINKER_SHARED_LIBRARY_FLAG = @CMAKE_LINKER_SHARED_LIBRARY_FLAG@\n"
  139. "CMAKE_LINKER_STATIC_LIBRARY_FLAG = @CMAKE_LINKER_STATIC_LIBRARY_FLAG@\n"
  140. "CMAKE_LINKER_OUTPUT_FILE_FLAG = @CMAKE_LINKER_OUTPUT_FILE_FLAG@\n"
  141. "CMAKE_CXXFLAGS = @CMAKE_CXX_FLAGS@ @BUILD_FLAGS@\n"
  142. "CMAKE_CXX_COMPILER = @CMAKE_CXX_COMPILER@\n"
  143. "CMAKE_OBJECT_FILE_SUFFIX = @CMAKE_OBJECT_FILE_SUFFIX@\n"
  144. "CMAKE_EXECUTABLE_SUFFIX = @CMAKE_EXECUTABLE_SUFFIX@\n"
  145. "CMAKE_STATICLIB_SUFFIX = @CMAKE_STATICLIB_SUFFIX@\n"
  146. "CMAKE_SHLIB_SUFFIX = @CMAKE_SHLIB_SUFFIX@\n";
  147. std::string buildType = "CMAKE_CXX_FLAGS_";
  148. buildType += m_Makefile->GetDefinition("CMAKE_BUILD_TYPE");
  149. buildType = cmSystemTools::UpperCase(buildType);
  150. m_Makefile->AddDefinition("BUILD_FLAGS",
  151. m_Makefile->GetDefinition(
  152. buildType.c_str()));
  153. buildType = "CMAKE_LINKER_FLAGS_";
  154. buildType += m_Makefile->GetDefinition("CMAKE_BUILD_TYPE");
  155. buildType = cmSystemTools::UpperCase(buildType);
  156. m_Makefile->AddDefinition("LINKER_BUILD_FLAGS",
  157. m_Makefile->GetDefinition(
  158. buildType.c_str()));
  159. std::string replaceVars = variables;
  160. m_Makefile->ExpandVariablesInString(replaceVars);
  161. fout << replaceVars.c_str();
  162. fout << "CMAKE_CURRENT_SOURCE = "
  163. << ShortPath(m_Makefile->GetStartDirectory() )
  164. << "\n";
  165. fout << "CMAKE_CURRENT_BINARY = "
  166. << ShortPath(m_Makefile->GetStartOutputDirectory())
  167. << "\n";
  168. fout << "CMAKE_SOURCE_DIR = "
  169. << ShortPath(m_Makefile->GetHomeDirectory()) << "\n";
  170. fout << "CMAKE_BINARY_DIR = "
  171. << ShortPath(m_Makefile->GetHomeOutputDirectory() )
  172. << "\n";
  173. // Output Include paths
  174. fout << "INCLUDE_FLAGS = ";
  175. std::vector<std::string>& includes = m_Makefile->GetIncludeDirectories();
  176. std::vector<std::string>::iterator i;
  177. fout << "-I" << cmSystemTools::EscapeSpaces(m_Makefile->GetStartDirectory()) << " ";
  178. for(i = includes.begin(); i != includes.end(); ++i)
  179. {
  180. std::string include = *i;
  181. // Don't output a -I for the standard include path "/usr/include".
  182. // This can cause problems with certain standard library
  183. // implementations because the wrong headers may be found first.
  184. if(include != "/usr/include")
  185. {
  186. fout << "-I" << cmSystemTools::EscapeSpaces(i->c_str()).c_str() << " ";
  187. }
  188. }
  189. fout << m_Makefile->GetDefineFlags();
  190. fout << "\n\n";
  191. }
  192. void cmNMakeMakefileGenerator::BuildInSubDirectory(std::ostream& fout,
  193. const char* directory,
  194. const char* target1,
  195. const char* target2)
  196. {
  197. if(target1)
  198. {
  199. std::string dir = directory;
  200. cmSystemTools::ConvertToWindowsSlashes(dir);
  201. fout << "\tif not exist " << cmSystemTools::EscapeSpaces(dir.c_str())
  202. << " "
  203. << "$(MAKE) rebuild_cache\n"
  204. << "\tcd .\\" << directory << "\n"
  205. << "\t$(MAKE) -$(MAKEFLAGS) " << target1 << "\n";
  206. }
  207. if(target2)
  208. {
  209. fout << "\t$(MAKE) -$(MAKEFLAGS) " << target2 << "\n";
  210. }
  211. std::string currentDir = m_Makefile->GetCurrentOutputDirectory();
  212. cmSystemTools::ConvertToWindowsSlashes(currentDir);
  213. fout << "\tcd " << cmSystemTools::EscapeSpaces(currentDir.c_str()) << "\n";
  214. }
  215. // This needs to be overriden because nmake requires commands to be quoted
  216. // if the are full paths to the executable????
  217. void cmNMakeMakefileGenerator::OutputMakeRule(std::ostream& fout,
  218. const char* comment,
  219. const char* target,
  220. const char* depends,
  221. const char* command,
  222. const char* command2,
  223. const char* command3,
  224. const char* command4)
  225. {
  226. if(!target)
  227. {
  228. cmSystemTools::Error("no target for OutputMakeRule");
  229. return;
  230. }
  231. std::string replace;
  232. if(comment)
  233. {
  234. replace = comment;
  235. m_Makefile->ExpandVariablesInString(replace);
  236. fout << "#---------------------------------------------------------\n";
  237. fout << "# " << comment;
  238. fout << "\n#\n";
  239. }
  240. fout << "\n";
  241. replace = target;
  242. m_Makefile->ExpandVariablesInString(replace);
  243. replace = cmSystemTools::EscapeSpaces(replace.c_str());
  244. fout << replace.c_str() << ": ";
  245. if(depends)
  246. {
  247. replace = depends;
  248. m_Makefile->ExpandVariablesInString(replace);
  249. fout << replace.c_str();
  250. }
  251. fout << "\n";
  252. const char* startCommand = "\t\"";
  253. const char* endCommand = "\"\n";
  254. if(!m_QuoteNextCommand)
  255. {
  256. startCommand = "\t";
  257. endCommand = "\n";
  258. }
  259. if(command)
  260. {
  261. replace = ShortPathCommand(command);
  262. m_Makefile->ExpandVariablesInString(replace);
  263. fout << startCommand << replace.c_str() << endCommand;
  264. }
  265. if(command2)
  266. {
  267. replace = ShortPathCommand(command2);
  268. m_Makefile->ExpandVariablesInString(replace);
  269. fout << startCommand << replace.c_str() << endCommand;
  270. }
  271. if(command3)
  272. {
  273. replace = ShortPathCommand(command3);
  274. m_Makefile->ExpandVariablesInString(replace);
  275. fout << startCommand << replace.c_str() << endCommand;
  276. }
  277. if(command4)
  278. {
  279. replace = ShortPathCommand(command4);
  280. m_Makefile->ExpandVariablesInString(replace);
  281. fout << startCommand << replace.c_str() << endCommand;
  282. }
  283. fout << "\n";
  284. // reset m_QuoteNextCommand, as the default should be to quote the
  285. // commands. We need the quotes when the command has a full path
  286. // to an executable. However, the quotes break things like the
  287. // linker command.
  288. m_QuoteNextCommand = true;
  289. }
  290. void
  291. cmNMakeMakefileGenerator::
  292. OutputBuildObjectFromSource(std::ostream& fout,
  293. const char* shortName,
  294. const cmSourceFile& source,
  295. const char* extraCompileFlags,
  296. bool shared)
  297. {
  298. std::string comment = "Build ";
  299. std::string objectFile = std::string(shortName) +
  300. this->GetOutputExtension(source.GetSourceExtension().c_str());
  301. comment += objectFile + " From ";
  302. comment += source.GetFullPath();
  303. std::string compileCommand;
  304. std::string ext = source.GetSourceExtension();
  305. if(ext == "c" )
  306. {
  307. compileCommand = "$(CMAKE_C_COMPILER) $(CMAKE_C_FLAGS) ";
  308. compileCommand += extraCompileFlags;
  309. if(shared)
  310. {
  311. compileCommand += "$(CMAKE_SHLIB_CFLAGS) ";
  312. }
  313. compileCommand += "$(INCLUDE_FLAGS) -c ";
  314. compileCommand +=
  315. cmSystemTools::EscapeSpaces(source.GetFullPath().c_str());
  316. compileCommand += " $(CMAKE_C_OUTPUT_OBJECT_FILE_FLAG)";
  317. compileCommand += objectFile;
  318. }
  319. else if (ext == "rc")
  320. {
  321. compileCommand = "$(RC) /fo\"";
  322. compileCommand += objectFile;
  323. compileCommand += "\" ";
  324. compileCommand +=
  325. cmSystemTools::EscapeSpaces(source.GetFullPath().c_str());
  326. }
  327. else if (ext == "def")
  328. {
  329. // no rule to output for this one
  330. return;
  331. }
  332. // assume c++ if not c rc or def
  333. else
  334. {
  335. compileCommand = "$(CMAKE_CXX_COMPILER) $(CMAKE_CXXFLAGS) ";
  336. compileCommand += extraCompileFlags;
  337. if(shared)
  338. {
  339. compileCommand += "$(CMAKE_SHLIB_CFLAGS) ";
  340. }
  341. compileCommand += "$(INCLUDE_FLAGS) -c ";
  342. compileCommand +=
  343. cmSystemTools::EscapeSpaces(source.GetFullPath().c_str());
  344. compileCommand += " $(CMAKE_C_OUTPUT_OBJECT_FILE_FLAG)";
  345. compileCommand += objectFile;
  346. }
  347. m_QuoteNextCommand = false;
  348. this->OutputMakeRule(fout,
  349. comment.c_str(),
  350. objectFile.c_str(),
  351. cmSystemTools::EscapeSpaces(
  352. source.GetFullPath().c_str()).c_str(),
  353. compileCommand.c_str());
  354. }
  355. void cmNMakeMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
  356. const char* name,
  357. const cmTarget &t)
  358. {
  359. std::string target = m_LibraryOutputPath + name + m_SharedLibraryExtension;
  360. std::string depend = "$(";
  361. depend += name;
  362. depend += "_SRC_OBJS) $(" + std::string(name) + "_DEPEND_LIBS)";
  363. std::string command = "$(CMAKE_LINKER) $(CMAKE_LINKER_SHARED_LIBRARY_FLAG) $(CMAKE_LINKER_FLAGS) @<<\n\t";
  364. command += " $(" + std::string(name) + "_SRC_OBJS) $(CMAKE_LINKER_OUTPUT_FILE_FLAG)";
  365. std::string dllpath = m_LibraryOutputPath + std::string(name) + m_SharedLibraryExtension;
  366. command += cmSystemTools::EscapeSpaces(dllpath.c_str());
  367. command += " ";
  368. std::strstream linklibs;
  369. this->OutputLinkLibraries(linklibs, name, t);
  370. linklibs << std::ends;
  371. command += linklibs.str();
  372. delete [] linklibs.str();
  373. const std::vector<cmSourceFile>& sources = t.GetSourceFiles();
  374. for(std::vector<cmSourceFile>::const_iterator i = sources.begin();
  375. i != sources.end(); ++i)
  376. {
  377. if(i->GetSourceExtension() == "def")
  378. {
  379. command += "/DEF:";
  380. command += i->GetFullPath();
  381. }
  382. }
  383. command += "\n<<\n";
  384. m_QuoteNextCommand = false;
  385. this->OutputMakeRule(fout, "rules for a shared library",
  386. target.c_str(),
  387. depend.c_str(),
  388. command.c_str());
  389. }
  390. void cmNMakeMakefileGenerator::OutputModuleLibraryRule(std::ostream& fout,
  391. const char* name,
  392. const cmTarget &target)
  393. {
  394. this->OutputSharedLibraryRule(fout, name, target);
  395. }
  396. void cmNMakeMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
  397. const char* name,
  398. const cmTarget &)
  399. {
  400. std::string target = m_LibraryOutputPath + std::string(name) + m_StaticLibraryExtension;
  401. std::string depend = "$(";
  402. depend += std::string(name) + "_SRC_OBJS)";
  403. std::string command = "$(CMAKE_LINKER) $(CMAKE_LINKER_STATIC_LIBRARY_FLAG) $(CMAKE_LINKER_FLAGS) @<<\n\t $(CMAKE_LINKER_OUTPUT_FILE_FLAG)";
  404. std::string libpath = m_LibraryOutputPath + std::string(name) + m_StaticLibraryExtension;
  405. command += cmSystemTools::EscapeSpaces(libpath.c_str());
  406. command += " $(";
  407. command += std::string(name) + "_SRC_OBJS)";
  408. command += "\n<<\n";
  409. std::string comment = "rule to build static library: ";
  410. comment += name;
  411. m_QuoteNextCommand = false;
  412. this->OutputMakeRule(fout,
  413. comment.c_str(),
  414. target.c_str(),
  415. depend.c_str(),
  416. command.c_str());
  417. }
  418. void cmNMakeMakefileGenerator::OutputExecutableRule(std::ostream& fout,
  419. const char* name,
  420. const cmTarget &t)
  421. {
  422. std::string target = m_ExecutableOutputPath + name;
  423. target += m_ExecutableExtension;
  424. std::string depend = "$(";
  425. depend += std::string(name) + "_SRC_OBJS) $(" + std::string(name) + "_DEPEND_LIBS)";
  426. std::string command =
  427. "$(CMAKE_CXX_COMPILER) $(CMAKE_CXXFLAGS) ";
  428. command += "$(" + std::string(name) + "_SRC_OBJS) ";
  429. std::string path = m_ExecutableOutputPath + name + m_ExecutableExtension;
  430. command += " $(CMAKE_C_OUTPUT_EXECUTABLE_FILE_FLAG)" +
  431. cmSystemTools::EscapeSpaces(path.c_str());
  432. command += " $(CMAKE_C_LINK_EXECUTABLE_FLAG) ";
  433. if(t.GetType() == cmTarget::WIN32_EXECUTABLE)
  434. {
  435. command += " /subsystem:windows ";
  436. }
  437. std::strstream linklibs;
  438. this->OutputLinkLibraries(linklibs, 0, t);
  439. linklibs << std::ends;
  440. command += linklibs.str();
  441. std::string comment = "rule to build executable: ";
  442. comment += name;
  443. m_QuoteNextCommand = false;
  444. this->OutputMakeRule(fout,
  445. comment.c_str(),
  446. target.c_str(),
  447. depend.c_str(),
  448. command.c_str());
  449. }
  450. void cmNMakeMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
  451. const char* targetLibrary,
  452. const cmTarget &tgt)
  453. {
  454. // Try to emit each search path once
  455. std::set<std::string> emitted;
  456. // Embed runtime search paths if possible and if required.
  457. // collect all the flags needed for linking libraries
  458. std::string linkLibs;
  459. std::vector<std::string>& libdirs = m_Makefile->GetLinkDirectories();
  460. for(std::vector<std::string>::iterator libDir = libdirs.begin();
  461. libDir != libdirs.end(); ++libDir)
  462. {
  463. std::string libpath = ShortPath(libDir->c_str());
  464. if(emitted.insert(libpath).second)
  465. {
  466. linkLibs += m_LibraryPathOption;
  467. cmSystemTools::ConvertToWindowsSlashes(libpath);
  468. linkLibs += libpath;
  469. linkLibs += " ";
  470. }
  471. }
  472. std::string librariesLinked;
  473. const cmTarget::LinkLibraries& libs = tgt.GetLinkLibraries();
  474. for(cmTarget::LinkLibraries::const_iterator lib = libs.begin();
  475. lib != libs.end(); ++lib)
  476. {
  477. // Don't link the library against itself!
  478. if(targetLibrary && (lib->first == targetLibrary)) continue;
  479. // ** should fix this later, it should check to see if this is
  480. // a debug build and add the library
  481. // don't look at debug libraries
  482. // if (lib->second == cmTarget::DEBUG) continue;
  483. // skip zero size library entries, this may happen
  484. // if a variable expands to nothing.
  485. if (lib->first.size() == 0) continue;
  486. if(emitted.insert(lib->first).second)
  487. {
  488. std::string regexp = ".*\\";
  489. regexp += m_Makefile->GetDefinition("CMAKE_STATICLIB_SUFFIX");
  490. regexp += "$";
  491. cmRegularExpression reg(regexp.c_str());
  492. // if it ends in .lib, then it is a full path and should
  493. // be escaped, and does not need .lib added
  494. if(reg.find(lib->first))
  495. {
  496. librariesLinked += ShortPath(lib->first.c_str());
  497. librariesLinked += " ";
  498. }
  499. else
  500. {
  501. librariesLinked += m_LibraryLinkOption;
  502. librariesLinked += lib->first;
  503. librariesLinked += m_StaticLibraryExtension + " ";
  504. }
  505. }
  506. }
  507. linkLibs += librariesLinked;
  508. fout << linkLibs;
  509. fout << "$(CMAKE_STANDARD_WINDOWS_LIBRARIES) ";
  510. }
  511. std::string cmNMakeMakefileGenerator::GetOutputExtension(const char* s)
  512. {
  513. std::string sourceExtension = s;
  514. if(sourceExtension == "def")
  515. {
  516. return "";
  517. }
  518. if(sourceExtension == "ico" || sourceExtension == "rc2")
  519. {
  520. return "";
  521. }
  522. if(sourceExtension == "rc")
  523. {
  524. return ".res";
  525. }
  526. return m_ObjectFileExtension;
  527. }
  528. void cmNMakeMakefileGenerator::OutputIncludeMakefile(std::ostream& fout,
  529. const char* file)
  530. {
  531. fout << "!include " << file << "\n";
  532. }
  533. bool cmNMakeMakefileGenerator::SamePath(const char* path1, const char* path2)
  534. {
  535. // first check to see if they are the same anyway
  536. if (strcmp(path1, path2) == 0)
  537. {
  538. return true;
  539. }
  540. // next short path and lower case both of them for the compare
  541. return
  542. cmSystemTools::LowerCase(ShortPath(path1)) ==
  543. cmSystemTools::LowerCase(ShortPath(path2));
  544. }
  545. void cmNMakeMakefileGenerator::OutputBuildLibraryInDir(std::ostream& fout,
  546. const char* path,
  547. const char* ,
  548. const char* fullpath)
  549. {
  550. std::string currentDir = m_Makefile->GetCurrentOutputDirectory();
  551. cmSystemTools::ConvertToWindowsSlashes(currentDir);
  552. fout << cmSystemTools::EscapeSpaces(fullpath)
  553. << ":\n\tcd " << cmSystemTools::EscapeSpaces(path)
  554. << "\n\t$(MAKE) " << cmSystemTools::EscapeSpaces(fullpath)
  555. << "\n\tcd " <<
  556. cmSystemTools::EscapeSpaces(currentDir.c_str()) << "\n";
  557. }