本文介绍了CMake - get_filename_component未知的组件目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对CMake有点麻烦。 我想尝试链接到GLFW并包含我自己项目的多个源文件。 (我从Visual Studio切换,使我的项目跨平台)。

I am having a bit of trouble with CMake. I am trying to link with GLFW and include multiple source files of my own project. (I'm switching from Visual Studio to make my project cross-platform).

GLFW位于文件夹deps / glfw-3.1.1中,源代码位于文件夹src

GLFW is in the folder deps/glfw-3.1.1 and my source code is in the folder src

这是我的CMakeLists.txt文件:

Here is my CMakeLists.txt file:

# Tell CMake to use a minimum of version 3.2
cmake_minimum_required(3.2)

project(Sparky)
# TODO: Versions

# Add all of our source code to the project
file(GLOB_RECURSE Sparky_SOURCES "src/*.cpp")
file(GLOB_RECURSE Sparky_HEADERS "src/*.h")

set(Sparky_INCLUDE_DIRS "")
foreach (_headerFile ${Sparky_HEADERS})
    get_filename_component(_dir ${_headerFile} path)
    list (APPEND Sparky_INCLUDE_DIRS ${_dir})
endforeach()
list(REMOVE_DUPLICATES Sparky_INCLUDE_DIRS)

add_subdirectory(deps/glfw-3.1.1)
include_directories(${Sparky_INCLUDE_DIRS})
include_directories(deps/glfw-3.1.1/include)

add_executable(Sparky ${Sparky_SOURCES}
target_link_libraries(Sparky glfw ${GLFW_LIBRARIES}))


推荐答案

似乎至少有一个迭代的变量_headerFile和路径的值错误。尝试在使用以下代码在foreach循环中启动get_filename_component之前打印这些变量的值。

It seems that there is at least an iteration with wrong values for variables _headerFile and path. Try to print values of these variables before launching get_filename_component in the foreach loop using the following code.

message(STATUS "_headerFile: ${_headerFile} )
message(STATUS "path: " ${path}  )

这些类型的错误可以由这些参数的错误值生成。

Sometimes these types of errors can be generated by wrong values of these parameters.

这篇关于CMake - get_filename_component未知的组件目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 15:56