Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell whether a given target is a library or executable?

Tags:

cmake

The built-in function install(TARGETS ...) installs library targets to another location than executable targets. I want to do something similar. Given a list of target names, I want to add all library targets among them to a list variable and all runtime targets to another variable.

I couldn't found a list of CMake's default target properties, but I guess add_library() and add_executable() add a property that can be used for this kind of distinction.

How to tell whether a given target is a library or executable (or even something else)?

like image 407
danijar Avatar asked Aug 09 '15 17:08

danijar


1 Answers

According to documentation, TYPE property can be used for distinguish standard CMake target types:

It will be one of STATIC_LIBRARY, MODULE_LIBRARY, SHARED_LIBRARY, EXECUTABLE or one of the internal target types.

Example:

get_target_property(target_type <target> TYPE)
if (target_type STREQUAL "EXECUTABLE")
  # Process executable target
endif ()
like image 183
Tsyvarev Avatar answered Sep 21 '22 14:09

Tsyvarev