Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get library full-native name on cmake?

Tags:

cmake

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 LOCATIONhas it but with the full path. The property OUTPUT_NAME does not return anything.

like image 663
quimnuss Avatar asked Mar 21 '13 14:03

quimnuss


People also ask

How do I add a library to CMake?

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.

What is target_ link_ libraries in CMake?

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() .

How does CMake find_ library work?

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 .


1 Answers

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+).

like image 134
Angew is no longer proud of SO Avatar answered Oct 15 '22 08:10

Angew is no longer proud of SO