0

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 
3
  • Do you also want CMake to run Doxygen? There will be nothing to open when CMake completes, because you then have to generate the documentation. Commented Mar 25, 2020 at 16:24
  • Yup, I want CMake to run Doxygen but I don't get what you mean by "nothing to open"? @squareskittles Is there no way to automatically open the main page of a doxygen documentation? Commented Mar 25, 2020 at 19:12
  • It wasn't clear if you intended to leave the doxygen command outside of CMake. Thank you for clarifying. Commented Mar 25, 2020 at 19:37

1 Answer 1

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() 
Sign up to request clarification or add additional context in comments.

3 Comments

The config file was initially in the root directory but I tried adding it in the build folder too. Didn't work.
@FelicitySmith Yes, the responses I gave assume your Doxygen successfully generates the documentation, and places it in a folder doc as a sibling to the .doxygen config file itself. But you can change the paths as necessary to match your configuration.
@FelicitySmith It also assumes that the Doxygen config file (and the generated doc folder) is in a source directory, not a build directory. But again, this is all configurable, so you can just modify the paths to fit your setup.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.