CMake找不到我指定的包含文件

CMake not finding include file I specified

本文关键字:包含 文件 找不到 CMake      更新时间:2024-09-27

我正试图使用CMake来调试我正在处理的JUCE失真项目,但我无法获得CMakeLists.txt文件。找到头文件JuceHeader.h,以便它可以构建和调试该项目。

文件结构如下:

distort (CMakeLists located here)
|
|_______Source
|       |
|       |________PluginEditor.cpp and .h, PluginProcessor.cpp and .h
|
|_______JuceLibraryCode
|
|________JuceHeader.h (and more)

以及完整的txt文件:

cmake_minimum_required(VERSION 3.0.0)
project(Distort VERSION 0.1.0)
include(CTest)
enable_testing()
set(HEADER_FILES /home/wolf/vst/distort/JuceLibraryCode)
set(SOURCES Source/PluginProcessor.cpp Source/PluginEditor.cpp ${HEADER_FILES}/JuceHeader.h)
add_executable(Distort ${SOURCES})
target_include_directories(Distort PRIVATE home/wolf/vst/distort/JuceLibraryCode/)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

它给出了一个错误,说它找不到JuceHeader.h

最后,错误输出:

[build] /home/wolf/vst/distort/Source/PluginProcessor.h:11:10: fatal error: 'JuceHeader.h' file not found
[build] #include <JuceHeader.h>
[build]          ^~~~~~~~~~~~~~
[build] In file included from /home/wolf/vst/distort/Source/PluginEditor.cpp:9:
[build] /home/wolf/vst/distort/Source/PluginProcessor.h:11:10: fatal error: 'JuceHeader.h' file not found
[build] #include <JuceHeader.h>

如有任何帮助,我们将不胜感激!:(

我认为home/wolf/vst/distort/JuceLibraryCode/应该是一个绝对路径,但给出了相对路径。但绝对路径并不是解决方案。

target_include_directories(Distort PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/JuceLibraryCode)

或者就像下面的一样

target_include_directories(Distort PRIVATE JuceLibraryCode)

对于一个相对较新的cmake版本,以下内容应该有效:

file(GLOB headers ${CMAKE_SOURCE_DIR}/JuceLibraryCode)
...
target_include_directories(Distort PRIVATE ${headers})
相关文章: