]> git.cworth.org Git - apitrace/blob - common/trace_resource.cpp
dump-images: Execute glretrace from source dir when running uninstalled
[apitrace] / common / trace_resource.cpp
1 /*********************************************************************
2  *
3  * Copyright 2011 Intel Corporation
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use, copy,
10  * modify, merge, publish, distribute, sublicense, and/or sell copies
11  * of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  *
26  *********************************************************************/
27
28
29 #include <iostream>
30
31 #include "os_string.hpp"
32 #include "trace_tools.hpp"
33
34
35
36 namespace trace {
37
38 os::String
39 findProgram(const char*programFilename)
40 {
41     os::String programPath;
42
43     os::String processDir = os::getProcessName();
44     processDir.trimFilename();
45
46     programPath = processDir;
47     programPath.join(programFilename);
48     if (programPath.exists()) {
49         return programPath;
50     }
51
52 #ifndef _WIN32
53     // Try absolute install directory
54     programPath = APITRACE_PROGRAMS_INSTALL_DIR;
55     programPath.join(programFilename);
56     if (programPath.exists()) {
57         return programPath;
58     }
59 #endif
60
61     return "";
62 }
63
64 os::String
65 findWrapper(const char *wrapperFilename)
66 {
67     os::String wrapperPath;
68
69     os::String processDir = os::getProcessName();
70     processDir.trimFilename();
71
72     // Try relative build directory
73     // XXX: Just make build and install directory layout match
74     wrapperPath = processDir;
75     wrapperPath.join("wrappers");
76     wrapperPath.join(wrapperFilename);
77     if (wrapperPath.exists()) {
78         return wrapperPath;
79     }
80
81     // Try relative install directory
82     wrapperPath = processDir;
83 #if defined(_WIN32)
84     wrapperPath.join("..\\lib\\wrappers");
85 #elif defined(__APPLE__)
86     wrapperPath.join("../lib/wrappers");
87 #else
88     wrapperPath.join("../lib/apitrace/wrappers");
89 #endif
90     wrapperPath.join(wrapperFilename);
91     if (wrapperPath.exists()) {
92         return wrapperPath;
93     }
94
95 #ifndef _WIN32
96     // Try absolute install directory
97     wrapperPath = APITRACE_WRAPPERS_INSTALL_DIR;
98     wrapperPath.join(wrapperFilename);
99     if (wrapperPath.exists()) {
100         return wrapperPath;
101     }
102 #endif
103
104     return "";
105 }
106
107 os::String
108 findScript(const char *scriptFilename)
109 {
110     os::String scriptPath;
111
112     os::String processDir = os::getProcessName();
113     processDir.trimFilename();
114
115     // Try relative build directory
116     // XXX: Just make build and install directory layout match
117     scriptPath = processDir;
118     scriptPath.join("scripts");
119     scriptPath.join(scriptFilename);
120     if (scriptPath.exists()) {
121         return scriptPath;
122     }
123
124     // Try relative install directory
125     scriptPath = processDir;
126 #if defined(_WIN32)
127     scriptPath.join("..\\lib\\scripts");
128 #elif defined(__APPLE__)
129     scriptPath.join("../lib/scripts");
130 #else
131     scriptPath.join("../lib/apitrace/scripts");
132 #endif
133     scriptPath.join(scriptFilename);
134     if (scriptPath.exists()) {
135         return scriptPath;
136     }
137
138 #ifndef _WIN32
139     // Try absolute install directory
140     scriptPath = APITRACE_SCRIPTS_INSTALL_DIR;
141     scriptPath.join(scriptFilename);
142     if (scriptPath.exists()) {
143         return scriptPath;
144     }
145 #endif
146
147     std::cerr << "error: cannot find " << scriptFilename << " script\n";
148
149     return "";
150 }
151
152
153 } /* namespace trace */