CMake depend on “all” target from custom target

北慕城南 提交于 2020-01-02 10:08:13

问题


I'm making a library that needs to be packaged in a fancy way, and as part of that, I have a script that contains these lines:

#only install the lib component, nd put in the a special directory
ADD_CUSTOM_TARGET(o_destdir_install
  COMMAND DESTDIR=${CMAKE_BINARY_DIR}/o_package ${CMAKE_COMMAND} -DCOMPONENT=lib -P cmake_install.cmake
  DEPENDS ${CMAKE_BINARY_DIR}/cmake_install.cmake
  COMMENT "Building o_package directory with DESTDIR"
  )
ADD_DEPENDENCIES(o_destdir_install all preinstall)

I've found this code from the old UseDebian.cmake dpkg builder, however it does NOT build all and preinstall before it runs the install. Making my target depend on a non-built-in target seems to work, but I can't depend on any built-in targets it seems. How can I get this to work?

Also it would be nice if I could depend on a single component install preferably without the hacking calling of cmake, but I'm fine either way


回答1:


Instead of hacking together your own install target, you should just piggy-back on the existing one using the install(CODE) form:

install(CODE "execute_process(COMMAND DESTDIR=${CMAKE_BINARY_DIR}/o_package ${CMAKE_COMMAND} -DCOMPONENT=lib -P cmake_install.cmake")



回答2:


You can depend on 'all' target using ALL keyword. See documentation.



来源:https://stackoverflow.com/questions/22875854/cmake-depend-on-all-target-from-custom-target

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!