=== modified file 'cmake/MirCommon.cmake'
--- cmake/MirCommon.cmake	2014-12-11 06:14:56 +0000
+++ cmake/MirCommon.cmake	2014-12-28 14:37:15 +0000
@@ -174,17 +174,10 @@
   add_executable(${TARGET} ${ARGN})
   set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME ${REAL_EXECUTABLE})
 
-  add_executable(${TARGET}-wrapper ${PROJECT_SOURCE_DIR}/cmake/src/wrapper.c)
-  set_property(TARGET ${TARGET}-wrapper
-               APPEND_STRING PROPERTY COMPILE_FLAGS " -DEXECUTABLE=\\\"${REAL_EXECUTABLE}\\\"")
-  set_property(TARGET ${TARGET}-wrapper
-               APPEND_STRING PROPERTY COMPILE_FLAGS " -DBUILD_PREFIX=\\\"${CMAKE_BINARY_DIR}\\\"")
-  set_property(TARGET ${TARGET}-wrapper
-               APPEND_STRING PROPERTY COMPILE_FLAGS " -D_BSD_SOURCE")
-  set_property(TARGET ${TARGET}-wrapper
-	       PROPERTY OUTPUT_NAME ${TARGET})
-
-  add_dependencies(${TARGET} ${TARGET}-wrapper)
+  add_custom_target(${TARGET}-wrapped
+    ln -fs wrapper ${CMAKE_BINARY_DIR}/bin/${TARGET}
+  )
+  add_dependencies(${TARGET} ${TARGET}-wrapped)
   
   install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/${REAL_EXECUTABLE}
           DESTINATION ${CMAKE_INSTALL_BINDIR}

=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt	2014-12-19 21:52:32 +0000
+++ src/CMakeLists.txt	2014-12-28 14:37:15 +0000
@@ -23,6 +23,12 @@
 add_subdirectory(client/)
 add_subdirectory(utils/)
 
+add_executable(wrapper wrapper.c)
+set_property(TARGET wrapper
+             APPEND_STRING PROPERTY COMPILE_FLAGS " -DEXECUTABLE_FORMAT=\\\".%s-uninstalled\\\"")
+set_property(TARGET wrapper
+             APPEND_STRING PROPERTY COMPILE_FLAGS " -D_BSD_SOURCE")
+
 set(
   MIR_GENERATED_INCLUDE_DIRECTORIES
   ${MIR_GENERATED_INCLUDE_DIRECTORIES}

=== renamed file 'cmake/src/wrapper.c' => 'src/wrapper.c'
--- cmake/src/wrapper.c	2014-12-03 00:24:52 +0000
+++ src/wrapper.c	2014-12-28 14:37:15 +0000
@@ -1,16 +1,59 @@
+/*
+ * Copyright © 2014 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Daniel van Vugt <daniel.van.vugt@canonical.com>
+ */
+
+#include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
-#include <assert.h>
 
 int main(int argc, char** argv)
 {
-    assert(argc > 0);
-    setenv("MIR_CLIENT_PLATFORM_PATH", BUILD_PREFIX "/lib/client-modules/", 1);
-
-    argv[0] = BUILD_PREFIX "/bin/" EXECUTABLE;
+    char path[1024], *dest = path, *dest_max = path+sizeof(path)-1;
+    char *pivot = path;
+    size_t pivot_max = 0;
+    const char *src = argv[0], *name = argv[0];
+
+    (void)argc;
+    while (*src && dest < dest_max)
+    {
+        *dest = *src;
+        if (*dest == '/')
+        {
+            pivot = dest + 1;
+            name = src + 1;
+        }
+        ++src;
+        ++dest;
+    }
+    pivot_max = dest_max - pivot;
+
+    strncpy(pivot, "../lib/client-modules/", pivot_max);
+    *dest_max = '\0';
+    setenv("MIR_CLIENT_PLATFORM_PATH", path, 1);
+    printf("MIR_CLIENT_PLATFORM_PATH=%s\n", path);
+
+    snprintf(pivot, pivot_max, EXECUTABLE_FORMAT, name);
+    *dest_max = '\0';
+    printf("exec=%s\n", path);
+
+    argv[0] = path;
     execv(argv[0], argv);
 
-    perror("Failed to execute real binary " EXECUTABLE);
+    fprintf(stderr, "Failed to execute: %s\n", path);
     return 1;
 }

