@@ -141,7 +141,7 @@ def build(self):
141141 """ )
142142 consumer = textwrap .dedent ("""
143143 cmake_minimum_required(VERSION 3.15)
144- project(MyHello)
144+ project(MyHello NONE )
145145 find_program(HELLOPROG hello)
146146 if(HELLOPROG)
147147 message(STATUS "Found hello prog: ${HELLOPROG}")
@@ -172,8 +172,7 @@ def package(self):
172172 """ )
173173 c .save ({"conanfile.py" : conanfile ,
174174 "hello.h" : "" , "hello.lib" : "" , "libhello.a" : "" ,
175- "libhello.so" : "" , "libhello.dll" : ""
176- })
175+ "libhello.so" : "" , "libhello.dll" : "" })
177176 c .run ("create ." )
178177 conanfile = textwrap .dedent (f"""
179178 from conan import ConanFile
@@ -188,7 +187,7 @@ def build(self):
188187 """ )
189188 consumer = textwrap .dedent ("""
190189 cmake_minimum_required(VERSION 3.15)
191- project(MyHello)
190+ project(MyHello NONE )
192191 find_file(HELLOINC hello.h)
193192 find_library(HELLOLIB hello)
194193 if(HELLOINC)
@@ -202,3 +201,88 @@ def build(self):
202201 c .run (f"build . -c tools.cmake.cmakedeps:new={ new_value } " )
203202 assert "Found hello header" in c .out
204203 assert "Found hello lib" in c .out
204+
205+ @pytest .mark .parametrize ("require_type" , ["requires" , "tool_requires" ])
206+ def test_include_modules (self , require_type ):
207+ """Test that cmake module files in builddirs of requires and tool_requires
208+ are accessible with include() in consumer CMakeLists
209+ """
210+ c = TestClient ()
211+ conanfile = textwrap .dedent ("""
212+ from conan import ConanFile
213+ from conan.tools.files import copy
214+ class TestConan(ConanFile):
215+ exports_sources = "*"
216+ def package(self):
217+ copy(self, "*", self.source_folder, self.package_folder)
218+ def package_info(self):
219+ self.cpp_info.builddirs.append("cmake")
220+ """ )
221+ c .save ({"conanfile.py" : conanfile ,
222+ "cmake/myowncmake.cmake" : 'MESSAGE("MYOWNCMAKE FROM hello!")' })
223+ c .run ("create . --name=hello --version=0.1" )
224+
225+ conanfile = textwrap .dedent (f"""
226+ from conan import ConanFile
227+ from conan.tools.cmake import CMake
228+ class PkgConan(ConanFile):
229+ settings = "os", "compiler", "arch", "build_type"
230+ { require_type } = "hello/0.1"
231+ generators = "CMakeToolchain", "CMakeConfigDeps"
232+
233+ def build(self):
234+ cmake = CMake(self)
235+ cmake.configure()
236+ cmake.build()
237+ """ )
238+ consumer = textwrap .dedent ("""
239+ cmake_minimum_required(VERSION 3.15)
240+ project(MyHello NONE)
241+ include(myowncmake)
242+ """ )
243+ c .save ({"conanfile.py" : conanfile ,
244+ "CMakeLists.txt" : consumer }, clean_first = True )
245+ c .run (f"build . -c tools.cmake.cmakedeps:new={ new_value } " )
246+ assert "MYOWNCMAKE FROM hello!" in c .out
247+
248+ def test_include_modules_both_build_host (self ):
249+ c = TestClient ()
250+ conanfile = textwrap .dedent ("""
251+ from conan import ConanFile
252+ from conan.tools.files import copy
253+ class TestConan(ConanFile):
254+ exports_sources = "*"
255+ def package(self):
256+ copy(self, "*", self.source_folder, self.package_folder)
257+ def package_info(self):
258+ self.cpp_info.builddirs.append("cmake")
259+ """ )
260+ c .save ({"conanfile.py" : conanfile ,
261+ "cmake/myowncmake.cmake" : 'MESSAGE("MYOWNCMAKE FROM hello!")' })
262+ c .run ("create . --name=hello --version=0.1" )
263+
264+ conanfile = textwrap .dedent (f"""
265+ from conan import ConanFile
266+ from conan.tools.cmake import CMake
267+ class PkgConan(ConanFile):
268+ settings = "os", "compiler", "arch", "build_type"
269+ requires = "hello/0.1"
270+ tool_requires = "hello/0.1"
271+ generators = "CMakeToolchain", "CMakeConfigDeps"
272+
273+ def build(self):
274+ cmake = CMake(self)
275+ cmake.configure()
276+ cmake.build()
277+ """ )
278+ consumer = textwrap .dedent ("""
279+ cmake_minimum_required(VERSION 3.15)
280+ project(MyHello NONE)
281+ include(myowncmake)
282+ """ )
283+ c .save ({"conanfile.py" : conanfile ,
284+ "CMakeLists.txt" : consumer }, clean_first = True )
285+ c .run (f"build . -c tools.cmake.cmakedeps:new={ new_value } " )
286+ assert "conanfile.py: There is already a 'hello/0.1' package " \
287+ "contributing to CMAKE_MODULE_PATH" in c .out
288+ assert "MYOWNCMAKE FROM hello!" in c .out
0 commit comments