andrewrk / libsoundio

C library for cross-platform real-time audio input and output
http://libsound.io/
MIT License
1.92k stars 229 forks source link

LIBSOUNDIO_LIBS as CMake Parent Scope Variable #244

Closed krumelmonster closed 1 year ago

krumelmonster commented 3 years ago

Setting the LIBSOUNDIO_LIBS to Parent Scope will allow it to be used as a CMake submodule like so:

add_subdirectory(libsoundio)
target_link_libraries(${PROJECT_NAME} PRIVATE
    ${LIBSOUNDIO_LIBS}
    )
lp35 commented 2 years ago

Hi, thanks for your PR!

Rule of thumbs for CMakeLists.txt: never pollute top-project that include a cmake project with PARENT_SCOPE variables!

PARENT_SCOPE is usually used for custom cmake functions.

Concerning your issue, Cmake know how to manage cross dependencies of a project.

add_subdirectory(libsoundio)
target_link_libraries(${PROJECT_NAME} PRIVATE
    libsoundio_shared
    )

is enough for CMake to compile your project and link to all necessary libraries (alsa, etc...) to make the project works, avoiding the need of your PR.

Regards!