FindITK.cmake 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #
  2. # Find an ITK installation or build tree.
  3. #
  4. # When ITK is found, the ITKConfig.cmake file is sourced to setup the
  5. # location and configuration of ITK. Please read this file, or
  6. # ITKConfig.cmake.in from the ITK source tree for the full list of
  7. # definitions. Of particular interest is
  8. #
  9. # ITK_USE_FILE - A CMake source file that can be included
  10. # to set the include directories, library
  11. # directories, and preprocessor macros.
  12. #
  13. # In addition to the variables read from ITKConfig.cmake, this find
  14. # module also defines
  15. #
  16. # ITK_DIR - The directory containing ITKConfig.cmake. This is either
  17. # the root of the build tree, or the lib/InsightToolkit
  18. # directory. This is the only cache entry.
  19. #
  20. # ITK_FOUND - Whether ITK was found. If this is true, ITK_DIR is okay.
  21. #
  22. # USE_ITK_FILE - The full path to the UseITK.cmake file. This is provided
  23. # for backward compatability. Use ITK_USE_FILE instead.
  24. #
  25. SET(ITK_DIR_STRING "directory containing ITKConfig.cmake. This is either the root of the build tree, or PREFIX/lib/InsightToolkit for an installation.")
  26. # Search only if the location is not already known.
  27. IF(NOT ITK_DIR)
  28. # Get the system search path as a list.
  29. IF(UNIX)
  30. STRING(REGEX MATCHALL "[^:]+" ITK_DIR_SEARCH1 "$ENV{PATH}")
  31. ELSE(UNIX)
  32. STRING(REGEX REPLACE "\\\\" "/" ITK_DIR_SEARCH1 "$ENV{PATH}")
  33. ENDIF(UNIX)
  34. STRING(REGEX REPLACE "/;" ";" ITK_DIR_SEARCH2 ${ITK_DIR_SEARCH1})
  35. # Construct a set of paths relative to the system search path.
  36. SET(ITK_DIR_SEARCH "")
  37. FOREACH(dir ${ITK_DIR_SEARCH2})
  38. SET(ITK_DIR_SEARCH ${ITK_DIR_SEARCH} "${dir}/../lib/InsightToolkit")
  39. ENDFOREACH(dir)
  40. #
  41. # Look for an installation or build tree.
  42. #
  43. FIND_PATH(ITK_DIR ITKConfig.cmake
  44. # Look for an environment variable ITK_DIR.
  45. $ENV{ITK_DIR}
  46. # Look in places relative to the system executable search path.
  47. ${ITK_DIR_SEARCH}
  48. # Look in standard UNIX install locations.
  49. /usr/local/lib/InsightToolkit
  50. /usr/lib/InsightToolkit
  51. # Read from the CMakeSetup registry entries. It is likely that
  52. # ITK will have been recently built.
  53. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
  54. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
  55. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
  56. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
  57. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
  58. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
  59. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
  60. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
  61. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
  62. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
  63. # Help the user find it if we cannot.
  64. DOC "The ${ITK_DIR_STRING}"
  65. )
  66. ENDIF(NOT ITK_DIR)
  67. # If ITK was found, load the configuration file to get the rest of the
  68. # settings.
  69. IF(ITK_DIR)
  70. SET(ITK_FOUND 1)
  71. INCLUDE(${ITK_DIR}/ITKConfig.cmake)
  72. # Set USE_ITK_FILE for backward-compatability.
  73. SET(USE_ITK_FILE ${ITK_USE_FILE})
  74. ELSE(ITK_DIR)
  75. SET(ITK_FOUND 0)
  76. IF(ITK_FIND_REQUIRED)
  77. MESSAGE(FATAL_ERROR "Please set ITK_DIR to the ${ITK_DIR_STRING}")
  78. ENDIF(ITK_FIND_REQUIRED)
  79. ENDIF(ITK_DIR)