Skip to content

Commit 765331d

Browse files
committed
Meson build: Fix dependency on generated files
Add meson.build files in all subdirectories of sigc++/ where .h and/or .cc files are generated. Looks like it's necessary in order to have all dependent .cc files recompiled when a .h.m4 file has been changed. Don't know if it has always been necessary, or if it has become necessary due to changes in Meson and/or Ninja.
1 parent 90c17ea commit 765331d

File tree

5 files changed

+148
-96
lines changed

5 files changed

+148
-96
lines changed

sigc++/adaptors/lambda/meson.build

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# sigc++/adaptors/lambda
2+
3+
# Input: python3, handle_built_files, m4_template, m4_include_dir
4+
# Output:
5+
# Input and output: built_h_files, built_cc_files, built_h_file_targets,
6+
# built_cc_file_targets
7+
8+
# .m4 files to build .h and .cc files from.
9+
adaptors_lambda_cc_m4_files = [
10+
'lambda.cc',
11+
]
12+
adaptors_lambda_h_m4_files = [
13+
'base.h',
14+
'select.h',
15+
]
16+
foreach file : adaptors_lambda_h_m4_files
17+
built_h_files += 'adaptors' / 'lambda' / file
18+
endforeach
19+
foreach file : adaptors_lambda_cc_m4_files
20+
built_cc_files += 'adaptors' / 'lambda' / file
21+
endforeach
22+
23+
if maintainer_mode
24+
# Maintainer mode. Generate .h and .cc files from .m4 files in macros/ directory.
25+
foreach file : adaptors_lambda_cc_m4_files + adaptors_lambda_h_m4_files
26+
built_file_target = custom_target('adaptors_lambda_' + file,
27+
input: 'macros' / file + '.m4',
28+
output: file,
29+
command: [
30+
python3, handle_built_files, 'build_from_m4',
31+
m4_include_dir,
32+
'@INPUT@',
33+
'@OUTPUT@',
34+
],
35+
depend_files: m4_template,
36+
build_by_default: maintainer_mode,
37+
install: false,
38+
)
39+
if file.endswith('.cc')
40+
built_cc_file_targets += built_file_target
41+
else
42+
built_h_file_targets += built_file_target
43+
endif
44+
endforeach
45+
endif

sigc++/adaptors/meson.build

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# sigc++/adaptors
2+
3+
# Input: python3, handle_built_files, m4_template, m4_include_dir
4+
# Output:
5+
# Input and output: built_h_files, built_h_file_targets
6+
7+
# .m4 files to build .h files from.
8+
adaptors_h_m4_files = [
9+
'adaptor_trait.h',
10+
'bind.h',
11+
'bind_return.h',
12+
'compose.h',
13+
'deduce_result_type.h',
14+
'exception_catch.h',
15+
'hide.h',
16+
'retype.h',
17+
'retype_return.h',
18+
'track_obj.h',
19+
]
20+
foreach file : adaptors_h_m4_files
21+
built_h_files += 'adaptors' / file
22+
endforeach
23+
24+
if maintainer_mode
25+
# Maintainer mode. Generate .h files from .m4 files in macros/ directory.
26+
foreach file : adaptors_h_m4_files
27+
built_h_file_targets += custom_target('adaptors_' + file,
28+
input: 'macros' / file + '.m4',
29+
output: file,
30+
command: [
31+
python3, handle_built_files, 'build_from_m4',
32+
m4_include_dir,
33+
'@INPUT@',
34+
'@OUTPUT@',
35+
],
36+
depend_files: m4_template,
37+
build_by_default: maintainer_mode,
38+
install: false,
39+
)
40+
endforeach
41+
endif

