Clion: auto documenting functions, classes

leon22 picture leon22 · Apr 4, 2015 · Viewed 9.2k times · Source

Is there any shortcut or something like this to add, e.g. documentation of a function or class (similar to "///" in Visual Studio and C#)?

Thanks!

Answer

Waxo picture Waxo · Aug 10, 2015

You can use /** <Enter>.
I have found a way to do it. I personally use Doxygen for documentation.
CLion plans to integrate it. You have to write all of it at this time. But when you have documented your code, you can build it with CMake (and then it appears in your build target on CLion).

Here's an example:

cmake_minimum_required(VERSION 3.2)
project(doxygen_test)

find_package(Doxygen)

set(SOURCE_FILES main.cc)

if(DOXYGEN_FOUND)

  set(DOXYGEN_INPUT ${SOURCE_FILES})
  set(DOXYGEN_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

  add_custom_command(
    OUTPUT ${DOXYGEN_OUTPUT}
    COMMAND ${CMAKE_COMMAND} -E echo_append "Building API Documentation..."
    COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_INPUT}
    COMMAND ${CMAKE_COMMAND} -E echo "Done."
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    DEPENDS ${DOXYGEN_INPUT}
  )

  add_custom_target(apidoc ALL DEPENDS ${DOXYGEN_OUTPUT})

  add_custom_target(apidoc_forced
    COMMAND ${CMAKE_COMMAND} -E echo_append "Building API Documentation..."
    COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_INPUT}
    COMMAND ${CMAKE_COMMAND} -E echo "Done."
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  )

endif(DOXYGEN_FOUND)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")


add_executable(doxygen_test ${SOURCE_FILES})

Sources:

  1. http://www.cmake.org/pipermail/cmake/2007-February/012796.html
  2. https://www.tty1.net/blog/2014/cmake-doxygen_en.html
  3. https://mementocodex.wordpress.com/2013/01/19/how-to-generate-code-documentation-with-doxygen-and-cmake-a-slightly-improved-approach/
  4. https://majewsky.wordpress.com/2010/08/14/tip-of-the-day-cmake-and-doxygen/