Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmFLTKWrapUICommand.cxx
blob6d6a58453a120578e77f1d3746e24b7cf73a68a2
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmFLTKWrapUICommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008/01/23 15:27:59 $
7 Version: $Revision: 1.38 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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 "cmFLTKWrapUICommand.h"
19 #include "cmSourceFile.h"
21 // cmFLTKWrapUICommand
22 bool cmFLTKWrapUICommand
23 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
25 if(args.size() < 2 )
27 this->SetError("called with incorrect number of arguments");
28 return false;
31 // what is the current source dir
32 std::string cdir = this->Makefile->GetCurrentDirectory();
33 const char* fluid_exe =
34 this->Makefile->GetRequiredDefinition("FLTK_FLUID_EXECUTABLE");
36 // get parameter for the command
37 this->Target = args[0]; // Target that will use the generated files
39 std::vector<std::string> newArgs;
40 this->Makefile->ExpandSourceListArguments(args,newArgs, 1);
42 // get the list of GUI files from which .cxx and .h will be generated
43 std::string outputDirectory = this->Makefile->GetCurrentOutputDirectory();
45 // Some of the generated files are *.h so the directory "GUI"
46 // where they are created have to be added to the include path
47 this->Makefile->AddIncludeDirectory( outputDirectory.c_str() );
49 for(std::vector<std::string>::iterator i = (newArgs.begin() + 1);
50 i != newArgs.end(); i++)
52 cmSourceFile *curr = this->Makefile->GetSource(i->c_str());
53 // if we should use the source GUI
54 // to generate .cxx and .h files
55 if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE"))
57 std::string outName = outputDirectory;
58 outName += "/";
59 outName += cmSystemTools::GetFilenameWithoutExtension(*i);
60 std::string hname = outName;
61 hname += ".h";
62 std::string origname = cdir + "/" + *i;
63 // add starting depends
64 std::vector<std::string> depends;
65 depends.push_back(origname);
66 depends.push_back(fluid_exe);
67 std::string cxxres = outName;
68 cxxres += ".cxx";
70 cmCustomCommandLine commandLine;
71 commandLine.push_back(fluid_exe);
72 commandLine.push_back("-c"); // instructs Fluid to run in command line
73 commandLine.push_back("-h"); // optionally rename .h files
74 commandLine.push_back(hname);
75 commandLine.push_back("-o"); // optionally rename .cxx files
76 commandLine.push_back(cxxres);
77 commandLine.push_back(origname);// name of the GUI fluid file
78 cmCustomCommandLines commandLines;
79 commandLines.push_back(commandLine);
81 // Add command for generating the .h and .cxx files
82 const char* no_main_dependency = 0;
83 const char* no_comment = 0;
84 const char* no_working_dir = 0;
85 this->Makefile->AddCustomCommandToOutput(cxxres.c_str(),
86 depends, no_main_dependency,
87 commandLines, no_comment,
88 no_working_dir);
89 this->Makefile->AddCustomCommandToOutput(hname.c_str(),
90 depends, no_main_dependency,
91 commandLines, no_comment,
92 no_working_dir);
94 cmSourceFile *sf = this->Makefile->GetSource(cxxres.c_str());
95 sf->AddDepend(hname.c_str());
96 sf->AddDepend(origname.c_str());
97 this->GeneratedSourcesClasses.push_back(sf);
101 // create the variable with the list of sources in it
102 size_t lastHeadersClass = this->GeneratedSourcesClasses.size();
103 std::string sourceListValue;
104 for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
106 if (classNum)
108 sourceListValue += ";";
110 sourceListValue += this->GeneratedSourcesClasses[classNum]->GetFullPath();
112 std::string varName = this->Target;
113 varName += "_FLTK_UI_SRCS";
114 this->Makefile->AddDefinition(varName.c_str(), sourceListValue.c_str());
116 return true;
119 void cmFLTKWrapUICommand::FinalPass()
121 // people should add the srcs to the target themselves, but the old command
122 // didn't support that, so check and see if they added the files in and if
123 // they didn;t then print a warning and add then anyhow
124 std::vector<cmSourceFile*> const& srcs =
125 this->Makefile->GetTargets()[this->Target].GetSourceFiles();
126 bool found = false;
127 for (unsigned int i = 0; i < srcs.size(); ++i)
129 if (srcs[i]->GetFullPath() ==
130 this->GeneratedSourcesClasses[0]->GetFullPath())
132 found = true;
133 break;
136 if (!found)
138 std::string msg =
139 "In CMake 2.2 the FLTK_WRAP_UI command sets a variable to the list of "
140 "source files that should be added to your executable or library. It "
141 "appears that you have not added these source files to your target. "
142 "You should change your CMakeLists.txt file to "
143 "directly add the generated files to the target. "
144 "For example FTLK_WRAP_UI(foo src1 src2 src3) "
145 "will create a variable named foo_FLTK_UI_SRCS that contains the list "
146 "of sources to add to your target when you call ADD_LIBRARY or "
147 "ADD_EXECUTABLE. For now CMake will add the sources to your target "
148 "for you as was done in CMake 2.0 and earlier. In the future this may "
149 "become an error.";
150 msg +="The problem was found while processing the source directory: ";
151 msg += this->Makefile->GetStartDirectory();
152 cmSystemTools::Message(msg.c_str(),"Warning");
153 // first we add the rules for all the .fl to .h and .cxx files
154 size_t lastHeadersClass = this->GeneratedSourcesClasses.size();
156 // Generate code for all the .fl files
157 for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
159 this->Makefile->GetTargets()[this->Target]
160 .AddSourceFile(this->GeneratedSourcesClasses[classNum]);