Search code examples
cmakeconan

How to tell conan 2.0 where to find the CMakeLists.txt if it not in the source folder? Conan Recipe?


how to tell conan that the CMakeLists.txt file is in another folder inside the source folder and not in the source folder? Currently it is looking for the CMakeLists.txt file in the source folder and says that it cannot find it. The file is in another folder.

src/cmakelistsfolder/CMakeLists.txt

Thank you in advance!


Solution

  • Conan client will run cmake trough the CMake helper. To customize where the configure command should be executed, which means, where CMakeLists.txt is installed, you should use the build_script_folder parameter when running cmake.configure

    For instance:

    def build(self):
        cmake = CMake(self)
        cmake.configure(build_script_folder=os.path.join(self.source_folder, "src", "cmakelistsfolder"))
        cmake.build()
    

    There are real cases in ConanCenterIndex, for instance, the octomap recipe: https://github.com/conan-io/conan-center-index/blob/master/recipes/octomap/all/conanfile.py#L82