cmake:找不到find_package库

时间:2014-09-25 15:10:29

标签: cmake

我是CMake的新手,目前我正在试图找出如何使用find_package()找到库。 我的目标是找到CryptoPP库 当我运行CMake时,它打印出来:

CMake Error at my_app/CMakeLists.txt:66 (message):
  Failed to find CryptoPP.

我的文件夹层次结构和CMake文件如下所示。那么,怎么了?

enter image description here

#====================================================================================
# my_app/my_app/cmake_modules/FindCryptopp.cmake ====================================
#====================================================================================

set(HDR_LIST sha.h 
            rsa.h 
            osrng.h 
            files.h 
            base32.h 
            randpool.h
            default.h)

set(LIB_LIST cryptlib.lib 
            cryptlibd.lib)

# check that includes we need are present
find_path(cryptopp_INCLUDE_DIR HDR_LIST PATHS ../../3rd_party_libs/cryptopp560)

# check that libraries we need are present
find_library(cryptopp_LIBRARIES LIB_LIST PATHS ../../3rd_party_libs/cryptopp560/win32/vc12 NO_DEFAULT_PATH)

set(Cryptopp_FOUND TRUE)

if (NOT cryptopp_INCLUDE_DIR)
    set(Cryptopp_FOUND FALSE)
endif (NOT cryptopp_INCLUDE_DIR)

if (NOT cryptopp_LIBRARIES)
    set(Cryptopp_FOUND FALSE)
endif (NOT cryptopp_LIBRARIES)

#====================================================================================
# my_app/my_app/CMakeLists.txt ======================================================
#====================================================================================
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
cmake_policy(SET CMP0015 NEW)

project("my_app")
set(HDR_LIST foo.h)
set(SRC_LIST foo.cpp
            main.cpp)

add_executable(my_app ${SRC_LIST} ${HDR_LIST})

target_link_libraries(my_app my_lib)


set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules)
find_package(Cryptopp)

if (Cryptopp_FOUND)
    message(STATUS "Includes for Cryptopp found in ${cryptopp_INCLUDE_DIR}")
    message(STATUS "Libraries for Cryptopp found in ${cryptopp_LIBRARIES}")
else()
    message(FATAL_ERROR "Failed to find CryptoPP.")
endif()

1 个答案:

答案 0 :(得分:0)

在列表前搜索文件替代放置NAMES。不允许只有一个文件名。