sigc++/functors/meson.build

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# sigc++/functors
2+
3+
# Input: python3, handle_built_files, m4_template, m4_include_dir
4+
# Output:
5+
# Input and output: built_h_files, built_h_file_targets
6+
7+
# .m4 files to build .h files from.
8+
functors_h_m4_files = [
9+
'functor_trait.h',
10+
'mem_fun.h',
11+
'ptr_fun.h',
12+
'slot.h',
13+
]
14+
foreach file : functors_h_m4_files
15+
built_h_files += 'functors' / file
16+
endforeach
17+
18+
if maintainer_mode
19+
# Maintainer mode. Generate .h files from .m4 files in macros/ directory.
20+
foreach file : functors_h_m4_files
21+
built_h_file_targets += custom_target('functors_' + file,
22+
input: 'macros' / file + '.m4',
23+
output: file,
24+
command: [
25+
python3, handle_built_files, 'build_from_m4',
26+
m4_include_dir,
27+
'@INPUT@',
28+
'@OUTPUT@',
29+
],
30+
depend_files: m4_template,
31+
build_by_default: maintainer_mode,
32+
install: false,
33+
)
34+
endforeach
35+
endif

sigc++/meson.build

Lines changed: 23 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# sigc++
22

33
# Input: sigcxx_build_dep, sigcxx_pcname, sigcxx_libversion, sigcxx_api_version,
4-
# install_includedir, project_source_root, sigc_res
4+
# install_includedir, project_source_root, sigc_res, python3,
5+
# handle_built_files
56
# Output: source_h_files, built_h_files, sigcxx_own_dep, built_files_root,
67
# built_h_file_targets
78

@@ -33,54 +34,28 @@ functors_h_files = [
3334
'functors' / 'slot_base.h',
3435
]
3536

36-
# .m4 files to build .h and .cc files from.
37-
adaptors_lambda_cc_m4_files = [
38-
'lambda.cc',
39-
]
37+
# .m4 files to build .h files from.
4038
sigc_h_m4_files = [
4139
'limit_reference.h',
4240
'signal.h',
4341
]
44-
adaptors_h_m4_files = [
45-
'adaptor_trait.h',
46-
'bind.h',
47-
'bind_return.h',
48-
'compose.h',
49-
'deduce_result_type.h',
50-
'exception_catch.h',
51-
'hide.h',
52-
'retype.h',
53-
'retype_return.h',
54-
'track_obj.h',
55-
]
56-
adaptors_lambda_h_m4_files = [
57-
'base.h',
58-
'select.h',
59-
]
60-
functors_h_m4_files = [
61-
'functor_trait.h',
62-
'mem_fun.h',
63-
'ptr_fun.h',
64-
'slot.h',
65-
]
42+
43+
m4_template = files('macros' / 'template.macros.m4')
44+
m4_include_dir = meson.current_source_dir() / 'macros'
6645

6746
source_h_files = sigc_h_files + adaptors_h_files + functors_h_files
6847

6948
built_h_files = sigc_h_m4_files
70-
foreach file : adaptors_h_m4_files
71-
built_h_files += 'adaptors' / file
72-
endforeach
73-
foreach file : adaptors_lambda_h_m4_files
74-
built_h_files += 'adaptors' / 'lambda' / file
75-
endforeach
76-
foreach file : functors_h_m4_files
77-
built_h_files += 'functors' / file
78-
endforeach
79-
8049
built_cc_files = []
81-
foreach file : adaptors_lambda_cc_m4_files
82-
built_cc_files += 'adaptors' / 'lambda' / file
83-
endforeach
50+
51+
# Force meson+ninja to generate source files before anything is compiled.
52+
# Compilation must depend on these targets.
53+
built_cc_file_targets = []
54+
built_h_file_targets = []
55+
56+
subdir('adaptors')
57+
subdir('adaptors/lambda')
58+
subdir('functors')
8459

8560
install_headers('sigc++.h', subdir: sigcxx_pcname / 'sigc++')
8661
install_headers(sigc_h_files, subdir: sigcxx_pcname / 'sigc++')
@@ -107,58 +82,26 @@ endif
10782

10883
if maintainer_mode
10984

110-
# Maintainer mode. Generate .h and .cc files from .m4 files in macros/ directories.
85+
# Maintainer mode. Generate .h and .cc files from .m4 files in macros/ directory.
86+
# .h and .cc files are also generated in subdirectories.
11187

11288
# docs/reference/meson.build needs this.
11389
built_files_root = project_build_root
11490

