-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenDeps.cmake
105 lines (88 loc) · 2.76 KB
/
GenDeps.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# This function is a reimplementation of godeps.sh in cmake.
#
# TODO: remove this, it is no longer used. In practice this winds up
# creating a giant amount of output/clutter when using cmake --trace,
# and doesn't seem to really offer a lot of other advantages.
function(godeps_in_cmake pack)
set(deps)
foreach( src ${ARGV})
set(impblock 0)
file(STRINGS ${src} lines)
foreach( line ${lines})
# Within an import block:
if(impblock)
string(REGEX MATCH "^\\)" endblock ${line})
if(endblock)
set(impblock 0)
break()
endif()
string(REGEX MATCH "^[ \t]*[A-Za-z0-9_\.]*[ \t]*\"([^\"]+)\".*"
imp ${line})
if(imp)
list(APPEND deps "${CMAKE_MATCH_1}.gox")
endif()
continue()
endif()
# Single import outside of an import block.
string(REGEX MATCH "^import[ \t]*[A-Za-z0-9_\.]*[ \t]*\"([^\"]+)\"" imp ${line})
if(imp)
list(APPEND deps "${CMAKE_MATCH_1}.gox")
continue()
endif()
# Start of import block
string(REGEX MATCH "^import[ \t]+\\\(" beginblock ${line})
if(beginblock)
set(impblock 1)
continue()
endif()
endforeach()
if(deps)
list(SORT deps)
list(REMOVE_DUPLICATES deps)
endif()
endforeach()
# Prune out "unsafe"
list(FIND deps "unsafe.gox" hasun)
if( hasun GREATER -1)
list(REMOVE_ITEM deps "unsafe.gox")
endif()
# Done
set(packdeps ${deps} PARENT_SCOPE)
endfunction()
# This version runs the godeps.sh shell script and captures the
# resulting output. Return value is in the variable 'packdeps'
# in the parent scope.
# Unnamed parameters:
#
# * Package path, e.g. "bufio" or "container/heap".
# * Script root (where to find godeps.sh)
#
# Named parameters:
#
# SOURCES Full paths of go source files in this package.
function(godeps pack libgo_scriptroot)
CMAKE_PARSE_ARGUMENTS(ARG "" "" "SOURCES" ${ARGN})
set(godepsdotsh "${libgo_scriptroot}/godeps.sh")
set(capturesh "${CMAKE_CURRENT_SOURCE_DIR}/capturescript.sh")
string(REPLACE "/" "_" ptarget "${pack}")
set(depouttmp "${libgo_binroot}/${ptarget}.dep")
string(REPLACE ";" " " packfiles "${ARG_SOURCES}")
set(packfiles "unused ${packfiles}")
# Kick off the script.
execute_process(COMMAND "${shell}" ${capturesh} ${godepsdotsh} ${depouttmp} ${packfiles})
# Read the result.
file(STRINGS ${depouttmp} depoutput)
separate_arguments(depoutput)
# godeps.sh produces output of the form:
# <pack>.dep: file.go file2.go ... pack1.gox pack2.gox ...
# We're interested in the gox files.
set(packdepstmp)
foreach( item ${depoutput})
string(REGEX MATCH "^.+\.gox$" gox ${item})
if(gox)
list(APPEND packdepstmp ${item})
endif()
endforeach()
#message(STATUS "deps for ${pack}: ${packdepstmp}")
set(packdeps ${packdepstmp} PARENT_SCOPE)
endfunction()