Browse Source

Avoid hardcoding to improve the chance of using it on Windows host.
[ci annotate]

Yao Wei Tjong 姚伟忠 10 years ago
parent
commit
f2289b10e1

+ 1 - 1
.travis.yml

@@ -177,7 +177,7 @@ env:
 before_script:
   - export TRAVIS_COMMIT=$TRAVIS_COMMIT~
   - export COMMIT_MESSAGE=$(git log --format=%B -n 1 $TRAVIS_COMMIT)
-  - git clone --depth 1 https://github.com/urho3d/fastcomp-clang.git && export FASTCOMP_CLANG_ROOT=$(pwd)/fastcomp-clang
+  - git clone --depth 1 https://github.com/urho3d/fastcomp-clang.git && export LLVM_CLANG_ROOT=$(pwd)/fastcomp-clang
   - export PATH=$(whereis -b ccache |grep -o '\S*lib\S*'):$PATH
   - export CXX=g++-4.9 CC=gcc-4.9
   - for compiler in gcc g++; do ln -s $(which ccache) $HOME/$compiler-4.9; done && export PATH=$HOME:$PATH

+ 21 - 8
CMake/Modules/Urho3D-CMake-common.cmake

@@ -45,7 +45,7 @@ endif ()
 include (CMakeDependentOption)
 option (URHO3D_C++11 "Enable C++11 standard")
 cmake_dependent_option (URHO3D_NOABI "If set then do not explicitly specify the ABI compiler flag for code generation (GCC and Clang only)" FALSE "NOT MSVC" FALSE)
-mark_as_advanced (URHO3D_NOABI)
+mark_as_advanced (URHO3D_C++11 URHO3D_NOABI)
 cmake_dependent_option (IOS "Setup build for iOS platform" FALSE "XCODE" FALSE)
 if (NOT MSVC AND NOT DEFINED URHO3D_DEFAULT_64BIT)  # Only do this once in the initial configure step
     # On non-MSVC compiler, default to build 64-bit when the host system has a 64-bit build environment
@@ -250,6 +250,25 @@ if (CMAKE_VERSION VERSION_GREATER 2.8 OR CMAKE_VERSION VERSION_EQUAL 2.8)
     endif ()
 endif()
 
+# Clang tools building
+if (URHO3D_CLANG_TOOLS)
+    # Ensure LLVM/Clang is installed
+    find_program (LLVM_CONFIG NAMES llvm-config llvm-config-64 llvm-config-32 HINTS $ENV{LLVM_CLANG_ROOT}/bin DOC "LLVM config tool" NO_CMAKE_FIND_ROOT_PATH)
+    if (NOT LLVM_CONFIG)
+        message (FATAL_ERROR "Could not find LLVM/Clang installation")
+    endif ()
+    # Require C++11 standard and no precompiled-header
+    set (URHO3D_C++11 1)
+    set (URHO3D_PCH 0)
+    # Set build options that would maximise the AST of Urho3D library
+    foreach (OPT URHO3D_ANGELSCRIPT URHO3D_LUA URHO3D_FILEWATCHER URHO3D_PROFILING URHO3D_LOGGING URHO3D_NAVIGATION URHO3D_NETWORK URHO3D_PHYSICS URHO3D_URHO2D URHO3D_DATABASE_SQLITE)
+        set (${OPT} 1)
+    endforeach()
+    foreach (OPT URHO3D_TESTING URHO3D_LUAJIT URHO3D_DATABASE_ODBC)
+        set (${OPT} 0)
+    endforeach()
+endif ()
+
 # Enable testing
 if (URHO3D_TESTING)
     enable_testing ()
@@ -390,12 +409,6 @@ if (URHO3D_DATABASE_SQLITE)
     add_definitions (-DURHO3D_DATABASE -DURHO3D_DATABASE_SQLITE)
 endif ()
 
-# Clang tools building requires C++11 standard
-if (URHO3D_CLANG_TOOLS)
-    set (URHO3D_C++11 1)
-    set (URHO3D_PCH 0)
-endif ()
-
 # Find Direct3D include & library directories in MS Windows SDK or DirectX SDK when not using OpenGL.
 if (WIN32 AND NOT URHO3D_OPENGL)
     find_package (Direct3D REQUIRED)
@@ -573,7 +586,7 @@ else ()
             set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics -Qunused-arguments")
         endif ()
         # Temporary workaround for Travis CI VM as Ubuntu 12.04 LTS still uses old glibc header files that do not have the necessary patch for Clang to work correctly
-        # TODO: Remove this workaround when Travis CI VM has been migrated to Ubuntu 14.04 LTS (or hopefully it will be CentOS :)
+        # TODO: Remove this workaround when Travis CI VM has been migrated to Ubuntu 14.04 LTS
         if (DEFINED ENV{CI} AND "$ENV{LINUX}")
             add_definitions (-D__extern_always_inline=inline)
         endif ()

+ 6 - 6
Docs/GettingStarted.dox

