Issue
Using CMake 3.23, I am trying to get the names of the files that add_library()
generates for a target in Windows.
add_library(talib source.cpp source.h)
It generates the following files:
talib.dll
talib.lib
talib.pdb
Is there any way to get the names of the above files? $<TARGET_FILE:talib>
only gives me talib.dll
, how can I get the rest of the filenames, and will it work for Linux libraries?
Solution
There are the following generator expressions. This is mostly quoting the documentation here:
https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html
$<TARGET_FILE:tgt>
-- Full path to thetgt
binary file. For shared libraries, this is the dynamic object file on all platforms.$<TARGET_LINKER_FILE:tgt>
-- File used when linking to thetgt
target. This will usually be the same as$<TARGET_FILE:tgt>
, but for a shared library on DLL platforms, it would be the.lib
import library associated with the DLL.$<TARGET_PDB_FILE:tgt>
-- Full path to the linker generated program database file (.pdb
) where tgt is the name of a target.
All of these resolve to absolute paths. The first two work on all systems (but might duplicate each other). The last one only works on PDB systems and will throw a fatal error that reads TARGET_PDB_FILE is not supported by the target linker.
on other systems.
To detect whether you are on a PDB system, you can check the variable CMAKE_<LANG>_LINKER_SUPPORTS_PDB
, where <LANG>
is C
, CXX
, etc.
Answered By - Alex Reinking Answer Checked By - Mildred Charles (WPSolving Admin)