Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

GLM linking in CMakeLists.txt

I cannot link glm library with my executable. I tried link via
${GLM_INCLUDE_DIRS}, ${GLM_LIBRARIES} and ${GLM_LIBRARY_DIRS} cmake variables but it does not work.

How can I link libraries and inludes of glm with my executable?

I am using find_package() method :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

find_package(glm REQUIRED PATHS "${GLM_BINARY_DIR}" NO_DEFAULT_PATH)

And does not have any problem with find_package() but these status messages below displays nothing :

message(STATUS "GLM includes ${GLM_INCLUDE_DIRS}")
message(STATUS "GLM libraries ${GLM_LIBRARY_DIRS}")

>Solution :

Config script for GLM defines IMPORTED target glm::glm.
So the correct way for use GLM in CMake code is to link with that target.
This is explicitly written in the documentation:

set(glm_DIR <installation prefix>/lib/cmake/glm) # if necessary
find_package(glm REQUIRED)
target_link_libraries(<your executable> glm::glm)

Variables like GLM_LIBRARIES or GLM_INCLUDE_DIRS are usually defined by Find scripts (shipped with CMake or with the consumer project).

Config scripts, shipped with the installed package, normally defines IMPORTED targets.

GLM doesn’t have a Find script (see FindGLM.cmake not in glm 0.9.7, is it a deprecated way to find libraries in CMAKE?), and PATHS option in find_package invocation explicitly requests Config script.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading