Set CMAKE_*_OUTPUT_DIRECTORY

Gather
 * all executables in ${CMAKE_BINARY_DIR}/bin
 * all libraries (static and dynamic) in ${CMAKE_BINARY_DIR}/lib

Change-Id: Ibc2fa1adfb6f0aea65d66d570259b79546bf3b07
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0244260..29834d1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -36,6 +36,10 @@
 
 PROJECT(CERES C CXX)
 
+SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+
 # Important: Always bump the second number (e.g. 1.3.x to 1.4.0) for any
 # release that changes the ABI. The ABI changes for almost any modification to
 # include/ceres (e.g. the public API). If you are unsure about whether
diff --git a/internal/ceres/CMakeLists.txt b/internal/ceres/CMakeLists.txt
index 6be2873..ef0bd68 100644
--- a/internal/ceres/CMakeLists.txt
+++ b/internal/ceres/CMakeLists.txt
@@ -180,8 +180,8 @@
   MACRO (CERES_TEST NAME)
     ADD_EXECUTABLE(${NAME}_test ${NAME}_test.cc)
     TARGET_LINK_LIBRARIES(${NAME}_test test_util ceres gtest)
-    ADD_TEST(${NAME}_test
-             ${NAME}_test
+    ADD_TEST(NAME ${NAME}_test
+             COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${NAME}_test
              --test_srcdir
              ${CMAKE_SOURCE_DIR}/data)
   ENDMACRO (CERES_TEST)