leon22
leon22

Reputation: 5669

Clion: auto documenting functions, classes

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!

Upvotes: 17

Views: 14685

Answers (2)

nastasiak2512
nastasiak2512

Reputation: 1937

Starting from 2016.2 EAP CLion supports Doxygen (http://blog.jetbrains.com/clion/2016/05/keep-your-code-documented/). Start with typing “/**” or “/*!” and then press Enter. In case your function has parameters, returns a value or throws an exception, you’ll get a stub to fill with the documentation text

Upvotes: 8

Waxo
Waxo

Reputation: 1976

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/

Upvotes: 16

Related Questions