From 6e63c1c1ad2e26e976cd9585b071d10c01b32b53 Mon Sep 17 00:00:00 2001
From: Stephen Birarda <commit@birarda.com>
Date: Fri, 13 Feb 2015 14:50:12 -0800
Subject: [PATCH] set the GLM_INCLUDE_DIRS var in cache so find hits it

---
 cmake/externals/glm/CMakeLists.txt              | 12 ++++++++----
 cmake/macros/AddDependencyExternalProject.cmake |  3 ---
 cmake/modules/FindGLM.cmake                     |  4 +---
 libraries/shared/CMakeLists.txt                 |  4 ++++
 4 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/cmake/externals/glm/CMakeLists.txt b/cmake/externals/glm/CMakeLists.txt
index a3b64b9370..8bf597ecc3 100644
--- a/cmake/externals/glm/CMakeLists.txt
+++ b/cmake/externals/glm/CMakeLists.txt
@@ -1,11 +1,15 @@
+set(EXTERNAL_NAME glm)
+
 include(ExternalProject)
 ExternalProject_Add(
-  glm
-  PREFIX glm
+  ${EXTERNAL_NAME}
+  PREFIX ${EXTERNAL_NAME}
   URL https://github.com/g-truc/glm/archive/0.9.5.4.zip
   CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
   LOG_DOWNLOAD ON
 )
-ExternalProject_Get_Property(glm install_dir)
 
-export(TARGETS glm FILE ${CMAKE_BINARY_DIR}/glm-config.cmake)
\ No newline at end of file
+ExternalProject_Get_Property(${EXTERNAL_NAME} install_dir)
+
+string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER)
+set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${install_dir}/include CACHE TYPE STRING)
\ No newline at end of file
diff --git a/cmake/macros/AddDependencyExternalProject.cmake b/cmake/macros/AddDependencyExternalProject.cmake
index c4c2c0d005..71c32e5e69 100644
--- a/cmake/macros/AddDependencyExternalProject.cmake
+++ b/cmake/macros/AddDependencyExternalProject.cmake
@@ -21,8 +21,5 @@ macro(ADD_DEPENDENCY_EXTERNAL_PROJECT _PROJ_NAME)
     add_subdirectory(${EXTERNAL_PROJECT_DIR}/${_PROJ_NAME} ${_PROJ_BINARY_DIR})
   endif ()
   
-  string(TOUPPER ${_PROJ_NAME} _PROJ_NAME_UPPER)
-  get_target_property(${_PROJ_NAME_UPPER}_INCLUDE_DIRS ${_PROJ_NAME} INCLUDE_DIRS)
-  
   add_dependencies(${TARGET_NAME} ${_PROJ_NAME})
 endmacro()
\ No newline at end of file
diff --git a/cmake/modules/FindGLM.cmake b/cmake/modules/FindGLM.cmake
index a75730b238..ace7360ea7 100644
--- a/cmake/modules/FindGLM.cmake
+++ b/cmake/modules/FindGLM.cmake
@@ -18,9 +18,7 @@ include("${MACRO_DIR}/HifiLibrarySearchHints.cmake")
 hifi_library_search_hints("glm")
 
 # locate header
-find_path(GLM_INCLUDE_DIR "glm/glm.hpp" HINTS ${GLM_SEARCH_DIRS})
-
-set(GLM_INCLUDE_DIRS "${GLM_INCLUDE_DIR}")
+find_path(GLM_INCLUDE_DIRS "glm/glm.hpp" HINTS ${GLM_SEARCH_DIRS})
 
 include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(GLM DEFAULT_MSG GLM_INCLUDE_DIRS)
diff --git a/libraries/shared/CMakeLists.txt b/libraries/shared/CMakeLists.txt
index 0bbb39fdb5..5af2343ec2 100644
--- a/libraries/shared/CMakeLists.txt
+++ b/libraries/shared/CMakeLists.txt
@@ -4,5 +4,9 @@ set(TARGET_NAME shared)
 # TODO: there isn't really a good reason to have Script linked here - let's get what is requiring it out (RegisteredMetaTypes.cpp)
 setup_hifi_library(Gui Network Script Widgets)
 
+add_dependency_external_project(glm)
+find_package(GLM REQUIRED)
+target_include_directories(${TARGET_NAME} PRIVATE ${GLM_INCLUDE_DIRS})
+
 # call macro to include our dependency includes and bubble them up via a property on our target
 include_dependency_includes()
\ No newline at end of file