[PATCH] D137914: [cmake] Simplify llvm_update_compile_flags

Trass3r via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 13 14:44:58 PST 2022


Trass3r created this revision.
Trass3r added a reviewer: davezarzycki.
Herald added a project: All.
Trass3r requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Using modern CMake for language-specific flags.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137914

Files:
  llvm/cmake/modules/AddLLVM.cmake


Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -5,12 +5,7 @@
 include(DetermineGCCCompatible)
 
 function(llvm_update_compile_flags name)
-  get_property(sources TARGET ${name} PROPERTY SOURCES)
-  if("${sources}" MATCHES "\\.c(;|$)")
-    set(update_src_props ON)
-  endif()
-
-  list(APPEND LLVM_COMPILE_CFLAGS " ${LLVM_COMPILE_FLAGS}")
+  target_compile_options(${name} PRIVATE ${LLVM_COMPILE_FLAGS})
 
   # LLVM_REQUIRES_EH is an internal flag that individual targets can use to
   # force EH
@@ -54,31 +49,8 @@
     list(APPEND LLVM_COMPILE_FLAGS "/GR")
   endif()
 
-  # Assume that;
-  #   - LLVM_COMPILE_FLAGS is list.
-  #   - PROPERTY COMPILE_FLAGS is string.
-  string(REPLACE ";" " " target_compile_flags " ${LLVM_COMPILE_FLAGS}")
-  string(REPLACE ";" " " target_compile_cflags " ${LLVM_COMPILE_CFLAGS}")
-
-  if(update_src_props)
-    foreach(fn ${sources})
-      get_filename_component(suf ${fn} EXT)
-      if("${suf}" STREQUAL ".cpp")
-        set_property(SOURCE ${fn} APPEND_STRING PROPERTY
-          COMPILE_FLAGS "${target_compile_flags}")
-      endif()
-      if("${suf}" STREQUAL ".c")
-        set_property(SOURCE ${fn} APPEND_STRING PROPERTY
-          COMPILE_FLAGS "${target_compile_cflags}")
-      endif()
-    endforeach()
-  else()
-    # Update target props, since all sources are C++.
-    set_property(TARGET ${name} APPEND_STRING PROPERTY
-      COMPILE_FLAGS "${target_compile_flags}")
-  endif()
-
-  set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS ${LLVM_COMPILE_DEFINITIONS})
+  target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${LLVM_COMPILE_FLAGS}>)
+  target_compile_definitions(${name} PRIVATE ${LLVM_COMPILE_DEFINITIONS})
 endfunction()
 
 function(add_llvm_symbol_exports target_name export_file)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137914.475018.patch
Type: text/x-patch
Size: 1915 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221113/591638e5/attachment.bin>


More information about the llvm-commits mailing list