From: José Fonseca Date: Thu, 30 May 2013 16:15:32 +0000 (+0100) Subject: cli: Allow to use `apitrace trace` from MSVC build directories. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=f73c1f8becb425336f6bf1b42cb7ea3fc121949d;p=apitrace cli: Allow to use `apitrace trace` from MSVC build directories. Also add a bit more verbose output when searching for wrappers. --- diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 689374d..713222f 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -40,4 +40,16 @@ if (NOT CMAKE_CROSSCOMPILING) ) endif () +if (MSVC) + # On MSVC builds tell which subdirectory the binaries with be (for each + # configuration) + set_target_properties (apitrace PROPERTIES + COMPILE_DEFINITIONS_DEBUG APITRACE_CONFIGURATION_SUBDIR="Debug" + COMPILE_DEFINITIONS_RELEASE APITRACE_CONFIGURATION_SUBDIR="Release" + COMPILE_DEFINITIONS_MINSIZEREL APITRACE_CONFIGURATION_SUBDIR="MinSizeRel" + COMPILE_DEFINITIONS_RELWITHDEBINFO APITRACE_CONFIGURATION_SUBDIR="RelWithDebInfo" + ) +endif () + + install (TARGETS apitrace RUNTIME DESTINATION bin) diff --git a/cli/cli_resources.cpp b/cli/cli_resources.cpp index a533b01..a4797e1 100644 --- a/cli/cli_resources.cpp +++ b/cli/cli_resources.cpp @@ -33,8 +33,18 @@ #include "cli_resources.hpp" +static bool +tryPath(const os::String &path, bool verbose) +{ + bool exists = path.exists(); + if (verbose) { + std::cerr << "info: " << (exists ? "found" : "did not find") << " " << path.str() << "\n"; + } + return exists; +} + os::String -findProgram(const char*programFilename) +findProgram(const char *programFilename, bool verbose) { os::String programPath; @@ -43,7 +53,7 @@ findProgram(const char*programFilename) programPath = processDir; programPath.join(programFilename); - if (programPath.exists()) { + if (tryPath(programPath, verbose)) { return programPath; } @@ -51,7 +61,7 @@ findProgram(const char*programFilename) // Try absolute install directory programPath = APITRACE_PROGRAMS_INSTALL_DIR; programPath.join(programFilename); - if (programPath.exists()) { + if (tryPath(programPath, verbose)) { return programPath; } #endif @@ -60,7 +70,7 @@ findProgram(const char*programFilename) } os::String -findWrapper(const char *wrapperFilename) +findWrapper(const char *wrapperFilename, bool verbose) { os::String wrapperPath; @@ -70,9 +80,16 @@ findWrapper(const char *wrapperFilename) // Try relative build directory // XXX: Just make build and install directory layout match wrapperPath = processDir; +#if defined(APITRACE_CONFIGURATION_SUBDIR) + // Go from `Debug\apitrace.exe` to `wrappers\Debug\foo.dll` on MSVC builds. + wrapperPath.join(".."); wrapperPath.join("wrappers"); + wrapperPath.join(APITRACE_CONFIGURATION_SUBDIR); +#else + wrapperPath.join("wrappers"); +#endif wrapperPath.join(wrapperFilename); - if (wrapperPath.exists()) { + if (tryPath(wrapperPath, verbose)) { return wrapperPath; } @@ -86,7 +103,7 @@ findWrapper(const char *wrapperFilename) wrapperPath.join("../lib/apitrace/wrappers"); #endif wrapperPath.join(wrapperFilename); - if (wrapperPath.exists()) { + if (tryPath(wrapperPath, verbose)) { return wrapperPath; } @@ -94,7 +111,7 @@ findWrapper(const char *wrapperFilename) // Try absolute install directory wrapperPath = APITRACE_WRAPPERS_INSTALL_DIR; wrapperPath.join(wrapperFilename); - if (wrapperPath.exists()) { + if (tryPath(wrapperPath, verbose)) { return wrapperPath; } #endif @@ -103,7 +120,7 @@ findWrapper(const char *wrapperFilename) } os::String -findScript(const char *scriptFilename) +findScript(const char *scriptFilename, bool verbose) { os::String scriptPath; @@ -116,7 +133,7 @@ findScript(const char *scriptFilename) scriptPath = APITRACE_SOURCE_DIR; scriptPath.join("scripts"); scriptPath.join(scriptFilename); - if (scriptPath.exists()) { + if (tryPath(scriptPath, verbose)) { return scriptPath; } #endif @@ -131,7 +148,7 @@ findScript(const char *scriptFilename) scriptPath.join("../lib/apitrace/scripts"); #endif scriptPath.join(scriptFilename); - if (scriptPath.exists()) { + if (tryPath(scriptPath, verbose)) { return scriptPath; } @@ -139,7 +156,7 @@ findScript(const char *scriptFilename) // Try absolute install directory scriptPath = APITRACE_SCRIPTS_INSTALL_DIR; scriptPath.join(scriptFilename); - if (scriptPath.exists()) { + if (tryPath(scriptPath, verbose)) { return scriptPath; } #endif diff --git a/cli/cli_resources.hpp b/cli/cli_resources.hpp index dde86dd..ee3882b 100644 --- a/cli/cli_resources.hpp +++ b/cli/cli_resources.hpp @@ -34,13 +34,13 @@ os::String -findProgram(const char*programFilename); +findProgram(const char *programFilename, bool verbose = false); os::String -findScript(const char *name); +findScript(const char *name, bool verbose = false); os::String -findWrapper(const char *wrapperFilename); +findWrapper(const char *wrapperFilename, bool verbose = false); #endif /* _CLI_RESOURCES_HPP_ */ diff --git a/cli/cli_trace.cpp b/cli/cli_trace.cpp index 8c7f5b1..52843c7 100644 --- a/cli/cli_trace.cpp +++ b/cli/cli_trace.cpp @@ -126,9 +126,9 @@ traceProgram(trace::API api, return 1; } - os::String wrapperPath = findWrapper(wrapperFilename); + os::String wrapperPath = findWrapper(wrapperFilename, verbose); if (!wrapperPath.length()) { - std::cerr << "error: failed to find " << wrapperFilename << "\n"; + std::cerr << "error: failed to find " << wrapperFilename << " wrapper\n"; goto exit; }