ctkFunctionGetIncludeDirs.cmake 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ###########################################################################
  2. #
  3. # Library: CTK
  4. #
  5. # Copyright (c) German Cancer Research Center,
  6. # Division of Medical and Biological Informatics
  7. #
  8. # Licensed under the Apache License, Version 2.0 (the "License");
  9. # you may not use this file except in compliance with the License.
  10. # You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS,
  16. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. # See the License for the specific language governing permissions and
  18. # limitations under the License.
  19. #
  20. ###########################################################################
  21. #! \ingroup CMakeUtilities
  22. function(ctkFunctionGetIncludeDirs var_include_dirs)
  23. if(NOT ARGN)
  24. message(FATAL_ERROR "No targets given")
  25. endif()
  26. set(_include_dirs ${${var_include_dirs}} ${CTK_CONFIG_H_INCLUDE_DIR})
  27. foreach(_target ${ARGN})
  28. # Add the include directories from the plugin dependencies
  29. # The variable ${_target}_DEPENDENCIES is set in the
  30. # macro ctkMacroValidateBuildOptions
  31. set(ctk_deps )
  32. set(ext_deps )
  33. ctkMacroGetAllProjectTargetLibraries("${${_target}_DEPENDENCIES}" ctk_deps)
  34. ctkMacroGetAllNonProjectTargetLibraries("${${_target}_DEPENDENCIES}" ext_deps)
  35. foreach(dep ${ctk_deps})
  36. if(${dep}_INCLUDE_SUFFIXES)
  37. foreach(_suffix ${${dep}_INCLUDE_SUFFIXES})
  38. list(APPEND _include_dirs ${${dep}_SOURCE_DIR}/${_suffix})
  39. endforeach()
  40. list(APPEND _include_dirs ${${dep}_BINARY_DIR})
  41. else()
  42. list(APPEND _include_dirs
  43. ${${dep}_SOURCE_DIR}
  44. ${${dep}_BINARY_DIR}
  45. )
  46. endif()
  47. # For external projects, CTKConfig.cmake contains variables
  48. # listening the include dirs for CTK libraries and plugins
  49. if(${dep}_INCLUDE_DIRS)
  50. list(APPEND _include_dirs ${${dep}_INCLUDE_DIRS})
  51. endif()
  52. endforeach()
  53. foreach(dep ${ext_deps})
  54. if(${dep}_INCLUDE_DIRS)
  55. string(REPLACE "^" ";" _ext_include_dirs "${${dep}_INCLUDE_DIRS}")
  56. list(APPEND _include_dirs ${_ext_include_dirs})
  57. endif()
  58. # This is for resolving include dependencies between
  59. # libraries / plugins from external projects using CTK
  60. if(${dep}_SOURCE_DIR AND ${dep}_INCLUDE_SUFFIXES)
  61. foreach(_suffix ${${dep}_INCLUDE_SUFFIXES})
  62. list(APPEND _include_dirs ${${dep}_SOURCE_DIR}/${_suffix})
  63. endforeach()
  64. list(APPEND _include_dirs ${${dep}_BINARY_DIR})
  65. elseif(${dep}_SOURCE_DIR)
  66. list(APPEND _include_dirs ${${dep}_SOURCE_DIR})
  67. endif()
  68. if(${dep}_BINARY_DIR)
  69. list(APPEND _include_dirs ${${dep}_BINARY_DIR})
  70. endif()
  71. endforeach()
  72. endforeach()
  73. if(_include_dirs)
  74. list(REMOVE_DUPLICATES _include_dirs)
  75. endif()
  76. set(${var_include_dirs} ${_include_dirs} PARENT_SCOPE)
  77. endfunction()