[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 10:13:23 PDT 2019


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

- Move cmake_miniimum_required and policies into project conditional, and change test to check for llvm_add_library instead of project name.


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,22 +1,36 @@
+# 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 )
 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)
-endif()
+  # 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)
+  project (benchmark)
 
-foreach(p
-    CMP0054 # CMake 3.1
-    CMP0056 # export EXE_LINKER_FLAGS to try_run
-    CMP0057 # Support no if() IN_LIST operator
-    )
-  if(POLICY ${p})
-    cmake_policy(SET ${p} NEW)
-  endif()
-endforeach()
+	foreach(p
+      CMP0054 # CMake 3.1
+      CMP0056 # export EXE_LINKER_FLAGS to try_run
+      CMP0057 # Support no if() IN_LIST operator
+      )
+    if(POLICY ${p})
+      cmake_policy(SET ${p} NEW)
+    endif()
+  endforeach()
+endif()
+
+if(COMMAND llvm_add_library)
+  function(benchmark_add_library target)
+    llvm_add_library(${target} ${ARGN})
+  endfunction()
+else()
+  function(benchmark_add_library target)
+    add_library(${target} ${ARGN})
+  endfunction()
+endif()
 
 option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON)
 option(BENCHMARK_ENABLE_EXCEPTIONS "Enable the use of exceptions in the benchmark library." ON)


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


More information about the llvm-commits mailing list