@@ -41,14 +41,61 @@ The full instantiation, that allows custom configuration can be done in the ``ge
41
41
42
42
def generate (self ):
43
43
cmake = CMakeDeps(self )
44
- cmake.configurations.append(" ReleaseShared" )
45
- if self .options[" hello" ].shared:
46
- cmake.configuration = " ReleaseShared"
47
44
cmake.generate()
48
45
49
- As it can be seen, it allows to define custom user CMake configurations besides the standard Release, Debug, etc ones.
50
- If the **settings.yml ** file is customized to add new configurations to the ``settings.build_type ``, then, adding it
51
- explicitly to ``.configurations `` is not necessary.
46
+ There are some attributes you can adjust in the created ``CMakeDeps `` object to change the default behavior:
47
+
48
+ configurations
49
+ ++++++++++++++
50
+
51
+ As it can be seen in the following example, it allows to define custom user CMake configurations besides the standard
52
+ Release, Debug, etc ones. If the **settings.yml ** file is customized to add new configurations to the
53
+ ``settings.build_type ``, then, adding it explicitly to ``.configurations `` is not necessary.
54
+
55
+ .. code-block :: python
56
+
57
+ ...
58
+ cmake = CMakeDeps(self )
59
+ cmake.configurations.append(" ReleaseShared" )
60
+ if self .options[" hello" ].shared:
61
+ cmake.configuration = " ReleaseShared"
62
+ cmake.generate()
63
+
64
+
65
+ build_context_suffix / build_context_build_modules
66
+ ++++++++++++++++++++++++++++++++++++++++++++++++++
67
+
68
+ When you have the same package as a **build-require ** and as a **regular require ** it will cause a conflict in the generator
69
+ because the file names of the config files will collide as well as the targets names, variables names etc.
70
+
71
+ This is a typical situation with a requirement like **protobuff **: You want it as a **build-require ** to generate **.cpp **
72
+ files trough the **protoc ** tool, but you also want to link the final application or library with **libprotoc ** library,
73
+ so you also have a **regular require **. Solving this conflict is specially important when we are cross-building because the
74
+ **protoc ** tool (that will run in the building machine) belongs to a different binary package than the **libprotoc ** library,
75
+ that will "run" in the host machine.
76
+
77
+ Also there is another issue with the **build_modules **. As you may know, the recipes of the requirements can declare a
78
+ `cppinfo.build_modules ` entry containing one or more **.cmake ** files. When the requirement is found by the cmake ``find_package() ``
79
+ function, Conan will include automatically these files. By default, Conan will include only the build modules from the
80
+ ``host `` context (regular requires) to avoid the collission, but you can change the default behavior.
81
+
82
+ So there are two attributes of the ``CMakeDeps `` which helps with these issues:
83
+
84
+ - **build_context_suffix **: You can specify a suffix for a requirement, so the files/targets/variables of the requirement
85
+ in the build context (build require) will be renamed.
86
+ - **build_context_build_modules **: By default Conan will include only the ``host `` (regular requires) build modules, but
87
+ you can specify require names so the build modules from the ``build `` context are included instead.
88
+
89
+
90
+ .. code-block :: python
91
+
92
+ ...
93
+ cmake = CMakeDeps(self )
94
+ # disambiguate the files, targets, etc
95
+ cmake.build_context_suffix = {" protobuff" : " _BUILD" }
96
+ # Choose the build modules from "build" context, so our CMakeLists can call the correct "protoc" tool
97
+ cmake.build_context_build_modules = [" protobuff" ]
98
+
52
99
53
100
.. _conan-cmake-toolchain :
54
101
0 commit comments