我有很多子文件夹
home
|
|-library1
|-library2
|
|-libraryn
每个子文件夹都包含一个可以自行编译的完整库(每个库都有不同的维护器)。到目前为止,它工作正常,并且我使用脚本编译它们。
现在我需要创建另一个库,它依赖于现有的库。为此,我创建了一个CMakeLists.txt
在主文件夹下,使用add_subdirectory
允许我编译所有库的命令。
我有类似的东西
cmake_minimum_required (VERSION 2.8)
add_subdirectory(library1)
add_subdirectory(library2)
...
add_subdirectory(libraryn)
当我尝试执行时cmake
我收到各种库的以下错误:
CMake Error at libraryY/CMakeLists.txt:63 (add_custom_target):
add_custom_target cannot create target "doc" because another target with
the same name already exists. The existing target is a custom target
created in source directory
"/path/to/libraryX". See
documentation for policy CMP0002 for more details.
发生这种情况是因为我们在每个库中创建了一个 doc 目标,以便编译库本身的 Doxygen 文档。当库被一一编译时,它工作得很好,但与主CMakeLists.txt
看来我做不到。
# Create doc target for doxygen documentation compilation.
find_package (Doxygen)
if (DOXYGEN_FOUND)
set (Doxygen_Dir ${CMAKE_BINARY_DIR}/export/${Library_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 (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)
有没有办法一次性编译这些项目而不修改这个目标?
如果您不想修改任何内容,以便可以将所有这些项目构建为子项目,那么您可以使用外部项目_添加构建和安装依赖项。
option
或者你可以使用option排除命令doc
构建目标:
# Foo/CMakeLists.txt
option(FOO_BUILD_DOCS "Build doc target for Foo project" OFF)
# ...
if(DOXYGEN_FOUND AND FOO_BUILD_DOCS)
add_custom_target(doc ...)
endif()
# Boo/CMakeLists.txt
option(BOO_BUILD_DOCS "Build doc target for Boo project" OFF)
# ...
if(DOXYGEN_FOUND AND BOO_BUILD_DOCS)
add_custom_target(doc ...)
endif()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)