CMakeLists.txt 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #
  2. # Copyright (c) 2008-2017 the Urho3D project.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. #
  22. # Set project name
  23. project (Urho3D-Docs)
  24. if (URHO3D_DOCS_QUIET)
  25. set (URHO3D_DOCS 1)
  26. endif ()
  27. # Macro for enabling IDE-specific integration with Urho3D documentation (See comments in Doxyfile for more detail instructions)
  28. macro (enable_help IDE)
  29. if (${IDE} OR CMAKE_EXTRA_GENERATOR MATCHES ${IDE})
  30. set (${IDE}_HELP YES)
  31. else ()
  32. set (${IDE}_HELP NO)
  33. endif ()
  34. endmacro ()
  35. # 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
  36. # 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
  37. unset (CMAKE_FIND_ROOT_PATH)
  38. # Find Doxygen and DOT packages
  39. if (URHO3D_DOCS)
  40. set (REQUIRED REQUIRED)
  41. endif ()
  42. find_package (Doxygen ${REQUIRED})
  43. if (DOXYGEN_FOUND)
  44. # It is not an error when DOT is not found, instead just switching off the Doxygen's HAVE_DOT option
  45. find_package_handle_standard_args (Dot REQUIRED_VARS DOXYGEN_DOT_EXECUTABLE)
  46. # Generate platform specific Doxyfile automatically
  47. if (NOT URHO3D_OPENGL EQUAL DOXYFILE_URHO3D_OPENGL OR ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
  48. set (DOXYFILE_URHO3D_OPENGL ${URHO3D_OPENGL} CACHE INTERNAL "URHO3D_OPENGL build option when Doxyfile was last generated")
  49. if (URHO3D_OPENGL)
  50. set (EXCLUDE_GRAPHICS_API Direct3D9)
  51. set (EXCLUDE_GRAPHICS_API2 Direct3D11)
  52. else ()
  53. set (EXCLUDE_GRAPHICS_API OpenGL)
  54. if (URHO3D_D3D11)
  55. set (EXCLUDE_GRAPHICS_API2 Direct3D9)
  56. else ()
  57. set (EXCLUDE_GRAPHICS_API2 Direct3D11)
  58. endif ()
  59. endif ()
  60. foreach (IDE XCODE MSVC Eclipse CodeBlocks)
  61. enable_help (${IDE})
  62. endforeach ()
  63. if (MSVC_HELP)
  64. find_package (HTMLHelp)
  65. # It is not an error when HTML help compiler is not found, instead just switching off the Doxygen's HHC option
  66. find_package_handle_standard_args (HTMLHelp REQUIRED_VARS HTML_HELP_COMPILER)
  67. endif ()
  68. configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/generated/Doxyfile)
  69. endif ()
  70. # Dump AngelScript and LuaScript API to Doxygen file if the corresponding host tool is available
  71. if (TARGET ScriptCompiler AND NOT CMAKE_CROSSCOMPILING)
  72. add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated/ScriptAPI.dox ${CMAKE_CURRENT_BINARY_DIR}/generated/AngelScriptAPI.h
  73. COMMAND ${CMAKE_BINARY_DIR}/bin/tool/ScriptCompiler -dumpapi ${CMAKE_SOURCE_DIR} ScriptAPI.dox AngelScriptAPI.h
  74. DEPENDS ScriptCompiler # ScriptCompiler implicitly depends on Urho3D already
  75. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated
  76. COMMENT "Dumping AngelScript API to ScriptAPI.dox")
  77. else ()
  78. add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated/ScriptAPI.dox ${CMAKE_CURRENT_BINARY_DIR}/generated/AngelScriptAPI.h
  79. COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/ScriptAPI.dox ${CMAKE_CURRENT_BINARY_DIR}/generated/ScriptAPI.dox
  80. COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/AngelScriptAPI.h ${CMAKE_CURRENT_BINARY_DIR}/generated/AngelScriptAPI.h
  81. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ScriptAPI.dox ${CMAKE_CURRENT_SOURCE_DIR}/AngelScriptAPI.h)
  82. endif ()
  83. if (TARGET tolua++ AND NOT CMAKE_CROSSCOMPILING)
  84. file (GLOB PKGS RELATIVE ${CMAKE_SOURCE_DIR}/Source/Urho3D/LuaScript/pkgs ${CMAKE_SOURCE_DIR}/Source/Urho3D/LuaScript/pkgs/*.pkg)
  85. list (SORT PKGS)
  86. set (PKGLIST "// This is a generated file. DO NOT EDIT!\n\n")
  87. foreach (PKG ${PKGS})
  88. set (PKGLIST "${PKGLIST}$pfile \"${PKG}\"\n")
  89. endforeach ()
  90. file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaPkgToDox.txt.new ${PKGLIST})
  91. execute_process (COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaPkgToDox.txt.new ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaPkgToDox.txt)
  92. execute_process (COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaPkgToDox.txt.new)
  93. file (GLOB_RECURSE API_PKG_FILES ${CMAKE_SOURCE_DIR}/Source/Urho3D/LuaScript/pkgs/*.pkg)
  94. add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaScriptAPI.dox
  95. 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
  96. DEPENDS tolua++ ${API_PKG_FILES} ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaPkgToDox.txt ${CMAKE_SOURCE_DIR}/Source/Urho3D/LuaScript/pkgs/ToDoxHook.lua
  97. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D/LuaScript/pkgs
  98. COMMENT "Dumping LuaScript API to LuaScriptAPI.dox")
  99. else ()
  100. add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaScriptAPI.dox
  101. COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/LuaScriptAPI.dox ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaScriptAPI.dox
  102. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/LuaScriptAPI.dox)
  103. endif ()
  104. # In quiet mode, redirect standard output stream of Doxygen to a null device
  105. if (URHO3D_DOCS_QUIET)
  106. set (REDIRECT_STDOUT 1>${NULL_DEVICE})
  107. endif ()
  108. # 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
  109. if (URHO3D_DOCS)
  110. set (ALL ALL)
  111. endif ()
  112. # Add custom 'doc' target for generating Urho3D documentation
  113. if (URHO3D_UPDATE_SOURCE_TREE)
  114. foreach (FILE ScriptAPI.dox AngelScriptAPI.h LuaScriptAPI.dox)
  115. list (APPEND UPDATE_COMMANDS COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/generated/${FILE} ${CMAKE_CURRENT_SOURCE_DIR}/${FILE})
  116. endforeach ()
  117. endif ()
  118. file (GLOB DOX_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.dox)
  119. add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/html/index.html
  120. COMMAND ${DOXYGEN_EXECUTABLE} generated/Doxyfile ${REDIRECT_STDOUT}
  121. DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/generated/Doxyfile ${DOX_FILES} ${CMAKE_CURRENT_BINARY_DIR}/generated/ScriptAPI.dox ${CMAKE_CURRENT_BINARY_DIR}/generated/LuaScriptAPI.dox
  122. COMMENT "Generating documentation with Doxygen")
  123. add_custom_target (doc ${ALL}
  124. ${UPDATE_COMMANDS}
  125. DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/html/index.html)
  126. endif ()
  127. # Make sure html output directory exists and not empty
  128. 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")
  129. # 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
  130. # 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
  131. install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/ DESTINATION ${DEST_SHARE_DIR}/Docs)
  132. # Define post build steps
  133. if (CMAKE_EXTRA_GENERATOR MATCHES Eclipse AND NOT CMAKE_HOST_WIN32)
  134. add_custom_command (TARGET doc
  135. COMMAND ${CMAKE_COMMAND} -E remove ~/.eclipse/`ls -1t ~/.eclipse |grep org.eclipse.platform_ |head -1`/plugins/html || true
  136. COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_BINARY_DIR}/html ~/.eclipse/`ls -1t ~/.eclipse |grep org.eclipse.platform_ |head -1`/plugins/html || true
  137. COMMENT "Creating symbolic link to HTML documentation in the Eclipse IDE")
  138. endif ()