Unknown CMake command "_add_library". #449

Closed
opened 2026-01-29 20:44:03 +00:00 by claunia · 3 comments
Owner

Originally created by @eehlers on GitHub (Mar 22, 2023).

Configuration of my project fails with:

CMake Error at C:/repos/vcpkg/packages/brotli_x64-windows/share/unofficial-brotli/unofficial-brotli-config.cmake:5 (_add_library):
Unknown CMake command "_add_library".

What am I doing wrong?

I fixed it temporarily by hacking the above mentioned file and deleting the leading underscore from "_add_library".

Originally created by @eehlers on GitHub (Mar 22, 2023). Configuration of my project fails with: CMake Error at C:/repos/vcpkg/packages/brotli_x64-windows/share/unofficial-brotli/unofficial-brotli-config.cmake:5 (_add_library): Unknown CMake command "_add_library". What am I doing wrong? I fixed it temporarily by hacking the above mentioned file and deleting the leading underscore from "_add_library".
Author
Owner

@nimcomputing commented on GitHub (Apr 6, 2023):

I believe the issue is with the vcpkg port of Brotli rather than Brotli itself: https://github.com/microsoft/vcpkg/tree/master/ports/brotli

Seems to be a typo in the file unofficial-brotli-config.cmake

I'm using a hacky work-around in my projects using Brotli from vcpkg with this in my CMakeLists.txt file:

file(READ "${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/share/unofficial-brotli/unofficial-brotli-config.cmake" brotli_cmake)
string(REPLACE "_add_library" "add_library" brotli_cmake "${brotli_cmake}")
file(WRITE "${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/share/unofficial-brotli/unofficial-brotli-config.cmake" "${brotli_cmake}")

Raised this issue against the Brotli port on the Vcpkg repo.

@nimcomputing commented on GitHub (Apr 6, 2023): I believe the issue is with the vcpkg port of Brotli rather than Brotli itself: [https://github.com/microsoft/vcpkg/tree/master/ports/brotli](https://github.com/microsoft/vcpkg/tree/master/ports/brotli) Seems to be a typo in the file [unofficial-brotli-config.cmake](https://github.com/microsoft/vcpkg/blob/master/ports/brotli/unofficial-brotli-config.cmake) I'm using a hacky work-around in my projects using Brotli from vcpkg with this in my CMakeLists.txt file: ``` file(READ "${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/share/unofficial-brotli/unofficial-brotli-config.cmake" brotli_cmake) string(REPLACE "_add_library" "add_library" brotli_cmake "${brotli_cmake}") file(WRITE "${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/share/unofficial-brotli/unofficial-brotli-config.cmake" "${brotli_cmake}") ``` Raised this [issue](https://github.com/microsoft/vcpkg/issues/30707) against the Brotli port on the Vcpkg repo.
Author
Owner

@eehlers commented on GitHub (Apr 18, 2023):

Thank you!

It seems that when you redefine a cmake function, the original function gets renamed with a leading underscore. brotli vcpkg redefines add_library which explains the call to _add_library. I see the response to the ticket you raised over on the other repo. It seems that the error arises because I am not calling unofficial-brotli-config.cmake in the way that it wants to be called but I do not understand their explanation so for now I am still stuck with my local hack.

Edit: Following their advice, I cleared the cache, and now it is working. Many thanks again for your thorough followup!

@eehlers commented on GitHub (Apr 18, 2023): Thank you! It seems that when you redefine a cmake function, the original function gets renamed with a leading underscore. ~brotli~ vcpkg redefines add_library which explains the call to _add_library. I see the response to the ticket you raised over on the other repo. It seems that the error arises because I am not calling unofficial-brotli-config.cmake in the way that it wants to be called but I do not understand their explanation so for now I am still stuck with my local hack. Edit: Following their advice, I cleared the cache, and now it is working. Many thanks again for your thorough followup!
Author
Owner

@eustas commented on GitHub (Jun 20, 2023):

Thanks for investigating / checking!

@eustas commented on GitHub (Jun 20, 2023): Thanks for investigating / checking!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/brotli#449