[PATCH] D61387: [CMake] Cache result of CXXFeatureCheck

Chris Bieneman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 1 10:08:58 PDT 2019


beanz created this revision.
beanz added reviewers: phosek, smeenai.
Herald added subscribers: lebedev.ri, mgorny.
Herald added a reviewer: lebedev.ri.
Herald added a project: LLVM.

This check is actually pretty expensive. When cross-compiling it compiles and links, when not cross compiling it compiles, links and runs. By not caching this value we re-run the test every time cmake gets re-invoked.

In my local tests this change reduced iterative CMake executions from ~10.2 seconds to ~9.7 seconds.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61387

Files:
  llvm/utils/benchmark/cmake/CXXFeatureCheck.cmake


Index: llvm/utils/benchmark/cmake/CXXFeatureCheck.cmake
===================================================================
--- llvm/utils/benchmark/cmake/CXXFeatureCheck.cmake
+++ llvm/utils/benchmark/cmake/CXXFeatureCheck.cmake
@@ -22,8 +22,9 @@
   string(TOUPPER ${FILE} VAR)
   string(TOUPPER "HAVE_${VAR}" FEATURE)
   if (DEFINED HAVE_${VAR})
-    set(HAVE_${VAR} 1 PARENT_SCOPE)
-    add_definitions(-DHAVE_${VAR})
+    if(HAVE_${VAR})
+      add_definitions(-DHAVE_${VAR})
+    endif()
     return()
   endif()
 
@@ -52,7 +53,7 @@
 
   if(RUN_${FEATURE} EQUAL 0)
     message("-- Performing Test ${FEATURE} -- success")
-    set(HAVE_${VAR} 1 PARENT_SCOPE)
+    set(HAVE_${VAR} On CACHE BOOL "CXX feature test")
     add_definitions(-DHAVE_${VAR})
   else()
     if(NOT COMPILE_${FEATURE})
@@ -60,5 +61,6 @@
     else()
       message("-- Performing Test ${FEATURE} -- compiled but failed to run")
     endif()
+    set(HAVE_${VAR} Off CACHE BOOL "CXX feature test")
   endif()
 endfunction()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61387.197581.patch
Type: text/x-patch
Size: 1000 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190501/5e02a06c/attachment.bin>


More information about the llvm-commits mailing list