我想为CMakeLists文件中的项目添加生成后事件。 此后生成事件必须将Qt库放在我的可执行文件附近。 我用add_custom_command
做到这一点:通过CMake生成共享库名称
set(libraryFileName ${QtDir}/bin/${packageName}.dll)
# Copy qt library after build
add_custom_command(
TARGET ${target} POST_BUILD #Path to cmake executable file
COMMAND "${CMAKE_COMMAND}" -E #CMake in command mode
copy #Copy command
"${libraryFileName}" #Path to the file
"$<TARGET_FILE_DIR:${target}>" #Where to copy
COMMENT "Copying to output directory")
的主要问题是如何正确生成libraryFileName每一个系统?我的意思是,我的灵魂工作适用于Windows,但对其他系统类型而言,我猜它会失败。有什么办法可以获得共享库的扩展而不是硬编码吗?
难道你不能只使用'$'作为'copy'的源位置吗? –
Florian
只记得还有一个[策略CMP0026](https://cmake.org/cmake/help/latest/policy/CMP0026.html),它将“禁止使用LOCATION属性构建目标”,并且会给出CMake新版本中的警告/错误。 – Florian