Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default library prefix for Windows in CMake

Tags:

cmake

I am building static and dynamic libraries on multiple UNIX and Windows platforms. On UNIX, the libraries are getting built with the 'lib' prefix, but on windows the 'lib' prefix is not getting added to the libraries.

I could add the 'lib' prefix for building libraries on Windows as below:

set_target_properties( <TARGET>
                       PROPERTIES
                       PREFIX "${PREFIX}lib"
                       IMPORT_PREFIX "${IMPORT_PREFIX}lib")

The problem is I have to do this for each and every target.

Is there a better way of doing this, maybe there is a way to enable the 'lib' prefix?

like image 203
Seeker Avatar asked Oct 26 '25 10:10

Seeker


1 Answers

As hinted in this question, you can control the library prefixes for all shared/static libraries in your CMake project using CMAKE_SHARED_LIBRARY_PREFIX and CMAKE_STATIC_LIBRARY_PREFIX:

project(MyProject)

if(WIN32)
    # Prefix all shared libraries with 'lib'.
    set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
    # Prefix all static libraries with 'lib'.
    set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
endif()
like image 123
Kevin Avatar answered Oct 29 '25 08:10

Kevin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!