Stop CMake from prepending `lib` to library names

China☆狼群 提交于 2021-02-04 15:35:13

问题


Sadly, CMake follows the awkward "implicit lib" convention, which inevitably causes problems when library names don't actually follow the convention (e.g. zlib), or have 'lib' as an explicit part of their name.

For example, suppose I want to add libusb:

add_library(libusb ...)

On Windows this will correctly produce libusb.lib. On Unix it will produce the hilarious liblibusb.a. Is there any way to prevent this behaviour? I know I can set the output name explicitly using OUTPUT_NAME but I'd have to use some funky generator expressions to preserve libusb.lib on Windows. I wonder if there is a better way?

(And no add_library(usb ... is not a solution; the library is called libusb not usb.)


回答1:


You can modify it via CMAKE_STATIC_LIBRARY_PREFIX. So in your case just do after your project() command:

set(CMAKE_STATIC_LIBRARY_PREFIX "")

Or you can change it per target via the PREFIX target property.



来源:https://stackoverflow.com/questions/41804282/stop-cmake-from-prepending-lib-to-library-names

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!