【问题标题】:cmake find_package not working on Mac OS Xcmake find_package 在 Mac OS X 上不起作用
【发布时间】:2014-06-07 12:44:22
【问题描述】:

只是试图创建我的第一个 cmake 项目。我有一个非常简单的设置,但似乎无法让 find_package 工作。我在 Mac OS X 10.9.3 上并从 dmg 包(cmake 版本 2.8.12.2)安装了 cmake。我创建了一个非常简单的 CMakeLists.txt,如下所示:

cmake_minimum_required (VERSION 2.8)
project (Tutorial)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} “${CMAKE_SOURCE_DIR}/cmake/Modules”)
message( STATUS ${CMAKE_MODULE_PATH} )
FIND_PACKAGE(GSL REQUIRED)

add_executable(Tutorial src/main.cpp)

并将 FindGSL.cmake 文件(已下载)放在 cmake/Module 文件夹中,如我的终端输出所示:

bash-3.2$ ls cmake/Modules/
FindGSL.cmake

然后我从 cmake 得到以下输出:

bash-3.2$ cmake ../
-- “/Users/adam/repos/ctmc/cmake/Modules”
CMake Error at CMakeLists.txt:6 (FIND_PACKAGE):
  By not providing "FindGSL.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "GSL", but
  CMake did not find one.

  Could not find a package configuration file provided by "GSL" with any of
  the following names:

    GSLConfig.cmake
    gsl-config.cmake

  Add the installation prefix of "GSL" to CMAKE_PREFIX_PATH or set "GSL_DIR"
  to a directory containing one of the above files.  If "GSL" provides a
  separate development package or SDK, be sure it has been installed.


-- Configuring incomplete, errors occurred!
See also "/Users/adam/repos/ctmc/build/CMakeFiles/CMakeOutput.log".

谁能指出我做错了什么?

【问题讨论】:

  • 对我来说很好。你确定文件/Users/adam/repos/ctmc/cmake/Modules/FindGSL.cmake 存在吗?
  • 很奇怪,是的,在 finder 中检查,从命令行似乎没有找到它,想知道它是文件权限还是我需要设置的某些环境变量!我回来后在另一台电脑上试试
  • 我也在 Linux 机器上尝试过,得到了同样的错误。如果 FindGSL.cmake 文件有错误会不会给出这个信息
  • 请注意,我已经通过使用 INCLUDE 而不是 FIND_PACKAGE 完成了所有工作。不知道为什么 find_package 不适合我
  • using INCLUDE instead of FIND_PACKAGE 不一样,是的,这真的很奇怪)

标签: macos cmake gsl


【解决方案1】:

检查您的cmake/Modules 目录权限。您没有 execute 权限 目录,以便您可以读取文件,如果您有 完整路径,但您找不到它:

> ls cmake/Modules/FindMy.cmake 
cmake/Modules/FindMy.cmake
> cat CMakeLists.txt 
cmake_minimum_required(VERSION 3.0)
project(Foo)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
find_package(My REQUIRED)
> cmake -H. -B_builds
... OK

再次没有x-permission

> chmod -x cmake/Modules/
> rm -rf _builds/
> cmake -H. -B_builds
...
CMake Error at CMakeLists.txt:5 (find_package):
  By not providing "FindMy.cmake" in CMAKE_MODULE_PATH this project has asked
  CMake to find a package configuration file provided by "My", but CMake did
  not find one.

【讨论】:

  • 太棒了!!这为我的帮助欢呼,我知道这一定是我在做的傻事
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-01-03
  • 1970-01-01
  • 1970-01-01
  • 2016-04-06
  • 2014-10-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多