此处描述了如何查找包以及如何编写自己的查找模块:
http ://www.cmake.org/Wiki/CMake:How_To_Find_Libraries
这是我的一个非常简单的查找模块。它位于我所有库所在的顶级目录中,因此在这种情况下,找到正确的路径相当简单。
# AsmjitConfig.cmake
# - Config file for the Asmjit package
# sets:
# Asmjit_FOUND
# Asmjit_INCLUDE_DIR
# Asmjit_LIBRARIES
set(Asmjit_FOUND FALSE)
find_library(Asmjit_LIBRARY NAMES asmjit HINTS ${CMAKE_CURRENT_LIST_DIR}/asmjit)
find_path(Asmjit_INCLUDE_DIR asmjit/asmjit.h HINTS ${CMAKE_CURRENT_LIST_DIR}/asmjit/src)
message(STATUS "${Asmjit_INCLUDE_DIR}")
message(STATUS "${Asmjit_LIBRARY}")
if(NOT Asmjit_LIBRARY OR NOT Asmjit_INCLUDE_DIR)
set(Asmjit_FOUND FALSE)
else()
set(Asmjit_FOUND TRUE)
endif()
在您的 CMakeLists.txt 中告诉 cmake 在哪里可以找到您的模块:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "path/to/librarys")
之后 find_package 应该可以正常工作。