[PATCH] D61660: [cmake] Make google benchmark project call llvm_add_library

Don Hinton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 8 09:51:42 PDT 2019


hintonda updated this revision to Diff 198689.
hintonda added a comment.

- Fix cut-n-paste typo.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61660/new/

https://reviews.llvm.org/D61660

Files:
  llvm/utils/benchmark/CMakeLists.txt
  llvm/utils/benchmark/src/CMakeLists.txt


Index: llvm/utils/benchmark/src/CMakeLists.txt
===================================================================
--- llvm/utils/benchmark/src/CMakeLists.txt
+++ 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)
Index: llvm/utils/benchmark/CMakeLists.txt
===================================================================
--- llvm/utils/benchmark/CMakeLists.txt
+++ llvm/utils/benchmark/CMakeLists.txt
@@ -1,12 +1,26 @@
 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 )
+  # 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61660.198689.patch
Type: text/x-patch
Size: 2450 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190508/aa229d30/attachment.bin>


More information about the llvm-commits mailing list