CMakeLists.txt 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #
  2. # Copyright (c) 2008-2020 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. if (CMAKE_PROJECT_NAME STREQUAL Urho3D)
  23. # Set project name
  24. project (Urho3D-Clang-Tools)
  25. # All Clang-tools must be natively built and output to bin/tool/clang subdir to differentiate them from the rest
  26. set_output_directories (${CMAKE_BINARY_DIR}/bin/tool/clang RUNTIME PDB)
  27. else ()
  28. # Set CMake minimum version
  29. cmake_minimum_required (VERSION 3.10.2)
  30. # Set project name
  31. project (Urho3D-ExternalProject-${URHO3D_CLANG_TOOLS})
  32. # Set CMake modules search path
  33. set (CMAKE_MODULE_PATH ${BAKED_CMAKE_SOURCE_DIR}/cmake/Modules)
  34. # Include UrhoCommon.cmake module after setting project name
  35. include (UrhoCommon)
  36. # Setup SDK-like include dir in the build tree for building the Clang-tools
  37. file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${DEST_INCLUDE_DIR}/ThirdParty)
  38. endif ()
  39. # LLVM/Clang is assumed to be installed in a system-wide location when not explicitly defined using env-var
  40. if (DEFINED ENV{LLVM_CLANG_ROOT})
  41. set (CMAKE_SYSROOT $ENV{LLVM_CLANG_ROOT})
  42. endif ()
  43. execute_process (COMMAND ${LLVM_CONFIG} --bindir OUTPUT_VARIABLE LLVM_BINDIR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
  44. # No exception and no RTTI
  45. if (MSVC)
  46. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c- /GR-")
  47. else ()
  48. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
  49. endif ()
  50. # Define common dependency libs
  51. set (LIBS clangTooling clangFrontend clangDriver clangParse clangSerialization clangSema clangEdit clangAnalysis clangToolingCore
  52. clangRewrite clangLex clangASTMatchers clangAST clangBasic
  53. LLVMBitReader LLVMMC LLVMMCParser LLVMOption LLVMSupport)
  54. execute_process (COMMAND ${LLVM_CONFIG} --system-libs OUTPUT_VARIABLE LLVM_SYSLIBS OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
  55. string (REGEX REPLACE " *-l" ";" LLVM_SYSLIBS "${LLVM_SYSLIBS}") # Stringify against empty output variable
  56. list (APPEND LIBS ${LLVM_SYSLIBS})
  57. set (INCLUDE_DIRS ${CMAKE_BINARY_DIR}/${DEST_INCLUDE_DIR}/ThirdParty)
  58. # Clang-tools can be built in two ways: on the fly in normal build one at a time or build all of them in a special Clang-tools build tree (for development)
  59. if (CMAKE_PROJECT_NAME MATCHES ExternalProject)
  60. # Externally build the Clang-tool for actual use in a normal build
  61. add_subdirectory (${URHO3D_CLANG_TOOLS})
  62. else ()
  63. # Define source files for the tools
  64. get_target_property (SOURCES Urho3D SOURCES)
  65. string (REGEX REPLACE "[^;]+\\.h" "" SOURCES "${SOURCES}") # Stringify to preserve the semicolons
  66. string (REGEX REPLACE "[^;]+generated[^;]+\\.cpp" "" SOURCES "${SOURCES}")
  67. file (GLOB BINDING_SOURCES RELATIVE ${CMAKE_SOURCE_DIR}/Source/Urho3D ${CMAKE_SOURCE_DIR}/Source/Urho3D/Script/*API.cpp)
  68. string (REGEX REPLACE "[^;]+API\\.cpp" "" ANNOTATED_SOURCES "${SOURCES}")
  69. # List of tools
  70. add_subdirectory (Annotator)
  71. add_subdirectory (AutoBinder)
  72. # List of targets
  73. if (EXISTS ${LLVM_BINDIR}/clang-query) # This tool is from clang-tools-extra repository which user may have not installed
  74. add_custom_target (ast-query
  75. COMMAND ${CMAKE_COMMAND} -E echo "Building AST for query, please be patient..."
  76. COMMAND ${LLVM_BINDIR}/clang-query -p ${CMAKE_BINARY_DIR} $$option ${SOURCES}
  77. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  78. COMMENT "Executing clang-query on Urho3D library source files")
  79. endif ()
  80. add_custom_target (ast
  81. COMMAND ${CMAKE_COMMAND} -E echo "Usage: option=-help make ast"
  82. COMMAND ${LLVM_BINDIR}/clang-check -p ${CMAKE_BINARY_DIR} $$option ${SOURCES}
  83. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  84. COMMENT "Executing clang-check on Urho3D library source files")
  85. add_custom_target (binding-ast
  86. COMMAND ${CMAKE_COMMAND} -E echo "Usage: option=-help make binding-ast"
  87. COMMAND ${LLVM_BINDIR}/clang-check -p ${CMAKE_BINARY_DIR} $$option ${BINDING_SOURCES}
  88. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  89. COMMENT "Executing clang-check on (existing) AngelScript API bindings source files")
  90. add_custom_target (annotate
  91. COMMAND ${CMAKE_BINARY_DIR}/bin/tool/clang/Annotator -p ${CMAKE_BINARY_DIR} ${SOURCES}
  92. DEPENDS Annotator
  93. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  94. COMMENT "Annotating Urho3D library source files")
  95. add_custom_target (autobinder
  96. COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/Source/Urho3D/generated
  97. COMMAND ${CMAKE_BINARY_DIR}/bin/tool/clang/AutoBinder -p ${CMAKE_BINARY_DIR} -t ${CMAKE_CURRENT_SOURCE_DIR}/AutoBinder/Templates -o ${CMAKE_BINARY_DIR}/Source/Urho3D/generated -s AngelScript -s LuaScript -s JavaScript ${ANNOTATED_SOURCES}
  98. DEPENDS AutoBinder
  99. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  100. COMMENT "Auto-binding for all script subsystems")
  101. add_custom_target (autobinder-angelscript
  102. COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/Source/Urho3D/generated
  103. COMMAND ${CMAKE_BINARY_DIR}/bin/tool/clang/AutoBinder -p ${CMAKE_BINARY_DIR} -t ${CMAKE_CURRENT_SOURCE_DIR}/AutoBinder/Templates -o ${CMAKE_BINARY_DIR}/Source/Urho3D/generated -s AngelScript ${ANNOTATED_SOURCES}
  104. DEPENDS AutoBinder
  105. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  106. COMMENT "Auto-binding for AngelScript")
  107. add_custom_target (autobinder-luascript
  108. COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/Source/Urho3D/generated
  109. COMMAND ${CMAKE_BINARY_DIR}/bin/tool/clang/AutoBinder -p ${CMAKE_BINARY_DIR} -t ${CMAKE_CURRENT_SOURCE_DIR}/AutoBinder/Templates -o ${CMAKE_BINARY_DIR}/Source/Urho3D/generated -s LuaScript ${ANNOTATED_SOURCES}
  110. DEPENDS AutoBinder
  111. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  112. COMMENT "Auto-binding for LuaScript")
  113. add_custom_target (autobinder-javascript
  114. COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/Source/Urho3D/generated
  115. COMMAND ${CMAKE_BINARY_DIR}/bin/tool/clang/AutoBinder -p ${CMAKE_BINARY_DIR} -t ${CMAKE_CURRENT_SOURCE_DIR}/AutoBinder/Templates -o ${CMAKE_BINARY_DIR}/Source/Urho3D/generated -s JavaScript ${ANNOTATED_SOURCES}
  116. DEPENDS AutoBinder
  117. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  118. COMMENT "Auto-binding for JavaScript")
  119. endif ()