如何为文件中安装的文件创建依赖关系
我有一个自定义目标&我的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论