cmake can't find header file?

Viewed 2366

I am not sure I understand why I am having this problem.. but cmake seem to have some problems with finding the header file located in a different project.

tree view of my system:

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

I’ve included the directory to the project which header files I am interested in, and also added the path in my target_inlcude_directories. The problems is my database.h cannot see record.h.

database/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})

record/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})

The weird part is that it sometimes is able to compile, and other times it get stuck with this not able to find the header?

what could the problem be?

0 Answers
Related