2014-06-07 82 views
2

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

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 /模块的文件夹(下载)如由我的终端输出:

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

任何人都可以指出我做错了什么?

+0

适合我。你确定存在'/ Users/adam/repos/ctmc/cmake/Modules/FindGSL.cmake'文件吗? –

+0

奇怪的是,在发现者和命令行检查似乎没有找到它,想知道它是权限的文件或我需要设置一些环境变量!我将在另一台计算机上尝试返回 – madawilliams

+0

我也在Linux机器上尝试过,并得到相同的错误。如果FindGSL.cmake文件中存在错误,它会提供此消息 – madawilliams

回答

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

太棒了!这很有效,因为我知道这应该是我正在做的傻事 – madawilliams