CMakeLists.txt 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # Copyright (c) 2008-2022 the Urho3D project
  2. # License: MIT
  3. # Set project name
  4. project (Urho3D-Docs)
  5. if (URHO3D_DOCS_QUIET)
  6. set (URHO3D_DOCS 1)
  7. endif ()
  8. # Macro for enabling IDE-specific integration with Urho3D documentation (See comments in Doxyfile for more detail instructions)
  9. macro (enable_help IDE)
  10. if (${IDE} OR CMAKE_EXTRA_GENERATOR MATCHES ${IDE})
  11. set (${IDE}_HELP YES)
  12. else ()
  13. set (${IDE}_HELP NO)
  14. endif ()
  15. endmacro ()
  16. # There could be bug in CMake find_package() command, it currently does not honor NO_CMAKE_FIND_ROOT_PATH option for a non-rooted search as per CMake's documentation
  17. # As a workaround, we unset CMAKE_FIND_ROOT_PATH (even when we are cross-compiling) but in this scope ONLY in order to always do a non-rooted search for Doxygen package
  18. unset (CMAKE_FIND_ROOT_PATH)
  19. # Find Doxygen and DOT packages
  20. if (URHO3D_DOCS)
  21. set (REQUIRED REQUIRED)
  22. endif ()
  23. # https://github.com/urho3d/Urho3D/issues/2757
  24. find_package (Doxygen 1.9.2 ${REQUIRED})
  25. if (DOXYGEN_FOUND)
  26. # It is not an error when DOT is not found, instead just switching off the Doxygen's HAVE_DOT option
  27. find_package_handle_standard_args (Dot REQUIRED_VARS DOXYGEN_DOT_EXECUTABLE)
  28. # Generate platform specific Doxyfile automatically
  29. if (NOT URHO3D_OPENGL EQUAL DOXYFILE_URHO3D_OPENGL OR ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
  30. set (DOXYFILE_URHO3D_OPENGL ${URHO3D_OPENGL} CACHE INTERNAL "URHO3D_OPENGL build option when Doxyfile was last generated")
  31. if (URHO3D_OPENGL)
  32. set (EXCLUDE_GRAPHICS_API Direct3D9)
  33. set (EXCLUDE_GRAPHICS_API2 Direct3D11)
  34. else ()
  35. set (EXCLUDE_GRAPHICS_API OpenGL)
  36. if (URHO3D_D3D11)
  37. set (EXCLUDE_GRAPHICS_API2 Direct3D9)
  38. else ()
  39. set (EXCLUDE_GRAPHICS_API2 Direct3D11)
  40. endif ()
  41. endif ()
  42. foreach (IDE XCODE MSVC Eclipse CodeBlocks)
  43. enable_help (${IDE})
  44. endforeach ()
  45. if (MSVC_HELP)
  46. find_package (HTMLHelp)
  47. # It is not an error when HTML help compiler is not found, instead just switching off the Doxygen's HHC option
  48. find_package_handle_standard_args (HTMLHelp REQUIRED_VARS HTML_HELP_COMPILER)
  49. endif ()
  50. configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/generated/Doxyfile)
  51. endif ()
  52. # Dump AngelScript and LuaScript API to Doxygen file if the corresponding host tool is available
  53. if (TARGET ScriptCompiler AND NOT CMAKE_CROSSCOMPILING)
  54. add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated/ScriptAPI.dox ${CMAKE_CURRENT_BINARY_DIR}/generated/AngelScriptAPI.h
  55. COMMAND ${CMAKE_BINARY_DIR}/bin/tool/ScriptCompiler -dumpapi ${CMAKE_SOURCE_DIR} ScriptAPI.dox AngelScriptAPI.h
  56. DEPENDS ScriptCompiler # ScriptCompiler implicitly depends on Urho3D already
  57. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated
  58. COMMENT "Dumping AngelScript API to ScriptAPI.dox")
  59. else ()
  60. add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated/ScriptAPI.dox ${CMAKE_CURRENT_BINARY_DIR}/generated/AngelScriptAPI.h
  61. COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/ScriptAPI.dox ${CMAKE_CURRENT_BINARY_DIR}/generated/ScriptAPI.dox
  62. COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/AngelScriptAPI.h ${CMAKE_CURRENT_BINARY_DIR}/generated/AngelScriptAPI.h
  63. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ScriptAPI.dox ${CMAKE_CURRENT_SOURCE_DIR}/AngelScriptAPI.h)
  64. endif ()
  65. if (TARGET tolua++ AND NOT CMAKE_CROSSCOMPILING)
  66. file (GLOB PKGS RELATIVE ${CMAKE_SOURCE_DIR}/Source/Urho3D/LuaScript/pkgs ${CMAKE_SOURCE_DIR}/Source/Urho3D/LuaScript/pkgs/*.pkg)
  67. list (SORT PKGS)
  68. set (PKGLIST "// This is a generated file. DO NOT EDIT!\n\n")
  69. foreach (PKG ${PKGS})
  70. set (PKGLIST "${PKGLIST}$pfile \"${PKG}\"\n")
  71. endforeach ()
  72. file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaPkgToDox.txt.new ${PKGLIST})
  73. execute_process (COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaPkgToDox.txt.new ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaPkgToDox.txt)
  74. execute_process (COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaPkgToDox.txt.new)
  75. file (GLOB_RECURSE API_PKG_FILES ${CMAKE_SOURCE_DIR}/Source/Urho3D/LuaScript/pkgs/*.pkg)
  76. add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaScriptAPI.dox
  77. COMMAND ${CMAKE_BINARY_DIR}/bin/tool/tolua++ -L ToDoxHook.lua -P -o ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaScriptAPI.dox ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaPkgToDox.txt
  78. DEPENDS tolua++ ${API_PKG_FILES} ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaPkgToDox.txt ${CMAKE_SOURCE_DIR}/Source/Urho3D/LuaScript/pkgs/ToDoxHook.lua
  79. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D/LuaScript/pkgs
  80. COMMENT "Dumping LuaScript API to LuaScriptAPI.dox")
  81. else ()
  82. add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaScriptAPI.dox
  83. COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/LuaScriptAPI.dox ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaScriptAPI.dox
  84. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/LuaScriptAPI.dox)
  85. endif ()
  86. # In quiet mode, redirect standard output stream of Doxygen to a null device
  87. if (URHO3D_DOCS_QUIET)
  88. set (REDIRECT_STDOUT 1>${NULL_DEVICE})
  89. endif ()
  90. # If URHO3D_DOCS build option is set then add the custom 'doc' target into the default 'all' target, i.e. a normal build would not only build the software but also the documentation
  91. if (URHO3D_DOCS)
  92. set (ALL ALL)
  93. endif ()
  94. # Add custom 'doc' target for generating Urho3D documentation
  95. if (URHO3D_UPDATE_SOURCE_TREE)
  96. foreach (FILE ScriptAPI.dox AngelScriptAPI.h LuaScriptAPI.dox)
  97. list (APPEND UPDATE_COMMANDS COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/generated/${FILE} ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
  98. endforeach ()
  99. endif ()
  100. file (GLOB DOX_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.dox)
  101. add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/html/index.html
  102. COMMAND ${DOXYGEN_EXECUTABLE} generated/Doxyfile ${REDIRECT_STDOUT}
  103. DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/generated/Doxyfile ${DOX_FILES} ${CMAKE_CURRENT_BINARY_DIR}/generated/ScriptAPI.dox ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaScriptAPI.dox
  104. COMMENT "Generating documentation with Doxygen")
  105. add_custom_target (doc ${ALL}
  106. ${UPDATE_COMMANDS}
  107. DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/html/index.html)
  108. endif ()
  109. # Make sure html output directory exists and not empty
  110. file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/html/Readme.txt "If the URHO3D_DOCS build option is set then the Urho3D documentation will be built automatically as part of the Urho3D library build. If build option is not set, however, then use 'doc' built-in target to generate the documentation manually (must do this before installing the SDK).\n")
  111. # Currently it is not possible to make built-in 'install' target to depend on 'doc' in CMake, therefore 'make doc' command need to be invoked manually before 'make install' in order to install the SDK with complete documentation
  112. # Unless, URHO3D_DOCS build option is set in which case the custom 'doc' target is part of the default 'all' target which in turn the 'install' target depends on, so a single 'make install' alone is suffice to install everything
  113. install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/ DESTINATION ${DEST_SHARE_DIR}/docs)
  114. # Define post build steps
  115. if (CMAKE_EXTRA_GENERATOR MATCHES Eclipse AND NOT CMAKE_HOST_WIN32)
  116. add_custom_command (TARGET doc
  117. COMMAND ${CMAKE_COMMAND} -E remove ~/.eclipse/`ls -1t ~/.eclipse |grep org.eclipse.platform_ |head -1`/plugins/html || true
  118. COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_BINARY_DIR}/html ~/.eclipse/`ls -1t ~/.eclipse |grep org.eclipse.platform_ |head -1`/plugins/html || true
  119. COMMENT "Creating symbolic link to HTML documentation in the Eclipse IDE")
  120. endif ()