Introduce "generator expressions" to add_test()
[cmake.git] / Source / cmakexbuild.cxx
blob4206a967ce1fd48d2b172ab929e0df97474c96fb
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmakexbuild.cxx,v $
5 Language: C++
6 Date: $Date: 2007-07-27 14:55:24 $
7 Version: $Revision: 1.5 $
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 <cmsys/Process.h>
18 #include "cmStandardIncludes.h"
19 #include "cmSystemTools.h"
21 // This is a wrapper program for xcodebuild
22 // it calls xcodebuild, and does two things
23 // it removes much of the output, all the setevn
24 // stuff. Also, it checks for the text file busy
25 // error, and re-runs xcodebuild until that error does
26 // not show up.
28 int RunXCode(std::vector<const char*>& argv, bool& hitbug)
30 hitbug = false;
31 cmsysProcess* cp = cmsysProcess_New();
32 cmsysProcess_SetCommand(cp, &*argv.begin());
33 cmsysProcess_SetTimeout(cp, 0);
34 cmsysProcess_Execute(cp);
35 std::vector<char> out;
36 std::vector<char> err;
37 std::string line;
38 int pipe = cmSystemTools::WaitForLine(cp, line, 100.0, out, err);
39 while(pipe != cmsysProcess_Pipe_None)
41 if(line.find("/bin/sh: bad interpreter: Text file busy")
42 != line.npos)
44 hitbug = true;
45 std::cerr << "Hit xcodebuild bug : " << line << "\n";
47 // if the bug is hit, no more output should be generated
48 // because it may contain bogus errors
49 // also remove all output with setenv in it to tone down
50 // the verbosity of xcodebuild
51 if(!hitbug && (line.find("setenv") == line.npos))
53 if(pipe == cmsysProcess_Pipe_STDERR)
55 std::cerr << line << "\n";
57 else if(pipe == cmsysProcess_Pipe_STDOUT)
59 std::cout << line << "\n";
62 pipe = cmSystemTools::WaitForLine(cp, line, 100, out, err);
64 cmsysProcess_WaitForExit(cp, 0);
65 if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exited)
67 return cmsysProcess_GetExitValue(cp);
69 if(cmsysProcess_GetState(cp) == cmsysProcess_State_Error)
71 return -1;
73 return -1;
76 int main(int ac, char*av[])
78 std::vector<const char*> argv;
79 argv.push_back("xcodebuild");
80 for(int i =1; i < ac; i++)
82 argv.push_back(av[i]);
84 argv.push_back(0);
85 bool hitbug = true;
86 int ret = 0;
87 while(hitbug)
89 ret = RunXCode(argv, hitbug);
91 if(ret < 0)
93 return 255;
95 return ret;