1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmFLTKWrapUICommand.cxx,v $
6 Date: $Date: 2002-06-27 19:57:09 $
7 Version: $Revision: 1.11 $
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 "cmFLTKWrapUICommand.h"
19 // cmFLTKWrapUICommand
20 bool cmFLTKWrapUICommand::InitialPass(std::vector
<std::string
> const& args
)
24 this->SetError("called with incorrect number of arguments");
28 // Now check and see if the value has been stored in the cache
29 // already, if so use that value and don't look for the program
30 const char* FLTK_WRAP_UI_value
= m_Makefile
->GetDefinition("FLTK_WRAP_UI");
31 if (FLTK_WRAP_UI_value
==0)
33 this->SetError("called with FLTK_WRAP_UI undefined");
37 if(cmSystemTools::IsOff(FLTK_WRAP_UI_value
))
39 this->SetError("called with FLTK_WRAP_UI off : ");
44 // what is the current source dir
45 std::string cdir
= m_Makefile
->GetCurrentDirectory();
47 // get parameter for the command
48 m_Target
= args
[0]; // Target that will use the generated files
49 m_GUISourceList
= args
[1]; // Source List of the GUI source files
51 std::vector
<std::string
> newArgs
;
52 m_Makefile
->ExpandSourceListArguments(args
,newArgs
, 1);
54 // get the list of GUI files from which .cxx and .h will be generated
55 std::string outputDirectory
= m_Makefile
->GetCurrentOutputDirectory();
57 // Some of the generated files are *.h so the directory "GUI"
58 // where they are created have to be added to the include path
59 m_Makefile
->AddIncludeDirectory( outputDirectory
.c_str() );
61 for(std::vector
<std::string
>::iterator i
= (newArgs
.begin() + 1);
62 i
!= newArgs
.end(); i
++)
64 cmSourceFile
*curr
= m_Makefile
->GetSource(i
->c_str());
65 // if we should use the source GUI
66 // to generate .cxx and .h files
67 if (!curr
|| !curr
->GetWrapExclude())
69 cmSourceFile header_file
;
70 cmSourceFile source_file
;
71 std::string srcName
= cmSystemTools::GetFilenameWithoutExtension(*i
);
72 const bool headerFileOnly
= true;
73 header_file
.SetName(srcName
.c_str(),
74 outputDirectory
.c_str(), "h",headerFileOnly
);
75 source_file
.SetName(srcName
.c_str(),
76 outputDirectory
.c_str(), "cxx",!headerFileOnly
);
77 std::string origname
= cdir
+ "/" + *i
;
78 std::string hname
= header_file
.GetFullPath();
79 std::string cxxname
= source_file
.GetFullPath();
80 m_WrapUserInterface
.push_back(origname
);
81 // add starting depends
82 source_file
.GetDepends().push_back(hname
);
83 source_file
.GetDepends().push_back(origname
);
84 header_file
.GetDepends().push_back(origname
);
85 m_GeneratedHeadersClasses
.push_back(header_file
);
86 m_GeneratedSourcesClasses
.push_back(source_file
);
93 void cmFLTKWrapUICommand::FinalPass()
96 // first we add the rules for all the .fl to .h and .cxx files
97 size_t lastHeadersClass
= m_GeneratedHeadersClasses
.size();
98 std::string fluid_exe
= "${FLTK_FLUID_EXE}";
101 std::string outputGUIDirectory
= m_Makefile
->GetCurrentOutputDirectory();
103 // Generate code for all the .fl files
104 for(size_t classNum
= 0; classNum
< lastHeadersClass
; classNum
++)
106 // set up .fl to .h and .cxx command
107 std::string hres
= outputGUIDirectory
;
109 hres
+= m_GeneratedHeadersClasses
[classNum
].GetSourceName() + "." +
110 m_GeneratedHeadersClasses
[classNum
].GetSourceExtension();
112 std::string cxxres
= outputGUIDirectory
;
114 cxxres
+= m_GeneratedSourcesClasses
[classNum
].GetSourceName() + "." +
115 m_GeneratedSourcesClasses
[classNum
].GetSourceExtension();
117 std::vector
<std::string
> cxxargs
;
118 cxxargs
.push_back("-c"); // instructs Fluid to run in command line
119 cxxargs
.push_back("-h"); // optionally rename .h files
120 cxxargs
.push_back(hres
);
121 cxxargs
.push_back("-o"); // optionally rename .cxx files
122 cxxargs
.push_back(cxxres
);
123 cxxargs
.push_back(m_WrapUserInterface
[classNum
]);// name of the GUI fluid file
125 std::vector
<std::string
> depends
;
127 std::vector
<std::string
> outputs
;
128 outputs
.push_back( cxxres
);
129 outputs
.push_back( hres
);
131 // Add command for generating the .h and .cxx files
132 m_Makefile
->AddCustomCommand(m_WrapUserInterface
[classNum
].c_str(),
133 fluid_exe
.c_str(), cxxargs
, depends
,
134 outputs
, m_Target
.c_str() );
135 cmSourceFile
* sf
= m_Makefile
->AddSource(m_GeneratedSourcesClasses
[classNum
]);
137 m_Makefile
->GetTargets()[m_Target
].GetSourceFiles().push_back( sf
);