[PATCH] D121035: [cmake] Use CMAKE_TRY_COMPILE_PLATFORM_VARIABLES

Shoaib Meenai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 4 17:56:57 PST 2022


smeenai created this revision.
smeenai added reviewers: mstorsjo, thakis, ychen.
Herald added a subscriber: mgorny.
Herald added a project: All.
smeenai requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Now that our minimum required CMake version is past 3.6, we can use
CMAKE_TRY_COMPILE_PLATFORM_VARIABLES instead of relying on environment
variable trickery. The two aren't entirely equivalent because
CMAKE_TRY_COMPILE_PLATFORM_VARIABLES is only used for try_compiles of
source files and not whole projects, but I ran LLVM configures before
and after this change and the generated CMakeCache.txt files were
identical, so this should be NFC for us.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121035

Files:
  llvm/cmake/platforms/WinMsvc.cmake


Index: llvm/cmake/platforms/WinMsvc.cmake
===================================================================
--- llvm/cmake/platforms/WinMsvc.cmake
+++ llvm/cmake/platforms/WinMsvc.cmake
@@ -83,21 +83,21 @@
 
 # When configuring CMake with a toolchain file against a top-level CMakeLists.txt,
 # it will actually run CMake many times, once for each small test program used to
-# determine what features a compiler supports.  Unfortunately, none of these
+# determine what features a compiler supports. By default, none of these
 # invocations share a CMakeCache.txt with the top-level invocation, meaning they
-# won't see the value of any arguments the user passed via -D.  Since these are
+# won't see the value of any arguments the user passed via -D. Since these are
 # necessary to properly configure MSVC in both the top-level configuration as well as
-# all feature-test invocations, we set environment variables with the values so that
-# these environments get inherited by child invocations. We can switch to
-# CMAKE_TRY_COMPILE_PLATFORM_VARIABLES once our minimum supported CMake version
-# is 3.6 or greater.
-function(init_user_prop prop)
-  if(${prop})
-    set(ENV{_${prop}} "${${prop}}")
-  else()
-    set(${prop} "$ENV{_${prop}}" PARENT_SCOPE)
-  endif()
-endfunction()
+# all feature-test invocations, we include them in CMAKE_TRY_COMPILE_PLATFORM_VARIABLES,
+# so that they get inherited by child invocations.
+list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
+  HOST_ARCH
+  LLVM_NATIVE_TOOLCHAIN
+  LLVM_WINSYSROOT
+  MSVC_VER
+  WINSDK_VER
+  winsdk_lib_symlinks_dir
+  winsdk_vfs_overlay_path
+  )
 
 function(generate_winsdk_vfs_overlay winsdk_include_dir output_path)
   set(include_dirs)
@@ -169,12 +169,6 @@
 set(CMAKE_SYSTEM_VERSION 10.0)
 set(CMAKE_SYSTEM_PROCESSOR AMD64)
 
-init_user_prop(HOST_ARCH)
-init_user_prop(LLVM_NATIVE_TOOLCHAIN)
-init_user_prop(LLVM_WINSYSROOT)
-init_user_prop(MSVC_VER)
-init_user_prop(WINSDK_VER)
-
 if(NOT HOST_ARCH)
   set(HOST_ARCH x86_64)
 endif()
@@ -269,11 +263,9 @@
 
 if(case_sensitive_filesystem)
   # Ensure all sub-configures use the top-level VFS overlay instead of generating their own.
-  init_user_prop(winsdk_vfs_overlay_path)
   if(NOT winsdk_vfs_overlay_path)
     set(winsdk_vfs_overlay_path "${CMAKE_BINARY_DIR}/winsdk_vfs_overlay.yaml")
     generate_winsdk_vfs_overlay("${WINSDK_INCLUDE}" "${winsdk_vfs_overlay_path}")
-    init_user_prop(winsdk_vfs_overlay_path)
   endif()
   list(APPEND COMPILE_FLAGS
        -Xclang -ivfsoverlay -Xclang "${winsdk_vfs_overlay_path}")
@@ -294,11 +286,9 @@
 
 if(case_sensitive_filesystem)
   # Ensure all sub-configures use the top-level symlinks dir instead of generating their own.
-  init_user_prop(winsdk_lib_symlinks_dir)
   if(NOT winsdk_lib_symlinks_dir)
     set(winsdk_lib_symlinks_dir "${CMAKE_BINARY_DIR}/winsdk_lib_symlinks")
     generate_winsdk_lib_symlinks("${WINSDK_LIB}/um/${WINSDK_ARCH}" "${winsdk_lib_symlinks_dir}")
-    init_user_prop(winsdk_lib_symlinks_dir)
   endif()
   list(APPEND LINK_FLAGS
        -libpath:"${winsdk_lib_symlinks_dir}")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121035.413180.patch
Type: text/x-patch
Size: 3086 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220305/a374fedc/attachment-0001.bin>


More information about the llvm-commits mailing list