FindFoo.cmake:
# Foo_FOUND - system has Foo
# Foo_INCLUDE_DIRS - the Foo include directories
# Foo_LIBRARIES - link these to use Foo
# Foo_VERSION
# Foo_DEFINITIONS - compiler switches required for using Foo
find_package(PkgConfig)
pkg_check_modules(PC_Foo QUIET Foo)
find_path(Foo_INCLUDE_DIR Foo/Foo.h
PATHS ${PC_Foo_INCLUDEDIR} ${PC_Foo_INCLUDE_DIRS}
)
find_library(Foo_LIBRARY Foo
PATHS ${PC_Foo_LIBDIR} ${PC_Foo_LIBRARY_DIRS}
)
set(Foo_VERSION ${PC_Foo_VERSION})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Foo
FOUND_VAR Foo_FOUND
REQUIRED_VARS
Foo_LIBRARY
Foo_INCLUDE_DIR
VERSION_VAR Foo_VERSION
)
if(Foo_FOUND)
set(Foo_LIBRARIES ${Foo_LIBRARY})
set(Foo_INCLUDE_DIRS ${Foo_INCLUDE_DIR})
set(Foo_DEFINITIONS ${PC_Foo_CFLAGS_OTHER})
endif()
mark_as_advanced(
Foo_INCLUDE_DIR
Foo_LIBRARY
)
的CMakeLists.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
PROJECT(sandbox)
set(CMAKE_AUTOMOC ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
FIND_PACKAGE(Qt5Core REQUIRED)
find_package(Foo REQUIRED)
include_directories(${Foo_INCLUDE_DIRS})
SET(sandbox_SOURCES main.cpp)
ADD_EXECUTABLE(sandbox ${sandbox_SOURCES})
QT5_USE_MODULES(sandbox Core)
TARGET_LINK_LIBRARIES(sandbox ${Foo_LIBRARIES})
#include <Bar1.h>
适用于我的计划,而#include <Foo/Bar1.h>
则不适用。而真正的问题是我无法构建我的程序,因为Bar1.h包含#include <Foo/Bar2.h>
和:
... Foo / Bar1.h:致命错误:Foo / Bar2.h:没有这样的文件或目录 编译终止。
CMake 3.5.1
答案 0 :(得分:0)
看起来问题是CMake缓存。我删除了CMakeFiles目录中的所有内容,然后CMake无法配置项目:
无法找到Foo(缺少:Foo_INCLUDE_DIR)
我必须将PATH_SUFFIXES
添加到find_path(),所有问题都消失了。