vtkModuleAPI.cmake 6.7 KB
Newer Older
1 2 3
#-----------------------------------------------------------------------------
# Private helper macros.

4 5 6 7 8 9 10
# _vtk_module_config_recurse(<namespace> <module>)
#
# Internal macro to recursively load module information into the supplied
# namespace, this is called from vtk_module_config. It should be noted that
# _${ns}_${mod}_USED must be cleared if this macro is to work correctly on
# subsequent invocations. The macro will load the module files using the
# vtk_module_load, making all of its variables available in the local scope.
11
macro(_vtk_module_config_recurse ns mod)
12
  if(NOT _${ns}_${mod}_USED)
13
    set(_${ns}_${mod}_USED 1)
14
    list(APPEND _${ns}_USED_MODULES ${mod})
15 16 17 18
    vtk_module_load("${mod}")
    list(APPEND ${ns}_LIBRARIES ${${mod}_LIBRARIES})
    list(APPEND ${ns}_INCLUDE_DIRS ${${mod}_INCLUDE_DIRS})
    list(APPEND ${ns}_LIBRARY_DIRS ${${mod}_LIBRARY_DIRS})
19
    list(APPEND ${ns}_RUNTIME_LIBRARY_DIRS ${${mod}_RUNTIME_LIBRARY_DIRS})
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
    foreach(iface IN LISTS ${mod}_IMPLEMENTS)
      list(APPEND _${ns}_AUTOINIT_${iface} ${mod})
      list(APPEND _${ns}_AUTOINIT ${iface})
    endforeach()
    foreach(dep IN LISTS ${mod}_DEPENDS)
      _vtk_module_config_recurse("${ns}" "${dep}")
    endforeach()
  endif()
endmacro()

#-----------------------------------------------------------------------------
# Public interface macros.

# vtk_module_load(<module>)
#
35 36
# Loads variables describing the given module, these include custom variables
# set by the module along with the standard ones listed below:
37 38 39 40 41
#  <module>_LOADED         = True if the module has been loaded
#  <module>_DEPENDS        = List of dependencies on other modules
#  <module>_LIBRARIES      = Libraries to link
#  <module>_INCLUDE_DIRS   = Header search path
#  <module>_LIBRARY_DIRS   = Library search path (for outside dependencies)
42
#  <module>_RUNTIME_LIBRARY_DIRS = Runtime linker search path
43 44
macro(vtk_module_load mod)
  if(NOT ${mod}_LOADED)
45
    include("${VTK_MODULES_DIR}/${mod}.cmake" OPTIONAL RESULT_VARIABLE _found)
46
    if(NOT _found)
47 48 49 50 51
      # When building applications outside VTK, they can provide extra module
      # config files by simply adding the corresponding locations to the
      # CMAKE_MODULE_PATH
      include(${mod} OPTIONAL)
    endif()
52 53 54 55 56 57
    if(NOT ${mod}_LOADED)
      message(FATAL_ERROR "No such module: \"${mod}\"")
    endif()
  endif()
endmacro()

58 59 60 61 62
# vtk_module_dep_includes(<module>)
#
# Loads the <module>_DEPENDS_INCLUDE_DIRS variable.
macro(vtk_module_dep_includes mod)
  vtk_module_load("${mod}")
63 64 65
  vtk_module_config(_dep_${mod} ${${mod}_DEPENDS})
  if(_dep_${mod}_INCLUDE_DIRS)
    set(${mod}_DEPENDS_INCLUDE_DIRS ${_dep_${mod}_INCLUDE_DIRS})
66 67 68
  endif()
endmacro()

69
# vtk_module_headers_load(<module>)
70
#
71 72 73 74
# Loads variables describing the headers/API of the given module, this is not
# loaded by vtk_module_config, and is mainly useful for wrapping generation:
#  <module>_HEADERS_LOADED      = True if the module header info has been loaded
#  <module>_HEADERS             = List of headers
75 76 77
#  <module>_HEADER_<header>_EXISTS
#  <module>_HEADER_<header>_ABSTRACT
#  <module>_HEADER_<header>_WRAP_EXCLUDE
78
#  <module>_HEADER_<header>_WRAP_EXCLUDE_PYTHON
79 80
macro(vtk_module_headers_load mod)
  if(NOT ${mod}_HEADERS_LOADED)
81 82
    include("${VTK_MODULES_DIR}/${mod}-Headers.cmake"
      OPTIONAL RESULT_VARIABLE _found)
83
    if(NOT _found)
84 85 86
      # When building applications outside VTK, they can provide extra module
      # config files by simply adding the corresponding locations to the
      # CMAKE_MODULE_PATH
87
      include(${mod}-Headers OPTIONAL)
