15

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

谢谢!

4

2 回答 2

14

您可以使用/** <Enter>.
我找到了一种方法。我个人使用 Doxygen 作为文档。
CLion 计划整合它。你必须在这个时候把它全部写下来。但是,当您记录了代码后,您可以使用 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/
于 2015-08-10T13:43:28.690 回答
7

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

于 2016-05-25T21:50:59.680 回答