1

我有一堆我必须构建的库。对于每个库,我创建 3 个符号链接。我使用创建两个符号链接:

add_library(${PROJECT_NAME} ${SRC})
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${perception_kit_VERSION})
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ${Boost_LIBS})

但其余两个是使用创建的:

#code for generating symlink. will work with make install
if (CMAKE_HOST_UNIX)
  set (libname_major_minor_patch "lib${PROJECT_NAME}.so.${perception_kit_VERSION_MAJOR}.${perception_kit_VERSION_MINOR}.${perception_kit_VERSION_PATCH}")
  set (libname_major_minor "lib${PROJECT_NAME}.so.${perception_kit_VERSION_MAJOR}.${perception_kit_VERSION_MINOR}")
  set (libname_major "lib${PROJECT_NAME}.so.${perception_kit_VERSION_MAJOR}")
  set (libname "lib${PROJECT_NAME}.so")

  install(CODE "
          EXECUTE_PROCESS (COMMAND ln -sf ${libname_major_minor_patch} ${libname_major_minor}  WORKING_DIRECTORY ${LIBRARY_OUTPUT_PATH} )
")
  install(CODE "
          EXECUTE_PROCESS (COMMAND ln -sf ${libname_major_minor_patch} ${libname_major}  WORKING_DIRECTORY ${LIBRARY_OUTPUT_PATH} )
")

endif(CMAKE_HOST_UNIX)

最后两个仅在使用 make install 时创建。有没有办法在不使用 make install 的情况下制作所有的符号链接。?

4

1 回答 1

5

要执行构建后命令,您可以使用add_custom_command(TARGET ...)

所以在这种情况下,我想你会想要类似的东西

add_custom_command(
    TARGET ${PROJECT_NAME} POST_BUILD
    COMMAND ln -sf ${libname_major_minor_patch} ${libname_major_minor}
    COMMAND ln -sf ${libname_major_minor_patch} ${libname_major}
)
于 2013-04-27T01:00:16.000 回答