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

Cmake 创建调用子项目自定义目标的自定义目标,cmake,subproject,Cmake,Subproject,我有很多子文件夹 home | |-library1 |-library2 | |-libraryn 我在主文件夹中有一个mainCMakeLists.txt,每个子文件夹都有一个CMakeLists.txt 在每个子项目中,我都有一个用于编译文档的自定义目标 # in library1/CMakelists.txt find_package (Doxygen) if (DOXYGEN_FOUND) set (Doxygen_Dir ${CMAKE_BINARY_DIR}/export/$

我有很多子文件夹

home
|
|-library1
|-library2
|
|-libraryn
我在主文件夹中有一个main
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\u doc
target

这是主要的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
  )
我想修改main CMakelists.txt的
doc
目标,以便执行所有libraryn\u doc自定义目标,因此我可以通过使用
make doc
而不是
make library1\u doc;,简单地构建文档。。。制作图书馆文档


我该怎么做?

只需修改
文档的依赖项,如下所示:

add_custom_target(doc
    DEPENDS library1_doc library2_doc library3_doc library4_doc)