2@brief Detect library
type of a library
4Sometimes it needs to be known whether a library is shared or
static on a
5system in
order to change the usage requirements of an imported
target
6representing that library. This commonly occurs between
static and shared
7builds that share a set of installed headers. This
function returns one of
8`SHARED`, `STATIC`, or `
UNKNOWN` into the variable passed as the first
12vtk_detect_library_type(<variable>
17 cmake_parse_arguments(PARSE_ARGV 1 vdlt
22 if (NOT DEFINED vdlt_PATH)
24 "The `PATH` argument is required.")
27 if (DEFINED vdlt_UNPARSED_ARGUMENTS)
29 "Unparsed arguments for vtk_detect_library_type: "
30 "${vdlt_UNPARSED_ARGUMENTS}")
35 "The `PATH` argument is empty.")
38 set(vdlt_type UNKNOWN)
39 # Windows libraries all end with `.lib`. We need to detect the type based on
40 # the contents of the library. However, MinGW does use different extensions.
41 if (WIN32 AND NOT MINGW)
42 find_program(DUMPBIN_EXECUTABLE
44 DOC
"Path to the dumpbin executable")
45 mark_as_advanced(DUMPBIN_EXECUTABLE)
47 COMMAND
"${DUMPBIN_EXECUTABLE}"
50 OUTPUT_VARIABLE vdlt_out
51 ERROR_VARIABLE vdlt_err
52 RESULT_VARIABLE vdlt_res)
55 "Failed to run `dumpbin` on ${vdlt_PATH}. Cannot determine "
56 "shared/static library type: ${vdlt_err}")
58 if (vdlt_out MATCHES
"DLL name :")
65 string(LENGTH
"${vdlt_PATH}" vdlt_path_len)
67 string(LENGTH
"${CMAKE_SHARED_LIBRARY_SUFFIX}" vdlt_shared_suffix_len)
68 math(EXPR vdlt_shared_idx
"${vdlt_path_len} - ${vdlt_shared_suffix_len}")
69 string(SUBSTRING
"${vdlt_PATH}" "${vdlt_shared_idx}" -1 vdlt_shared_check)
71 string(LENGTH
"${CMAKE_STATIC_LIBRARY_SUFFIX}" vdlt_static_suffix_len)
72 math(EXPR vdlt_static_idx
"${vdlt_path_len} - ${vdlt_static_suffix_len}")
73 string(SUBSTRING
"${vdlt_PATH}" "${vdlt_static_idx}" -1 vdlt_static_check)
75 if (vdlt_shared_check STREQUAL CMAKE_SHARED_LIBRARY_SUFFIX)
77 elseif (vdlt_static_check STREQUAL CMAKE_STATIC_LIBRARY_SUFFIX)
81 # when
import suffix !=
static suffix, we can disambiguate
static and
import
82 if (WIN32 AND NOT CMAKE_IMPORT_LIBRARY_SUFFIX STREQUAL CMAKE_STATIC_LIBRARY_SUFFIX)
83 string(LENGTH
"${CMAKE_IMPORT_LIBRARY_SUFFIX}" vdlt_import_suffix_len)
84 math(EXPR vdlt_import_idx
"${vdlt_path_len} - ${vdlt_import_suffix_len}")
85 string(SUBSTRING
"${vdlt_PATH}" "${vdlt_import_idx}" -1 vdlt_import_check)
86 if (vdlt_import_check STREQUAL CMAKE_IMPORT_LIBRARY_SUFFIX)
98@brief Detect whether an imported
target is shared or not
100This is intended
for use with modules
using
102not. Generally,
this should be replaced with the `Find` module providing
this
103information and modifying the usage requirements as necessary instead, but it
104is not always possible.
110Sets `<name>_is_shared` in the caller
's scope if `<target>` is a shared
111library. If it is an `UNKNOWN_LIBRARY`, a cache variable is exposed to allow
112the user to provide the information if it ends up breaking something.
114function (vtk_detect_library_shared name target)
115 if (VTK_MODULE_USE_EXTERNAL_${name})
116 get_property(library_type
119 if (library_type STREQUAL "SHARED_LIBRARY")
121 elseif (library_type STREQUAL "UNKNOWN_LIBRARY")
122 option("VTK_MODULE_${name}_IS_SHARED" "Whether the ${name} in use is shared or not" ON)
123 mark_as_advanced("VTK_MODULE_${name}_IS_SHARED")
124 set(is_shared "${VTK_MODULE_${name}_IS_SHARED}")
129 set(is_shared "${BUILD_SHARED_LIBS}")
132 set("${name}_is_shared"
function vtk_module_third_party_external()
External third party package.
boost::graph_traits< vtkGraph * >::vertex_descriptor target(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
function vtk_detect_library_type(output)
Detect library type of a library.
function vtk_detect_library_shared(name, target)
Detect whether an imported target is shared or not.