[CMake] Lib prefix: Windows vs. Unix/MinGW convention

Olivier Croquette ocroquette at free.fr
Tue Jul 10 03:21:50 EDT 2018


Hello,

some projects I am working on are built using CMake and MinGW on 
Windows. It works fine, unfortunately there are come inconsistencies 
regarding the names of the generated libraries. Some are prefixed with 
"lib" like on Unix systems, some are not, like usual on Windows.

It seems that this can be controlled easily by adding the following 
lines in the top CMakeLists.txt:

if(MINGW)
   set(CMAKE_SHARED_LIBRARY_PREFIX "")
   set(CMAKE_STATIC_LIBRARY_PREFIX "")
endif()

As a CMake beginner, I still have some questions though:

1. Are there some side-effects? For instance, can it cause libraries not 
to be found when using them across projects?

2. Should I use if(WIN32) rather than if(MINGW)?

3. Why isn't CMake doing that by default? The convention of the target 
platform should prevail over the convention of the toolchain, shouldn't it?

Thanks!

Olivier




More information about the CMake mailing list