cmake find_package无法在Mac OS X上运行

时间:2014-06-07 12:44:22

标签: macos cmake gsl

试图创建我的第一个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".

有谁可以指出我做错了什么?

1 个答案:

答案 0 :(得分:2)

检查您的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 - 权限

> 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.