@@ -283,17 +283,17 @@ If "URHO3D_DOCS" build option is set then a normal build would not only build Ur
 
 The prerequisites are Doxygen and Graphviz. Tools to dump the \ref ScriptAPI "AngelScript API" for the default \ref Script "scripting" subsystem and the \ref LuaScriptAPI "LuaScript API" (when the LuaScript subsystem is also enabled) are being built at the same time when all the native tools are built.
 
-\section Building_Shaders Compiling Direct3D shaders
+\section Building_Clang_tools Clang-tools build
 
-When building for Direct3D9 with the Windows 8 SDK (Visual Studio 2012+), copy d3dcompiler_46.dll from "C:\Program Files (x86)\Windows Kits\8.0\bin\x86" to build tree's "bin" directory so that Urho3D executables will run correctly. When building for Direct3D11, copy d3dcompiler_47.dll from "C:\Program Files (x86)\Windows Kits\8.1\bin\x86" to the "bin" directory. In both cases, if compiling Urho3D as 64-bit, copy from the "bin\x64" directory instead.
+If "URHO3D_CLANG_TOOLS" build option is set then CMake would generate a special build tree for the purpose of developing the Clang-tools. Before doing this, the development software package of LLVM/Clang must be already installed in the host system. Alternatively you can use built it from source and install it into the host system. If it is not installed in a system-wide installation location then use the LLVM_CLANG_ROOT environment variable to point to the root path of this custom location (the root is the parent directory containing the bin, lib, include and share subdirectories). If you have built Emscripten-SDK from its source in your host system then you can also just install the Fastcomp/Clang found inside the Emscripten-SDK by navigating to the Fastcomp/Clang build tree and issuing a 'make install' command as usual. Using Fastcomp/Clang is fine because we are only interested in using Clang as 3rd-party library instead of as compiler.
 
-OpenGL does not depend on a separate shader compiler DLL.
+Check the Source/Clang-Tools/CMakeLists.txt to get the list of targets currently available or under development. Normal build targets won't work properly in this special build tree. See also https://github.com/urho3d/Urho3D/issues/887 to find out more about the current development plan and leave a comment there if you would like to help to contribute the development.
 
-\section Building_Clang_tools Clang-tools build
+\section Building_Shaders Compiling Direct3D shaders
 
-If "URHO3D_CLANG_TOOLS" build option is set then CMake would generate a special build tree for the purpose of developing the Clang-tools. Normal build targets won't work in this special build tree. Before doing this, the development software package of LLVM/Clang or Fastcomp/Clang (from Emscripten-SDK) must be already installed in the host system. If using Fastcomp/Clang and it is not installed in the system-wide installation location then use the FASTCOMP_CLANG_ROOT environment variable to point to the root path of this custom location (the root is the parent directory containing the bin, lib, include and share subdirectories).
+When building for Direct3D9 with the Windows 8 SDK (Visual Studio 2012+), copy d3dcompiler_46.dll from "C:\Program Files (x86)\Windows Kits\8.0\bin\x86" to build tree's "bin" directory so that Urho3D executables will run correctly. When building for Direct3D11, copy d3dcompiler_47.dll from "C:\Program Files (x86)\Windows Kits\8.1\bin\x86" to the "bin" directory. In both cases, if compiling Urho3D as 64-bit, copy from the "bin\x64" directory instead.
 
-Check the Source/Clang-Tools/CMakeLists.txt to get the list of targets currently available or under development. See also https://github.com/urho3d/Urho3D/issues/887 to find out more about the current development plan and leave a comment there if you would like to help to contribute the development.
+OpenGL does not depend on a separate shader compiler DLL.
 
 \section Using_ccache Using ccache
 

+ 1 - 1
Rakefile

@@ -197,7 +197,7 @@ end
 # Usage: NOT intended to be used manually
 desc 'Build and run the annotate migration tool'
 task :annotate do
-  system 'rake cmake URHO3D_CLANG_TOOLS=1 URHO3D_LUA=1 URHO3D_DATABASE_SQLITE=1 && rake make annotate' or abort 'Failed to annotate'
+  system 'rake cmake URHO3D_CLANG_TOOLS=1 && rake make annotate' or abort 'Failed to annotate'
 end
 
 # Usage: NOT intended to be used manually (if you insist then try: rake ci)

+ 0 - 7
Source/Clang-Tools/Annotator/CMakeLists.txt

@@ -26,13 +26,6 @@ set (TARGET_NAME Annotator)
 # Define source files
 define_source_files ()
 
-# Define dependency libs
-set (LIBS clangRewriteFrontend clangStaticAnalyzerFrontend clangTooling clangStaticAnalyzerCheckers clangStaticAnalyzerCore
-        clangFrontend clangDriver clangParse clangSerialization clangSema clangEdit clangAnalysis clangASTMatchers clangAST
-        clangToolingCore clangRewrite clangLex clangBasic
-        LLVMBitReader LLVMCore LLVMMC LLVMOption LLVMMCParser LLVMSupport
-        z tinfo)
-
 # Setup target
 if (APPLE)
     setup_macosx_linker_flags (CMAKE_EXE_LINKER_FLAGS)

