CMakeLists.txt 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. 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 and CMake policy required by UrhoCommon module
  29. cmake_minimum_required (VERSION 3.2.3)
  30. if (COMMAND cmake_policy)
  31. # Libraries linked via full path no longer produce linker search paths
  32. cmake_policy (SET CMP0003 NEW)
  33. # INTERFACE_LINK_LIBRARIES defines the link interface
  34. cmake_policy (SET CMP0022 NEW)
  35. # Disallow use of the LOCATION target property - so we set to OLD as we still need it
  36. cmake_policy (SET CMP0026 OLD)
  37. # MACOSX_RPATH is enabled by default
  38. cmake_policy (SET CMP0042 NEW)
  39. endif ()
  40. # Set project name
  41. project (Urho3D-ExternalProject-${URHO3D_CLANG_TOOLS})
  42. # Set CMake modules search path
  43. set (CMAKE_MODULE_PATH ${BAKED_CMAKE_SOURCE_DIR}/CMake/Modules)
  44. # Include UrhoCommon.cmake module after setting project name
  45. include (UrhoCommon)
  46. # Setup SDK-like include dir in the build tree for building the Clang-tools
  47. file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${DEST_INCLUDE_DIR}/ThirdParty)
  48. endif ()
  49. # LLVM/Clang is assumed to be installed in a system-wide location when not explicitily defined using env-var
  50. if (DEFINED ENV{LLVM_CLANG_ROOT})
  51. set (CMAKE_SYSROOT $ENV{LLVM_CLANG_ROOT})
  52. endif ()
  53. execute_process (COMMAND ${LLVM_CONFIG} --bindir OUTPUT_VARIABLE LLVM_BINDIR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
  54. # No exception and no RTTI
  55. if (MSVC)
  56. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c- /GR-")
  57. else ()
  58. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
  59. endif ()
  60. # Define common dependency libs
  61. set (LIBS clangTooling clangFrontend clangDriver clangParse clangSerialization clangSema clangEdit clangAnalysis clangToolingCore
  62. clangRewrite clangLex clangASTMatchers clangAST clangBasic
  63. LLVMBitReader LLVMMC LLVMMCParser LLVMOption LLVMSupport)
  64. execute_process (COMMAND ${LLVM_CONFIG} --system-libs OUTPUT_VARIABLE LLVM_SYSLIBS OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
  65. string (REGEX REPLACE " *-l" ";" LLVM_SYSLIBS "${LLVM_SYSLIBS}") # Stringify against empty output variable
  66. list (APPEND LIBS ${LLVM_SYSLIBS})
  67. set (INCLUDE_DIRS ${CMAKE_BINARY_DIR}/${DEST_INCLUDE_DIR}/ThirdParty)
  68. # 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)
  69. if (CMAKE_PROJECT_NAME MATCHES ExternalProject)
  70. # Externally build the Clang-tool for actual use in a normal build
  71. add_subdirectory (${URHO3D_CLANG_TOOLS})
  72. else ()
  73. # Define source files for the tools
  74. get_target_property (SOURCES Urho3D SOURCES)
  75. string (REGEX REPLACE "[^;]+\\.h" "" SOURCES "${SOURCES}") # Stringify to preserve the semicolons
  76. string (REGEX REPLACE "[^;]+generated[^;]+\\.cpp" "" SOURCES "${SOURCES}")
  77. file (GLOB BINDING_SOURCES RELATIVE ${CMAKE_SOURCE_DIR}/Source/Urho3D ${CMAKE_SOURCE_DIR}/Source/Urho3D/Script/*API.cpp)
  78. string (REGEX REPLACE "[^;]+API\\.cpp" "" ANNOTATED_SOURCES "${SOURCES}")
  79. # List of tools
  80. add_subdirectory (Annotator)
  81. add_subdirectory (AutoBinder)
  82. # List of targets
  83. if (EXISTS ${LLVM_BINDIR}/clang-query) # This tool is from clang-tools-extra repository which user may have not installed
  84. add_custom_target (ast-query
  85. COMMAND ${CMAKE_COMMAND} -E echo "Building AST for query, please be patient..."
  86. COMMAND ${LLVM_BINDIR}/clang-query -p ${CMAKE_BINARY_DIR} $$option ${SOURCES}
  87. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  88. COMMENT "Executing clang-query on Urho3D library source files")
  89. endif ()
  90. add_custom_target (ast
  91. COMMAND ${CMAKE_COMMAND} -E echo "Usage: option=-help make ast"
  92. COMMAND ${LLVM_BINDIR}/clang-check -p ${CMAKE_BINARY_DIR} $$option ${SOURCES}
  93. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  94. COMMENT "Executing clang-check on Urho3D library source files")
  95. add_custom_target (binding-ast
  96. COMMAND ${CMAKE_COMMAND} -E echo "Usage: option=-help make binding-ast"
  97. COMMAND ${LLVM_BINDIR}/clang-check -p ${CMAKE_BINARY_DIR} $$option ${BINDING_SOURCES}
  98. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  99. COMMENT "Executing clang-check on (existing) AngelScript API bindings source files")
  100. add_custom_target (annotate
  101. COMMAND ${CMAKE_BINARY_DIR}/bin/tool/clang/Annotator -p ${CMAKE_BINARY_DIR} ${SOURCES}
  102. DEPENDS Annotator
  103. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  104. COMMENT "Annotating Urho3D library source files")
  105. add_custom_target (autobinder
  106. COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/Source/Urho3D/generated
  107. 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}
  108. DEPENDS AutoBinder
  109. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  110. COMMENT "Auto-binding for all script subsystems")
  111. add_custom_target (autobinder-angelscript
  112. COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/Source/Urho3D/generated
  113. 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}
  114. DEPENDS AutoBinder
  115. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  116. COMMENT "Auto-binding for AngelScript")
  117. add_custom_target (autobinder-luascript
  118. COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/Source/Urho3D/generated
  119. 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}
  120. DEPENDS AutoBinder
  121. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  122. COMMENT "Auto-binding for LuaScript")
  123. add_custom_target (autobinder-javascript
  124. COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/Source/Urho3D/generated
  125. 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}
  126. DEPENDS AutoBinder
  127. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
  128. COMMENT "Auto-binding for JavaScript")
  129. endif ()