cmake找不到头文件?

时间:2017-11-12 16:59:24

标签: c++ cmake

我不确定我明白为什么会遇到这个问题.. 但是cmake似乎在找到位于不同项目中的头文件时遇到了一些问题。

我的系统树视图:

tree
.
├─ build
├─ CMakeLists.txt
├─ src
├── CMakeLists.txt
├── include
│   ├── CMakeLists.txt
│   ├── database
│   │   ├── CMakeLists.txt
│   │   ├── database.cpp
│   │   └── database.h
│   ├── match
│   │   ├── CMakeLists.txt
│   │   ├── match.cpp
│   │   └── match.h
│   ├── record
│   │   ├── CMakeLists.txt
│   │   ├── record.cpp
│   │   └── record.h
│   └── spectogram
│       ├── CMakeLists.txt
│       ├── spectogram.cpp
│       └── spectogram.h
└── main.cpp

我已经将目录包含在项目中我感兴趣的头文件中,并且还添加了我的路径 target_inlcude_directories。问题是我的database.h看不到record.h。

数据库/的CMakeLists.txt:

project(database)
MESSAGE(“In database CMAKELIST”)


#
# Build static library
add_library(database database.cpp database.h)
include_directories(${record_SOURCE_DIR} ${spectogram_SOURCE_DIR})

target_compile_features(database PUBLIC cxx_defaulted_functions)
target_include_directories(database PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${record_SOURCE_DIR} ${spectogram_SOURCE_DIR})

记录/ CMakeList.txt:

project(record)
MESSAGE( “In record CMAKELIST” )
# Include externalproject {portaudio} if lib/portaudio don't exist.

INCLUDE(ExternalProject)
ExternalProject_Add(project_portaudio
    GIT_REPOSITORY      https://git.assembla.com/portaudio.git
    PREFIX              lib/portaudio
    UPDATE_COMMAND      ""
    CONFIGURE_COMMAND   <SOURCE_DIR>/configure --enable-cxx
    BUILD_IN_SOURCE     0
    BUILD_COMMAND       make
    INSTALL_COMMAND     sudo make install
)
ExternalProject_Get_Property(project_portaudio BINARY_DIR)
ExternalProject_Get_Property(project_portaudio SOURCE_DIR)

SET(portaudio_lib_dir "${BINARY_DIR}/lib/.libs")
SET(portaudio_inc_dir "${SOURCE_DIR}/include")

add_library(record STATIC record.cpp record.h AudioFile.cpp AudioFile.h)

add_library(portaudio STATIC IMPORTED)

set_target_properties(portaudio PROPERTIES
    IMPORTED_LOCATION "${portaudio_lib_dir}/libportaudio.so")

set_property(TARGET portaudio APPEND PROPERTY
    INTERFACE_INCLUDE_DIRECTORIES ${SOURCE_DIR}/include)

add_dependencies(portaudio project_portaudio)     # Not sure if this is allowed for imported targets though

find_package(Threads REQUIRED)
find_package(ALSA REQUIRED)

IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
   SET(EXTRA_LIBS rt asound jack)
ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")

#
# this makes sure we have compiler flags that allow class::class() = default (>= C++11)
target_link_libraries(record PUBLIC  ${EXTRA_LIBS} ${ALSA_LIBRARIES} portaudio Threads::Threads )
target_compile_features(record PUBLIC cxx_defaulted_functions)
target_include_directories(record PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${project_portaudio})

奇怪的是它有时能够编译,有时它会因为无法找到标题而陷入困境?

问题是什么?

0 个答案:

没有答案