使用CMake打开Doxygen文档的主页 [英] Open Main Page of Doxygen Documentation with CMake
问题描述
我有一个使用Google测试的项目。我在根目录中有以下CMake文件:
I have a project where I use Google Tests. I have the following CMake file in the root directory:
set(CMAKE_C_COMPILER gcc)
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
project(PROJECT)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(SOURCES src/a.cpp src/b.cpp)
set(TESTSOURCES test/tests.cpp src/a.cpp src/br.cpp)
set(HEADERS src/a.h src/b.h src/c.h src/c.h)
set(CMAKE_CXX_FLAGS "${MAKE_CXX_FLAGS} -std=c++0x")
find_package(Qt5 COMPONENTS Core Widgets REQUIRED)
find_package(CURL REQUIRED)
# Locate GTest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
if(CMAKE_COMPILER_IS_GNUCC)
add_definitions(-Wall -Werror -lcurl)
endif(CMAKE_COMPILER_IS_GNUCC)
add_executable(tests ${TESTSOURCES} ${HEADERS} )
target_link_libraries(beergame-tests curl Qt5::Widgets ${GTEST_LIBRARIES} pthread)
目前,我还没有在CMakeLists.txt中添加任何有关文档的内容。要生成文档,我只使用 doxygen配置文件
,它会在我的Latex文件夹中创建html / latex文档。但是,它并没有真正打开文档及其主页。
For now, I have not added anything about the documentation into the CMakeLists.txt. To generate documentation, I just use doxygen config-file
, which creates html/latex documentation in my latex folder. However, it doesn't really open the documentation and its main page.
如何编辑CMakeLists.txt,使其自动打开文档,并使用
How can I edit my CMakeLists.txt in such a way that it automatically opens the documentation and with what command?
要运行 tests.cpp
,请执行以下操作:
To run the tests.cpp
, I do this:
cd build
cmake ..
make
推荐答案
如果要在CMake完成之前构建并打开Doxygen文档 ,则可以使用 execute_process()
以便在CMake配置阶段。您可以将 firefox< path-to-html> /index.html
(或某些其他浏览器)作为单独的 COMMAND
在文档建立后打开文档。
If you want to build and open the Doxygen documentation before CMake completes, you can use execute_process()
to build it during the CMake configuration stage. You can call firefox <path-to-html>/index.html
(or some other browser) as a separate COMMAND
to open the documentation after it builds.
find_package(Doxygen)
if(DOXYGEN_FOUND)
execute_process(
COMMAND ${DOXYGEN_EXECUTABLE} config-file.doxygen
COMMAND firefox ${CMAKE_CURRENT_SOURCE_DIR}/doc/html/index.html
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating and opening documentation for project: tests"
)
endif()
注意,在Windows 10上,您可能不需要指定要使用的浏览器;只需在 COMMAND
之后列出 index.html
文件,即可在默认浏览器中将其打开。
Note, on Windows 10, you may not need to specify the browser to use; simply listing the index.html
file after COMMAND
will open it in the default browser.
如果计划将Doxygen内置到单独的 target 中,则可以使用 add_custom_target()
:
If you plan on making your Doxygen build into a separate target, you can do something similar using add_custom_target()
:
find_package(Doxygen)
if(DOXYGEN_FOUND)
add_custom_target(tests-Documentation
COMMAND ${DOXYGEN_EXECUTABLE} config-file.doxygen
COMMAND firefox ${CMAKE_CURRENT_SOURCE_DIR}/doc/html/index.html
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating documentation for project: tests"
VERBATIM
)
endif()
这篇关于使用CMake打开Doxygen文档的主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!