88
    endif()
89
    if(NOT ${mod}_HEADERS_LOADED)
90 91 92 93 94
      message(FATAL_ERROR "No such module: \"${mod}\"")
    endif()
  endif()
endmacro()

95 96 97 98 99 100 101
# vtk_module_config(<namespace> [modules...])
#
# Configures variables describing the given modules and their dependencies:
#  <namespace>_DEFINITIONS  = Preprocessor definitions
#  <namespace>_LIBRARIES    = Libraries to link
#  <namespace>_INCLUDE_DIRS = Header search path
#  <namespace>_LIBRARY_DIRS = Library search path (for outside dependencies)
102
#  <namespace>_RUNTIME_LIBRARY_DIRS = Runtime linker search path
103 104 105 106 107 108
#
# Calling this macro also recursively calls vtk_module_load for all modules
# explicitly named, and their dependencies, making them available in the local
# scope. This means that module level information can be accessed once this
# macro has been called.
#
109 110
# Do not name a module as the namespace.
macro(vtk_module_config ns)
111 112 113 114 115 116 117 118 119 120 121 122
  set(_${ns}_MISSING ${ARGN})
  if(_${ns}_MISSING)
    list(REMOVE_ITEM _${ns}_MISSING ${VTK_MODULES_ENABLED})
  endif()
  if(_${ns}_MISSING)
    set(msg "")
    foreach(mod ${_${ns}_MISSING})
      set(msg "${msg}\n  ${mod}")
    endforeach()
    message(FATAL_ERROR "Requested modules not available:${msg}")
  endif()

123 124 125 126
  set(${ns}_DEFINITIONS "")
  set(${ns}_LIBRARIES "")
  set(${ns}_INCLUDE_DIRS "")
  set(${ns}_LIBRARY_DIRS "")
127
  set(${ns}_RUNTIME_LIBRARY_DIRS "")
128
  set(_${ns}_AUTOINIT "")
129 130

  set(_${ns}_USED_MODULES "")
131 132 133
  foreach(mod ${ARGN})
    _vtk_module_config_recurse("${ns}" "${mod}")
  endforeach()
134 135 136 137 138
  foreach(mod ${_${ns}_USED_MODULES})
    unset(_${ns}_${mod}_USED)
  endforeach()
  unset(_${ns}_USED_MODULES)

139
  foreach(v ${ns}_LIBRARIES ${ns}_INCLUDE_DIRS ${ns}_LIBRARY_DIRS
140
            ${ns}_RUNTIME_LIBRARY_DIRS _${ns}_AUTOINIT)
141 142 143 144 145 146 147 148
    if(${v})
      list(REMOVE_DUPLICATES ${v})
    endif()
  endforeach()

  list(SORT _${ns}_AUTOINIT) # Deterministic order.
  foreach(mod ${_${ns}_AUTOINIT})
    list(SORT _${ns}_AUTOINIT_${mod}) # Deterministic order.
149
    list(REMOVE_DUPLICATES _${ns}_AUTOINIT_${mod})
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
    list(LENGTH _${ns}_AUTOINIT_${mod} _ai_len)
    string(REPLACE ";" "," _ai "${_ai_len}(${_${ns}_AUTOINIT_${mod}})")
    if(${_ai_len} GREATER 1 AND "${CMAKE_GENERATOR}" MATCHES "Visual Studio")
      # VS IDE project files cannot handle a comma (,) in a
      # preprocessor definition value outside a quoted string.
      # Generate a header file to do the definition and define
      # ${mod}_INCLUDE to tell ${mod}Module.h to include it.
      # Name the file after its content to guarantee uniqueness.
      string(REPLACE ";" "_" _inc
        "${CMAKE_BINARY_DIR}/CMakeFiles/${mod}_AUTOINIT_${_${ns}_AUTOINIT_${mod}}.h")
      set(CMAKE_CONFIGURABLE_FILE_CONTENT "#define ${mod}_AUTOINIT ${_ai}")
      configure_file(${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in ${_inc})
      list(APPEND ${ns}_DEFINITIONS "${mod}_INCLUDE=\"${_inc}\"")
    else()
      # Directly define ${mod}_AUTOINIT.
      list(APPEND ${ns}_DEFINITIONS "${mod}_AUTOINIT=${_ai}")
    endif()
    unset(_${ns}_AUTOINIT_${mod})
  endforeach()
  unset(_${ns}_AUTOINIT)
endmacro()
171

172 173 174
# vtk_add_to_module_search_path(<source> <build>)
#
# Call to add a single module to the module search path.
175 176
macro(vtk_add_to_module_search_path src bld)
  list(APPEND vtk_module_search_path "${src},${bld}")
177
endmacro()