Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop CMake from prepending `lib` to library names

Tags:

cmake

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.)

like image 438
Timmmm Avatar asked Jan 23 '17 10:01

Timmmm


1 Answers

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.

like image 70
Florian Avatar answered Sep 28 '22 08:09

Florian