为什么 cmake 许可证<>样式不包括?

Why won't cmake permit <> style include?

本文关键字:样式 不包括 gt lt cmake 许可证 为什么      更新时间:2023-10-16

我对cmake很陌生,但我在Visual Studio上使用它来开发一个必须在linux上运行的程序。我需要以这种方式包括以下内容:

#include <xscontroller/xscontrol_def.h>
#include <xscontroller/xsdevice_def.h>
#include <xscontroller/xsscanner.h>
#include <xstypes/xsoutputconfigurationarray.h>
#include <xstypes/xsdatapacket.h>
#include <xstypes/xstime.h>
#include <xscommon/xsens_mutex.h>

然而,只有当我执行以下操作时,visualstudio才能识别这些文件:

#include "xscontroller/xscontrol_def.h"
#include "xscontroller/xsdevice_def.h"
#include "xscontroller/xsscanner.h"
#include "xstypes/xsoutputconfigurationarray.h"
#include "xstypes/xsdatapacket.h"
#include "xstypes/xstime.h"
#include "xscommon/xsens_mutex.h"

我在VS中的项目结构相当简单:

ANT
-out
-xscommon
-xscontroller
-xstypes
-ANT.cpp
-CMakeLists.txt
.
.
.

我需要的includes在three-xs文件夹中,我相信它们必须用<gt;无论是在visualstudio中还是在linux上编译代码时,因为每个头中的引用都是在<gt;表单,这就是导致此错误的原因:

xscallbackplainc.h:68:10: fatal error: xstypes/pstdint.h: No such file or directory
#include <xstypes/pstdint.h>
^~~~~~~~~~~~~~~~~~~

在编译时。

简单地说,我真的只需要知道什么命令(无论是在CMakeLists.txt中还是在其他地方(将允许在项目中和在linux上通过ssh编译的项目中进行这种引用。我知道#include ""#include <>之间的区别,但我是cmake的新手,到处找都找不到答案。

实现这一点的最简单方法是使用include_directories命令。只需将以下内容添加到您的ANT/CMakeLists.txt:

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

尽管我强烈建议使用target_include_directories()。两者的区别在于target_include_directories()仅为一个目标[1]指定了包含目录。

[1] 。目标是通过add_executable()add_library():指定的任何内容

cmake_minimum_required(VERSION 3.12)
project(ANT)
add_executable(ANT ANT.cpp) #other source files as necessary
#format of target_include_directories:
# target_include_directories(target_name PUBLIC|PRIVATE PATH_TO_DIR) 
target_include_directories(ANT PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

我已经发布了关于链接的问题,希望它有意义。应该清楚我不知道自己在做什么。