xiph/ogg

CMake issue when linking ogg library into vorbis

rilpires opened this issue · 1 comments

So, first I was struggling with finding Ogg Package. In my project, that is builded with CMake, I have both Ogg and Vorbis repositories as submodules:

/deps/ogg/<ogg repository>
/deps/vorbis/<vorbis repository>
CMakeLists.txt

Alongside others dependencies, I have these two sections dedicated to include Ogg and Vorbis in my CMakeLists.txt

(...)
# OGG
add_subdirectory("deps/ogg")
list( APPEND LINK_LIBRARIES ogg )

# Vorbis
set( OGG_ROOT ${PROJECT_SOURCE_DIR}/deps/ogg )
set( OGG_LIBRARY ogg )
add_subdirectory("deps/vorbis")
list( APPEND LINK_LIBRARIES vorbisfile )
(...)

I took a look at FindOgg.cmake (Vorbis repo) to find out that I should hint OGG_ROOT, but should I have defined OGG_LIBRARY as well? I'm kinda new to CMake so that was a bit confusing to me, since I thought that the point with find_package(Ogg) was to define OGG_LIBRARY. If I don't define OGG_LIBRARY, find_package(Ogg) fails.

Anyway, from here everything works fine until linking stage. I got it working after editing Vorbis's CMakeLists.txt:

(...)
    target_link_libraries(vorbis
        PUBLIC Ogg::ogg
        PRIVATE $<$<BOOL:${HAVE_LIBM}>:m>
    )
(...)

Ogg::ogg was being included simply as "ogg", i.e.:
/usr/bin/g++-9 -g (.....) deps/ogg/libogg.a deps/vorbis/lib/libvorbisfile.a deps/vorbis/lib/libvorbis.a ogg (....)
Is this somehow related to how I defined OGG_LIBRARY? I managed to fix it by changing Ogg::ogg to ${OGG_LIBRARY}:

(...)
    target_link_libraries(vorbis
        PUBLIC ${OGG_LIBRARY}
        PRIVATE $<$<BOOL:${HAVE_LIBM}>:m>
    )
(...)

Nevermind, just found that this was discussed in xiph/vorbis#69