Creating GLFW3 Application Using CMAKE - GLFW_LIBRARIES Not Installed

I am trying to create a small project using glfw3, but no matter what I do, I can not get pkgconfig to set GLFW_LIBRARIES.

Here is my CMakeList.txt

cmake_minimum_required(VERSION 3.3)
project(LearnGLSL)

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

if (CMAKE_BUILD_TYPE STREQUAL "")
    set(CMAKE_BUILD_TYPE Debug)
endif()


if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/debug")
    set(PROJECT_BINARY_DIR "${CMAKE_SOURCE_DIR}/build/debug")
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")


file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})


find_package(OpenGL REQUIRED)

find_package(PkgConfig REQUIRED)
pkg_check_modules(GLFW REQUIRED glfw3)



include_directories(
        ${OPENGL_INCLUDE_DIR}
        ${GLFW_INCLUDE_DIRS}
)


set(SOURCE_FILES main.cpp gl_core_4_3.cpp)

message(WARNING "${GLFW_LIBRARIES}")

add_executable(LearnGLSL ${SOURCE_FILES})
target_link_libraries(LearnGLSL ${OPENGL_gl_LIBRARY} ${GLFW_LIBRARIES})


add_custom_command(TARGET LearnGLSL  POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_directory
        ${CMAKE_SOURCE_DIR}/assets
        ${PROJECT_BINARY_DIR}
        COMMENT "Copy resources to build tree")

Glfw3 is installed here

-- Installing: /usr/local/include/GLFW
-- Installing: /usr/local/include/GLFW/glfw3native.h
-- Installing: /usr/local/include/GLFW/glfw3.h
-- Installing: /usr/local/lib/cmake/glfw/glfw3Config.cmake
-- Installing: /usr/local/lib/cmake/glfw/glfw3ConfigVersion.cmake
-- Installing: /usr/local/lib/cmake/glfw/glfwTargets.cmake
-- Installing: /usr/local/lib/cmake/glfw/glfwTargets-noconfig.cmake
-- Installing: /usr/local/lib/pkgconfig/glfw3.pc
-- Installing: /usr/local/lib/libglfw3.a

I will be the first to admit that I'm not very comfortable with CMAKE, but that seems simple enough, and I did everything I could to find Google. perhaps this is a typo that I do not notice. Any help appreciated thanks

Oh, I forgot to mention that when I create this project, I get undefined references to glfw functions. I assumed that this is the result of GLFW_LIBRARIES that does not receive the given value.

+4
source share
2

, GLFW pkgconfig, , pkgconfig . GLFW CMake, CMake, .

, . CMake CMake v3.1.2. shaxbee fork adasworks fork ( shaxbee )

GLFW , , :

find_package(glfw3 REQUIRED)
...
target_link_libraries(LearnGLSL ... glfw)

CMakeLists.txt, script, :

cmake_minimum_required(VERSION 3.3)
project(LearnGLSL)

set(CMAKE_CXX_STANDARD 11) # no explicit compiler flags if possible

# don't read CMAKE_BUILD_TYPE, it has no meaning with multiconfig
# generators
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/build/debug")

# PROJECT_BINARY_DIR should not be set at all
# You establish the BINARY_DIR with the initial cmake command
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})

find_package(OpenGL REQUIRED)
find_package(glfw3 REQUIRED)

include_directories(${OPENGL_INCLUDE_DIR})

add_executable(LearnGLSL main.cpp gl_core_4_3.cpp)
target_link_libraries(LearnGLSL ${OPENGL_gl_LIBRARY} glfw)

add_custom_command(TARGET LearnGLSL POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory
    ${CMAKE_SOURCE_DIR}/assets
    ${PROJECT_BINARY_DIR}
    COMMENT "Copy resources to build tree")
+2

CMake 3.1 pkg_check_modules CMAKE_PREFIX_PATH .pc . find_library, pkgconfig/ . , <prefix> CMAKE_PREFIX_PATH .pc :

<prefix>/lib[64]/[<arch>/]pkgconfig

( 64 , ).

, /usr/local/lib/pkgconfig/glfw3.pc, CMAKE_PREFIX_PATH /usr/local pkg_check_modules, . ​​:

1) CMakeLists.txt script

2)

cmake -DCMAKE_PREFIX_PATH=<...> <source-dir>

3) ( ).


CMake 3.1 ( ) PKG_CONFIG_PATH.

. /usr/local/lib/pkgconfig/glfw3.pc PKG_CONFIG_PATH /usr/local/lib/pkgconfig.

0

Source: https://habr.com/ru/post/1620846/


All Articles