ctkMacroValidateBuildOptions.cmake 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. ###########################################################################
  2. #
  3. # Library: CTK
  4. #
  5. # Copyright (c) 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. SET(EXTERNAL_TARGETS ) # This is used in CMakeLists.txt
  77. FOREACH(target_info ${target_directories_with_target_name})
  78. # extract target_dir and option_name
  79. STRING(REPLACE "^^" "\\;" target_info ${target_info})
  80. SET(target_info_list ${target_info})
  81. LIST(GET target_info_list 0 target_dir)
  82. LIST(GET target_info_list 1 option_name)
  83. #MESSAGE(STATUS target_dir:${target_dir})
  84. #MESSAGE(STATUS option_name:${option_name})
  85. #MESSAGE(STATUS option_name-value:${${option_name}})
  86. # make sure the directory exists
  87. IF(NOT EXISTS ${target_dir}/CMakeLists.txt)
  88. MESSAGE(FATAL_ERROR "Target directory ${target_dir}/CMakeLists.txt doesn't exists !")
  89. ENDIF()
  90. # extract project name from CMakeLists.txt
  91. FILE(STRINGS "${target_dir}/CMakeLists.txt" project_string
  92. REGEX "^ *(P|p)(R|r)(O|o)(J|j)(E|e)(C|c)(T|t)\\("
  93. LIMIT_COUNT 10)
  94. STRING(REGEX MATCH "\\((.*)\\)" target_project_name ${project_string})
  95. STRING(REGEX REPLACE "\\(|\\)" "" target_project_name ${target_project_name})
  96. IF(${target_project_name} STREQUAL "")
  97. MESSAGE(FATAL_ERROR "Failed to extract project name from ${target_dir}/CMakeLists.txt")
  98. ENDIF()
  99. #MESSAGE(STATUS target_project_name:${target_project_name})
  100. IF(${${option_name}})
  101. # Obtain dependency path
  102. ctkMacroSetPaths("${QT_INSTALLED_LIBRARY_DIR}")
  103. EXECUTE_PROCESS(
  104. COMMAND "${executable}" "${CTK_BINARY_DIR}/DGraphInput-alldep-withext.txt" -sort ${target_project_name}
  105. WORKING_DIRECTORY ${CTK_BINARY_DIR}
  106. RESULT_VARIABLE RESULT_VAR
  107. OUTPUT_VARIABLE dep_path
  108. ERROR_VARIABLE error
  109. OUTPUT_STRIP_TRAILING_WHITESPACE
  110. )
  111. IF(RESULT_VAR)
  112. MESSAGE(FATAL_ERROR "Failed to obtain dependence path of ${target_project_name}.\n${RESULT_VAR}\n${CTK_BINARY_DIR}\n${error}")
  113. ENDIF()
  114. # Set a variable for each target containing its dependencies
  115. # Needed for setting individual include directories for plugins,
  116. # depending on other plugins.
  117. SET(${target_project_name}_DEPENDENCIES )
  118. # Convert 'dep_path' to a list
  119. STRING(REPLACE " " "\\;" dep_path_list ${dep_path})
  120. SET(dep_path_list ${dep_path_list})
  121. LIST(REMOVE_ITEM dep_path_list ${target_project_name})
  122. LIST(APPEND ${target_project_name}_DEPENDENCIES ${dep_path_list})
  123. #MESSAGE("path for ${target_project_name} is: ${dep_path_list}")
  124. # Check if all CTK targets included in the dependency path are enabled
  125. SET(ctk_dep_path_list )
  126. SET(ext_dep_path_list ${dep_path_list})
  127. ctkMacroGetAllCTKTargetLibraries("${dep_path_list}" ctk_dep_path_list)
  128. IF(ctk_dep_path_list)
  129. LIST(REMOVE_ITEM ext_dep_path_list ${ctk_dep_path_list})
  130. ENDIF()
  131. IF(ext_dep_path_list)
  132. LIST(APPEND EXTERNAL_TARGETS ${ext_dep_path_list})
  133. ENDIF()
  134. FOREACH(dep ${ctk_dep_path_list})
  135. ctkMacroGetOptionName("${target_directories_with_target_name}" ${dep} dep_option)
  136. IF(NOT ${${dep_option}})
  137. # Enable option
  138. MESSAGE(STATUS "Enabling option [${dep_option}] required by [${target_project_name}]")
  139. SET(${dep_option} ON CACHE BOOL "Enable ${target_project_name} library" FORCE)
  140. ENDIF()
  141. ENDFOREACH()
  142. ENDIF()
  143. ENDFOREACH()
  144. IF(EXTERNAL_TARGETS)
  145. LIST(REMOVE_DUPLICATES EXTERNAL_TARGETS)
  146. ENDIF()
  147. #MESSAGE(STATUS "Validated: CTK_LIB_*, CTK_PLUGIN_*, CTK_APP_*")
  148. ENDMACRO()