STYLE: Fix line-too-long
[cmake.git] / Source / cmFLTKWrapUICommand.cxx
blob2750b00c86337a87bdbda311cf2a652626fb4d67
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmFLTKWrapUICommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008-06-23 15:08:57 $
7 Version: $Revision: 1.39 $
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 cmTarget* target = this->Makefile->FindTarget(this->Target.c_str());
125 if(!target)
127 std::string msg =
128 "FLTK_WRAP_UI was called with a target that was never created: ";
129 msg += this->Target;
130 msg +=". The problem was found while processing the source directory: ";
131 msg += this->Makefile->GetStartDirectory();
132 msg += ". This FLTK_WRAP_UI call will be ignored.";
133 cmSystemTools::Message(msg.c_str(),"Warning");
134 return;
136 std::vector<cmSourceFile*> const& srcs =
137 target->GetSourceFiles();
138 bool found = false;
139 for (unsigned int i = 0; i < srcs.size(); ++i)
141 if (srcs[i]->GetFullPath() ==
142 this->GeneratedSourcesClasses[0]->GetFullPath())
144 found = true;
145 break;
148 if (!found)
150 std::string msg =
151 "In CMake 2.2 the FLTK_WRAP_UI command sets a variable to the list of "
152 "source files that should be added to your executable or library. It "
153 "appears that you have not added these source files to your target. "
154 "You should change your CMakeLists.txt file to "
155 "directly add the generated files to the target. "
156 "For example FTLK_WRAP_UI(foo src1 src2 src3) "
157 "will create a variable named foo_FLTK_UI_SRCS that contains the list "
158 "of sources to add to your target when you call ADD_LIBRARY or "
159 "ADD_EXECUTABLE. For now CMake will add the sources to your target "
160 "for you as was done in CMake 2.0 and earlier. In the future this may "
161 "become an error.";
162 msg +="The problem was found while processing the source directory: ";
163 msg += this->Makefile->GetStartDirectory();
164 cmSystemTools::Message(msg.c_str(),"Warning");
165 // first we add the rules for all the .fl to .h and .cxx files
166 size_t lastHeadersClass = this->GeneratedSourcesClasses.size();
168 // Generate code for all the .fl files
169 for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
171 this->Makefile->GetTargets()[this->Target]
172 .AddSourceFile(this->GeneratedSourcesClasses[classNum]);