From 2d6a5dd67f2fdc346e7ccba55643db30ecfd3a82 Mon Sep 17 00:00:00 2001 From: Julian Büning Date: Mon, 22 Oct 2018 15:42:49 +0200 Subject: CMake: enable reuse of LLVM's googletest src and targets Fixes an issue that occurs with USE_CMAKE_FIND_PACKAGE_LLVM=ON and LLVM compiled from sources, which then exports gtest and gtest_main targets. In case gtest and gtest_main targets are not imported from LLVM and GTEST_SRC_DIR is not set, CMake can now reuse the googletest sources from LLVM_BUILD_MAIN_SRC_DIR (if available) with USE_CMAKE_FIND_PACKAGE_LLVM=ON. This last limitation is due to LLVM making modifications to the CMakeLists.txt of googletest that requires add_llvm_library() from AddLLVM.cmake. --- cmake/find_llvm.cmake | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'cmake') diff --git a/cmake/find_llvm.cmake b/cmake/find_llvm.cmake index 02c99960..874bd1ae 100644 --- a/cmake/find_llvm.cmake +++ b/cmake/find_llvm.cmake @@ -20,8 +20,14 @@ option(USE_CMAKE_FIND_PACKAGE_LLVM "Use find_package(LLVM CONFIG) to find LLVM" OFF) if (USE_CMAKE_FIND_PACKAGE_LLVM) + # Use find_package() to detect LLVM in the user's environment. + # The user can force a particular copy by passing + # `-DLLVM_DIR=/path/to/LLVMConfig.cmake` to CMake. find_package(LLVM CONFIG REQUIRED) + list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") + include(AddLLVM) + # Provide function to map LLVM components to libraries. function(klee_get_llvm_libs output_var) llvm_map_components_to_libnames(${output_var} ${ARGN}) @@ -31,9 +37,8 @@ if (USE_CMAKE_FIND_PACKAGE_LLVM) set(LLVM_ENABLE_VISIBILITY_INLINES_HIDDEN OFF) else() # Use the llvm-config binary to get the information needed. - # Try to detect it in the user's environment. The user can - # force a particular binary by passing `-DLLVM_CONFIG_BINARY=/path/to/llvm-config` - # to CMake. + # Try to detect it in the user's environment. The user can force a particular + # binary by passing `-DLLVM_CONFIG_BINARY=/path/to/llvm-config` to CMake. find_program(LLVM_CONFIG_BINARY NAMES llvm-config) message(STATUS "LLVM_CONFIG_BINARY: ${LLVM_CONFIG_BINARY}") @@ -142,6 +147,11 @@ else() _run_llvm_config(LLVM_TOOLS_BINARY_DIR "--bindir") _run_llvm_config(TARGET_TRIPLE "--host-target") + _run_llvm_config(LLVM_BUILD_MAIN_SRC_DIR "--src-root") + if (NOT EXISTS "${LLVM_BUILD_MAIN_SRC_DIR}") + set(LLVM_BUILD_MAIN_SRC_DIR "") + endif() + # Provide function to map LLVM components to libraries. function(klee_get_llvm_libs OUTPUT_VAR) _run_llvm_config(_llvm_libs "--libfiles" ${ARGN}) -- cgit 1.4.1