1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmUnixMakefileGenerator.cxx,v $
6 Date: $Date: 2002-07-31 17:45:07 $
7 Version: $Revision: 1.224 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmUnixMakefileGenerator.h"
18 #include "cmMakefile.h"
19 #include "cmStandardIncludes.h"
20 #include "cmSystemTools.h"
21 #include "cmSourceFile.h"
22 #include "cmMakeDepend.h"
23 #include "cmCacheManager.h"
24 #include "cmGeneratedFileStream.h"
26 cmUnixMakefileGenerator::cmUnixMakefileGenerator()
27 :m_SharedLibraryExtension("$(SHLIB_SUFFIX)"),
28 m_ObjectFileExtension(".o"),
29 m_ExecutableExtension(""),
30 m_StaticLibraryExtension(".a"),
31 m_LibraryPrefix("lib")
37 cmUnixMakefileGenerator::~cmUnixMakefileGenerator()
42 void cmUnixMakefileGenerator::GenerateMakefile()
44 // for backwards compatibility if niether c or cxx is
45 // enabled, the enable cxx
46 if(! (this->GetLanguageEnabled("C") ||
47 this->GetLanguageEnabled("CXX")))
49 this->EnableLanguage("CXX");
53 // suppoirt override in output directories
54 if (m_Makefile
->GetDefinition("LIBRARY_OUTPUT_PATH"))
56 m_LibraryOutputPath
= m_Makefile
->GetDefinition("LIBRARY_OUTPUT_PATH");
57 if(m_LibraryOutputPath
.size())
59 if(m_LibraryOutputPath
[m_LibraryOutputPath
.size() -1] != '/')
61 m_LibraryOutputPath
+= "/";
63 if(!cmSystemTools::MakeDirectory(m_LibraryOutputPath
.c_str()))
65 cmSystemTools::Error("Error failed create "
66 "LIBRARY_OUTPUT_PATH directory:",
67 m_LibraryOutputPath
.c_str());
69 m_Makefile
->AddLinkDirectory(m_LibraryOutputPath
.c_str());
72 if (m_Makefile
->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
74 m_ExecutableOutputPath
=
75 m_Makefile
->GetDefinition("EXECUTABLE_OUTPUT_PATH");
76 if(m_ExecutableOutputPath
.size())
78 if(m_ExecutableOutputPath
[m_ExecutableOutputPath
.size() -1] != '/')
80 m_ExecutableOutputPath
+= "/";
82 if(!cmSystemTools::MakeDirectory(m_ExecutableOutputPath
.c_str()))
84 cmSystemTools::Error("Error failed to create "
85 "EXECUTABLE_OUTPUT_PATH directory:",
86 m_ExecutableOutputPath
.c_str());
88 m_Makefile
->AddLinkDirectory(m_ExecutableOutputPath
.c_str());
95 // Generate the cache only stuff
96 this->GenerateCacheOnly();
97 // if recurse then generate for all sub- makefiles
100 this->RecursiveGenerateCacheOnly();
103 // normal makefile output
108 md
.SetMakefile(m_Makefile
);
109 md
.GenerateMakefileDependencies();
110 this->ProcessDepends(md
);
111 // output the makefile fragment
112 this->OutputMakefile("Makefile");
116 void cmUnixMakefileGenerator::ProcessDepends(const cmMakeDepend
&md
)
118 // Now create cmDependInformation objects for files in the directory
119 cmTargets
&tgts
= m_Makefile
->GetTargets();
120 for(cmTargets::iterator l
= tgts
.begin(); l
!= tgts
.end(); l
++)
122 std::vector
<cmSourceFile
*> &classes
= l
->second
.GetSourceFiles();
123 for(std::vector
<cmSourceFile
*>::iterator i
= classes
.begin();
124 i
!= classes
.end(); ++i
)
126 if(!(*i
)->GetIsAHeaderFileOnly())
129 const cmDependInformation
*info
=
130 md
.GetDependInformationForSourceFile(*(*i
));
132 // Delete any hints from the source file's dependencies.
133 (*i
)->GetDepends().erase((*i
)->GetDepends().begin(), (*i
)->GetDepends().end());
135 // Now add the real dependencies for the file.
138 for(cmDependInformation::DependencySet::const_iterator d
=
139 info
->m_DependencySet
.begin();
140 d
!= info
->m_DependencySet
.end(); ++d
)
142 // Make sure the full path is given. If not, the dependency was
144 if((*d
)->m_FullPath
!= "")
146 (*i
)->GetDepends().push_back((*d
)->m_FullPath
);
156 // This is where CMakeTargets.make is generated
157 void cmUnixMakefileGenerator::OutputMakefile(const char* file
)
159 // Create sub directories fro aux source directories
160 std::vector
<std::string
>& auxSourceDirs
=
161 m_Makefile
->GetAuxSourceDirectories();
162 if( auxSourceDirs
.size() )
164 // For the case when this is running as a remote build
165 // on unix, make the directory
166 for(std::vector
<std::string
>::iterator i
= auxSourceDirs
.begin();
167 i
!= auxSourceDirs
.end(); ++i
)
169 if(i
->c_str()[0] != '/')
171 std::string dir
= m_Makefile
->GetCurrentOutputDirectory();
172 if(dir
.size() && dir
[dir
.size()-1] != '/')
177 cmSystemTools::MakeDirectory(dir
.c_str());
181 cmSystemTools::MakeDirectory(i
->c_str());
185 // Create a stream that writes to a temporary file
186 // then does a copy at the end. This is to allow users
187 // to hit control-c during the make of the makefile
188 cmGeneratedFileStream
tempFile(file
);
189 tempFile
.SetAlwaysCopy(true);
190 std::ostream
& fout
= tempFile
.GetStream();
193 cmSystemTools::Error("Error can not open for write: ", file
);
196 fout
<< "# CMAKE generated Makefile, DO NOT EDIT!\n"
197 << "# Generated by \"" << this->GetName() << "\""
198 << " Generator, CMake Version "
199 << cmMakefile::GetMajorVersion() << "."
200 << cmMakefile::GetMinorVersion() << "\n"
201 << "# Generated from the following files:\n# "
202 << m_Makefile
->GetHomeOutputDirectory() << "/CMakeCache.txt\n";
203 std::vector
<std::string
> lfiles
= m_Makefile
->GetListFiles();
205 std::sort(lfiles
.begin(), lfiles
.end(), std::less
<std::string
>());
207 std::vector
<std::string
>::iterator new_end
=
208 std::unique(lfiles
.begin(), lfiles
.end());
209 lfiles
.erase(new_end
, lfiles
.end());
211 for(std::vector
<std::string
>::const_iterator i
= lfiles
.begin();
212 i
!= lfiles
.end(); ++i
)
214 fout
<< "# " << i
->c_str() << "\n";
217 fout
<< "# Suppresses display of executed commands\n";
218 fout
<< ".SILENT:\n";
219 fout
<< "# disable some common implicit rules to speed things up\n";
220 fout
<< ".SUFFIXES:\n";
221 fout
<< ".SUFFIXES:.hpuxmakemusthaverule\n";
222 // create a make variable with all of the sources for this Makefile
223 // for depend purposes.
224 fout
<< "CMAKE_MAKEFILE_SOURCES = ";
225 for(std::vector
<std::string
>::const_iterator i
= lfiles
.begin();
226 i
!= lfiles
.end(); ++i
)
228 fout
<< " " << this->ConvertToOutputPath(i
->c_str());
230 // Add the cache to the list
231 std::string cacheFile
= m_Makefile
->GetHomeOutputDirectory();
232 cacheFile
+= "/CMakeCache.txt";
233 fout
<< " " << this->ConvertToOutputPath(cacheFile
.c_str());
235 this->OutputMakeVariables(fout
);
236 // Set up the default target as the VERY first target, so that make with no arguments will run it
239 "Default target executed when no arguments are given to make, first make sure cmake.depends exists, cmake.check_depends is up-to-date, check the sources, then build the all target",
242 "$(MAKE) $(MAKESILENT) cmake.depends",
243 "$(MAKE) $(MAKESILENT) cmake.check_depends",
244 "$(MAKE) $(MAKESILENT) -f cmake.check_depends",
245 "$(MAKE) $(MAKESILENT) all");
247 this->OutputTargetRules(fout
);
248 this->OutputDependLibs(fout
);
249 this->OutputTargets(fout
);
250 this->OutputSubDirectoryRules(fout
);
251 std::string dependName
= m_Makefile
->GetStartOutputDirectory();
252 dependName
+= "/cmake.depends";
253 if(!this->m_CacheOnly
)
255 std::ofstream
dependout(dependName
.c_str());
258 cmSystemTools::Error("Error can not open for write: ", dependName
.c_str());
261 dependout
<< "# .o dependencies in this directory." << std::endl
;
263 std::string checkDepend
= m_Makefile
->GetStartOutputDirectory();
264 checkDepend
+= "/cmake.check_depends";
265 std::ofstream
checkdependout(checkDepend
.c_str());
268 cmSystemTools::Error("Error can not open for write: ", checkDepend
.c_str());
271 checkdependout
<< "# This file is used as a tag file, that all sources depend on. If a source changes, then the rule to rebuild this file will cause cmake.depends to be rebuilt." << std::endl
;
272 // if there were any depends output, then output the check depends
273 // information inot checkdependout
274 if(this->OutputObjectDepends(dependout
))
276 this->OutputCheckDepends(checkdependout
);
280 checkdependout
<< "all:\n\t@echo cmake.depends is up-to-date\n";
283 this->OutputCustomRules(fout
);
284 this->OutputMakeRules(fout
);
285 this->OutputInstallRules(fout
);
286 // only add the depend include if the depend file exists
287 if(cmSystemTools::FileExists(dependName
.c_str()))
289 this->OutputIncludeMakefile(fout
, "cmake.depends");
293 void cmUnixMakefileGenerator::OutputIncludeMakefile(std::ostream
& fout
,
296 fout
<< "include " << file
<< "\n";
301 cmUnixMakefileGenerator::GetOutputExtension(const char*)
303 return m_ObjectFileExtension
;
308 // Output the rules for any targets
309 void cmUnixMakefileGenerator::OutputTargetRules(std::ostream
& fout
)
311 // for each target add to the list of targets
312 fout
<< "TARGETS = ";
313 const cmTargets
&tgts
= m_Makefile
->GetTargets();
314 // list libraries first
315 for(cmTargets::const_iterator l
= tgts
.begin();
316 l
!= tgts
.end(); l
++)
318 if (l
->second
.IsInAll())
320 std::string path
= m_LibraryOutputPath
+ m_LibraryPrefix
;
321 if(l
->second
.GetType() == cmTarget::STATIC_LIBRARY
)
323 path
= path
+ l
->first
+ m_StaticLibraryExtension
;
325 << this->ConvertToOutputPath(path
.c_str());
327 else if(l
->second
.GetType() == cmTarget::SHARED_LIBRARY
)
329 path
= path
+ l
->first
+
330 m_Makefile
->GetDefinition("CMAKE_SHLIB_SUFFIX");
332 << this->ConvertToOutputPath(path
.c_str());
334 else if(l
->second
.GetType() == cmTarget::MODULE_LIBRARY
)
336 path
= path
+ l
->first
+
337 m_Makefile
->GetDefinition("CMAKE_MODULE_SUFFIX");
339 << this->ConvertToOutputPath(path
.c_str());
344 for(cmTargets::const_iterator l
= tgts
.begin();
345 l
!= tgts
.end(); l
++)
347 if ((l
->second
.GetType() == cmTarget::EXECUTABLE
||
348 l
->second
.GetType() == cmTarget::WIN32_EXECUTABLE
) &&
351 std::string path
= m_ExecutableOutputPath
+ l
->first
+
352 m_ExecutableExtension
;
353 fout
<< " \\\n" << this->ConvertToOutputPath(path
.c_str());
356 // list utilities last
357 for(cmTargets::const_iterator l
= tgts
.begin();
358 l
!= tgts
.end(); l
++)
360 if (l
->second
.GetType() == cmTarget::UTILITY
&&
363 fout
<< " \\\n" << l
->first
.c_str();
367 // get the classes from the source lists then add them to the groups
368 for(cmTargets::const_iterator l
= tgts
.begin();
369 l
!= tgts
.end(); l
++)
371 std::vector
<cmSourceFile
*> classes
= l
->second
.GetSourceFiles();
372 if (classes
.begin() != classes
.end())
374 fout
<< this->CreateMakeVariable(l
->first
.c_str(), "_SRC_OBJS") << " = ";
375 for(std::vector
<cmSourceFile
*>::iterator i
= classes
.begin();
376 i
!= classes
.end(); i
++)
378 if(!(*i
)->IsAHeaderFileOnly())
380 std::string
outExt(this->GetOutputExtension((*i
)->GetSourceExtension().c_str()));
383 fout
<< "\\\n" << this->ConvertToOutputPath((*i
)->GetSourceName().c_str())
384 << outExt
.c_str() << " ";
389 fout
<< this->CreateMakeVariable(l
->first
.c_str(), "_SRC_OBJS_QUOTED") << " = ";
390 for(std::vector
<cmSourceFile
*>::iterator i
= classes
.begin();
391 i
!= classes
.end(); i
++)
393 if(!(*i
)->IsAHeaderFileOnly())
395 std::string
outExt(this->GetOutputExtension((*i
)->GetSourceExtension().c_str()));
398 fout
<< "\\\n\"" << this->ConvertToOutputPath((*i
)->GetSourceName().c_str())
399 << outExt
.c_str() << "\" ";
406 fout
<< "CLEAN_OBJECT_FILES = ";
407 for(cmTargets::const_iterator l
= tgts
.begin();
408 l
!= tgts
.end(); l
++)
410 std::vector
<cmSourceFile
*> classes
= l
->second
.GetSourceFiles();
411 if (classes
.begin() != classes
.end())
413 fout
<< "$(" << this->CreateMakeVariable(l
->first
.c_str(), "_SRC_OBJS")
422 * Output the linking rules on a command line. For executables,
423 * targetLibrary should be a NULL pointer. For libraries, it should point
424 * to the name of the library. This will not link a library against itself.
426 void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream
& fout
,
427 const char* targetLibrary
,
430 // Try to emit each search path once
431 std::set
<std::string
> emitted
;
433 // Embed runtime search paths if possible and if required.
434 bool outputRuntime
= true;
435 std::string runtimeFlag
;
436 std::string runtimeSep
;
437 std::vector
<std::string
> runtimeDirs
;
439 bool cxx
= tgt
.HasCxx();
442 // if linking a c executable use the C runtime flag as cc
443 // may not be the same program that creates shared libaries
444 // and may have different flags
445 if( tgt
.GetType() == cmTarget::EXECUTABLE
)
447 if(m_Makefile
->GetDefinition("CMAKE_C_SHLIB_RUNTIME_FLAG"))
449 runtimeFlag
= m_Makefile
->GetDefinition("CMAKE_C_SHLIB_RUNTIME_FLAG");
454 if(m_Makefile
->GetDefinition("CMAKE_SHLIB_RUNTIME_FLAG"))
456 runtimeFlag
= m_Makefile
->GetDefinition("CMAKE_SHLIB_RUNTIME_FLAG");
459 if(m_Makefile
->GetDefinition("CMAKE_SHLIB_RUNTIME_SEP"))
461 runtimeSep
= m_Makefile
->GetDefinition("CMAKE_SHLIB_RUNTIME_SEP");
466 if(m_Makefile
->GetDefinition("CMAKE_CXX_SHLIB_RUNTIME_FLAG"))
468 runtimeFlag
= m_Makefile
->GetDefinition("CMAKE_CXX_SHLIB_RUNTIME_FLAG");
471 if(m_Makefile
->GetDefinition("CMAKE_CXX_SHLIB_RUNTIME_SEP"))
473 runtimeSep
= m_Makefile
->GetDefinition("CMAKE_CXX_SHLIB_RUNTIME_SEP");
479 // concatenate all paths or no?
480 bool runtimeConcatenate
= ( runtimeSep
!="" );
481 if(runtimeFlag
== "" || m_Makefile
->IsOn("CMAKE_SKIP_RPATH") )
483 outputRuntime
= false;
486 // Some search paths should never be emitted
488 emitted
.insert("/usr/lib");
490 // collect all the flags needed for linking libraries
491 std::string linkLibs
;
492 const std::vector
<std::string
>& libdirs
= tgt
.GetLinkDirectories();
493 for(std::vector
<std::string
>::const_iterator libDir
= libdirs
.begin();
494 libDir
!= libdirs
.end(); ++libDir
)
496 std::string libpath
= this->ConvertToOutputPath(libDir
->c_str());
497 if(emitted
.insert(libpath
).second
)
499 std::string::size_type pos
= libDir
->find("-L");
500 if((pos
== std::string::npos
|| pos
> 0)
501 && libDir
->find("${") == std::string::npos
)
506 runtimeDirs
.push_back( libpath
);
514 std::string librariesLinked
;
515 const cmTarget::LinkLibraries
& libs
= tgt
.GetLinkLibraries();
516 for(cmTarget::LinkLibraries::const_iterator lib
= libs
.begin();
517 lib
!= libs
.end(); ++lib
)
519 // Don't link the library against itself!
520 if(targetLibrary
&& (lib
->first
== targetLibrary
)) continue;
521 // don't look at debug libraries
522 if (lib
->second
== cmTarget::DEBUG
) continue;
523 // skip zero size library entries, this may happen
524 // if a variable expands to nothing.
525 if (lib
->first
.size() == 0) continue;
526 // if it is a full path break it into -L and -l
527 cmRegularExpression
reg("([ \t]*\\-l)|([ \t]*\\-framework)|(\\${)");
528 if(lib
->first
.find('/') != std::string::npos
529 && !reg
.find(lib
->first
))
531 std::string dir
, file
;
532 cmSystemTools::SplitProgramPath(lib
->first
.c_str(),
534 std::string libpath
= this->ConvertToOutputPath(dir
.c_str());
535 if(emitted
.insert(libpath
).second
)
542 runtimeDirs
.push_back( libpath
);
545 cmRegularExpression
libname("lib(.*)(\\.so|\\.sl|\\.a|\\.dylib).*");
546 cmRegularExpression
libname_noprefix("(.*)(\\.so|\\.sl|\\.a|\\.dylib).*");
547 if(libname
.find(file
))
549 librariesLinked
+= "-l";
550 file
= libname
.match(1);
551 librariesLinked
+= file
;
552 librariesLinked
+= " ";
554 else if(libname_noprefix
.find(file
))
556 librariesLinked
+= "-l";
557 file
= libname_noprefix
.match(1);
558 librariesLinked
+= file
;
559 librariesLinked
+= " ";
562 // not a full path, so add -l name
565 if(!reg
.find(lib
->first
))
567 librariesLinked
+= "-l";
569 librariesLinked
+= lib
->first
;
570 librariesLinked
+= " ";
574 linkLibs
+= librariesLinked
;
578 if(outputRuntime
&& runtimeDirs
.size()>0)
580 // For the runtime search directories, do a "-Wl,-rpath,a:b:c" or
581 // a "-R a -R b -R c" type link line
583 std::vector
<std::string
>::iterator itr
= runtimeDirs
.begin();
586 for( ; itr
!= runtimeDirs
.end(); ++itr
)
588 if(runtimeConcatenate
)
590 fout
<< runtimeSep
<< *itr
;
594 fout
<< " " << runtimeFlag
<< *itr
;
602 std::string
cmUnixMakefileGenerator::CreateTargetRules(const cmTarget
&target
,
603 const char* targetName
)
605 std::string customRuleCode
= "";
606 bool initNext
= false;
607 for (std::vector
<cmCustomCommand
>::const_iterator cr
=
608 target
.GetCustomCommands().begin();
609 cr
!= target
.GetCustomCommands().end(); ++cr
)
611 cmCustomCommand
cc(*cr
);
612 cc
.ExpandVariables(*m_Makefile
);
613 if (cc
.GetSourceName() == targetName
)
617 customRuleCode
+= "\n\t";
623 std::string command
= this->ConvertToOutputPath(cc
.GetCommand().c_str());
624 customRuleCode
+= command
+ " " + cc
.GetArguments();
627 return customRuleCode
;
631 void cmUnixMakefileGenerator::OutputSharedLibraryRule(std::ostream
& fout
,
635 std::string target
= m_LibraryOutputPath
+ "lib" + name
+ "$(SHLIB_SUFFIX)";
636 std::string depend
= "$(";
637 depend
+= this->CreateMakeVariable(name
, "_SRC_OBJS");
638 depend
+= ") $(" + this->CreateMakeVariable(name
, "_DEPEND_LIBS") + ")";
639 std::string command
= "$(RM) lib";
641 command
+= "$(SHLIB_SUFFIX)";
642 std::string command2
;
645 command2
= "$(CMAKE_CXX_LINK_SHARED) $(CMAKE_CXX_SHLIB_LINK_FLAGS) "
646 "$(CMAKE_CXX_SHLIB_BUILD_FLAGS) $(CMAKE_CXX_FLAGS) -o \\\n";
650 command2
= "$(CMAKE_C_LINK_SHARED) $(CMAKE_SHLIB_LINK_FLAGS) "
651 "$(CMAKE_SHLIB_BUILD_FLAGS) -o \\\n";
654 std::string libName
= m_LibraryOutputPath
+ "lib" + std::string(name
) + "$(SHLIB_SUFFIX)";
655 libName
= this->ConvertToOutputPath(libName
.c_str());
656 command2
+= libName
+ " \\\n";
657 command2
+= "\t $(" + this->CreateMakeVariable(name
, "_SRC_OBJS") + ") ";
658 cmStringStream linklibs
;
659 this->OutputLinkLibraries(linklibs
, name
, t
);
660 command2
+= linklibs
.str();
661 std::string customCommands
= this->CreateTargetRules(t
, name
);
663 if(customCommands
.size() > 0)
665 cc
= customCommands
.c_str();
667 this->OutputMakeRule(fout
, "rules for a shared library",
675 void cmUnixMakefileGenerator::OutputModuleLibraryRule(std::ostream
& fout
,
679 std::string target
= m_LibraryOutputPath
+ "lib" + std::string(name
) + "$(MODULE_SUFFIX)";
680 std::string depend
= "$(";
681 depend
+= this->CreateMakeVariable(name
, "_SRC_OBJS")
682 + ") $(" + this->CreateMakeVariable(name
, "_DEPEND_LIBS") + ")";
683 std::string command
= "$(RM) lib" + std::string(name
) + "$(MODULE_SUFFIX)";
684 std::string command2
;
687 command2
= "$(CMAKE_CXX_LINK_SHARED) $(CMAKE_CXX_MODULE_LINK_FLAGS) "
688 "$(CMAKE_CXX_MODULE_BUILD_FLAGS) $(CMAKE_CXX_FLAGS) -o \\\n";
692 command2
= "$(CMAKE_C_LINK_SHARED) $(CMAKE_SHLIB_LINK_FLAGS) "
693 "$(CMAKE_SHLIB_BUILD_FLAGS) -o \\\n";
696 std::string libName
= m_LibraryOutputPath
+ "lib" + std::string(name
) + "$(MODULE_SUFFIX)";
697 libName
= this->ConvertToOutputPath(libName
.c_str());
698 command2
+= libName
+ " \\\n";
699 command2
+= "\t $(" + this->CreateMakeVariable(name
, "_SRC_OBJS") + ") ";
700 cmStringStream linklibs
;
701 this->OutputLinkLibraries(linklibs
, std::string(name
).c_str(), t
);
702 command2
+= linklibs
.str();
703 std::string customCommands
= this->CreateTargetRules(t
, name
);
705 if(customCommands
.size() > 0)
707 cc
= customCommands
.c_str();
709 this->OutputMakeRule(fout
, "rules for a shared module library",
718 void cmUnixMakefileGenerator::OutputStaticLibraryRule(std::ostream
& fout
,
722 std::string target
= m_LibraryOutputPath
+ "lib" + std::string(name
) + ".a";
723 target
= this->ConvertToOutputPath(target
.c_str());
724 std::string depend
= "$(";
725 depend
+= this->CreateMakeVariable(name
, "_SRC_OBJS") + ")";
729 command
= "$(CMAKE_CXX_AR) $(CMAKE_CXX_AR_ARGS) ";
733 command
= "$(CMAKE_AR) $(CMAKE_AR_ARGS) ";
737 command
+= this->CreateMakeVariable(name
, "_SRC_OBJS") + ")";
738 std::string command2
= "$(CMAKE_RANLIB) ";
740 std::string comment
= "rule to build static library: ";
742 std::string customCommands
= this->CreateTargetRules(t
, name
);
744 if(customCommands
.size() > 0)
746 cc
= customCommands
.c_str();
748 this->OutputMakeRule(fout
,
757 void cmUnixMakefileGenerator::OutputExecutableRule(std::ostream
& fout
,
761 std::string target
= m_ExecutableOutputPath
+ name
;
762 std::string depend
= "$(";
763 depend
+= this->CreateMakeVariable(name
, "_SRC_OBJS")
764 + ") $(" + this->CreateMakeVariable(name
, "_DEPEND_LIBS") + ")";
769 "$(CMAKE_CXX_COMPILER) $(CMAKE_CXX_SHLIB_LINK_FLAGS) $(CMAKE_CXX_FLAGS) ";
774 "$(CMAKE_C_COMPILER) $(CMAKE_C_SHLIB_LINK_FLAGS) $(CMAKE_C_FLAGS) ";
776 command
+= "$(" + this->CreateMakeVariable(name
, "_SRC_OBJS") + ") ";
777 cmStringStream linklibs
;
778 this->OutputLinkLibraries(linklibs
, 0, t
);
779 command
+= linklibs
.str();
780 std::string outputFile
= m_ExecutableOutputPath
+ name
;
781 command
+= " -o " + this->ConvertToOutputPath(outputFile
.c_str());
782 std::string comment
= "rule to build executable: ";
785 std::string customCommands
= this->CreateTargetRules(t
, name
);
787 if(customCommands
.size() > 0)
789 cc
= customCommands
.c_str();
791 this->OutputMakeRule(fout
,
801 void cmUnixMakefileGenerator::OutputUtilityRule(std::ostream
& fout
,
805 std::string customCommands
= this->CreateTargetRules(t
, name
);
807 if(customCommands
.size() > 0)
809 cc
= customCommands
.c_str();
811 std::string comment
= "Rule to build Utility ";
814 const std::vector
<cmCustomCommand
> &ccs
= t
.GetCustomCommands();
815 for(std::vector
<cmCustomCommand
>::const_iterator i
= ccs
.begin();
818 const std::vector
<std::string
> & dep
= i
->GetDepends();
819 for(std::vector
<std::string
>::const_iterator d
= dep
.begin();
826 this->OutputMakeRule(fout
,
835 void cmUnixMakefileGenerator::OutputTargets(std::ostream
& fout
)
838 const cmTargets
&tgts
= m_Makefile
->GetTargets();
839 for(cmTargets::const_iterator l
= tgts
.begin();
840 l
!= tgts
.end(); l
++)
842 switch(l
->second
.GetType())
844 case cmTarget::STATIC_LIBRARY
:
845 this->OutputStaticLibraryRule(fout
, l
->first
.c_str(), l
->second
);
847 case cmTarget::SHARED_LIBRARY
:
848 this->OutputSharedLibraryRule(fout
, l
->first
.c_str(), l
->second
);
850 case cmTarget::MODULE_LIBRARY
:
851 this->OutputModuleLibraryRule(fout
, l
->first
.c_str(), l
->second
);
853 case cmTarget::EXECUTABLE
:
854 case cmTarget::WIN32_EXECUTABLE
:
855 this->OutputExecutableRule(fout
, l
->first
.c_str(), l
->second
);
857 case cmTarget::UTILITY
:
858 this->OutputUtilityRule(fout
, l
->first
.c_str(), l
->second
);
860 // This is handled by the OutputCustomRules method
861 case cmTarget::INSTALL_FILES
:
862 // This is handled by the OutputInstallRules method
863 case cmTarget::INSTALL_PROGRAMS
:
864 // This is handled by the OutputInstallRules method
872 // For each target that is an executable or shared library, generate
873 // the "<name>_DEPEND_LIBS" variable listing its library dependencies.
874 void cmUnixMakefileGenerator::OutputDependLibs(std::ostream
& fout
)
876 // Build a set of libraries that will be linked into any target in
878 std::set
<std::string
> used
;
881 const cmTargets
&tgts
= m_Makefile
->GetTargets();
882 for(cmTargets::const_iterator l
= tgts
.begin();
883 l
!= tgts
.end(); l
++)
885 // Each dependency should only be emitted once per target.
886 std::set
<std::string
> emitted
;
887 if ((l
->second
.GetType() == cmTarget::SHARED_LIBRARY
)
888 || (l
->second
.GetType() == cmTarget::MODULE_LIBRARY
)
889 || (l
->second
.GetType() == cmTarget::EXECUTABLE
)
890 || (l
->second
.GetType() == cmTarget::WIN32_EXECUTABLE
))
892 fout
<< this->CreateMakeVariable(l
->first
.c_str(), "_DEPEND_LIBS") << " = ";
894 // A library should not depend on itself!
895 emitted
.insert(l
->first
);
897 // Now, look at all link libraries specific to this target.
898 const cmTarget::LinkLibraries
& tlibs
= l
->second
.GetLinkLibraries();
899 for(cmTarget::LinkLibraries::const_iterator lib
= tlibs
.begin();
900 lib
!= tlibs
.end(); ++lib
)
902 // Record that this library was used.
903 used
.insert(lib
->first
);
905 // Don't emit the same library twice for this target.
906 if(emitted
.insert(lib
->first
).second
)
908 // Output this dependency.
909 this->OutputLibDepend(fout
, lib
->first
.c_str());
913 // Now, look at all utilities specific to this target.
914 const std::set
<cmStdString
>& tutils
= l
->second
.GetUtilities();
915 for(std::set
<cmStdString
>::const_iterator util
= tutils
.begin();
916 util
!= tutils
.end(); ++util
)
918 // Record that this utility was used.
921 // Don't emit the same utility twice for this target.
922 if(emitted
.insert(*util
).second
)
924 // Output this dependency.
925 this->OutputExeDepend(fout
, util
->c_str());
935 // Loop over the libraries used and make sure there is a rule to
936 // build them in this makefile. If the library is in another
937 // directory, add a rule to jump to that directory and make sure it
939 for(std::set
<std::string
>::const_iterator lib
= used
.begin();
940 lib
!= used
.end(); ++lib
)
942 // loop over the list of directories that the libraries might
943 // be in, looking for an ADD_LIBRARY(lib...) line. This would
944 // be stored in the cache
945 std::string libPath
= *lib
+ "_CMAKE_PATH";
946 const char* cacheValue
= m_Makefile
->GetDefinition(libPath
.c_str());
947 // if cache and not the current directory add a rule, to
948 // jump into the directory and build for the first time
950 (!this->SamePath(m_Makefile
->GetCurrentOutputDirectory(), cacheValue
)))
952 // add the correct extension
953 std::string ltname
= *lib
+"_LIBRARY_TYPE";
955 = m_Makefile
->GetDefinition(ltname
.c_str());
956 // if it was a library..
959 std::string library
= m_LibraryPrefix
;
961 std::string libpath
= cacheValue
;
962 if(libType
&& std::string(libType
) == "SHARED")
964 library
+= m_Makefile
->GetDefinition("CMAKE_SHLIB_SUFFIX");
966 else if(libType
&& std::string(libType
) == "MODULE")
968 library
+= m_Makefile
->GetDefinition("CMAKE_MODULE_SUFFIX");
970 else if(libType
&& std::string(libType
) == "STATIC")
972 library
+= m_StaticLibraryExtension
;
976 cmSystemTools::Error("Unknown library type!");
979 if(m_LibraryOutputPath
.size())
981 libpath
= m_LibraryOutputPath
;
988 // put out a rule to build the library if it does not exist
989 this->OutputBuildTargetInDir(fout
,
994 GetDefinition("LIBRARY_OUTPUT_PATH")
997 // something other than a library...
1000 std::string exepath
= cacheValue
;
1001 if(m_ExecutableOutputPath
.size())
1003 exepath
= m_ExecutableOutputPath
;
1010 this->OutputBuildTargetInDir(fout
,
1015 GetDefinition("EXECUTABLE_OUTPUT_PATH")
1022 void cmUnixMakefileGenerator::OutputBuildTargetInDir(std::ostream
& fout
,
1024 const char* library
,
1025 const char* fullpath
,
1026 const char* outputPath
)
1028 const char* makeTarget
= library
;
1029 if(outputPath
&& strcmp( outputPath
, "" ) != 0)
1031 makeTarget
= fullpath
;
1033 fout
<< this->ConvertToOutputPath(fullpath
)
1034 << ":\n\tcd " << this->ConvertToOutputPath(path
)
1035 << "; $(MAKE) $(MAKESILENT) cmake.depends"
1036 << "; $(MAKE) $(MAKESILENT) cmake.check_depends"
1037 << "; $(MAKE) $(MAKESILENT) -f cmake.check_depends"
1038 << "; $(MAKE) $(MAKESILENT) "
1039 << this->ConvertToOutputPath(makeTarget
) << "\n\n";
1043 bool cmUnixMakefileGenerator::SamePath(const char* path1
, const char* path2
)
1045 return strcmp(path1
, path2
) == 0;
1048 void cmUnixMakefileGenerator::OutputLibDepend(std::ostream
& fout
,
1051 std::string libPath
= name
;
1052 libPath
+= "_CMAKE_PATH";
1053 const char* cacheValue
= m_Makefile
->GetDefinition(libPath
.c_str());
1056 // if there is a cache value, then this is a library that cmake
1057 // knows how to build, so we can depend on it
1058 std::string libpath
;
1059 if (!this->SamePath(m_Makefile
->GetCurrentOutputDirectory(), cacheValue
))
1061 // if the library is not in the current directory, then get the full
1063 if(m_LibraryOutputPath
.size())
1065 libpath
= m_LibraryOutputPath
;
1066 libpath
+= m_LibraryPrefix
;
1070 libpath
= cacheValue
;
1072 libpath
+= m_LibraryPrefix
;
1077 // library is in current Makefile so use lib as a prefix
1078 libpath
= m_LibraryOutputPath
;
1079 libpath
+= m_LibraryPrefix
;
1081 // add the library name
1083 // add the correct extension
1084 std::string ltname
= name
;
1085 ltname
+= "_LIBRARY_TYPE";
1086 const char* libType
= m_Makefile
->GetDefinition(ltname
.c_str());
1087 if(libType
&& std::string(libType
) == "SHARED")
1089 libpath
+= m_Makefile
->GetDefinition("CMAKE_SHLIB_SUFFIX");
1091 else if (libType
&& std::string(libType
) == "MODULE")
1093 libpath
+= m_Makefile
->GetDefinition("CMAKE_MODULE_SUFFIX");
1095 else if (libType
&& std::string(libType
) == "STATIC")
1097 libpath
+= m_StaticLibraryExtension
;
1099 fout
<< this->ConvertToOutputPath(libpath
.c_str()) << " ";
1104 void cmUnixMakefileGenerator::OutputExeDepend(std::ostream
& fout
,
1107 std::string exePath
= name
;
1108 exePath
+= "_CMAKE_PATH";
1109 const char* cacheValue
= m_Makefile
->GetDefinition(exePath
.c_str());
1112 // if there is a cache value, then this is a executable/utility that cmake
1113 // knows how to build, so we can depend on it
1114 std::string exepath
;
1115 if (!this->SamePath(m_Makefile
->GetCurrentOutputDirectory(), cacheValue
))
1117 // if the exe/utility is not in the current directory, then get the full
1119 if(m_ExecutableOutputPath
.size())
1121 exepath
= m_ExecutableOutputPath
;
1125 exepath
= cacheValue
;
1131 // library is in current Makefile
1132 exepath
= m_ExecutableOutputPath
;
1134 // add the library name
1136 // add the correct extension
1137 if (m_Makefile
->GetDefinition("CMAKE_EXECUTABLE_SUFFIX"))
1139 std::string replaceVars
=
1140 m_Makefile
->GetDefinition("CMAKE_EXECUTABLE_SUFFIX");
1141 if (!strcmp(replaceVars
.c_str(),"@CMAKE_EXECUTABLE_SUFFIX@"))
1145 exepath
+= replaceVars
;
1147 fout
<< this->ConvertToOutputPath(exepath
.c_str()) << " ";
1153 // fix up names of directories so they can be used
1154 // as targets in makefiles.
1155 inline std::string
FixDirectoryName(const char* dir
)
1157 std::string s
= dir
;
1158 // replace ../ with 3 under bars
1159 size_t pos
= s
.find("../");
1160 if(pos
!= std::string::npos
)
1162 s
.replace(pos
, 3, "___");
1164 // replace / directory separators with a single under bar
1166 while(pos
!= std::string::npos
)
1168 s
.replace(pos
, 1, "_");
1175 void cmUnixMakefileGenerator::BuildInSubDirectory(std::ostream
& fout
,
1177 const char* target1
,
1178 const char* target2
,
1181 std::string directory
= this->ConvertToOutputPath(dir
);
1184 fout
<< "\t@if test ! -d " << directory
1185 << "; then $(MAKE) rebuild_cache; fi\n";
1188 fout
<< "\techo " << directory
<< ": building " << target1
<< "\n";
1190 fout
<< "\t@cd " << directory
1191 << "; $(MAKE) " << target1
<< "\n";
1197 fout
<< "\techo " << directory
<< ": building " << target2
<< "\n";
1199 fout
<< "\t@cd " << directory
1200 << "; $(MAKE) " << target2
<< "\n";
1207 cmUnixMakefileGenerator::
1208 OutputSubDirectoryVars(std::ostream
& fout
,
1211 const char* target1
,
1212 const char* target2
,
1214 const std::vector
<std::string
>& SubDirectories
,
1221 if( SubDirectories
.size() == 0)
1225 fout
<< "# Variable for making " << target
<< " in subdirectories.\n";
1226 fout
<< var
<< " = \\\n";
1228 for(i
=0; i
< SubDirectories
.size(); i
++)
1230 std::string subdir
= FixDirectoryName(SubDirectories
[i
].c_str());
1231 fout
<< target
<< "_" << subdir
.c_str();
1232 if(i
== SubDirectories
.size()-1)
1241 fout
<< "# Targets for making " << target
<< " in subdirectories.\n";
1242 std::string last
= "";
1243 for(unsigned int i
=0; i
< SubDirectories
.size(); i
++)
1245 std::string subdir
= FixDirectoryName(SubDirectories
[i
].c_str());
1246 fout
<< target
<< "_" << subdir
.c_str() << ": " << depend
;
1248 // Make each subdirectory depend on previous one. This forces
1249 // parallel builds (make -j 2) to build in same order as a single
1250 // threaded build to avoid dependency problems.
1253 fout
<< " " << target
<< "_" << last
.c_str();
1258 std::string dir
= m_Makefile
->GetCurrentOutputDirectory();
1260 dir
+= SubDirectories
[i
];
1261 this->BuildInSubDirectory(fout
, dir
.c_str(),
1262 target1
, target2
, silent
);
1268 // output rules for decending into sub directories
1269 void cmUnixMakefileGenerator::OutputSubDirectoryRules(std::ostream
& fout
)
1271 // Output Sub directory build rules
1272 const std::vector
<std::string
>& SubDirectories
1273 = m_Makefile
->GetSubDirectories();
1275 if( SubDirectories
.size() == 0)
1279 this->OutputSubDirectoryVars(fout
,
1286 this->OutputSubDirectoryVars(fout
, "SUBDIR_CLEAN", "clean",
1290 this->OutputSubDirectoryVars(fout
, "SUBDIR_DEPEND", "depend",
1294 this->OutputSubDirectoryVars(fout
, "SUBDIR_INSTALL", "install",
1303 // Output the depend information for all the classes
1304 // in the makefile. These would have been generated
1305 // by the class cmMakeDepend GenerateMakefile
1306 bool cmUnixMakefileGenerator::OutputObjectDepends(std::ostream
& fout
)
1309 // Iterate over every target.
1310 std::map
<cmStdString
, cmTarget
>& targets
= m_Makefile
->GetTargets();
1311 for(std::map
<cmStdString
, cmTarget
>::const_iterator target
= targets
.begin();
1312 target
!= targets
.end(); ++target
)
1314 // Iterate over every source for this target.
1315 const std::vector
<cmSourceFile
*>& sources
= target
->second
.GetSourceFiles();
1316 for(std::vector
<cmSourceFile
*>::const_iterator source
= sources
.begin();
1317 source
!= sources
.end(); ++source
)
1319 if(!(*source
)->IsAHeaderFileOnly())
1321 if(!(*source
)->GetDepends().empty())
1323 fout
<< (*source
)->GetSourceName() << m_ObjectFileExtension
<< " :";
1324 // Iterate through all the dependencies for this source.
1325 for(std::vector
<std::string
>::const_iterator dep
=
1326 (*source
)->GetDepends().begin();
1327 dep
!= (*source
)->GetDepends().end(); ++dep
)
1330 << this->ConvertToOutputPath(dep
->c_str());
1343 // Output the depend information for all the classes
1344 // in the makefile. These would have been generated
1345 // by the class cmMakeDepend GenerateMakefile
1346 void cmUnixMakefileGenerator::OutputCheckDepends(std::ostream
& fout
)
1348 std::set
<std::string
> emittedLowerPath
;
1349 std::set
<std::string
> emitted
;
1350 // Iterate over every target.
1351 std::map
<cmStdString
, cmTarget
>& targets
= m_Makefile
->GetTargets();
1352 fout
<< "# Suppresses display of executed commands\n";
1353 fout
<< ".SILENT:\n";
1354 fout
<< "# disable some common implicit rules to speed things up\n";
1355 fout
<< ".SUFFIXES:\n";
1356 fout
<< ".SUFFIXES:.hpuxmakemusthaverule\n";
1357 this->OutputMakeVariables(fout
);
1358 fout
<< "default:\n";
1359 fout
<< "\t$(MAKE) $(MAKESILENT) -f cmake.check_depends all\n"
1360 << "\t$(MAKE) $(MAKESILENT) -f cmake.check_depends cmake.depends\n\n";
1362 for(std::map
<cmStdString
, cmTarget
>::const_iterator target
= targets
.begin();
1363 target
!= targets
.end(); ++target
)
1365 // Iterate over every source for this target.
1366 const std::vector
<cmSourceFile
*>& sources
= target
->second
.GetSourceFiles();
1367 for(std::vector
<cmSourceFile
*>::const_iterator source
= sources
.begin();
1368 source
!= sources
.end(); ++source
)
1370 if(!(*source
)->IsAHeaderFileOnly())
1372 if(!(*source
)->GetDepends().empty())
1374 for(std::vector
<std::string
>::const_iterator dep
=
1375 (*source
)->GetDepends().begin();
1376 dep
!= (*source
)->GetDepends().end(); ++dep
)
1378 std::string dependfile
=
1379 this->ConvertToOutputPath(cmSystemTools::CollapseFullPath(dep
->c_str()).c_str());
1380 // use the lower path function to create uniqe names
1381 std::string lowerpath
= this->LowerCasePath(dependfile
.c_str());
1382 if(emittedLowerPath
.insert(lowerpath
).second
)
1384 emitted
.insert(dependfile
);
1385 fout
<< " \\\n" << dependfile
;
1392 fout
<< "\n\n# if any of these files changes run make dependlocal\n";
1393 fout
<< "cmake.depends: ";
1394 std::set
<std::string
>::iterator i
;
1395 for(i
= emitted
.begin(); i
!= emitted
.end(); ++i
)
1397 fout
<< " \\\n" << *i
;
1399 fout
<< "\n\t$(MAKE) $(MAKESILENT) dependlocal\n\n";
1401 fout
<< "# if a .h file is removed then run make dependlocal\n\n";
1402 for(std::set
<std::string
>::iterator i
= emitted
.begin();
1403 i
!= emitted
.end(); ++i
)
1406 << "\t$(MAKE) $(MAKESILENT) dependlocal\n\n";
1410 // Output each custom rule in the following format:
1411 // output: source depends...
1413 void cmUnixMakefileGenerator::OutputCustomRules(std::ostream
& fout
)
1415 // We may be modifying the source groups temporarily, so make a copy.
1416 std::vector
<cmSourceGroup
> sourceGroups
= m_Makefile
->GetSourceGroups();
1418 const cmTargets
&tgts
= m_Makefile
->GetTargets();
1419 for(cmTargets::const_iterator tgt
= tgts
.begin();
1420 tgt
!= tgts
.end(); ++tgt
)
1422 // add any custom rules to the source groups
1423 for (std::vector
<cmCustomCommand
>::const_iterator cr
=
1424 tgt
->second
.GetCustomCommands().begin();
1425 cr
!= tgt
->second
.GetCustomCommands().end(); ++cr
)
1427 // if the source for the custom command is the same name
1428 // as the target, then to not create a rule in the makefile for
1429 // the custom command, as the command will be fired when the other target
1431 if ( cr
->GetSourceName().compare(tgt
->first
) !=0)
1433 cmSourceGroup
& sourceGroup
=
1434 m_Makefile
->FindSourceGroup(cr
->GetSourceName().c_str(),
1436 cmCustomCommand
cc(*cr
);
1437 cc
.ExpandVariables(*m_Makefile
);
1438 sourceGroup
.AddCustomCommand(cc
);
1443 // Loop through every source group.
1444 for(std::vector
<cmSourceGroup
>::const_iterator sg
=
1445 sourceGroups
.begin(); sg
!= sourceGroups
.end(); ++sg
)
1447 const cmSourceGroup::BuildRules
& buildRules
= sg
->GetBuildRules();
1448 if(buildRules
.empty())
1451 std::string name
= sg
->GetName();
1454 fout
<< "# Start of source group \"" << name
.c_str() << "\"\n";
1457 // Loop through each source in the source group.
1458 for(cmSourceGroup::BuildRules::const_iterator cc
=
1459 buildRules
.begin(); cc
!= buildRules
.end(); ++ cc
)
1461 std::string source
= cc
->first
;
1462 const cmSourceGroup::Commands
& commands
= cc
->second
.m_Commands
;
1463 // Loop through every command generating code from the current source.
1464 for(cmSourceGroup::Commands::const_iterator c
= commands
.begin();
1465 c
!= commands
.end(); ++c
)
1467 // escape spaces and convert to native slashes path for
1469 std::string command
=
1470 this->ConvertToOutputPath(c
->second
.m_Command
.c_str());
1472 // now add the arguments
1473 command
+= c
->second
.m_Arguments
;
1474 const cmSourceGroup::CommandFiles
& commandFiles
= c
->second
;
1475 // if the command has no outputs, then it is a utility command
1477 if(commandFiles
.m_Outputs
.size() == 0)
1479 std::string depends
;
1480 // collect out all the dependencies for this rule.
1481 for(std::set
<std::string
>::const_iterator d
=
1482 commandFiles
.m_Depends
.begin();
1483 d
!= commandFiles
.m_Depends
.end(); ++d
)
1485 std::string dep
= this->ConvertToOutputPath(d
->c_str());
1490 this->OutputMakeRule(fout
,
1496 // Write a rule for every output generated by this command.
1497 for(std::set
<std::string
>::const_iterator output
=
1498 commandFiles
.m_Outputs
.begin();
1499 output
!= commandFiles
.m_Outputs
.end(); ++output
)
1501 std::string src
= this->ConvertToOutputPath(source
.c_str());
1502 std::string depends
;
1504 // Collect out all the dependencies for this rule.
1505 for(std::set
<std::string
>::const_iterator d
=
1506 commandFiles
.m_Depends
.begin();
1507 d
!= commandFiles
.m_Depends
.end(); ++d
)
1509 std::string dep
= this->ConvertToOutputPath(d
->c_str());
1514 this->OutputMakeRule(fout
,
1524 fout
<< "# End of source group \"" << name
.c_str() << "\"\n\n";
1530 void cmUnixMakefileGenerator::GenerateCacheOnly()
1532 cmSystemTools::MakeDirectory(m_Makefile
->GetStartOutputDirectory());
1533 std::string dest
= m_Makefile
->GetStartOutputDirectory();
1534 dest
+= "/Makefile";
1535 std::cout
<< "cmake: creating : " << dest
.c_str() << std::endl
;
1536 this->OutputMakefile(dest
.c_str());
1540 void cmUnixMakefileGenerator::RecursiveGenerateCacheOnly()
1542 std::vector
<cmMakefile
*> makefiles
;
1543 m_Makefile
->FindSubDirectoryCMakeListsFiles(makefiles
);
1544 for(std::vector
<cmMakefile
*>::iterator i
= makefiles
.begin();
1545 i
!= makefiles
.end(); ++i
)
1547 cmMakefile
* mf
= *i
;
1548 if(m_Makefile
->GetDefinition("RUN_CONFIGURE"))
1550 mf
->AddDefinition("RUN_CONFIGURE", true);
1552 cmUnixMakefileGenerator
* gen
=
1553 static_cast<cmUnixMakefileGenerator
*>(mf
->GetMakefileGenerator());
1554 gen
->SetCacheOnlyOn();
1555 gen
->SetRecurseOff();
1556 mf
->GenerateMakefile();
1558 // CLEAN up the makefiles created
1559 for(unsigned int i
=0; i
< makefiles
.size(); ++i
)
1561 delete makefiles
[i
];
1565 void cmUnixMakefileGenerator::OutputMakeVariables(std::ostream
& fout
)
1567 const char* variables
=
1568 "# the standard shell for make\n"
1571 "CMAKE_RANLIB = @CMAKE_RANLIB@\n"
1572 "CMAKE_AR = @CMAKE_AR@\n"
1573 "CMAKE_AR_ARGS = @CMAKE_AR_ARGS@\n"
1574 "CMAKE_CXX_AR = @CMAKE_CXX_AR@\n"
1575 "CMAKE_CXX_AR_ARGS = @CMAKE_CXX_AR_ARGS@\n"
1576 "CMAKE_C_FLAGS = @CMAKE_C_FLAGS@\n"
1577 "CMAKE_C_COMPILER = @CMAKE_C_COMPILER@\n"
1578 "CMAKE_C_LINK_SHARED = @CMAKE_C_LINK_SHARED@\n"
1579 "CMAKE_CXX_LINK_SHARED = @CMAKE_CXX_LINK_SHARED@\n"
1580 "CMAKE_SHLIB_CFLAGS = @CMAKE_SHLIB_CFLAGS@\n"
1582 "CMAKE_CXX_SHLIB_CFLAGS = @CMAKE_CXX_SHLIB_CFLAGS@\n"
1583 "CMAKE_CXX_SHLIB_BUILD_FLAGS = @CMAKE_CXX_SHLIB_BUILD_FLAGS@\n"
1584 "CMAKE_CXX_SHLIB_LINK_FLAGS = @CMAKE_CXX_SHLIB_LINK_FLAGS@\n"
1585 "CMAKE_CXX_MODULE_BUILD_FLAGS = @CMAKE_CXX_MODULE_BUILD_FLAGS@\n"
1586 "CMAKE_CXX_MODULE_LINK_FLAGS = @CMAKE_CXX_MODULE_LINK_FLAGS@\n"
1587 "CMAKE_CXX_SHLIB_RUNTIME_FLAG = @CMAKE_CXX_SHLIB_RUNTIME_FLAG@\n"
1588 "CMAKE_CXX_SHLIB_RUNTIME_SEP = @CMAKE_CXX_SHLIB_RUNTIME_SEP@\n"
1591 "CMAKE_CXX_COMPILER = @CMAKE_CXX_COMPILER@\n"
1592 "CMAKE_CXX_FLAGS = @CMAKE_CXX_FLAGS@\n"
1594 "CMAKE_SHLIB_BUILD_FLAGS = @CMAKE_SHLIB_BUILD_FLAGS@\n"
1595 "CMAKE_SHLIB_LINK_FLAGS = @CMAKE_SHLIB_LINK_FLAGS@\n"
1596 "CMAKE_C_SHLIB_LINK_FLAGS = @CMAKE_C_SHLIB_LINK_FLAGS@\n"
1597 "CMAKE_MODULE_BUILD_FLAGS = @CMAKE_MODULE_BUILD_FLAGS@\n"
1598 "CMAKE_MODULE_LINK_FLAGS = @CMAKE_MODULE_LINK_FLAGS@\n"
1599 "CMAKE_C_SHLIB_RUNTIME_FLAG = @CMAKE_C_SHLIB_RUNTIME_FLAG@\n"
1600 "CMAKE_SHLIB_RUNTIME_FLAG = @CMAKE_SHLIB_RUNTIME_FLAG@\n"
1601 "CMAKE_SHLIB_RUNTIME_SEP = @CMAKE_SHLIB_RUNTIME_SEP@\n"
1602 "DL_LIBS = @CMAKE_DL_LIBS@\n"
1603 "SHLIB_LD_LIBS = @CMAKE_SHLIB_LD_LIBS@\n"
1604 "SHLIB_SUFFIX = @CMAKE_SHLIB_SUFFIX@\n"
1605 "MODULE_SUFFIX = @CMAKE_MODULE_SUFFIX@\n"
1606 "THREAD_LIBS = @CMAKE_THREAD_LIBS@\n"
1609 std::string replaceVars
= variables
;
1610 m_Makefile
->ExpandVariablesInString(replaceVars
);
1611 fout
<< replaceVars
.c_str();
1612 fout
<< "CMAKE_COMMAND = "
1613 << this->ConvertToOutputPath(m_Makefile
->GetDefinition("CMAKE_COMMAND"))
1615 if(m_Makefile
->GetDefinition("CMAKE_EDIT_COMMAND"))
1617 fout
<< "CMAKE_EDIT_COMMAND = "
1618 << this->ConvertToOutputPath(m_Makefile
->GetDefinition("CMAKE_EDIT_COMMAND"))
1622 fout
<< "CMAKE_CURRENT_SOURCE = " <<
1623 this->ConvertToOutputPath(m_Makefile
->GetStartDirectory()) << "\n";
1624 fout
<< "CMAKE_CURRENT_BINARY = " <<
1625 this->ConvertToOutputPath(m_Makefile
->GetStartOutputDirectory()) << "\n";
1626 fout
<< "CMAKE_SOURCE_DIR = " <<
1627 this->ConvertToOutputPath(m_Makefile
->GetHomeDirectory()) << "\n";
1628 fout
<< "CMAKE_BINARY_DIR = " <<
1629 this->ConvertToOutputPath(m_Makefile
->GetHomeOutputDirectory()) << "\n";
1630 // Output Include paths
1631 fout
<< "INCLUDE_FLAGS = ";
1632 std::vector
<std::string
>& includes
= m_Makefile
->GetIncludeDirectories();
1633 std::vector
<std::string
>::iterator i
;
1635 this->ConvertToOutputPath(m_Makefile
->GetStartDirectory()) << " ";
1636 for(i
= includes
.begin(); i
!= includes
.end(); ++i
)
1638 std::string include
= *i
;
1639 // Don't output a -I for the standard include path "/usr/include".
1640 // This can cause problems with certain standard library
1641 // implementations because the wrong headers may be found first.
1642 if(include
!= "/usr/include")
1644 fout
<< "-I" << this->ConvertToOutputPath(i
->c_str()) << " ";
1647 fout
<< m_Makefile
->GetDefineFlags();
1652 void cmUnixMakefileGenerator::OutputInstallRules(std::ostream
& fout
)
1655 = m_Makefile
->GetDefinition("CMAKE_ROOT");
1656 fout
<< "INSTALL = " << root
<< "/Templates/install-sh -c\n";
1657 fout
<< "INSTALL_PROGRAM = $(INSTALL)\n";
1658 fout
<< "INSTALL_DATA = $(INSTALL) -m 644\n";
1660 const cmTargets
&tgts
= m_Makefile
->GetTargets();
1661 fout
<< "install: $(SUBDIR_INSTALL)\n";
1662 fout
<< "\t@echo \"Installing ...\"\n";
1665 = m_Makefile
->GetDefinition("CMAKE_INSTALL_PREFIX");
1668 prefix
= "/usr/local";
1671 for(cmTargets::const_iterator l
= tgts
.begin();
1672 l
!= tgts
.end(); l
++)
1674 if (l
->second
.GetInstallPath() != "")
1676 // first make the directories for each target
1677 fout
<< "\t@if [ ! -d $(DESTDIR)" << prefix
<< l
->second
.GetInstallPath() <<
1679 fout
<< "\t echo \"Making directory $(DESTDIR)" << prefix
1680 << l
->second
.GetInstallPath() << " \"; \\\n";
1681 fout
<< "\t mkdir -p $(DESTDIR)" << prefix
<< l
->second
.GetInstallPath()
1683 fout
<< "\t chmod 755 $(DESTDIR)" << prefix
<< l
->second
.GetInstallPath()
1685 fout
<< "\t else true; \\\n";
1687 // now install the target
1688 switch (l
->second
.GetType())
1690 case cmTarget::STATIC_LIBRARY
:
1691 fout
<< "\t$(INSTALL_DATA) " << m_LibraryOutputPath
<< "lib"
1694 fout
<< " $(DESTDIR)" << prefix
<< l
->second
.GetInstallPath() << "\n";
1696 case cmTarget::SHARED_LIBRARY
:
1697 fout
<< "\t$(INSTALL_DATA) " << m_LibraryOutputPath
<< "lib"
1699 fout
<< m_Makefile
->GetDefinition("CMAKE_SHLIB_SUFFIX");
1700 fout
<< " $(DESTDIR)" << prefix
<< l
->second
.GetInstallPath() << "\n";
1702 case cmTarget::MODULE_LIBRARY
:
1703 fout
<< "\t$(INSTALL_DATA) " << m_LibraryOutputPath
<< "lib"
1705 fout
<< m_Makefile
->GetDefinition("CMAKE_MODULE_SUFFIX");
1706 fout
<< " $(DESTDIR)" << prefix
<< l
->second
.GetInstallPath() << "\n";
1708 case cmTarget::WIN32_EXECUTABLE
:
1709 case cmTarget::EXECUTABLE
:
1710 fout
<< "\t$(INSTALL_PROGRAM) " << m_ExecutableOutputPath
1712 << cmSystemTools::GetExecutableExtension()
1713 << " $(DESTDIR)" << prefix
<< l
->second
.GetInstallPath() << "\n";
1715 case cmTarget::INSTALL_FILES
:
1717 const std::vector
<std::string
> &sf
= l
->second
.GetSourceLists();
1718 std::vector
<std::string
>::const_iterator i
;
1719 for (i
= sf
.begin(); i
!= sf
.end(); ++i
)
1721 fout
<< "\t@ echo \"Installing " << *i
<< " \"\n";
1722 fout
<< "\t@if [ -f " << *i
<< " ] ; then \\\n";
1723 // avoid using install-sh to install install-sh
1724 // does not work on windows....
1725 if(*i
== "install-sh")
1731 fout
<< "\t $(INSTALL_DATA) ";
1734 << " $(DESTDIR)" << prefix
<< l
->second
.GetInstallPath() << "; \\\n";
1735 fout
<< "\t elif [ -f $(CMAKE_CURRENT_SOURCE)/" << *i
<< " ] ; then \\\n";
1736 // avoid using install-sh to install install-sh
1737 // does not work on windows....
1738 if(*i
== "install-sh")
1744 fout
<< "\t $(INSTALL_DATA) ";
1746 fout
<< "$(CMAKE_CURRENT_SOURCE)/" << *i
1747 << " $(DESTDIR)" << prefix
<< l
->second
.GetInstallPath() << "; \\\n";
1748 fout
<< "\telse \\\n";
1749 fout
<< "\t echo \" ERROR!!! Unable to find: " << *i
1755 case cmTarget::INSTALL_PROGRAMS
:
1757 const std::vector
<std::string
> &sf
= l
->second
.GetSourceLists();
1758 std::vector
<std::string
>::const_iterator i
;
1759 for (i
= sf
.begin(); i
!= sf
.end(); ++i
)
1761 fout
<< "\t@ echo \"Installing " << *i
<< " \"\n";
1762 fout
<< "\t@if [ -f " << *i
<< " ] ; then \\\n";
1763 // avoid using install-sh to install install-sh
1764 // does not work on windows....
1765 if(*i
== "install-sh")
1771 fout
<< "\t $(INSTALL_PROGRAM) ";
1774 << " $(DESTDIR)" << prefix
<< l
->second
.GetInstallPath() << "; \\\n";
1775 fout
<< "\t elif [ -f $(CMAKE_CURRENT_SOURCE)/" << *i
<< " ] ; then \\\n";
1776 // avoid using install-sh to install install-sh
1777 // does not work on windows....
1778 if(*i
== "install-sh")
1784 fout
<< "\t $(INSTALL_PROGRAM) ";
1786 fout
<< "$(CMAKE_CURRENT_SOURCE)/" << *i
1787 << " $(DESTDIR)" << prefix
<< l
->second
.GetInstallPath() << "; \\\n";
1788 fout
<< "\telse \\\n";
1789 fout
<< "\t echo \" ERROR!!! Unable to find: " << *i
1795 case cmTarget::UTILITY
:
1803 void cmUnixMakefileGenerator::OutputMakeRules(std::ostream
& fout
)
1805 this->OutputMakeRule(fout
,
1806 "Default build rule",
1808 "cmake.depends $(TARGETS) $(SUBDIR_BUILD)",
1810 this->OutputMakeRule(fout
,
1811 "remove generated files",
1814 "-@ $(RM) $(CLEAN_OBJECT_FILES) $(EXECUTABLES)"
1815 " $(TARGETS) $(GENERATED_QT_FILES) $(GENERATED_FLTK_FILES)");
1817 // collect up all the sources
1818 std::string allsources
;
1819 std::map
<cmStdString
, cmTarget
>& targets
= m_Makefile
->GetTargets();
1820 for(std::map
<cmStdString
, cmTarget
>::const_iterator target
= targets
.begin();
1821 target
!= targets
.end(); ++target
)
1823 // Iterate over every source for this target.
1824 const std::vector
<cmSourceFile
*>& sources
= target
->second
.GetSourceFiles();
1825 for(std::vector
<cmSourceFile
*>::const_iterator source
= sources
.begin();
1826 source
!= sources
.end(); ++source
)
1828 if(!(*source
)->IsAHeaderFileOnly())
1830 allsources
+= " \\\n";
1831 allsources
+= this->ConvertToOutputPath((*source
)->GetFullPath().c_str());
1836 this->OutputMakeRule(fout
,
1837 "Rule to build the cmake.depends and Makefile as side effect, if a source cmakelist file is out of date.",
1839 "$(CMAKE_MAKEFILE_SOURCES)",
1841 "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
1842 "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)"
1844 this->OutputMakeRule(fout
,
1845 "Rule to build the cmake.check_depends and Makefile as side effect, if any source file has changed.",
1846 "cmake.check_depends",
1849 "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
1850 "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)"
1853 this->OutputMakeRule(fout
,
1854 "Rule to force the build of cmake.depends",
1858 "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
1859 "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
1860 this->OutputMakeRule(fout
,
1861 "Rule to force the build of cmake.depends "
1862 "in the current directory only.",
1866 "-S$(CMAKE_CURRENT_SOURCE) -O$(CMAKE_CURRENT_BINARY) "
1867 "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
1869 this->OutputMakeRule(fout
,
1870 "Rebuild CMakeCache.txt file",
1872 "$(CMAKE_BINARY_DIR)/CMakeCache.txt",
1874 "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
1875 // if CMAKE_EDIT_COMMAND is defined then add a rule to run it
1876 // called edit_cache
1877 if(m_Makefile
->GetDefinition("CMAKE_EDIT_COMMAND"))
1879 this->OutputMakeRule(fout
,
1880 "Edit the CMakeCache.txt file with ccmake or CMakeSetup",
1883 "$(CMAKE_EDIT_COMMAND) "
1884 "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
1887 this->OutputMakeRule(fout
,
1888 "Create CMakeCache.txt file",
1889 "$(CMAKE_BINARY_DIR)/CMakeCache.txt",
1892 "-H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)");
1894 this->OutputMakeRule(fout
,
1895 "Rule to keep make from removing Makefiles "
1896 "if control-C is hit during a run of cmake.",
1898 "Makefile cmake.depends",
1901 this->OutputSourceObjectBuildRules(fout
);
1903 std::string ctest
= m_Makefile
->GetDefinition("CMAKE_COMMAND");
1904 ctest
= cmSystemTools::GetFilenamePath(ctest
.c_str());
1907 ctest
+= cmSystemTools::GetExecutableExtension();
1908 if(!cmSystemTools::FileExists(ctest
.c_str()))
1910 ctest
= m_Makefile
->GetDefinition("CMAKE_COMMAND");
1911 ctest
= cmSystemTools::GetFilenamePath(ctest
.c_str());
1914 ctest
+= cmSystemTools::GetExecutableExtension();
1916 if(!cmSystemTools::FileExists(ctest
.c_str()))
1918 ctest
= m_Makefile
->GetDefinition("CMAKE_COMMAND");
1919 ctest
= cmSystemTools::GetFilenamePath(ctest
.c_str());
1920 ctest
+= "/Release/";
1922 ctest
+= cmSystemTools::GetExecutableExtension();
1924 if (cmSystemTools::FileExists(ctest
.c_str()))
1926 this->OutputMakeRule(fout
,
1930 this->ConvertToOutputPath(ctest
.c_str()).c_str());
1935 cmUnixMakefileGenerator::
1936 OutputBuildObjectFromSource(std::ostream
& fout
,
1937 const char* shortName
,
1938 const cmSourceFile
& source
,
1939 const char* extraCompileFlags
,
1942 // Header files shouldn't have build rules.
1943 if(source
.IsAHeaderFileOnly())
1948 std::string comment
= "Build ";
1949 std::string objectFile
= std::string(shortName
) + m_ObjectFileExtension
;
1950 objectFile
= this->ConvertToOutputPath(objectFile
.c_str());
1951 comment
+= objectFile
+ " From ";
1952 comment
+= source
.GetFullPath();
1953 std::string compileCommand
;
1954 std::string ext
= source
.GetSourceExtension();
1957 compileCommand
= "$(CMAKE_C_COMPILER) $(CMAKE_C_FLAGS) ";
1958 compileCommand
+= extraCompileFlags
;
1961 compileCommand
+= "$(CMAKE_SHLIB_CFLAGS) ";
1963 compileCommand
+= "$(INCLUDE_FLAGS) -c ";
1965 this->ConvertToOutputPath(source
.GetFullPath().c_str());
1966 compileCommand
+= " -o ";
1967 compileCommand
+= objectFile
;
1971 compileCommand
= "$(CMAKE_CXX_COMPILER) $(CMAKE_CXX_FLAGS) ";
1972 compileCommand
+= extraCompileFlags
;
1975 compileCommand
+= "$(CMAKE_SHLIB_CFLAGS) ";
1977 compileCommand
+= "$(INCLUDE_FLAGS) -c ";
1979 this->ConvertToOutputPath(source
.GetFullPath().c_str());
1980 compileCommand
+= " -o ";
1981 compileCommand
+= objectFile
;
1983 this->OutputMakeRule(fout
,
1986 this->ConvertToOutputPath(source
.GetFullPath().
1988 compileCommand
.c_str());
1993 void cmUnixMakefileGenerator::OutputSourceObjectBuildRules(std::ostream
& fout
)
1995 fout
<< "# Rules to build " << m_ObjectFileExtension
1996 << " files from their sources:\n";
1998 std::set
<std::string
> rules
;
2000 // Iterate over every target.
2001 std::map
<cmStdString
, cmTarget
>& targets
= m_Makefile
->GetTargets();
2002 for(std::map
<cmStdString
, cmTarget
>::const_iterator target
= targets
.begin();
2003 target
!= targets
.end(); ++target
)
2005 bool shared
= ((target
->second
.GetType() == cmTarget::SHARED_LIBRARY
) ||
2006 (target
->second
.GetType() == cmTarget::MODULE_LIBRARY
));
2007 std::string exportsDef
= "";
2010 exportsDef
= "-D"+target
->first
+"_EXPORTS ";
2012 // Iterate over every source for this target.
2013 const std::vector
<cmSourceFile
*>& sources
= target
->second
.GetSourceFiles();
2014 for(std::vector
<cmSourceFile
*>::const_iterator source
= sources
.begin();
2015 source
!= sources
.end(); ++source
)
2017 if(!(*source
)->IsAHeaderFileOnly())
2019 std::string shortName
;
2020 std::string sourceName
;
2021 // If the full path to the source file includes this
2022 // directory, we want to use the relative path for the
2023 // filename of the object file. Otherwise, we will use just
2024 // the filename portion.
2025 if((cmSystemTools::GetFilenamePath((*source
)->GetFullPath()).find(m_Makefile
->GetCurrentDirectory()) == 0)
2026 || (cmSystemTools::GetFilenamePath((*source
)->GetFullPath()).find(m_Makefile
->
2027 GetCurrentOutputDirectory()) == 0))
2029 sourceName
= (*source
)->GetSourceName()+"."+(*source
)->GetSourceExtension();
2030 shortName
= (*source
)->GetSourceName();
2032 // The path may be relative. See if a directory needs to be
2033 // created for the output file. This is a ugly, and perhaps
2034 // should be moved elsewhere.
2035 std::string relPath
=
2036 cmSystemTools::GetFilenamePath((*source
)->GetSourceName());
2039 std::string outPath
= m_Makefile
->GetCurrentOutputDirectory();
2040 outPath
+= "/"+relPath
;
2041 cmSystemTools::MakeDirectory(outPath
.c_str());
2046 sourceName
= (*source
)->GetFullPath();
2047 shortName
= cmSystemTools::GetFilenameName((*source
)->GetSourceName());
2049 std::string shortNameWithExt
= shortName
+
2050 (*source
)->GetSourceExtension();
2051 // Only output a rule for each .o once.
2052 if(rules
.find(shortNameWithExt
) == rules
.end())
2054 if((*source
)->GetCompileFlags())
2056 exportsDef
+= (*source
)->GetCompileFlags();
2059 this->OutputBuildObjectFromSource(fout
,
2064 rules
.insert(shortNameWithExt
);
2071 void cmUnixMakefileGenerator::OutputMakeRule(std::ostream
& fout
,
2072 const char* comment
,
2074 const char* depends
,
2075 const char* command
,
2076 const char* command2
,
2077 const char* command3
,
2078 const char* command4
)
2082 cmSystemTools::Error("no target for OutputMakeRule");
2086 std::string replace
;
2090 m_Makefile
->ExpandVariablesInString(replace
);
2091 fout
<< "#---------------------------------------------------------\n";
2092 fout
<< "# " << replace
;
2098 m_Makefile
->ExpandVariablesInString(replace
);
2099 fout
<< this->ConvertToOutputPath(replace
.c_str()) << ": ";
2104 m_Makefile
->ExpandVariablesInString(replace
);
2105 fout
<< replace
.c_str();
2109 const char* commands
[] = { command
, command2
, command3
, command4
};
2111 for (unsigned int i
= 0; i
< sizeof(commands
) / sizeof(commands
[0]); ++i
)
2115 replace
= commands
[i
];
2116 m_Makefile
->ExpandVariablesInString(replace
);
2117 if(replace
[0] != '-' && replace
.find("echo") != 0
2118 && replace
.find("$(MAKE)") != 0)
2120 std::string echostring
= replace
;
2121 // for unix we want to quote the output of echo
2122 // for nmake and borland, the echo should not be quoted
2123 if(strcmp(this->GetName(), "Unix Makefiles") == 0)
2125 cmSystemTools::ReplaceString(echostring
, "\\\n", " ");
2126 cmSystemTools::ReplaceString(echostring
, " \t", " ");
2127 cmSystemTools::ReplaceString(echostring
, "\n\t", "\"\n\techo \"");
2128 fout
<< "\techo \"" << echostring
.c_str() << "\"\n";
2132 cmSystemTools::ReplaceString(echostring
, "\n\t", "\n\techo ");
2133 fout
<< "\techo " << echostring
.c_str() << "\n";
2136 fout
<< "\t" << replace
.c_str() << "\n";
2142 void cmUnixMakefileGenerator::SetLocal (bool local
)
2146 m_CacheOnly
= false;
2156 void cmUnixMakefileGenerator::EnableLanguage(const char* lang
)
2160 // see man putenv for explaination of this stupid code....
2161 static char envCXX
[5000];
2162 static char envCC
[5000];
2163 if(m_Makefile
->GetDefinition("CMAKE_CXX_COMPILER"))
2165 std::string env
= "CXX=${CMAKE_CXX_COMPILER}";
2166 m_Makefile
->ExpandVariablesInString(env
);
2167 strncpy(envCXX
, env
.c_str(), 4999);
2171 if(m_Makefile
->GetDefinition("CMAKE_C_COMPILER"))
2173 std::string env
= "CC=${CMAKE_C_COMPILER}";
2174 m_Makefile
->ExpandVariablesInString(env
);
2175 strncpy(envCC
, env
.c_str(), 4999);
2181 = this->ConvertToOutputPath(m_Makefile
->GetDefinition("CMAKE_ROOT"));
2182 // if no lang specified use CXX
2187 // if CXX or C, then enable C
2188 if((!this->GetLanguageEnabled(lang
) && lang
[0] == 'C'))
2190 std::string cmd
= root
;
2191 cmd
+= "/Templates/cconfigure";
2192 cmSystemTools::RunCommand(cmd
.c_str(), output
,
2193 this->ConvertToOutputPath(m_Makefile
->GetHomeOutputDirectory()).c_str());
2194 std::string fpath
= m_Makefile
->GetHomeOutputDirectory();
2195 fpath
+= "/CCMakeSystemConfig.cmake";
2196 m_Makefile
->ReadListFile(NULL
,fpath
.c_str());
2197 this->SetLanguageEnabled("C");
2200 if(!this->GetLanguageEnabled(lang
) || strcmp(lang
, "CXX") == 0)
2202 std::string cmd
= root
;
2203 cmd
+= "/Templates/cxxconfigure";
2204 cmSystemTools::RunCommand(cmd
.c_str(), output
,
2205 this->ConvertToOutputPath(m_Makefile
->GetHomeOutputDirectory()).c_str());
2206 std::string fpath
= m_Makefile
->GetHomeOutputDirectory();
2207 fpath
+= "/CXXCMakeSystemConfig.cmake";
2208 m_Makefile
->ReadListFile(NULL
,fpath
.c_str());
2209 this->SetLanguageEnabled("CXX");
2211 m_Makefile
->AddDefinition("RUN_CONFIGURE", true);