When building my project with CMake, I would like it to link to libraries statically (if available). Right now, it finds .dll.a
files, regardless of the existence of .a
files.
For example, take linking to libpng in a small sample project:
cmake_minimum_required(VERSION 3.15)
project(Test)
add_executable(Test main.cpp)
find_package(PNG REQUIRED)
message(${PNG_LIBRARIES})
target_link_libraries(Test PRIVATE ${PNG_LIBRARIES})
For the message
, it outputs
C:/msys64/mingw64/lib/libpng.dll.aC:/msys64/mingw64/lib/libz.dll.a
But the libpng.a
and libz.a
files are also available in the same directory. How can I tell CMake to link with .a
files?
I am using MinGW-w64 with msys64 on Windows 10, but would prefer a solution that is cross-platform.