2

In my project I use add_custom_command to generate some output file:

    add_custom_command(
        OUTPUT ${LIB_NAME}
        # commands
    )
    add_custom_target(Core-static DEPENDS ${LIB_NAME})

I then have instruction to install the library:

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${LIB_NAME}"
        DESTINATION "${CORE_INSTALL_DIR}/lib/"
)

When I manualy build Core-static target, I can then successfuly run installation. However, running install does not trigger the custom command and the library is not produced resulting in an error. Also, for some reason rebuilding the solution (in Visual Studio) does not trigger Core-static project build.

1 Answer 1

2

In CMake, installing triggers only ALL (pseudo-)target.

For make your file installable, you need to force ALL target to build your file. Currently, your custom target Core-static is not buit by default (by ALL target). For fix that, add ALL keyword when create the target:

add_custom_target(Core-static ALL DEPENDS ${LIB_NAME})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.