1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmFLTKWrapUICommand.cxx,v $
6 <<<<<<< cmFLTKWrapUICommand.cxx
7 Date: $Date: 2008/01/23 15:27:59 $
8 Version: $Revision: 1.38 $
10 Date: $Date: 2008-06-23 15:08:57 $
11 Version: $Revision: 1.39 $
14 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
15 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
17 This software is distributed WITHOUT ANY WARRANTY; without even
18 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 PURPOSE. See the above copyright notices for more information.
21 =========================================================================*/
22 #include "cmFLTKWrapUICommand.h"
24 #include "cmSourceFile.h"
26 // cmFLTKWrapUICommand
27 bool cmFLTKWrapUICommand
28 ::InitialPass(std::vector
<std::string
> const& args
, cmExecutionStatus
&)
32 this->SetError("called with incorrect number of arguments");
36 // what is the current source dir
37 std::string cdir
= this->Makefile
->GetCurrentDirectory();
38 const char* fluid_exe
=
39 this->Makefile
->GetRequiredDefinition("FLTK_FLUID_EXECUTABLE");
41 // get parameter for the command
42 this->Target
= args
[0]; // Target that will use the generated files
44 std::vector
<std::string
> newArgs
;
45 this->Makefile
->ExpandSourceListArguments(args
,newArgs
, 1);
47 // get the list of GUI files from which .cxx and .h will be generated
48 std::string outputDirectory
= this->Makefile
->GetCurrentOutputDirectory();
50 // Some of the generated files are *.h so the directory "GUI"
51 // where they are created have to be added to the include path
52 this->Makefile
->AddIncludeDirectory( outputDirectory
.c_str() );
54 for(std::vector
<std::string
>::iterator i
= (newArgs
.begin() + 1);
55 i
!= newArgs
.end(); i
++)
57 cmSourceFile
*curr
= this->Makefile
->GetSource(i
->c_str());
58 // if we should use the source GUI
59 // to generate .cxx and .h files
60 if (!curr
|| !curr
->GetPropertyAsBool("WRAP_EXCLUDE"))
62 std::string outName
= outputDirectory
;
64 outName
+= cmSystemTools::GetFilenameWithoutExtension(*i
);
65 std::string hname
= outName
;
67 std::string origname
= cdir
+ "/" + *i
;
68 // add starting depends
69 std::vector
<std::string
> depends
;
70 depends
.push_back(origname
);
71 depends
.push_back(fluid_exe
);
72 std::string cxxres
= outName
;
75 cmCustomCommandLine commandLine
;
76 commandLine
.push_back(fluid_exe
);
77 commandLine
.push_back("-c"); // instructs Fluid to run in command line
78 commandLine
.push_back("-h"); // optionally rename .h files
79 commandLine
.push_back(hname
);
80 commandLine
.push_back("-o"); // optionally rename .cxx files
81 commandLine
.push_back(cxxres
);
82 commandLine
.push_back(origname
);// name of the GUI fluid file
83 cmCustomCommandLines commandLines
;
84 commandLines
.push_back(commandLine
);
86 // Add command for generating the .h and .cxx files
87 const char* no_main_dependency
= 0;
88 const char* no_comment
= 0;
89 const char* no_working_dir
= 0;
90 this->Makefile
->AddCustomCommandToOutput(cxxres
.c_str(),
91 depends
, no_main_dependency
,
92 commandLines
, no_comment
,
94 this->Makefile
->AddCustomCommandToOutput(hname
.c_str(),
95 depends
, no_main_dependency
,
96 commandLines
, no_comment
,
99 cmSourceFile
*sf
= this->Makefile
->GetSource(cxxres
.c_str());
100 sf
->AddDepend(hname
.c_str());
101 sf
->AddDepend(origname
.c_str());
102 this->GeneratedSourcesClasses
.push_back(sf
);
106 // create the variable with the list of sources in it
107 size_t lastHeadersClass
= this->GeneratedSourcesClasses
.size();
108 std::string sourceListValue
;
109 for(size_t classNum
= 0; classNum
< lastHeadersClass
; classNum
++)
113 sourceListValue
+= ";";
115 sourceListValue
+= this->GeneratedSourcesClasses
[classNum
]->GetFullPath();
117 std::string varName
= this->Target
;
118 varName
+= "_FLTK_UI_SRCS";
119 this->Makefile
->AddDefinition(varName
.c_str(), sourceListValue
.c_str());
124 void cmFLTKWrapUICommand::FinalPass()
126 // people should add the srcs to the target themselves, but the old command
127 // didn't support that, so check and see if they added the files in and if
128 // they didn;t then print a warning and add then anyhow
129 cmTarget
* target
= this->Makefile
->FindTarget(this->Target
.c_str());
133 "FLTK_WRAP_UI was called with a target that was never created: ";
135 msg
+=". The problem was found while processing the source directory: ";
136 msg
+= this->Makefile
->GetStartDirectory();
137 msg
+= ". This FLTK_WRAP_UI call will be ignored.";
138 cmSystemTools::Message(msg
.c_str(),"Warning");
141 std::vector
<cmSourceFile
*> const& srcs
=
142 target
->GetSourceFiles();
144 for (unsigned int i
= 0; i
< srcs
.size(); ++i
)
146 if (srcs
[i
]->GetFullPath() ==
147 this->GeneratedSourcesClasses
[0]->GetFullPath())
156 "In CMake 2.2 the FLTK_WRAP_UI command sets a variable to the list of "
157 "source files that should be added to your executable or library. It "
158 "appears that you have not added these source files to your target. "
159 "You should change your CMakeLists.txt file to "
160 "directly add the generated files to the target. "
161 "For example FTLK_WRAP_UI(foo src1 src2 src3) "
162 "will create a variable named foo_FLTK_UI_SRCS that contains the list "
163 "of sources to add to your target when you call ADD_LIBRARY or "
164 "ADD_EXECUTABLE. For now CMake will add the sources to your target "
165 "for you as was done in CMake 2.0 and earlier. In the future this may "
167 msg
+="The problem was found while processing the source directory: ";
168 msg
+= this->Makefile
->GetStartDirectory();
169 cmSystemTools::Message(msg
.c_str(),"Warning");
170 // first we add the rules for all the .fl to .h and .cxx files
171 size_t lastHeadersClass
= this->GeneratedSourcesClasses
.size();
173 // Generate code for all the .fl files
174 for(size_t classNum
= 0; classNum
< lastHeadersClass
; classNum
++)
176 this->Makefile
->GetTargets()[this->Target
]
177 .AddSourceFile(this->GeneratedSourcesClasses
[classNum
]);