I am currently in the process of porting a Linux codebase on Windows. I finally got everything to compile and run, except for one thing: I do not know how to handle .dll files. So far I have been copying them manually because I was working on a single cmake configuration, but this is far from ideal.
So my question is: how can I make my executable work with CMake ? As far as I understand, DLL files HAVE to be in the same directory, so I probably need to copy them, but I do not understand the proper way to do it. I have been googling and results were not very satisfying (usually they had code snippets for specific libs and it seemed relatively 'quick and dirty').
I have multiple dependencies I need to get dlls from, most notably OpenCV, Qt, openssl, etc.
Is there a way to do it in a "generic" way, as in getting a property from an imported target and copying it ? I don't really want to explicitly list every single .dll...
In my CMakeLists I handle my dependencies using Find_Package
and using target_link_libraries
with the imported target.
I'm just wondering what is the best way to do this, or if I am doing something fundamentally wrong.
Edit: Consider the following CMakeLists.txt:
cmake_minimum_required (VERSION 3.8)
project ("OpenCV_HelloWorld")
find_package(OpenCV 4.4.0 REQUIRED COMPONENTS core imgproc video)
# Add source to this project's executable.
add_executable (OpenCV_HelloWorld OpenCV_HelloWorld.cpp OpenCV_HelloWorld.h) # pretty much empty files, the main just declares a cv::Mat
target_link_libraries(OpenCV_HelloWorld ${OpenCV_LIBS} )
This compiles properly, however, when trying to run it I get a message saying I need opencv_core440.dll. What would be the best way to correct this ?