-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds new 'build' and 'source' bool args for include_directories() func.
Motivation: Frequent, unnecessary (and maybe even problematic) doubling up of both build and src-relative include search paths as discussed here: #11919 'build' specifies whether the include dirs should be treated as build- relative and 'src', whether source-relative. They both default to true to keep previous behaviour when unspecified. Added new 'test cases/common/267 include_directories use types' test (should these live under 'common'?). Added documentation and new feature snippet. Respect the new bools in vs2010backend (and adding more type annotations to help readability).
- Loading branch information
Showing
15 changed files
with
272 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## Added a new `build` and 'source' args to `include_directories(...)` | ||
|
||
The previous behaviour of `include_directories(...)` is that it ends up adding | ||
both source-relative and build-relative include search paths to the compile | ||
options or, if using absolute paths, then simply duplicating the same absolute | ||
include search path. Even if the user wants _either_ a build-relative _or_ | ||
src-relative path only, they're forced to use both, which could cause problems | ||
as well as just adding unnecessary compile options. | ||
|
||
New `build` and `source` bool arguments are added to `include_directories(...)`. | ||
If unspecified, both `build` and `source` default to True. | ||
It is invalid for both to be False. | ||
It is invalid to use absolute paths with _only_ 'build' set to True, since a | ||
user asking for build-relative absolute include directories is meaningless or | ||
at least suggests a misunderstanding. | ||
|
||
Absolute include search paths are allowed if `source` is `true`. If `build` | ||
is also `true`, any absolute paths will only be added once. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
test cases/common/267 include_directories relative/meson.build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
project('include dirs type tests', 'cpp', meson_version: '>=1.3.0' ) | ||
|
||
fs = import('fs') | ||
|
||
# Copy src header, with a modification, to build dir so we can test finding it though | ||
# 'src-relative', 'build-relative', and 'src-and-build-relative' use types. | ||
configure_file( input: 'whereareyoufindingme.h', | ||
output: 'whereareyoufindingme.h', | ||
configuration: {'SRC_DIR': 'build dir'} | ||
) | ||
|
||
# Test that src-relative uses the unadulerated src header | ||
exe_src = executable( | ||
'prog_src', | ||
'src/main.cpp', | ||
implicit_include_directories: false, | ||
include_directories: include_directories('.', build: false, source: true)) | ||
test('src-relative', exe_src, args: ['Hello from @SRC_DIR@']) | ||
|
||
fs = import('fs') | ||
|
||
# Test that build-relative uses the tweaked header, copied to the build dir. | ||
exe_build = executable( | ||
'prog_build', | ||
'src/main.cpp', | ||
implicit_include_directories: false, | ||
include_directories: include_directories('.', build: true, source: false)) | ||
test('build-relative', exe_build, args: ['Hello from build dir']) | ||
|
||
# Check 'src-and-build-relative' by including one header that's only found under the src and one that only found under the build dir. | ||
subdir('moreheaders') | ||
exe_both = executable( | ||
'prog_both', | ||
'src/main2.cpp', | ||
implicit_include_directories: false, | ||
include_directories: include_directories('moreheaders', build: true, source: true), | ||
dependencies: build_only_h_dep, | ||
) | ||
test('both', exe_both, args: ['Src-only','Build-only']) | ||
|
||
# Finally check the same but through ensuring that unspecified 'build' and 'source' defaults to both true | ||
exe_both_default = executable( | ||
'prog_both_default', | ||
'src/main2.cpp', | ||
implicit_include_directories: false, | ||
include_directories: include_directories('moreheaders'), | ||
dependencies: build_only_h_dep, | ||
) | ||
test('both default', exe_both_default, args: ['Src-only','Build-only']) |
1 change: 1 addition & 0 deletions
1
test cases/common/267 include_directories relative/moreheaders/build_only._h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#define BUILD_ONLY_MSG "Build-only" |
7 changes: 7 additions & 0 deletions
7
test cases/common/267 include_directories relative/moreheaders/meson.build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# It's a shame configure_file(..., copy: true) has been deprecated. | ||
# It was simpler for this use-case and would do the copying at setup/configure-time rather than at build-time, | ||
# which better fits our usage. | ||
|
||
fs = import('fs') | ||
build_only_h = fs.copyfile('build_only._h','build_only.h') | ||
build_only_h_dep = declare_dependency(sources: build_only_h) |
1 change: 1 addition & 0 deletions
1
test cases/common/267 include_directories relative/moreheaders/src_only.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#define SRC_ONLY_MSG "Src-only" |
Oops, something went wrong.