2016-06-11 11 views
0

FindFoo.cmake:Bibliothek kann nicht seine eigenen Header sehen

# 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> Werke in meinem Programm während #include <Foo/Bar1.h> nicht. und das eigentliche Problem ist, dass ich mein Programm nicht bauen kann, weil Bar1.h enthält #include <Foo/Bar2.h> und:

...Foo/Bar1.h: fatal error: Foo/Bar2.h: No such file or directory compilation terminated.

CMake 3.5.1

+0

Mit gegebenen 'find_path' Aufruf Include-Anweisung' #include 'sollte funktionieren. Wahrscheinlich verwenden Sie das Ergebnis von 'find_package (Foo)' falsch, aber Sie zeigen Ihre 'CMakeLists.txt' nicht. – Tsyvarev

+0

hinzugefügt CMakeLists.txt zu der Frage. – theorist

Antwort

0

sieht aus wie das Problem war CMake-Cache. Ich löschte alles aus dem CMakeFiles Verzeichnis und CMake konnte das Projekt nicht konfigurieren:

Could NOT find Foo (missing: Foo_INCLUDE_DIR)

ich hatte PATH_SUFFIXES zu find_path() hinzuzufügen, und alle Probleme sind weg.

Verwandte Themen