Home > database >  How to copy all the shared conan libraries into the build folder?
How to copy all the shared conan libraries into the build folder?

Time:06-24

I have custom conan packages that output c shared libraries. (dylib or dll) Whenever I build my CMake project I would like all these shared libraries to be copied to the directory where the executable is. How can I achieve this?

CodePudding user response:

You need to use the imports method of a conanfile.txt or conanfile.py that you use in your CMake project.

Here the documentation: https://docs.conan.io/en/latest/reference/conanfile/methods.html#imports

With aconanfile.py it look like this

def imports(self):
   self.copy("*.dll", "", "bin")
   self.copy("*.dylib", "", "lib")

and with a conanfile.txt (https://docs.conan.io/en/latest/reference/conanfile_txt.html?highlight=imports#imports)

[imports]
bin, *.dll -> ./bin # Copies all dll files from packages bin folder to my local "bin" folder
lib, *.dylib* -> ./bin # Copies all dylib files from packages lib folder to my local "bin" folder

With that you should be able to have your binaries inside your build folder.

After that you only need to use the file function in CMake to copy your lib where you want to. Documenation for file function You will certainly use something like this

file(COPY_FILE ${CMAKE_BINARY_DIR}/bin/lib.dll <path_to_exe>)

I hope this help!

  • Related