ctkMacroValidateBuildOptions.cmake 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. ###########################################################################
  2. #
  3. # Library: CTK
  4. #
  5. # Copyright (c) 2010 Kitware Inc.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.commontk.org/LICENSE
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. ###########################################################################
  20. #
  21. #
  22. #
  23. MACRO(ctkMacroGetOptionName target_directories_with_target_name target_name option_name_var)
  24. FOREACH(target_info ${target_directories_with_target_name})
  25. # extract target_dir and option_name
  26. #MESSAGE("target_info:${target_info}")
  27. STRING(REPLACE "^^" "\\;" target_info_list ${target_info})
  28. SET(target_info_list ${target_info_list})
  29. LIST(GET target_info_list 0 _target_dir)
  30. LIST(GET target_info_list 1 _option_name)
  31. LIST(GET target_info_list 2 _target_name)
  32. IF(${_target_name} STREQUAL ${target_name})
  33. SET(${option_name_var} ${_option_name})
  34. ENDIF()
  35. ENDFOREACH()
  36. ENDMACRO()
  37. #
  38. #
  39. #
  40. MACRO(ctkMacroValidateBuildOptions dir executable target_directories)
  41. IF(NOT EXISTS ${dir})
  42. MESSAGE(FATAL_ERROR "Directory ${dir} doesn't exist!")
  43. ENDIF()
  44. IF(NOT EXISTS ${executable})
  45. MESSAGE(FATAL_ERROR "Executable ${executable} doesn't exist!")
  46. ENDIF()
  47. SET(target_directories_with_target_name)
  48. # Create target_directories_with_target_name
  49. FOREACH(target_info ${target_directories})
  50. # extract target_dir and option_name
  51. STRING(REPLACE "^^" "\\;" target_info ${target_info})
  52. SET(target_info_list ${target_info})
  53. LIST(GET target_info_list 0 target_dir)
  54. LIST(GET target_info_list 1 option_name)
  55. #MESSAGE(STATUS target_dir:${target_dir})
  56. #MESSAGE(STATUS option_name:${option_name})
  57. #MESSAGE(STATUS option_name-value:${${option_name}})
  58. # make sure the directory exists
  59. IF(NOT EXISTS ${target_dir}/CMakeLists.txt)
  60. MESSAGE(FATAL_ERROR "Target directory ${target_dir}/CMakeLists.txt doesn't exists !")
  61. ENDIF()
  62. # extract project name from CMakeLists.txt
  63. FILE(STRINGS "${target_dir}/CMakeLists.txt" project_string
  64. REGEX "^ *(P|p)(R|r)(O|o)(J|j)(E|e)(C|c)(T|t)\\("
  65. LIMIT_COUNT 10)
  66. STRING(REGEX MATCH "\\((.*)\\)" target_project_name ${project_string})
  67. STRING(REGEX REPLACE "\\(|\\)" "" target_project_name ${target_project_name})
  68. IF(${target_project_name} STREQUAL "")
  69. MESSAGE(FATAL_ERROR "Failed to extract project name from ${target_dir}/CMakeLists.txt")
  70. ENDIF()
  71. #MESSAGE(STATUS target_project_name:${target_project_name})
  72. LIST(APPEND target_directories_with_target_name
  73. ${target_dir}^^${option_name}^^${target_project_name}
  74. )
  75. ENDFOREACH()
  76. FOREACH(target_info ${target_directories_with_target_name})
  77. # extract target_dir and option_name
  78. STRING(REPLACE "^^" "\\;" target_info ${target_info})
  79. SET(target_info_list ${target_info})
  80. LIST(GET target_info_list 0 target_dir)
  81. LIST(GET target_info_list 1 option_name)
  82. #MESSAGE(STATUS target_dir:${target_dir})
  83. #MESSAGE(STATUS option_name:${option_name})
  84. #MESSAGE(STATUS option_name-value:${${option_name}})
  85. # make sure the directory exists
  86. IF(NOT EXISTS ${target_dir}/CMakeLists.txt)
  87. MESSAGE(FATAL_ERROR "Target directory ${target_dir}/CMakeLists.txt doesn't exists !")
  88. ENDIF()
  89. # extract project name from CMakeLists.txt
  90. FILE(STRINGS "${target_dir}/CMakeLists.txt" project_string
  91. REGEX "^ *(P|p)(R|r)(O|o)(J|j)(E|e)(C|c)(T|t)\\("
  92. LIMIT_COUNT 10)
  93. STRING(REGEX MATCH "\\((.*)\\)" target_project_name ${project_string})
  94. STRING(REGEX REPLACE "\\(|\\)" "" target_project_name ${target_project_name})
  95. IF(${target_project_name} STREQUAL "")
  96. MESSAGE(FATAL_ERROR "Failed to extract project name from ${target_dir}/CMakeLists.txt")
  97. ENDIF()
  98. #MESSAGE(STATUS target_project_name:${target_project_name})
  99. IF(${${option_name}})
  100. # Obtain dependency path
  101. ctkFunctionExecuteProcess(
  102. COMMAND "${executable}" "${CTK_BINARY_DIR}/DGraphInput-alldep.txt" -paths ${target_project_name}
  103. PATH_LIST \"${QT_INSTALLED_LIBRARY_DIR}\"
  104. WORKING_DIRECTORY ${CTK_BINARY_DIR}
  105. RESULT_VARIABLE RESULT_VAR
  106. OUTPUT_VARIABLE dep_paths
  107. ERROR_VARIABLE error
  108. OUTPUT_STRIP_TRAILING_WHITESPACE
  109. )
  110. IF(RESULT_VAR)
  111. MESSAGE(FATAL_ERROR "Failed to obtain dependence path of ${subir}.\n${RESULT_VAR}\n${CTK_BINARY_DIR}\n${error}")
  112. ENDIF()
  113. FOREACH(dep_path ${dep_paths})
  114. # Convert 'dep_path' to a list
  115. STRING(REPLACE " " "\\;" dep_path_list ${dep_path})
  116. SET(dep_path_list ${dep_path_list})
  117. #MESSAGE("path for ${target_project_name} is: ${dep_path}")
  118. # Check if all target included in the dependency path are enabled
  119. FOREACH(dep ${dep_path_list})
  120. ctkMacroGetOptionName("${target_directories_with_target_name}" ${dep} dep_option)
  121. IF(NOT ${${dep_option}})
  122. # Enable option
  123. MESSAGE(STATUS "Enabling option [${dep_option}] required by [${target_project_name}]")
  124. SET(${dep_option} ON CACHE BOOL "Enable ${target_project_name} library" FORCE)
  125. ENDIF()
  126. ENDFOREACH()
  127. ENDFOREACH()
  128. ENDIF()
  129. ENDFOREACH()
  130. #MESSAGE(STATUS "Validated: CTK_LIB_*, CTK_PLUGIN_*, CTK_APP_*")
  131. ENDMACRO()