CMake fix_bundle如何忽略嵌入的dll
Posted
技术标签:
【中文标题】CMake fix_bundle如何忽略嵌入的dll【英文标题】:CMake fix_bundle how to ignore embedded dll 【发布时间】:2020-01-10 17:19:54 【问题描述】:我的系统有一些链接在其他嵌入式可执行文件中的 dll,例如来自 MSYS 的命令。
目录结构:
MySystem/
|_ mysystem.exe
|_ CMakeLists.txt
|_ embedded system/
|_ msys_command1.exe
|_ msys_command2.exe
|_ msys-1.0.dll
当它从 CMake 运行 fixup_bundle 时,会显示以下警告:
EXEC : warning : cannot resolve item 'msys-1.0.dll'
possible problems:
need more directories?
need to use InstallRequiredSystemLibraries?
run in install tree instead of build tree?
EXEC : -- warning : gp_resolved_file_type non-absolute file 'msys-1.0.dll' returning type 'other' -- possibly incorrect
--
EXEC : warning : cannot resolve item 'msys-1.0.dll'
possible problems:
need more directories?
need to use InstallRequiredSystemLibraries?
run in install tree instead of build tree?
MSYS 命令位于软件嵌入目录中。 如果我将嵌入目录放在 fixup_bundle 路径上,则 dll 将被复制到我的可执行目录中,但我不希望这种行为。
有没有办法忽略这些 dll?
我已尝试使用 fixup_bundle 宏 IGNORE_ITEM,但没有成功。
除此之外,问题还会传播到 CPack:
CPack: Create package using NSIS
CPack: Install projects
CPack: - Install project: MySystem
Error copying file "msys-1.0.dll" to "D:/mysystem/solution/build/_CPack_Packages/win64/NSIS/MySystem/msys-1.0.dll".
Error copying file "msys-intl-8.dll" to "D:/mysystem/solution/build/_CPack_Packages/win64/NSIS/MySystem/msys-intl-8.dll".
Error copying file "Qt5Core.dll" to "D:/mysystem/solution/build/_CPack_Packages/win64/NSIS/MySystem/Qt5Core.dll".
Error copying file "Qt5Gui.dll" to "D:/mysystem/solution/build/_CPack_Packages/win64/NSIS/MySystem/Qt5Gui.dll".
Error copying file "Qt5Network.dll" to "D:/mysystem/solution/build/_CPack_Packages/win64/NSIS/MySystem/Qt5Network.dll".
Error copying file "Qt5Widgets.dll" to "D:/mysystem/solution/build/_CPack_Packages/win64/NSIS/MySystem/Qt5Widgets.dll".
Error copying file "libprotobuf.dll" to "D:/mysystem/solution/build/_CPack_Packages/win64/NSIS/MySystem/libprotobuf.dll".
Error copying file "lua.dll" to "D:/mysystem/solution/build/_CPack_Packages/win64/NSIS/MySystem/lua.dll".
Error copying file "qwt.dll" to "D:/mysystem/solution/build/_CPack_Packages/win64/NSIS/MySystem/qwt.dll".
CPack: Create package
【问题讨论】:
这里有同样的问题,目前还没有修复。可能需要写一个自定义版本的fixup_bundle 【参考方案1】:不确定这是否是您需要的,但我创建了一个自定义的 fixup_bundle
函数,该函数也使用 IGNORE_ITEM
键跳过库。
我如下调用 fixup_bundle2:
install(CODE "
set(CMAKE_MODULE_PATH $CMAKE_MODULE_PATH $CMAKE_SOURCE_DIR/dist/cmake)
include(InstallRequiredSystemLibraries)
include(BundleUtilities)
include(FixUp)
fixup_bundle2(\"\$CMAKE_INSTALL_PREFIX/$APPS\" \"$LIBS\" \"$DIRS\" IGNORE_ITEM \"exe_with_z64;exe_with_zip;libopenvr_api_so\")"
)
注意set(CMAKE_MODULE_PATH...
行,它包含我自己从我的 FixUp.cmake 文件中提供的 fixup_bundle2。另请注意,我需要指定libopenvr_api_so
,而实际上它是libopenvr_api.so
。
fixup_bundle2
是fixup_bundle
的副本,在foreach(key $keys)
循环中添加了以下内容:
# also ignore libs in INGORE_ITEM
if(key IN_LIST CFG_IGNORE_ITEM)
message(STATUS "skipping $key")
continue()
endif()
你还需要设置
cmake_policy(SET CMP0057 NEW)
显然在 FixUp.cmake 文件中。
【讨论】:
以上是关于CMake fix_bundle如何忽略嵌入的dll的主要内容,如果未能解决你的问题,请参考以下文章
带有 XCode 目标的 CMake,生成忽略发布配置的调试符号设置