From 76b7103fed9782fb9dc7ee01fd68a9a53e382631 Mon Sep 17 00:00:00 2001 From: Henrique Jung Date: Sun, 1 Oct 2017 03:26:42 -0300 Subject: [PATCH] [CMake] Build LLVM from the submodule if there's no suitable version When RPCS3 is compiled with LLVM (default option), CMake only tries to find LLVM on the default system installation. So the OS must have a sytstem-wide installation of LLVM of at least version 4.0, which is not available on many GNU/Linux distributions (e.g. Ubuntu 16.04, Debian Stretch). If CMake can not find a suitable version, it silently falls back to compile RPCS3 without LLVM. This patch makes CMake defaults to compile the LLVM submodule if and only if a suitable LLVM version is not found installed on the system. Due to a build time check on LLVM, in-tree builds will not work when building the submodule (LLVM does not allow in-source builds). For this reason, the instruction for building on CMake were updated. --- README.md | 3 ++- rpcs3/CMakeLists.txt | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e95be45ff8..c505a9cba8 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,8 @@ To initialize the repository don't forget to execute `git submodule update --ini 1) `git clone https://github.com/RPCS3/rpcs3.git`
2) `cd rpcs3/`
3) `git submodule update --init`
-4) `cmake CMakeLists.txt && make GitVersion && make`
+4) `cd ../ && mkdir rpcs3_build && cd rpcs3_build` +4) `cmake ../rpcs3/ && make GitVersion && make`
5) Run RPCS3 with `./bin/rpcs3`
If you are on MacOS and want to build with brew llvm and qt don't forget to add the following environment variables diff --git a/rpcs3/CMakeLists.txt b/rpcs3/CMakeLists.txt index d093c4c9dd..641be7d324 100644 --- a/rpcs3/CMakeLists.txt +++ b/rpcs3/CMakeLists.txt @@ -166,6 +166,29 @@ find_package(OpenGL REQUIRED) find_package(OpenAL REQUIRED) if (NOT WITHOUT_LLVM) find_package(LLVM 4.0 CONFIG) + if (NOT LLVM_FOUND) + message("System LLVM was not found, LLVM will be built from the submodule.") + + set(LLVM_TARGETS_TO_BUILD "X86" CACHE INTERNAL "") + option(LLVM_BUILD_RUNTIME OFF) + option(LLVM_BUILD_TOOLS OFF) + option(LLVM_INCLUDE_DOCS OFF) + option(LLVM_INCLUDE_EXAMPLES OFF) + option(LLVM_INCLUDE_TESTS OFF) + option(LLVM_INCLUDE_TOOLS OFF) + option(LLVM_INCLUDE_UTILS OFF) + option(WITH_POLLY OFF) + + # LLVM needs to be built out-of-tree + add_subdirectory(../llvm ../llvm_build) + set(LLVM_DIR "${CMAKE_CURRENT_BINARY_DIR}/../llvm_build/lib/cmake/llvm/") + + # now tries to find LLVM again + find_package(LLVM 4.0 CONFIG) + if (NOT LLVM_FOUND) + message(WARNING "Couldn't build LLVM from the submodule. You might need to run `git submodule update --init`") + endif() + endif() endif()