1 include(CMakeParseArguments)
 
    4 @brief Detect library 
type of a library
 
    6 Sometimes it needs to be known whether a library is shared or 
static on a
 
    7 system in 
order to change the usage requirements of an imported 
target 
    8 representing that library. This commonly occurs between 
static and shared
 
    9 builds that share a set of installed headers. This 
function returns one of
 
   10 `SHARED`, `STATIC`, or `UNKNOWN` into the variable passed as the first
 
   19   cmake_parse_arguments(vdlt
 
   25   if (NOT DEFINED vdlt_PATH)
 
   27       "The `PATH` argument is required.")
 
   30   if (DEFINED vdlt_UNPARSED_ARGUMENTS)
 
   33       "${vdlt_UNPARSED_ARGUMENTS}
") 
   38       "The `PATH` argument is empty.
") 
   41   set(vdlt_type UNKNOWN) 
   42   # Windows libraries all end with `.lib`. We need to detect the type based on 
   43   # the contents of the library. However, MinGW does use different extensions. 
   44   if (WIN32 AND NOT MINGW) 
   45     find_program(DUMPBIN_EXECUTABLE 
   47       DOC   "Path to the dumpbin executable
") 
   48     mark_as_advanced(DUMPBIN_EXECUTABLE) 
   50       COMMAND "${DUMPBIN_EXECUTABLE}
" 
   53       OUTPUT_VARIABLE vdlt_out 
   54       ERROR_VARIABLE  vdlt_err 
   55       RESULT_VARIABLE vdlt_res) 
   58         "Failed to run `dumpbin` 
on ${vdlt_PATH}. Cannot determine 
" 
   59         "shared/
static library 
type: ${vdlt_err}
") 
   61       if (vdlt_out MATCHES "DLL 
name     :
") 
   68     string(LENGTH "${vdlt_PATH}
" vdlt_path_len) 
   70     string(LENGTH "${CMAKE_SHARED_LIBRARY_SUFFIX}
" vdlt_shared_suffix_len) 
   71     math(EXPR vdlt_shared_idx "${vdlt_path_len} - ${vdlt_shared_suffix_len}
") 
   72     string(SUBSTRING "${vdlt_PATH}
" "${vdlt_shared_idx}
" -1 vdlt_shared_check) 
   74     string(LENGTH "${CMAKE_STATIC_LIBRARY_SUFFIX}
" vdlt_static_suffix_len) 
   75     math(EXPR vdlt_static_idx "${vdlt_path_len} - ${vdlt_static_suffix_len}
") 
   76     string(SUBSTRING "${vdlt_PATH}
" "${vdlt_static_idx}
" -1 vdlt_static_check) 
   78     if (vdlt_shared_check STREQUAL CMAKE_SHARED_LIBRARY_SUFFIX) 
   80     elseif (vdlt_static_check STREQUAL CMAKE_STATIC_LIBRARY_SUFFIX) 
   84     # when import suffix != static suffix, we can disambiguate static and import 
   85     if (WIN32 AND NOT CMAKE_IMPORT_LIBRARY_SUFFIX STREQUAL CMAKE_STATIC_LIBRARY_SUFFIX) 
   86       string(LENGTH "${CMAKE_IMPORT_LIBRARY_SUFFIX}
" vdlt_import_suffix_len) 
   87       math(EXPR vdlt_import_idx "${vdlt_path_len} - ${vdlt_import_suffix_len}
") 
   88       string(SUBSTRING "${vdlt_PATH}
" "${vdlt_import_idx}
" -1 vdlt_import_check) 
   89       if (vdlt_import_check STREQUAL CMAKE_IMPORT_LIBRARY_SUFFIX) 
  101 @brief Detect whether an imported target is shared or not 
  103 This is intended for use with modules using 
  104 @ref vtk_module_third_party_external to detect whether that module is shared or 
  105 not. Generally, this should be replaced with the `Find` module providing this 
  106 information and modifying the usage requirements as necessary instead, but it 
  107 is not always possible. 
  110 vtk_detect_library_shared(<name> <target>) 
  113 Sets `<name>_is_shared` in the caller's scope if `<target>` is a shared 
  114 library. If it is an `UNKNOWN_LIBRARY`, a cache variable is exposed to allow 
  115 the user to provide the information if it ends up breaking something. 
  117 function (vtk_detect_library_shared name target) 
  118   if (VTK_MODULE_USE_EXTERNAL_${name}) 
  119     get_property(library_type 
  122     if (library_type STREQUAL "SHARED_LIBRARY
") 
  124     elseif (library_type STREQUAL "UNKNOWN_LIBRARY
") 
  125       option("VTK_MODULE_${
name}_IS_SHARED
" "Whether the ${
name} in use is shared or not
" ON) 
  126       mark_as_advanced("VTK_MODULE_${
name}_IS_SHARED
") 
  127       set(is_shared "${VTK_MODULE_${
name}_IS_SHARED}
") 
  132     set(is_shared "${BUILD_SHARED_LIBS}
") 
  135   set("${
name}_is_shared
"