3d511e8
From 02f26a88537b0b02dd0df77fc858e9449c7e3847 Mon Sep 17 00:00:00 2001
3d511e8
From: Krzysztof Kurek <krzysio.kurek@pm.me>
3d511e8
Date: Sat, 30 Jan 2021 21:08:48 +0100
3d511e8
Subject: [PATCH] Add installation support from PR #1054
3d511e8
3d511e8
This is based on commit 887827b762111a8e6b4765513b4be212fa6a5426,
3d511e8
discovered from https://github.com/g-truc/glm/pull/1054
3d511e8
---
3d511e8
 CMakeLists.txt                    | 16 ++++++++++++++--
3d511e8
 cmake/glm/glmConfig-version.cmake | 11 -----------
3d511e8
 cmake/glm/glmConfig.cmake         | 22 ----------------------
3d511e8
 glm/CMakeLists.txt                | 10 +++++++++-
3d511e8
 manual.md                         | 21 ++++++++++++++++++++-
3d511e8
 5 files changed, 43 insertions(+), 37 deletions(-)
3d511e8
 delete mode 100644 cmake/glm/glmConfig-version.cmake
3d511e8
 delete mode 100644 cmake/glm/glmConfig.cmake
3d511e8
3d511e8
diff --git a/CMakeLists.txt b/CMakeLists.txt
3d511e8
index 843e7546..642a5fde 100644
3d511e8
--- a/CMakeLists.txt
3d511e8
+++ b/CMakeLists.txt
3d511e8
@@ -3,13 +3,25 @@ cmake_policy(VERSION 3.2)
3d511e8
 
3d511e8
 set(GLM_VERSION "0.9.9")
3d511e8
 project(glm VERSION ${GLM_VERSION} LANGUAGES CXX)
3d511e8
-enable_testing()
3d511e8
+message(STATUS "GLM: Version " ${GLM_VERSION})
3d511e8
 
3d511e8
 add_subdirectory(glm)
3d511e8
 add_library(glm::glm ALIAS glm)
3d511e8
 
3d511e8
 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
3d511e8
 
3d511e8
-add_subdirectory(test)
3d511e8
+	include(CPack)
3d511e8
+	install(DIRECTORY glm DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PATTERN "CMakeLists.txt" EXCLUDE)
3d511e8
+	install(EXPORT glm FILE glmConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/glm NAMESPACE glm::)
3d511e8
+	include(CMakePackageConfigHelpers)
3d511e8
+	write_basic_package_version_file("glmConfigVersion.cmake" COMPATIBILITY AnyNewerVersion)
3d511e8
+	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/glmConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/glm)
3d511e8
+
3d511e8
+	include(CTest)
3d511e8
+	if(BUILD_TESTING)
3d511e8
+		add_subdirectory(test)
3d511e8
+	endif()
3d511e8
 
