From a72a3fef22a2fbf240597f6fe9f58883b17fe27a Mon Sep 17 00:00:00 2001
From: Ray Donnelly <mingw.android@gmail.com>
Date: Wed, 22 Jul 2015 09:58:02 +0100
Subject: [PATCH 6/6] CMake: Handle installation

---
 CMakeLists.txt | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d6ab5d8..0bf8574 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,6 +29,8 @@ file(GLOB glsl_sources src/glsl/*.cpp src/glsl/*.c)
 file(GLOB glsl_sources_remove src/glsl/main.cpp src/glsl/builtin_stubs.cpp)
 list(REMOVE_ITEM glsl_sources ${glsl_sources_remove})
 add_library(glsl_optimizer ${glsl_sources})
+set_property(TARGET glsl_optimizer PROPERTY PUBLIC_HEADER src/glsl/glsl_optimizer.h)
+
 target_link_libraries(glsl_optimizer glcpp-library mesa)
 
 add_executable(glsl_compiler src/glsl/main.cpp)
@@ -53,3 +55,26 @@ target_link_libraries(glslopt glsl_optimizer)
 
 #add_executable(glcpp src/glsl/glcpp/glcpp.c)
 #target_link_libraries(glcpp glsl_optimizer)
+
+# <taken from>
+# http://www.cmake.org/pipermail/cmake/2010-February/035466.html
+# compute default library install dir
+set (_DEFAULT_LIBRARY_INSTALL_DIR lib)
+if (EXISTS "${CMAKE_INSTALL_PREFIX}/lib32/" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
+ set (_DEFAULT_LIBRARY_INSTALL_DIR lib32)
+elif (EXISTS "${CMAKE_INSTALL_PREFIX}/lib64/" AND CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set (_DEFAULT_LIBRARY_INSTALL_DIR lib64)
+endif ()
+# the library install dir
+set(LIBRARY_INSTALL_DIR "${_DEFAULT_LIBRARY_INSTALL_DIR}" CACHE PATH "Installation directory for libraries")
+# make the library install dir an absolute path (can be important e.g. when using CONFIGURE_FILE to embed
+# the library installation directory into a file)
+if(NOT IS_ABSOLUTE "${LIBRARY_INSTALL_DIR}")
+  set(LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIBRARY_INSTALL_DIR}")
+endif()
+# </taken from>
+
+install(TARGETS glsl_optimizer glsl_compiler glsl_test glslopt PUBLIC_HEADER
+        ARCHIVE DESTINATION "${LIBRARY_INSTALL_DIR}"
+        RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin"
+        PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_PREFIX}/include")
-- 
2.4.5

