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.