Issue
I have a GitHub repository containing two cmake projects. Lets say the name of the repo is "Audio" and it contains a directory "AudioGui" and a directory "AudioLib". The "AudioLib" project is a shared library which includes and links a header from another GitHub repository.
AudioLib can be built and its cmake contains:
include(FetchContent)
FetchContent_Declare(
AudioFile
GIT_REPOSITORY https://github.com/adamstark/AudioFile.git
GIT_TAG 1.1.0
)
FetchContent_MakeAvailable(AudioFile)
target_link_libraries(AudioLib PUBLIC
Qt${QT_VERSION_MAJOR}::Core
AudioFile
)
AudioGui, which cannot be built but cmake returns no errors, contains in its cmake:
include(FetchContent)
FetchContent_Declare(
Audio
GIT_REPOSITORY https://github.com/myname/Audio.git
GIT_TAG 1.0.1
)
FetchContent_MakeAvailable(Audio)
target_link_libraries(AudioGui PUBLIC
Qt${QT_VERSION_MAJOR}::Widgets
Audio
)
The problem is that the includes of the headers inside AudioGui can be done this way: #include "_deps/audio-src/AudioLib/Converter_global.h" #include "_deps/audio-src/AudioLib/converter.h" instead of #include "AudioLib/Converter_global.h" #include "AudioLib/converter.h" and even in that way I get an error that the header AudioFile.h (which is included in AudioLib and directly to AudioGui) cannot be found.
Any ideas on what I am doing wrong?
Solution
Since AudioFile is a third party library for the client programs, AudioFile.h must not be included in AudioLib's headers (a pointer and a forward declaration of AudioFile should be used instead in order to not having external dependencies). You can see the full CmakeLists files here: https://michae9.wordpress.com/2022/09/01/shared-lib-to-be-used-by-client-programs-with-cmake/
Answered By - michalis Answer Checked By - Terry (WPSolving Volunteer)