diff --git a/conan_provider.cmake b/conan_provider.cmake index 1d3ca4c4..e0ce429a 100644 --- a/conan_provider.cmake +++ b/conan_provider.cmake @@ -275,7 +275,8 @@ macro(conan_provide_dependency package_name) if(${index} EQUAL -1) list(PREPEND CMAKE_PREFIX_PATH "${CONAN_GENERATORS_FOLDER}") endif() - find_package(${ARGN} BYPASS_PROVIDER CMAKE_FIND_ROOT_PATH_BOTH) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) + find_package(${ARGN} BYPASS_PROVIDER) endmacro() diff --git a/tests/resources/cmake_module/CMakeLists.txt b/tests/resources/cmake_module/CMakeLists.txt new file mode 100644 index 00000000..e94e56b0 --- /dev/null +++ b/tests/resources/cmake_module/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.24) +project(MyApp CXX) + +set(CMAKE_CXX_STANDARD 17) +find_package(Threads REQUIRED) diff --git a/tests/test_smoke.py b/tests/test_smoke.py index 3afff32c..2f1b77cb 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -134,6 +134,20 @@ def test_reconfigure_on_conanfile_changes(self, capfd, chdir_build): assert all(expected in out for expected in expected_conan_install_outputs) +class TestCmakeModule: + @pytest.fixture(scope="class", autouse=True) + def cmake_module_setup(self): + src_dir = Path(__file__).parent.parent + shutil.copytree(src_dir / 'tests' / 'resources' / 'cmake_module', ".", dirs_exist_ok=True) + yield + + def test_cmake_module(self, capfd, chdir_build): + "Ensure that the Find.cmake modules from the CMake install work" + run("cmake .. -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -DCMAKE_BUILD_TYPE=Release") + out, _ = capfd.readouterr() + assert "Found Threads: TRUE" in out + + class TestSubdir: @pytest.fixture(scope="class", autouse=True) def subdir_setup(self): @@ -177,7 +191,8 @@ def test_no_os_version(self, capfd, chdir_build): class TestAndroid: @pytest.fixture(scope="class", autouse=True) def android_setup(self): - shutil.rmtree("build") + if os.path.exists("build"): + shutil.rmtree("build") yield def test_android_armv8(self, capfd, chdir_build):