创建调用子项目自定义目标的自定义目标

时间:2014-07-29 16:04:08

标签: cmake subproject

我有很多子文件夹

home
|
|-library1
|-library2
|
|-libraryn

主文件夹中有一个主CMakeLists.txt,每个子文件夹都有一个CMakeLists.txt。

在每个子项目中,我都有一个用于编译文档的自定义目标

# in library1/CMakelists.txt
find_package (Doxygen)
if (DOXYGEN_FOUND)
  set (Doxygen_Dir ${CMAKE_BINARY_DIR}/export/${library1_Version}/doc)
  # Copy images folder
  file (GLOB IMAGES_SRC "images/*")
  file (COPY ${IMAGES_SRC} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/images)
  configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
  add_custom_target (library1_doc
    ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMMENT "Generating doxygen documentation" VERBATIM
  )
else (DOXYGEN_FOUND)
  message (STATUS "Doxygen must be installed in order to compile doc")
endif (DOXYGEN_FOUND)

# in libraryn/CMakelists.txt
find_package (Doxygen)
if (DOXYGEN_FOUND)
  set (Doxygen_Dir ${CMAKE_BINARY_DIR}/export/${library1_Version}/doc)
  # Copy images folder
  file (GLOB IMAGES_SRC "images/*")
  file (COPY ${IMAGES_SRC} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/images)
  configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
  add_custom_target (libraryn_doc
    ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMMENT "Generating doxygen documentation" VERBATIM
  )
else (DOXYGEN_FOUND)
  message (STATUS "Doxygen must be installed in order to compile doc")
endif (DOXYGEN_FOUND)

如您所见,在每个子项目中,我都会创建一个libraryn_doc目标。

这是主要的CMakeLists.txt:

cmake_minimum_required (VERSION 2.8)

### Versions ###
# This exports the library version
set (library1_Version 0.0)

### Projects ###
add_subdirectory (library1)
add_subdirectory (library2)
add_subdirectory (library3)
add_subdirectory (library4)

### Project dependencies ###
add_dependencies (librrary4 library1)

### Project documentation ###
add_custom_target(doc
  DEPENDS library1 library2 library3 library4
  )

我想修改主CMakelists.txt的doc目标,以便执行所有libraryn_doc自定义目标,因此我只需使用make doc而不是make library1_doc; ... make libraryn_doc来构建文档。< / p>

我该怎么做?

1 个答案:

答案 0 :(得分:2)

只需修改doc目标的依赖关系,如下所示:

add_custom_target(doc
    DEPENDS library1_doc library2_doc library3_doc library4_doc)
相关问题