3d511e8
 endif(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
3d511e8
+
3d511e8
+
3d511e8
diff --git a/cmake/glm/glmConfig-version.cmake b/cmake/glm/glmConfig-version.cmake
3d511e8
deleted file mode 100644
3d511e8
index 6e63a4a3..00000000
3d511e8
--- a/cmake/glm/glmConfig-version.cmake
3d511e8
+++ /dev/null
3d511e8
@@ -1,11 +0,0 @@
3d511e8
-if(${PACKAGE_FIND_VERSION_MAJOR} EQUAL 0)
3d511e8
-    if (${PACKAGE_FIND_VERSION} VERSION_LESS ${GLM_VERSION})
3d511e8
-        set(PACKAGE_VERSION_COMPATIBLE 1)  
3d511e8
-    endif()
3d511e8
-    if(${PACKAGE_FIND_VERSION} VERSION_EQUAL ${GLM_VERSION})
3d511e8
-        set(PACKAGE_VERSION_EXACT 1)  
3d511e8
-    endif()
3d511e8
-else()
3d511e8
-    set(PACKAGE_VERSION_UNSUITABLE 1)
3d511e8
-endif()
3d511e8
-
3d511e8
diff --git a/cmake/glm/glmConfig.cmake b/cmake/glm/glmConfig.cmake
3d511e8
deleted file mode 100644
3d511e8
index 4fba5116..00000000
3d511e8
--- a/cmake/glm/glmConfig.cmake
3d511e8
+++ /dev/null
3d511e8
@@ -1,22 +0,0 @@
3d511e8
-cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
3d511e8
-cmake_policy(VERSION 3.2)
3d511e8
-
3d511e8
-set(GLM_VERSION 0.9.9)
3d511e8
-
3d511e8
-get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
3d511e8
-get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
3d511e8
-get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
3d511e8
-if (_IMPORT_PREFIX STREQUAL "/")
3d511e8
-  set(_IMPORT_PREFIX "")
3d511e8
-endif()
3d511e8
-
3d511e8
-# Set the old GLM_INCLUDE_DIRS variable for backwards compatibility
3d511e8
-set(GLM_INCLUDE_DIRS ${_IMPORT_PREFIX})
3d511e8
-
3d511e8
-add_library(glm::glm INTERFACE IMPORTED)
3d511e8
-set_target_properties(glm::glm PROPERTIES
3d511e8
-    INTERFACE_INCLUDE_DIRECTORIES ${GLM_INCLUDE_DIRS})
3d511e8
-
3d511e8
-mark_as_advanced(glm_DIR)
3d511e8
-set(_IMPORT_PREFIX)
3d511e8
-
3d511e8
diff --git a/glm/CMakeLists.txt b/glm/CMakeLists.txt
3d511e8
index 4ff51c81..cee0d2e7 100644
3d511e8
--- a/glm/CMakeLists.txt
3d511e8
+++ b/glm/CMakeLists.txt
3d511e8
@@ -43,7 +43,15 @@ source_group("SIMD Files" FILES ${SIMD_INLINE})
3d511e8
 source_group("SIMD Files" FILES ${SIMD_HEADER})
3d511e8
 
3d511e8
 add_library(glm INTERFACE)
3d511e8
-target_include_directories(glm INTERFACE ../)
3d511e8
+
3d511e8
+include(GNUInstallDirs)
3d511e8
+
3d511e8
+target_include_directories(glm INTERFACE
3d511e8
+	$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
3d511e8
+	$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
3d511e8
+)
3d511e8
+
3d511e8
+install(TARGETS glm EXPORT glm)
3d511e8
 
3d511e8
 if(BUILD_STATIC_LIBS)
3d511e8
 add_library(glm_static STATIC ${ROOT_TEXT} ${ROOT_MD} ${ROOT_NAT}
3d511e8
diff --git a/manual.md b/manual.md
3d511e8
index a7f6956f..d53df3d7 100644
3d511e8
--- a/manual.md
3d511e8
+++ b/manual.md
3d511e8
@@ -277,7 +277,26 @@ GLM does not depend on external libraries or headers such as `<GL/gl.h>`, [`
3d511e8
 
3d511e8
 ###  1.5. Finding GLM with CMake
3d511e8
 
3d511e8
-GLM packages a `glmConfig.cmake` and `glmConfig-version.cmake` in the root of the repository and the release archives. To find GLM with CMake you can pass `-Dglm_DIR=<path to glm root>/cmake/glm/` when running CMake. You can then either add `${GLM_INCLUDE_DIRS}` to your target's include directories, or link against the imported `glm::glm` target.
3d511e8
+When installed, GLM provides the CMake package configuration files `glmConfig.cmake` and `glmConfigVersion.cmake`.
3d511e8
+
3d511e8
+To use these configurations files, you may need to set the `glm_DIR` variable to the directory containing the configuration files `<installation prefix>/lib/cmake/glm/`.
3d511e8
+
3d511e8
+Use the `find_package` CMake command to load the configurations into your project. Lastly, either link your executable against the `glm::glm` target or add `${GLM_INCLUDE_DIRS}` to your target's include directories:
3d511e8
+
3d511e8
+```cmake
3d511e8
+set(glm_DIR <installation prefix>/lib/cmake/glm) # if necessary
3d511e8
+find_package(glm REQUIRED)
3d511e8
+target_link_libraries(<your executable> glm::glm)
3d511e8
+```
3d511e8
+
3d511e8
+To use GLM as a submodule in a project instead, use `add_subdirectory` to expose the same target, or add the directory to your target's 
3d511e8
+
3d511e8
+```cmake
3d511e8
+add_subdirectory(glm)
3d511e8
+target_link_libraries(<your executable> glm::glm)
3d511e8
+# or
3d511e8
+target_include_directories(<your executable> glm)
3d511e8
+```
3d511e8
 
3d511e8
 ---
3d511e8
 
3d511e8
-- 
3d511e8
2.29.2
3d511e8