使用cmake做工程构建时,有关install的一些小技巧

  1. cmake自带变量CMAKE_INSTALL_PREFIX不能随着subdir传递下去,必须要在最外层指定
  2. 由我们自定义的变量可以随着subdir传递下去
  3. 拷贝目录用如下cmake命令:
INSTALL(DIRECTORY ${WORK_PATH}/auto_part_tool 
             DESTINATION "usr/bin"
             DIRECTORY_PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ
             FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
                              GROUP_EXECUTE GROUP_READ WORLD_READ
        )  
  1. 拷贝后制作软链接用如下cmake命令:
ADD_CUSTOM_TARGET(make_ln ALL
        COMMAND cp ${WORK_PATH}/systemd ${CMAKE_INSTALL_PREFIX}/etc/ -rf
        COMMAND if [ ! -d ${LN_PATH} ]; then mkdir ${LN_PATH}\; fi
        COMMAND ln -s ../reach_setup.service reach_setup.service
        COMMAND mv ./reach_setup.service ${LN_PATH}/
)

该命令会在make时触发,ALL选项表示这个make_ln目标始终需要构建。(先制作软链接,后把软链接移动到目标目录下)

你可能感兴趣的:(技,代码库,cmake)