问题
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)
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.
How can I edit my CMakeLists.txt in such a way that it automatically opens the documentation and with what command?
To run the tests.cpp
, I do this:
cd build
cmake ..
make
回答1:
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()
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.
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()
来源:https://stackoverflow.com/questions/60852895/open-main-page-of-doxygen-documentation-with-cmake