我正在尝试使用CMake构建基于QT的应用程序,一切顺利。我遵循了this教程,我可以构建我的应用程序。现在我想在使用npm run build
构建之前运行add_custom_command
它似乎没有按预期进行。
构建过程失败,
RCC: Error in 'tray-icon/systray.qrc': Cannot find file 'html/js/app.full.js'
AUTORCC: error: process for.build/Debug/x64/tray-icon/CMakeFiles/tray-icon.dir/qrc_systray.cpp failed:
RCC: Error in 'tray-icon/systray.qrc': Cannot find file 'html/js/app.full.js'
您能否告诉我如何在npm
的构建验证步骤之前执行tray-icon/systray.qrc
命令?
这是我的cmake文件
cmake_minimum_required(VERSION 2.8.11)
project(tray-icon)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5Widgets 5.5)
find_package(Qt5Qml 5.5)
find_package(Qt5WebEngine 5.5)
find_package(Qt5WebEngineCore 5.5)
find_package(Qt5WebEngineWidgets 5.5)
# generate rules for building source files from the resources
set(SOURCES tray-icon.cpp window.cpp systray.qrc)
set(CMAKE_VERBOSE_MAKEFILE 1)
#adds target
add_executable(tray-icon ${SOURCES})
# custom build command for javascript part of the application
add_custom_command (
TARGET "tray-icon"
PRE_BUILD COMMAND npm run build
)
# Find the QtWidgets library
target_link_libraries(tray-icon
Qt5::Widgets
Qt5::WebEngine
Qt5::WebEngineWidgets)
install(TARGETS tray-icon DESTINATION .)
# custom build command for javascript part of the application
add_custom_target(
tray-icon_automoc
)
add_custom_target (
npm-target
COMMAND cd ${PROJECT_SOURCE_DIR} && cd html && npm install && npm run build
)
答案 0 :(得分:1)
您可以尝试add_custom_target和add_dependencies。
add_custom_target (
npm-target
COMMAND npm run build
)
add_dependencies(tray-icon npm-target)
要克服评论中提到的问题,您应该能够使用AUTOGEN_TARGET_DEPENDS目标属性添加依赖项。可以将其设置为_automoc目标的依赖项列表。