This adds a new method, partial_dependency to all dependencies. These sub dependencies are copies of the original dependency, but with one or more of the attributes replaced with an empty list. This allows creating a sub dependency that has only cflags or drops link_arguments, for example.pull/3372/head
parent
1952ef5ae1
commit
92487ea33d
15 changed files with 356 additions and 2 deletions
@ -0,0 +1,25 @@ |
||||
## Added new partial_dependency method to dependencies and libraries |
||||
|
||||
It is now possible to use only part of a dependency in a target. This allows, |
||||
for example, to only use headers with convenience libraries to avoid linking |
||||
to the same library multiple times. |
||||
|
||||
```meson |
||||
|
||||
dep = dependency('xcb') |
||||
|
||||
helper = static_library( |
||||
'helper', |
||||
['helper1.c', 'helper2.c'], |
||||
dependencies : dep.partial_dependency(includes : true), |
||||
] |
||||
|
||||
final = shared_library( |
||||
'final', |
||||
['final.c'], |
||||
dependencyes : dep, |
||||
) |
||||
``` |
||||
|
||||
A partial dependency will have the same name version as the full dependency it |
||||
is derived from, as well as any values requested. |
@ -0,0 +1,16 @@ |
||||
/* Copyright © 2018 Intel Corporation
|
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
#error "Included C sources that shouldn't be." |
@ -0,0 +1,16 @@ |
||||
/* Copyright © 2018 Intel Corporation
|
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
int foo(void); |
@ -0,0 +1,25 @@ |
||||
/* Copyright © 2018 Intel Corporation
|
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
#include "foo.h" |
||||
|
||||
int main() { |
||||
int a = foo(); |
||||
if (a == 1) { |
||||
return 0; |
||||
} else { |
||||
return 1; |
||||
} |
||||
} |
@ -0,0 +1,28 @@ |
||||
# Copyright © 2018 Intel Corporation |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
dec_dep = declare_dependency( |
||||
sources : files('headers/foo.c'), |
||||
include_directories : include_directories('headers'), |
||||
) |
||||
|
||||
sub_dep = dec_dep.partial_dependency(includes : true) |
||||
|
||||
dec_exe = executable( |
||||
'declare_dep', |
||||
files('main.c', 'other.c'), |
||||
dependencies : sub_dep, |
||||
) |
||||
|
||||
test('Declare Dependency', dec_exe) |
@ -0,0 +1,20 @@ |
||||
/* Copyright © 2018 Intel Corporation
|
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
#include "foo.h" |
||||
|
||||
int foo(void) { |
||||
return 1; |
||||
} |
@ -0,0 +1,17 @@ |
||||
# Copyright © 2018 Intel Corporation |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
project('partial dependency', ['c', 'cpp']) |
||||
|
||||
subdir('declare_dependency') |
@ -0,0 +1,20 @@ |
||||
/* Copyright © 2018 Intel Corporation
|
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
#include "foo.hpp" |
||||
|
||||
vec Foo::vector() { |
||||
return myvec; |
||||
} |
@ -0,0 +1,27 @@ |
||||
/* Copyright © 2018 Intel Corporation
|
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
#include <boost/fusion/container/vector.hpp> |
||||
|
||||
typedef boost::fusion::vector<int> vec; |
||||
|
||||
|
||||
class Foo { |
||||
public: |
||||
Foo() {}; |
||||
vec vector(); |
||||
private: |
||||
const vec myvec = vec(4); |
||||
}; |
@ -0,0 +1,28 @@ |
||||
/* Copyright © 2018 Intel Corporation
|
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
#include <iostream> |
||||
#include <boost/fusion/include/at_c.hpp> |
||||
#include "foo.hpp" |
||||
|
||||
|
||||
int main() { |
||||
auto foo = Foo(); |
||||
vec v = foo.vector(); |
||||
std::cout << boost::fusion::at_c<0>(v) << std::endl; |
||||
|
||||
return 0; |
||||
} |
||||
|
@ -0,0 +1,31 @@ |
||||
# Copyright © 2018 Intel Corporation |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
dep_boost = dependency('boost') |
||||
dep_boost_headers = dep_boost.partial_dependency(compile_args : true) |
||||
|
||||
libfoo = static_library( |
||||
'foo', |
||||
'foo.cpp', |
||||
dependencies : dep_boost_headers, |
||||
) |
||||
|
||||
exe_external_dep = executable( |
||||
'external_dep', |
||||
'main.cpp', |
||||
dependencies : dep_boost, |
||||
link_with : libfoo |
||||
) |
||||
|
||||
test('External Dependency', exe_external_dep) |
Loading…
Reference in new issue