Clion:自动记录函数,类

时间:2015-04-04 17:25:57

标签: c++ c ide documentation clion

是否有任何快捷方式或类似的东西要添加,例如函数或类的文档(类似于Visual Studio和C#中的"///")?

谢谢!

2 个答案:

答案 0 :(得分:11)

您可以使用/** <Enter> 我找到了一种方法。我个人使用Doxygen作为文档 CLion plans to integrate it。 你必须在此时写下所有内容。但是,当您记录了代码时,可以使用CMake构建它(然后它出现在CLion的构建目标中)。

以下是一个例子:

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})

来源:

  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/

答案 1 :(得分:5)

从2016年开始.2 EAP CLion支持Doxygen(http://blog.jetbrains.com/clion/2016/05/keep-your-code-documented/)。首先输入“/ **”或“/ *!”,然后按Enter键。如果你的函数有参数,返回一个值或抛出一个异常,你将得到一个存根来填充文档文本