You first need to use add_library() in package A. In package B you will need an add_executable().
add_dependencies(myexecutable ${catkin_EXPORTED_TARGETS})  You first need to use add_library() in package A. In package B you will need an add_executable(). After that is done you need to tell CMake about the dependency between both using: add_dependencies(myexecutable${catkin_EXPORTED_TARGETS})