+ 20 - 8
Source/Clang-Tools/CMakeLists.txt

@@ -23,10 +23,10 @@
 # Set project name
 project (Urho3D-Clang-Tools)
 
-# Fastcomp/Clang libs and headers are assumed to be installed in system-wide location when not explicitily defined using env-var
-if (DEFINED ENV{FASTCOMP_CLANG_ROOT})
-    link_directories ($ENV{FASTCOMP_CLANG_ROOT}/lib)
-    include_directories ($ENV{FASTCOMP_CLANG_ROOT}/include)
+# LLVM/Clang libs and headers are assumed to be installed in system-wide location when not explicitily defined using env-var
+if (DEFINED ENV{LLVM_CLANG_ROOT})
+    link_directories ($ENV{LLVM_CLANG_ROOT}/lib)
+    include_directories ($ENV{LLVM_CLANG_ROOT}/include)
 endif ()
 
 # No exception and no RTTI
@@ -39,14 +39,26 @@ endif ()
 # All tools must be natively built and output to bin/tool subdir to differentiate them from target platfrom binaries in the bin directory
 set_tool_output_directories ()
 
-add_subdirectory (Annotator)
-
-# Add a custom target to start the annotate task
+# Define source files for the tools
 get_target_property (SOURCES Urho3D SOURCES)
 string (REGEX REPLACE "[^;]+\\.h" "" SOURCES "${SOURCES}")   # Stringify to preserve the semicolons
 string (REGEX REPLACE "[^;]+generated[^;]+\\.cpp" "" SOURCES "${SOURCES}")
+
+# Define common dependency libs
+set (LIBS clangRewriteFrontend clangStaticAnalyzerFrontend clangTooling clangStaticAnalyzerCheckers clangStaticAnalyzerCore
+        clangFrontend clangDriver clangParse clangSerialization clangSema clangEdit clangAnalysis clangASTMatchers clangAST
+        clangToolingCore clangRewrite clangLex clangBasic
+        LLVMBitReader LLVMCore LLVMMC LLVMOption LLVMMCParser LLVMSupport)
+execute_process (COMMAND ${LLVM_CONFIG} --system-libs OUTPUT_VARIABLE LLVM_SYSLIBS OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
+string (REGEX REPLACE " *-l" ";" LLVM_SYSLIBS "${LLVM_SYSLIBS}")   # Stringify against empty output variable
+list (APPEND LIBS ${LLVM_SYSLIBS})
+
+# List of tools
+add_subdirectory (Annotator)
+
+# List of targets
 add_custom_target (annotate
-    COMMAND ${CMAKE_BINARY_DIR}/bin/tool/Annotator -ast-dump -ast-dump-filter=Urho3D::Audio -p ${CMAKE_BINARY_DIR} Audio/Audio.cpp   # just dump Audio.cpp for now -- ${SOURCES}
+    COMMAND ${CMAKE_BINARY_DIR}/bin/tool/Annotator -ast-dump -ast-dump-filter=Urho3D -p ${CMAKE_BINARY_DIR} ${SOURCES} >NULL_DEVICE
     DEPENDS Annotator
     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Source/Urho3D
     COMMENT "Annotating Urho3D library source files")

+ 8 - 8
Source/Urho3D/CMakeLists.txt

@@ -25,15 +25,15 @@ set (TARGET_NAME Urho3D)
 
 # Generate JSON compilation database format specification
 if (URHO3D_CLANG_TOOLS)
-    if (DEFINED ENV{FASTCOMP_CLANG_ROOT})
-        set (FASTCOMP_CLANG_ROOT $ENV{FASTCOMP_CLANG_ROOT})
-    else ()
-        set (FASTCOMP_CLANG_ROOT /usr/local)    # FIXME: Not sure where is the default system-wide location on Windows
-    endif ()
-    file (STRINGS ${FASTCOMP_CLANG_ROOT}/include/clang/Basic/Version.inc CLANG_VERSION REGEX "#define CLANG_VERSION ")
-    string (REPLACE "#define CLANG_VERSION " "" CLANG_VERSION ${CLANG_VERSION})
-    include_directories (${FASTCOMP_CLANG_ROOT}/lib/clang/${CLANG_VERSION}/include)
     set (CMAKE_EXPORT_COMPILE_COMMANDS 1)
+    execute_process (COMMAND ${LLVM_CONFIG} --version OUTPUT_VARIABLE LLVM_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
+    string (REGEX REPLACE "([.0123456789]+).*" \\1 LLVM_VERSION "${LLVM_VERSION}")      # Stringify against empty output variable
+    execute_process (COMMAND ${LLVM_CONFIG} --libdir OUTPUT_VARIABLE LLVM_LIBDIR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
+    include_directories (${LLVM_LIBDIR}/clang/${LLVM_VERSION}/include)
+    # TODO: Remove this workaround when Travis CI VM has been migrated to Ubuntu 14.04 LTS
+    if (DEFINED ENV{CI})
+        add_definitions (-D__extern_always_inline=inline)
+    endif ()
 endif ()
 
 add_definitions (-DURHO3D_IS_BUILDING)