3

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?

Kevin
  • 16,549
  • 8
  • 60
  • 74
Seeker
  • 101
  • 2
  • 10

1 Answers1

3

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()
Kevin
  • 16,549
  • 8
  • 60
  • 74