我正在尝试在CMakeLists文件中为我的项目添加post build事件。
这个构建后的事件必须将Qt库放在我的可执行文件附近。
我使用add_custom_command
来执行此操作:
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,但我想其他系统类型都会失败。有没有办法获得共享库的扩展而不是硬编码?
答案 0 :(得分:0)
我找到了解决方案。但它可能只适用于Qt。
# Get package location
get_target_property(location ${qtVersion}::${shortPackageName} LOCATION)
# 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
"${location}" #Path to the file
"$<TARGET_FILE_DIR:${target}>" #Where to copy
COMMENT "Copying ${packageName}...")
答案 1 :(得分:0)
您可以添加平台检查器并根据该检查设置变量。
object CheckCommand "apt" {
import "plugin-check-command"
command = [ PluginDir + "/check_apt" ]
timeout = 5m
arguments += {
"--critical" = {
description = "If the full package information of any of the upgradable packages match this REGEXP, the plugin will return CRITICAL status. Can be specified multiple times."
value = "$apt_critical$"
}
"--dist-upgrade" = {
description = "Perform a dist-upgrade instead of normal upgrade. Like with -U OPTS can be provided to override the default options."
value = "$apt_dist_upgrade$"
}
"--exclude" = {
description = "Exclude packages matching REGEXP from the list of packages that would otherwise be included. Can be specified multiple times."
value = "$apt_exclude$"
}
"--extra-opts" = {
description = "Read options from an ini file."
value = "$apt_extra_opts$"
}
"--include" = {
description = "Include only packages matching REGEXP. Can be specified multiple times the values will be combined together."
value = "$apt_include$"
}
"--timeout" = {
description = "Seconds before plugin times out (default: 10)."
value = "$apt_timeout$"
}
"--upgrade" = {
description = "[Default] Perform an upgrade. If an optional OPTS argument is provided, apt-get will be run with these command line options instead of the default."
value = "$apt_upgrade$"
}
}
}