2014-06-07 85 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