2012-11-13 5 views
2

나는 CMake에 관한 질문이 있습니다. 최근 GLEW 나 Mercurial 같은 표준 설치에 많은 모듈이 추가되었습니다. 당신이 당신의 자신의 버전을 제공하도록 강요되도록 cmake find modules wrt version

그러나 설치 기반의 많은, 사용할 수있는 모든 새로운 모듈없이 이전 버전이있을 수 있습니다 (예를 들어) FindGLEW.cmake

은 주어진 여부를 확인 할 수 있나요 FindXXX 모듈을 사용할 수 있으며이 경우이를 사용하십시오. 그렇지 않으면 적절한 대안을 제공합니까? 아니면 런타임에 cmake 버전을 확인하십시오 (하지만 항상 신뢰할 수있는 것은 아니며 유지 관리하는 데 어려움이 있습니다) ...?

도움 주셔서 감사합니다.

답변

1

CMake의 include 명령 w.r.t 모듈의 기본 검색 동작은 다음과 같습니다 이름 <modulename>.cmake

파일은 다음 CMake 모듈 디렉토리에 CMAKE_MODULE_PATH 먼저 검색됩니다.

(그것에 조금 더있다 - 워드 프로세서를 참조하거나 cmake --help-command include 실행) 당신이 요구하는지 무엇

이 반대 것으로 보인다; 먼저 CMake 모듈 디렉토리에있는 공식 모듈을 확인하고, 존재하지 않는다면 자신의 모듈을 사용하기 위해 넘어 간다.

가정 당신의 모듈은 ${CMAKE_SOURCE_DIR}/my_cmake_modules, 당신은 수행하여 CMake의 기본 동작을 반전 할 수 있습니다 : 정확히 공식 사람에 따라 자신의 모듈 이름을 경우

set(CMAKE_MODULE_PATH ${CMAKE_ROOT}/Modules ${CMAKE_SOURCE_DIR}/my_cmake_modules) 

, 다음이 당신의 목표를 달성해야한다. 나중에 스크립트에서 정상 CMake 동작으로 복귀하고자하는 경우, 당신이 할 수있는이 도움이

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/my_cmake_modules) 
+0

그래, 내가 찾고 있던 행동입니다! 감사 – koda

0

을 위의 솔루션에 대한 가능한 대안으로, 나는이 cmake 정책을 발견

CMP0017 
    Prefer files from the CMake module directory when including from 
    there. 

    Starting with CMake 2.8.4, if a cmake-module shipped with CMake (i.e. 
    located in the CMake module directory) calls include() or 
    find_package(), the files located in the the CMake module directory 
    are preferred over the files in CMAKE_MODULE_PATH. This makes sure 
    that the modules belonging to CMake always get those files included 
    which they expect, and against which they were developed and tested. 
    In call other cases, the files found in CMAKE_MODULE_PATH still take 
    precedence over the ones in the CMake module directory. The OLD 
    behaviour is to always prefer files from CMAKE_MODULE_PATH over files 
    from the CMake modules directory. 

    This policy was introduced in CMake version 2.8.4. CMake version 
    2.8.9 warns when the policy is not set and uses OLD behavior. Use the 
    cmake_policy command to set it to OLD or NEW explicitly. 

희망 .