diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a5cf99631..69de5395fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,9 +6,14 @@ option(LLVM_SPIRV_INCLUDE_TESTS "Generate build targets for the llvm-spirv lit tests." ${LLVM_INCLUDE_TESTS}) -# check if we build inside llvm or not -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - set(BUILD_EXTERNAL YES) +if (NOT DEFINED LLVM_SPIRV_BUILD_EXTERNAL) + # check if we build inside llvm or not + if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(LLVM_SPIRV_BUILD_EXTERNAL YES) + endif(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) +endif (NOT DEFINED LLVM_SPIRV_BUILD_EXTERNAL) + +if(LLVM_SPIRV_BUILD_EXTERNAL) project(LLVM_SPIRV VERSION ${LLVM_SPIRV_VERSION} @@ -43,11 +48,7 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) include(AddLLVM) message(STATUS "Found LLVM: ${LLVM_VERSION}") -else(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - set(BUILD_EXTERNAL NO) -endif(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) -if(BUILD_EXTERNAL) find_program(CCACHE_EXE_FOUND ccache) if(CCACHE_EXE_FOUND) message(STATUS "Found ccache: ${CCACHE_EXE_FOUND}") diff --git a/README.md b/README.md index 96e20396e0..5e4fbcc0a1 100644 --- a/README.md +++ b/README.md @@ -38,13 +38,23 @@ make llvm-spirv -j`nproc` ### Build with pre-built LLVM -If you have a custom build(based on the latest version) of LLVM libraries you can link the translator against it. +If you have a custom build (based on the latest version) of LLVM libraries you +can link the translator against it. + ``` git clone https://github.com/KhronosGroup/SPIRV-LLVM-Translator.git mkdir SPIRV-LLVM-Translator/build && cd SPIRV-LLVM-Translator/build cmake .. -DLLVM_DIR=/lib/cmake/llvm/ make llvm-spirv -j`nproc` ``` + +If the translator is used as part of another CMake project, you will need +to define `LLVM_SPIRV_BUILD_EXTERNAL`: + +``` +cmake .. -DLLVM_DIR=/lib/cmake/llvm/ -DLLVM_SPIRV_BUILD_EXTERNAL=YES +``` + Where `llvm_build_dir` is the LLVM build directory. ### LLVM in-tree build diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 211f804c9d..3348c034ad 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -40,7 +40,7 @@ configure_lit_site_cfg( ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py ) -if(NOT BUILD_EXTERNAL) +if(NOT LLVM_SPIRV_BUILD_EXTERNAL) set(LLVM_SPIRV_TEST_DEPS FileCheck count @@ -63,7 +63,7 @@ if(NOT BUILD_EXTERNAL) llvm-readobj ) endif(NOT SPIRV_SKIP_DEBUG_INFO_TESTS) -endif(NOT BUILD_EXTERNAL) +endif(NOT LLVM_SPIRV_BUILD_EXTERNAL) add_lit_testsuite(check-llvm-spirv "Running the LLVM-SPIRV regression tests" @@ -77,7 +77,7 @@ add_lit_testsuite(check-llvm-spirv "Running the LLVM-SPIRV regression tests" # to enable a custom test target on cmake below 3.11 # starting with 3.11 "test" is only reserved if ENABLE_TESTING(ON) -if(BUILD_EXTERNAL) +if(LLVM_SPIRV_BUILD_EXTERNAL) cmake_policy(PUSH) if(POLICY CMP0037 AND ${CMAKE_VERSION} VERSION_LESS "3.11.0") cmake_policy(SET CMP0037 OLD) @@ -87,4 +87,4 @@ if(BUILD_EXTERNAL) check-llvm-spirv ) cmake_policy(POP) -endif(BUILD_EXTERNAL) +endif(LLVM_SPIRV_BUILD_EXTERNAL) diff --git a/tools/llvm-spirv/CMakeLists.txt b/tools/llvm-spirv/CMakeLists.txt index cf5541202f..9aa96d9c41 100644 --- a/tools/llvm-spirv/CMakeLists.txt +++ b/tools/llvm-spirv/CMakeLists.txt @@ -14,7 +14,7 @@ add_llvm_tool(llvm-spirv NO_INSTALL_RPATH ) -if (BUILD_EXTERNAL) +if (LLVM_SPIRV_BUILD_EXTERNAL) target_link_libraries(llvm-spirv PRIVATE LLVMSPIRVLib) endif()