diff --git a/llvm/utils/benchmark/CMakeLists.txt b/llvm/utils/benchmark/CMakeLists.txt --- a/llvm/utils/benchmark/CMakeLists.txt +++ b/llvm/utils/benchmark/CMakeLists.txt @@ -1,12 +1,27 @@ cmake_minimum_required (VERSION 2.8.12) -# Tell cmake 3.0+ that it's safe to clear the PROJECT_VERSION variable in the -# call to project() below. -if(POLICY CMP0048) - cmake_policy(SET CMP0048 NEW) +# If we are not building as a part of another project, e.g., LLVM, +# build Benchmark as an standalone project. +if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + project(Clang) + # Tell cmake 3.0+ that it's safe to clear the PROJECT_VERSION variable in the + # call to project() below. + if(POLICY CMP0048) + cmake_policy(SET CMP0048 NEW) + endif() + + project (benchmark) endif() -project (benchmark) +if(CMAKE_PROJECT_NAME STREQUAL "LLVM") + function(benchmark_add_library target) + llvm_add_library(${target} ${ARGN}) + endfunction() +else() + function(benchmark_add_library target) + add_library(${target} ${ARGN}) + endfunction() +endif() foreach(p CMP0054 # CMake 3.1 diff --git a/llvm/utils/benchmark/src/CMakeLists.txt b/llvm/utils/benchmark/src/CMakeLists.txt --- a/llvm/utils/benchmark/src/CMakeLists.txt +++ b/llvm/utils/benchmark/src/CMakeLists.txt @@ -16,7 +16,7 @@ list(REMOVE_ITEM SOURCE_FILES "${item}") endforeach() -add_library(benchmark ${SOURCE_FILES}) +benchmark_add_library(benchmark ${SOURCE_FILES}) set_target_properties(benchmark PROPERTIES OUTPUT_NAME "benchmark" VERSION ${GENERIC_LIB_VERSION} @@ -45,7 +45,7 @@ endif() # Benchmark main library -add_library(benchmark_main "benchmark_main.cc") +benchmark_add_library(benchmark_main "benchmark_main.cc") set_target_properties(benchmark_main PROPERTIES OUTPUT_NAME "benchmark_main" VERSION ${GENERIC_LIB_VERSION} @@ -77,8 +77,8 @@ "${version_config}" VERSION ${GIT_VERSION} COMPATIBILITY SameMajorVersion ) -configure_file("${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in" "${project_config}" @ONLY) -configure_file("${PROJECT_SOURCE_DIR}/cmake/benchmark.pc.in" "${pkg_config}" @ONLY) +configure_file("${CMAKE_CURRENT_LIST_DIR}/../cmake/Config.cmake.in" "${project_config}" @ONLY) +configure_file("${CMAKE_CURRENT_LIST_DIR}/../cmake/benchmark.pc.in" "${pkg_config}" @ONLY) if (BENCHMARK_ENABLE_INSTALL) # Install target (will install the library to specified CMAKE_INSTALL_PREFIX variable)