1 ###########################################################################
5 # Copyright (c) Kitware Inc.
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
11 # http://www.apache.org/licenses/LICENSE-2.0.txt
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.
19 ###########################################################################
22 #! Generate a DGrapgh input file expected by DGraph executable.
25 function(ctkFunctionGenerateDGraphInput dir target_directories)
27 message(FATAL_ERROR "Directory ${dir} doesn't exist!")
30 CtkMacroParseArguments(MY
32 "WITH_OPTION;WITH_EXTERNALS"
40 set(isolated_vertex_candidates)
42 foreach(target_info ${target_directories})
44 # extract target_dir and option_name
45 string(REPLACE "^^" "\\;" target_info ${target_info})
46 set(target_info_list ${target_info})
47 list(GET target_info_list 0 target_dir)
48 list(GET target_info_list 1 option_name)
49 #message(STATUS target_dir:${target_dir})
50 #message(STATUS option_name:${option_name})
51 #message(STATUS option_name-value:${${option_name}})
53 # make sure the directory exists
54 if(NOT EXISTS ${target_dir}/CMakeLists.txt)
55 message(FATAL_ERROR "Target directory ${target_dir}/CMakeLists.txt doesn't exists !")
60 set(include_dep ${${option_name}})
63 # extract project name from CMakeLists.txt
64 file(STRINGS "${target_dir}/CMakeLists.txt" project_string
65 REGEX "^ *(P|p)(R|r)(O|o)(J|j)(E|e)(C|c)(T|t)\\("
67 string(REGEX MATCH "\\((.*)\\)" target_project_name ${project_string})
68 string(REGEX REPLACE "\\(|\\)" "" target_project_name ${target_project_name})
69 if(${target_project_name} STREQUAL "")
70 message(FATAL_ERROR "Failed to extract project name from ${target_dir}/CMakeLists.txt")
72 #message(STATUS target_project_name:${target_project_name})
74 # Make sure the variable is cleared
78 ctkFunctionCollectTargetLibraryNames(${target_dir} dependencies)
79 if(${target_project_name}_OPTIONAL_DEPENDENCIES)
80 list(APPEND dependencies ${${target_project_name}_OPTIONAL_DEPENDENCIES})
83 # Make sure the variable is cleared
87 set(ctk_dependencies ${dependencies})
89 # filter dependencies starting with CTK org org_commontk_
90 ctkMacroGetAllProjectTargetLibraries("${dependencies}" ctk_dependencies)
94 list(APPEND vertices ${target_project_name})
96 # isolated vertex candidate
97 list(APPEND isolated_vertex_candidates ${target_project_name})
100 # Generate XML related to the dependencies
101 foreach(dependency_name ${ctk_dependencies})
102 list(APPEND edges ${dependency_name})
103 set(dgraph_list ${dgraph_list} "${target_project_name} ${dependency_name}\n")
104 list(APPEND vertices ${dependency_name})
111 foreach(isolated_vertex_candidate ${isolated_vertex_candidates})
113 foreach(dgraph_entry ${dgraph_list})
114 string(REPLACE "\n" "" dgraph_entry "${dgraph_entry}")
115 string(REPLACE " " ";" dgraph_entry "${dgraph_entry}")
116 list(FIND dgraph_entry ${isolated_vertex_candidate} _index)
117 if(_index GREATER -1)
124 list(APPEND vertices ${isolated_vertex_candidate})
125 set(dgraph_list "${isolated_vertex_candidate}\n" ${dgraph_list})
130 list(REMOVE_DUPLICATES vertices)
132 list(LENGTH vertices numberOfVertices)
133 list(LENGTH edges numberOfEdges)
135 set(dgraph_list "${numberOfVertices} ${numberOfEdges}\n" ${dgraph_list})
138 set(filename "${dir}/DGraphInput.txt")
139 elseif(MY_WITH_EXTERNALS)
140 set(filename "${dir}/DGraphInput-alldep-withext.txt")
142 set(filename "${dir}/DGraphInput-alldep.txt")
145 file(WRITE ${filename} ${dgraph_list})
146 message(STATUS "Generated: ${filename}")