From ecf8cd8703f5f74c5b6e310dd86b90f2f0cda515 Mon Sep 17 00:00:00 2001
From: Michael Reuter <reuterma@ornl.gov>
Date: Wed, 5 Jan 2011 20:34:24 +0000
Subject: [PATCH] Attempt to get GMock/GTest into CMake for real. Headers and
 libgmock generate a huge number of linker errors that look to be
 self-inflicted, so test compilation fails. No working solution found. This
 refs #1881.

---
 Code/Mantid/Build/CMake/FindGMock.cmake       | 20 ++++++++++++++++++-
 Code/Mantid/Build/CMake/FindGTest.cmake       | 11 +++++++++-
 .../Framework/MDAlgorithms/CMakeLists.txt     |  6 +++++-
 .../Framework/MDDataObjects/CMakeLists.txt    |  2 +-
 4 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/Code/Mantid/Build/CMake/FindGMock.cmake b/Code/Mantid/Build/CMake/FindGMock.cmake
index b62606c4e1a..11e9d1e78b1 100644
--- a/Code/Mantid/Build/CMake/FindGMock.cmake
+++ b/Code/Mantid/Build/CMake/FindGMock.cmake
@@ -1,4 +1,22 @@
 # Find the Google Mock headers and libraries
+# GMOCK_INCLUDE_DIR where to find gmock.h
 # GMOCK_FOUND If false, do not try to use Google Mock
 
-set ( GMOCK_FOUND FALSE )
+find_path ( GMOCK_INCLUDE_DIR gmock/gmock.h 
+  PATHS ${PROJECT_SOURCE_DIR}/TestingTools/include
+        ${PROJECT_SOURCE_DIR}/../TestingTools/include
+)
+
+find_library ( GMOCK_LIB NAMES gmock
+  PATHS ${PROJECT_SOURCE_DIR}/TestingTools/lib
+        ${PROJECT_SOURCE_DIR}/../TestingTools/lib
+)
+
+set ( GMOCK_LIBRARIES optimized ${GMOCK_LIB} )
+
+# handle the QUIETLY and REQUIRED arguments and set GMOCK_FOUND to TRUE if 
+# all listed variables are TRUE
+include ( FindPackageHandleStandardArgs )
+find_package_handle_standard_args( GMOCK DEFAULT_MSG GMOCK_INCLUDE_DIR 
+  GMOCK_LIBRARIES
+)
diff --git a/Code/Mantid/Build/CMake/FindGTest.cmake b/Code/Mantid/Build/CMake/FindGTest.cmake
index 9ebed4cfb77..1727981a405 100644
--- a/Code/Mantid/Build/CMake/FindGTest.cmake
+++ b/Code/Mantid/Build/CMake/FindGTest.cmake
@@ -1,4 +1,13 @@
 # Find the Google Test headers and libraries
+# GTEST_INCLUDE_DIR where to find gtest.h
 # GTEST_FOUND If false, do not try to use Google Test
 
-set ( GTEST_FOUND FALSE )
+find_path ( GTEST_INCLUDE_DIR gtest/gtest.h
+  PATHS ${PROJECT_SOURCE_DIR}/TestingTools/include
+        ${PROJECT_SOURCE_DIR}/../TestingTools/include
+)
+
+# handle the QUIETLY and REQUIRED arguments and set GTEST_FOUND to TRUE if 
+# all listed variables are TRUE
+include ( FindPackageHandleStandardArgs )
+find_package_handle_standard_args( GTest DEFAULT_MSG GTEST_INCLUDE_DIR )
diff --git a/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt b/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
index 447ea989e78..f9bdf9c64a0 100644
--- a/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
+++ b/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
@@ -116,8 +116,12 @@ target_link_libraries ( MDAlgorithms ${MANTIDLIBS} )
 # Create test file projects
 if ( CXXTEST_FOUND )
   if ( GMOCK_FOUND AND GTEST_FOUND )
+    message ( STATUS "A: ${GMOCK_LIBRARIES}")
+    message ( STATUS "B: ${GMOCK_INCLUDE_DIR}")
+    message ( STATUS "C: ${GTEST_INCLUDE_DIR}")
     cxxtest_add_test ( MDAlgorithmsTest ${TEST_FILES} ${GMOCK_TEST_FILES})
-    target_link_libraries( MDAlgorithmsTest MDAlgorithms MDDataObjects gmock)
+    target_link_libraries( MDAlgorithmsTest MDAlgorithms MDDataObjects 
+      ${GMOCK_LIBRARIES} )
   else ()
     cxxtest_add_test ( MDAlgorithmsTest ${TEST_FILES} )
     target_link_libraries( MDAlgorithmsTest MDAlgorithms MDDataObjects )
diff --git a/Code/Mantid/Framework/MDDataObjects/CMakeLists.txt b/Code/Mantid/Framework/MDDataObjects/CMakeLists.txt
index d1aa9c4f6ce..83f6bdfcc80 100644
--- a/Code/Mantid/Framework/MDDataObjects/CMakeLists.txt
+++ b/Code/Mantid/Framework/MDDataObjects/CMakeLists.txt
@@ -67,7 +67,7 @@ if ( CXXTEST_FOUND )
   include_directories(${HDF5_INCLUDE_DIRS} inc)
   if ( GMOCK_FOUND AND GTEST_FOUND )
     cxxtest_add_test ( MDDataObjectsTest ${TEST_FILES} ${GMOCK_TEST_FILES} )
-    target_link_libraries( MDDataObjectsTest MDDataObjects ${MANTIDLIBS} ${HDF5_LIBRARIES} gmock )
+    target_link_libraries( MDDataObjectsTest MDDataObjects ${MANTIDLIBS} ${HDF5_LIBRARIES} ${GMOCK_LIBRARIES} )
   else ()
     cxxtest_add_test ( MDDataObjectsTest ${TEST_FILES} )
     target_link_libraries( MDDataObjectsTest MDDataObjects ${MANTIDLIBS} ${HDF5_LIBRARIES} )
-- 
GitLab