Cmake GNUInstallDirs 变量为空

Joã*_*eto 1 cmake

尝试使用 编译我的项目时cmake .,变量CMAKE_INSTALL_LIBDIR为空,我不知道为什么。

我正在尝试发布以下内容(第 40 行):

install(TARGETS fpthread
    EXPORT fpthread_config
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
Run Code Online (Sandbox Code Playgroud)

我收到以下错误消息:

CMake Error at CMakeLists.txt:40 (install):
  install TARGETS given no LIBRARY DESTINATION for shared library target
  "fpthread".
Run Code Online (Sandbox Code Playgroud)

发出以下结果为空字符串:

MESSAGE(STATUS ${CMAKE_INSTALL_LIBDIR})
Run Code Online (Sandbox Code Playgroud)

我已经尝试了 Cmake 3.5(通过包管理器安装)和 Cmake 3.11(最新版本,从源代码编译)。

vre*_*vre 5

重新整理我之前的评论作为答案:

要从 GNUInstallDirs 模块访问变量,您需要添加

include(GNUInstallDirs)
Run Code Online (Sandbox Code Playgroud)

到您的 CMakeLists.txt 文件。默认情况下不包含该模块。