3

So I have seen the other posts regarding moving external dll files to the current project's .exe output location for use at runtime but I seem to be running into an odd issue that I can't find information on.

I am using the following custom command to copy my libfreenect2 dlls into my output directory for my project:

add_custom_command(TARGET kinect_feeds POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
        "libfreenect2_output_path/bin/*.dll"
        $<TARGET_FILE_DIR:kinect_feeds>)

CMake sets up my project just fine, but when I go to run the command in Visual Studio it errors out when trying to copy the files. I think the issue is with the wildcard character. I used the error output in the Visual Studio to copy the complete command into by git bash window and it works as expected. Also Visual Studio has no problem moving multiple files if they are explicitly defined like so:

add_custom_command(TARGET kinect_feeds POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
        "libfreenect2_output_path/bin/freenect2.dll"
        "libfreenect2_output_path/bin/glfw3.dll"
        $<TARGET_FILE_DIR:kinect_feeds>)

My question is, do wildcard characters not work in CMake commands when being executed by Visual Studio or is there something that I am missing? For now I will just type out all of the DLL files explicitly, but I was hoping to avoid this.

I am using the latest version of CMake and Visual Studio 2015 Community Edition.

Wired365
  • 199
  • 1
  • 13
  • Wildcard quoting in this case is "shell" dependent. It's been a long time since I've used VS, but maybe single-quotes around your wildcard would have worked, instead of double quotes. – nega Apr 13 '17 at 22:34
  • I gave single quotes a try and it still didn't like the command. I'll look into what VS might accept as a wildcard. I'm thinking I might have to get clever with escaping characters. – Wired365 May 01 '17 at 14:31

1 Answers1

2

I'm running into the same issue with CMake 3.6.1 and Visual Studio 2012. I don't think Visual Studio has any impact though, because I get the errors from the command line as well

From a CMD prompt:

> cmake -E copy .\data\*.bin \temp
Error copying file ".\data\*.bin" to "\temp".

This question references a CMake bug report regarding wildcards, that was supposed to be fixed in CMake 3.5, but doesn't appear to work on Windows with CMake 3.6.1.

I think your solution to list each file individually is the current solution.

fuzzyd123
  • 21
  • 2
  • Yeah, confusing. The enhancement added to v3.5 didn't actually add wildcard support, it merely extended the copy command to accept multiple source files followed by a single destination directory HOWEVER depending upon the environment, the shell interpreter may (or may not) expand a source file specification containing a wildcard/glob pattern before cmake processes it. I'm seeing `cmake -E copy /foo/bar/* /baz` **appear** to work on a linux host, but not Windows (obviously insert real paths to taste). – Richard Lang Oct 23 '18 at 04:46