CMakeLists.txt 7.9 KB

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