How to create a dependency for a FILES install in cmake

513 Views Asked by At

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
)
0

There are 0 best solutions below