Usage of TARGET_RUNTIME_DLLS generator expression

Hi,

I’d like to copy all the dlls that are required for running a target to the output directory.
In particular, I want to use the locally built optimization library ipopt, which depends on Intel’s MKL library.

My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.0.0)
project(IpoptTest VERSION 0.1.0)

set(IPOPT_DIR "C:/Libs/Ipopt")
find_library(IPOPT "ipopt.dll" "${IPOPT_DIR}/lib")

add_executable(IpoptTest main.cpp OptiProblem.cpp)
target_include_directories(IpoptTest PRIVATE "${IPOPT_DIR}/include")
target_link_libraries(IpoptTest PRIVATE "${IPOPT}")

add_custom_command(TARGET IpoptTest POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:IpoptTest> $<TARGET_FILE_DIR:IpoptTest>
  COMMAND_EXPAND_LISTS
  ) 

The command to copy the dlls is taken from (https://cmake.org/cmake/help/v3.21/manual/cmake-generator-expressions.7.html#genex:TARGET_RUNTIME_DLLS).

However, when I run it, I get the output

[build] EXEC : CMake error : cmake version 3.23.22060601-MSVC_2 [C:\Programmieren\Projekte\IpoptTest\build\IpoptTest.vcxproj]
[build]   Usage: C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe -E <command> [arguments...]
[build]   Available commands: 
[build]     capabilities              - Report capabilities built into cmake in JSON format
[build]     cat <files>...            - concat the files and print them to the standard output
....

Apparently CMake fails to execute the copy command.

Is there any way to have CMake automatically determine all the required dlls?
There is an ipopt.pc file in a pkgconfig folder, which seems to contain the paths of libraries ipopt depends upon (however, it contains the .lib not the .dll files). Would it make my life easier, if I used pkgconfig?

Thanks in advance and best regards,
oz

1 Like

I also have the same problem.
Oddly the dependency dlls still seem to get copied though, but the overall build fails.

FWIW these links helped me get TARGET_RUNTIME_DLLS working in my project. They cover all the important aspects of this CMake feature.

Also if you are using this feature I’d raise your CMake minimum required. Since it requires 3.21

cmake_minimum_required(VERSION 3.21)