115-
m4_and_built_files = []
116-
foreach file : adaptors_lambda_cc_m4_files + adaptors_lambda_h_m4_files
117-
m4_and_built_files += [['adaptors' / 'lambda' / 'macros' / file + '.m4',
118-
'adaptors' / 'lambda' / file]]
119-
endforeach
12091
foreach file : sigc_h_m4_files
121-
m4_and_built_files += [['macros' / file + '.m4', file]]
122-
endforeach
123-
foreach file : adaptors_h_m4_files
124-
m4_and_built_files += [['adaptors' / 'macros' / file + '.m4', 'adaptors' / file]]
125-
endforeach
126-
foreach file : functors_h_m4_files
127-
m4_and_built_files += [['functors' / 'macros' / file + '.m4', 'functors' / file]]
128-
endforeach
129-
130-
# Force meson+ninja to generate source files before anything is compiled.
131-
# Compilation must depend on these targets.
132-
built_cc_file_targets = []
133-
built_h_file_targets = []
134-
135-
foreach m4_and_built_file : m4_and_built_files
136-
input_file = m4_and_built_file[0]
137-
output_file = m4_and_built_file[1]
138-
if output_file.endswith('.cc')
139-
stamp_file = output_file.underscorify() + '.cc'
140-
else
141-
stamp_file = output_file.underscorify() + '.stamp'
142-
endif
143-
built_file_target = custom_target(output_file.underscorify(),
144-
input: input_file,
145-
output: stamp_file,
92+
built_h_file_targets += custom_target(file,
93+
input: 'macros' / file + '.m4',
94+
output: file,
14695
command: [
14796
python3, handle_built_files, 'build_from_m4',
148-
meson.current_source_dir() / 'macros',
97+
m4_include_dir,
14998
'@INPUT@',
150-
meson.current_build_dir() / output_file,
15199
'@OUTPUT@',
152100
],
153-
depend_files: 'macros' / 'template.macros.m4',
101+
depend_files: m4_template,
154102
build_by_default: maintainer_mode,
155103
install: false,
156104
)
157-
if output_file.endswith('.cc')
158-
built_cc_file_targets += built_file_target
159-
else
160-
built_h_file_targets += built_file_target
161-
endif
162105
endforeach
163106

164107
extra_include_dirs = ['..']
@@ -181,8 +124,7 @@ else # not maintainer_mode
181124
# Not maintainer mode. Compile built source code files in
182125
# project_source_root/untracked/sigc++.
183126

184-
# docs/reference/meson.build needs these.
185-
built_h_file_targets = []
127+
# docs/reference/meson.build needs this.
186128
built_files_root = project_source_root / 'untracked'
187129

188130
# Two cases:

tools/handle-built-files.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616

1717
# Invoked from custom_target() in meson.build.
1818
def build_from_m4():
19-
# argv[2] argv[3] argv[4] argv[5]
20-
# <include_dir> <input_file> <output_file> <stamp_file>
19+
# argv[2] argv[3] argv[4]
20+
# <include_dir> <input_file> <output_file>
2121

2222
include_dir = sys.argv[2]
2323
input_file = sys.argv[3]
2424
output_file = sys.argv[4]
25-
stamp_file = sys.argv[5]
2625

2726
# Create the destination directory, if it does not exist.
2827
output_dir = os.path.dirname(output_file)
@@ -33,18 +32,8 @@ def build_from_m4():
3332
'-I', include_dir,
3433
input_file,
3534
]
36-
output_file_obj = open(output_file, mode='w')
37-
result = subprocess.run(cmd, stdout=output_file_obj)
38-
output_file_obj.close()
39-
40-
if result.returncode:
41-
return result.returncode
42-
43-
if stamp_file.endswith('.cc'):
44-
shutil.copy(output_file, stamp_file)
45-
else:
46-
Path(stamp_file).touch(exist_ok=True)
47-
return 0
35+
with open(output_file, mode='w') as output_file_obj:
36+
return subprocess.run(cmd, stdout=output_file_obj).returncode
4837

4938
# Invoked from meson.add_install_script().
5039
def install_built_h_files():

0 commit comments

Comments
 (0)