I need to pass the native name (libfoo.so or foo.dll) of a builded library to a add_custom_command.
How can I get the full library name of a target?
the property LOCATION
has it but with the full path. The property OUTPUT_NAME does not return anything.
To add a library in CMake, use the add_library() command and specify which source files should make up the library. Rather than placing all of the source files in one directory, we can organize our project with one or more subdirectories. In this case, we will create a subdirectory specifically for our library.
target_link_libraries(<target> [item1 [item2 [...]]] [[debug|optimized|general] <item>] ...) Specify libraries or flags to use when linking a given target. The named <target> must have been created in the current directory by a command such as add_executable() or add_library() .
find_library tells CMake that we're looking for a library and once we have found it, to store the path to it in the variable LIBIMAGEPIPELINE_LIBRARY . Likely filenames are passed with NAMES LibImagePipeline . It is good practice to pass the names without the file extension like .
You can use the generator expression $<TARGET_FILE_NAME:tgt>
, where tgt
is the logical CMake name of your target.
Example:
add_library(myLib a.cpp)
add_custom_command(
OUTPUT someOutput
COMMAND myProcessor --input $<TARGET_FILE_NAME:myLib> --output someOutput
# ...
)
For more on generator expressions, refer to the documentation of add_custom_command()
(for CMake 2.x) or to the dedicated generator expression documentation (for CMake 3+).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With