I'm having trouble Linking glfw and glm

I’m using VS to add in the Libraries of GLFW and GLM to my project. I’m very new but it gives me an error saying it’s not built.

CMake Error at C:\Users\patri\Documents\Game_dev\Engines\EndBullet\CMakeLists.txt:42 (target_link_libraries):
Attempt to add link library “glm” to target “Engine” which is not built
in this directory.

The code

cmake_policy(SET CMP0079 NEW)
Hsd to do this, what does this do?

Attempt to add link library "glm" to target "Engine" which is not built in this directory

That is strange, because you have


and so in

target_link_libraries("${CMAKE_PROJECT_NAME}" PRIVATE glm glfw)

the ${CMAKE_PROJECT_NAME} should evaluate to EndBullet, not to Engine. It could be that one of the CMakeLists.txt’s in added sub-directories modifies this variable or something.

Also, from the only CMakeLists.txt file that you shared it seems that there is not a single target declared (neither a library nor an executable), which GLM and GLFW are supposed to be linked with.

I’d recommend avoiding using the CMAKE_PROJECT_NAME variable and just use the target name directly. If you look at the docs for CMAKE_PROJECT_NAME, pay attention to how it describes the variable’s behavior. You’re likely picking up the Engine project name from the top-level CMakeLists.txt that’s pulling in the one you’ve pasted. You likely are not creating a library named that and so the target_link_libraries is failing because the target doesn’t exist.

You may instead be meaning to use the PROJECT_NAME variable which likely has the behavior you’re looking for since it picks up the last call to project().

At any rate, you should be using EndBullet directly instead of trying to use the CMake variable. The name shouldn’t change often, so using the variable loses some of its benefit. It also avoids this sort of confusion on how these CMake variables behave.

If you’re doing this, you may as well just require CMake 3.13 since it won’t work in older versions anyways. Update this at the top of your project:

cmake_minimum_required(VERSION 3.13)

And then you won’t need to set the policy either.