Skip to content
Permalink
Browse files
Add a CMake Package config
  • Loading branch information
Twinklebear committed Nov 1, 2019
1 parent ea678fa commit 15158e8aa906365cd2219dbb37352345d8ab5bf1
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 0 deletions.
@@ -67,5 +67,11 @@ build_script:

test_script:
- ctest -j4 -C %CONFIGURATION%
- cd ..
- ps: |
mkdir build_test_cmake
cd build_test_cmake
cmake ..\test\cmake\ -G "$env:generator" -Dglm_DIR="$env:APPVEYOR_BUILD_FOLDER"
- cmake --build . --config %CONFIGURATION% -- /m /v:minimal

deploy: off
@@ -33,6 +33,8 @@ CMakeFiles
cmake_install.cmake
install_manifest.txt
*.cmake
!glmConfig.cmake
!glmConfig-version.cmake
# ^ May need to add future .cmake files as exceptions

# Test logs
@@ -56,3 +58,4 @@ build*
/.vscode
/CMakeSettings.json
.DS_Store
*.swp

Large diffs are not rendered by default.

@@ -0,0 +1,13 @@
set(PACKAGE_VERSION 0.9.9)

if(${PACKAGE_FIND_VERSION_MAJOR} EQUAL 0)
if (${PACKAGE_FIND_VERSION} VERSION_LESS ${GLM_VERSION})
set(PACKAGE_VERSION_COMPATIBLE 1)
endif()
if(${PACKAGE_FIND_VERSION} VERSION_EQUAL ${GLM_VERSION})
set(PACKAGE_VERSION_EXACT 1)
endif()
else()
set(PACKAGE_VERSION_UNSUITABLE 1)
endif()

@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
cmake_policy(VERSION 3.2)

set(GLM_VERSION 0.9.9)
# Set the old GLM_INCLUDE_DIRS variable for backwards compatibility
set(GLM_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR})

add_library(glm::glm INTERFACE IMPORTED)
set_target_properties(glm::glm PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR})

mark_as_advanced(glm_DIR)

@@ -14,6 +14,7 @@
+ [1.2. Using separated headers](#section1_2)
+ [1.3. Using extension headers](#section1_3)
+ [1.4. Dependencies](#section1_4)
+ [1.5. Finding GLM with CMake](#section1_5)
+ [2. Preprocessor configurations](#section2)
+ [2.1. GLM\_FORCE\_MESSAGES: Platform auto detection and default configuration](#section2_1)
+ [2.2. GLM\_FORCE\_PLATFORM\_UNKNOWN: Force GLM to no detect the build platform](#section2_2)
@@ -273,6 +274,10 @@ glm::mat4 transform(glm::vec2 const& Orientation, glm::vec3 const& Translate, gl

GLM does not depend on external libraries or headers such as `<GL/gl.h>`, [`<GL/glcorearb.h>`](http://www.opengl.org/registry/api/GL/glcorearb.h), `<GLES3/gl3.h>`, `<GL/glu.h>`, or `<windows.h>`.

### <a name="section1_5"></a> 1.5. Finding GLM with CMake

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>` 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.

---
<div style="page-break-after: always;"> </div>

@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(test_find_glm)

find_package(glm REQUIRED)

add_executable(test_find_glm test_find_glm.cpp)
target_link_libraries(test_find_glm glm::glm)

@@ -0,0 +1,22 @@
#include <iostream>
#include <glm/glm.hpp>
#include <glm/ext.hpp>

glm::mat4 camera(float Translate, glm::vec2 const& Rotate)
{
glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, 4.0f / 3.0f, 0.1f, 100.f);
glm::mat4 View = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Translate));
View = glm::rotate(View, Rotate.y, glm::vec3(-1.0f, 0.0f, 0.0f));
View = glm::rotate(View, Rotate.x, glm::vec3(0.0f, 1.0f, 0.0f));
glm::mat4 Model = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f));
return Projection * View * Model;
}

int main()
{
const glm::mat4 m = camera(1.f, glm::vec2(1.f, 0.5f));
std::cout << "matrix diagonal: " << m[0][0] << ", "
<< m[1][1] << ", " << m[2][2] << ", " << m[3][3] << "\n";
return 0;
}

0 comments on commit 15158e8

Please sign in to comment.