如何为文件中安装的文件创建依赖关系

发布于 2025-01-18 06:19:57 字数 1306 浏览 2 评论 0原文

我有一个自定义目标&我的 CMakeLists.txt 中的自定义命令为 c 库构建包装器的 .jar,这是该项目的主要焦点。我正在使用 install(FILES ...) (因为即使我用 install(TARGETS ...) 指定 ARCHIVE cmake 也会抱怨目标不是库或可执行文件)。自定义目标永远不会构建,因为除了 install(FILES ...) 之外,没有任何东西依赖于它。我如何告诉 cmake 有关依赖项的信息,以便构建目标?

这是 CMakeLists.txt 的相关部分。在此版本中,我已将 ALL 添加到自定义目标以强制构建,但我希望仅在构建 ALL_BUILD 或包目标时构建此目标。

add_custom_command(
    OUTPUT
        ${CMAKE_SOURCE_DIR}/interface/java_binding/target/libktx-${PROJECT_VERSION}-source.jar
        ${CMAKE_SOURCE_DIR}/interface/java_binding/target/libktx-${PROJECT_VERSION}.jar
    COMMAND
        ${MAVEN_EXECUTABLE} -Drevision=${PROJECT_VERSION} -Dmaven.test.skip=true package
    DEPENDS
        ktx-jni
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/interface/java_binding
)

add_custom_target( ktx-jar ALL
    DEPENDS
        ${CMAKE_SOURCE_DIR}/interface/java_binding/target/libktx-${PROJECT_VERSION}-source.jar
        ${CMAKE_SOURCE_DIR}/interface/java_binding/target/libktx-${PROJECT_VERSION}.jar
    WORKING_DIRECTORY
        ${CMAKE_SOURCE_DIR}/interface/java_binding
    COMMENT
        "Java wrapper target"
)

install(FILES
    ${CMAKE_SOURCE_DIR}/interface/java_binding/target/libktx-${PROJECT_VERSION}.jar
    TYPE LIB
    COMPONENT jni
)

I have a custom target & custom command in my CMakeLists.txt to build a .jar of the wrapper for the c library which is the main focus of the project. I am using install(FILES ...) (because even if I specify ARCHIVE with install(TARGETS ...) cmake complains that the target is not a library or executable). The custom target is never built because nothing depends on it except the install(FILES ...). How can I tell cmake about the dependency so the target gets built?

Here is the relevant part of the CMakeLists.txt. In this version I've add ALL to the custom target to force the build but I would prefer this target only be built when the ALL_BUILD or package targets are being built.

add_custom_command(
    OUTPUT
        ${CMAKE_SOURCE_DIR}/interface/java_binding/target/libktx-${PROJECT_VERSION}-source.jar
        ${CMAKE_SOURCE_DIR}/interface/java_binding/target/libktx-${PROJECT_VERSION}.jar
    COMMAND
        ${MAVEN_EXECUTABLE} -Drevision=${PROJECT_VERSION} -Dmaven.test.skip=true package
    DEPENDS
        ktx-jni
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/interface/java_binding
)

add_custom_target( ktx-jar ALL
    DEPENDS
        ${CMAKE_SOURCE_DIR}/interface/java_binding/target/libktx-${PROJECT_VERSION}-source.jar
        ${CMAKE_SOURCE_DIR}/interface/java_binding/target/libktx-${PROJECT_VERSION}.jar
    WORKING_DIRECTORY
        ${CMAKE_SOURCE_DIR}/interface/java_binding
    COMMENT
        "Java wrapper target"
)

install(FILES
    ${CMAKE_SOURCE_DIR}/interface/java_binding/target/libktx-${PROJECT_VERSION}.jar
    TYPE LIB
    COMPONENT jni
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文