cmake包含文件,然后是文件路径

时间:2017-11-09 10:40:11

标签: path cmake include

  • 源文件和CMakeLists.txt。 (路径:〜/ work / src)
  • unittest的来源。和CMakeLists.txt(路径:〜/ work / src / unittest /)

在〜/ work / src / unittest / CMakeLists.txt中,我使用include命令

include (${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists.txt)

在〜/ work / src / CMakeLists.txt中,

file (STRINGS "../profile" profile)

我想在unittest路径中使用cmake。

错误消息: CMake Error at ~/work/src/CMakeLists.txt:13 (file): file STRINGS file "~/work/src/unittest/../profile" cannot be read. Call Stack (most recent call first): CMakeLists.txt:6 (include) 我能怎么做?

1 个答案:

答案 0 :(得分:0)

include() CMake-script时,您不会更改当前的源目录(和二进制文件)。但通常CMakeLists.txt期望源目录反映CMakeLists.txt本身的位置。

使用include()

而不是CMakeLists.txt add_subdirectory
add_subdirectory(
    "${CMAKE_CURRENT_SOURCE_DIR}/../" # Source directory, contains CMakeLists.txt file
    "myproject" # Build directory, will be created and used for output files
)