Linking GLFW on CLion with CMake

2019-07-09 05:03发布

问题:

Does anyone know how to link glfw to a CLion project? CLion is based on CMake so if you have knowledge on CMake, you can help.

What I want to do is, to put my dependencies into my project folder so when I push my code to git, others who download the code won't have to do any linking locally, the environment will be set up for them.

I tried to moving the root folder of glfw to the project folder, but from then on, I have failed to successfully adjust my CMakelist.txt file to actually be able to link the library properly. I couldn't get it to work. I tried following the tutorial on the glfw website but that assumes you know your way around CMake with the addition of sub directories and all and that's where I fail anyway.

This is my CMakelists.txt file that doesn't work.

cmake_minimum_required(VERSION 3.3)
project(Boomer)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

include_directories(${PROJECT_SOURCE_DIR}/glfw-3.1.2.bin.WIN64)

set(SOURCE_FILES main.cpp)
add_executable(Boomer ${SOURCE_FILES})

Any help would be appreicated.

回答1:

try this:

find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
INCLUDE_DIRECTORIES(${GLFW_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(Boomer ${GLFW_STATIC_LIBRARIES})