c++ - 如何使用 CMake 从根文件夹外部添加包含目录?

标签 c++ cmake

这是我的第一个 CMakeLists.txt 代码:

#cmake_minimum_required (VERSION 2.6)
project (project)

add_subdirectory(src)

include_directories(${/path_to_directory}/include)

这是子目录下的CMakeLists.txt

set (CMAKE_C_FLAGS "-WALL -g")

file(GLOB SRCS *.cpp *.hpp *.h)

add_executable(source ${SRCS})

我仍然无法在我的项目中包含 path_to_directory

编辑:这也不起作用:

file(GLOB mylib *.cpp *.hpp *.h)

add_executable(includeSource ${mystuff})
target_include_directories(
    mystuff
    PUBLIC ${path_to_directory}/include
)

最佳答案

即使问题不清楚,我猜你想要 target_include_directories(here 文档)而不是 include_directories

来自文档:

Specify include directories or targets to use when compiling a given target.

您可以将其用作:

target_include_directories(
    your_target_name
    PUBLIC ${/path_to_directory}/include
)

关于c++ - 如何使用 CMake 从根文件夹外部添加包含目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35258919/

相关文章:

c++ - 使用 Cmake 编写简单的 CUDA 程序

c++ - 如何处理状态转换并将 "if"语句替换为多态类型?

android - 在Gradle中针对不同ABI的CMAKE参数

c++ - CMake 包支持 - 未找到包含和库

c++ - 有没有办法 "statically"将共享的 .so(或 .o)库插入可执行文件?

c++ - CLion 会自动从标准输入打印回输入,是否有任何解决方法?

visual-studio-2012 - 在 CMake 中根据 Release/Debug 构建类型创建一个目录

c++ - 我是否在头文件中正确地创建了一个对象?

c++ - SDL2 - 垂直同步不工作

c++ - boost::bind 返回的仿函数是否只有绑定(bind)参数等同于不带参数的函数?