https://github.com/paulhuggett created 
https://github.com/llvm/llvm-project/pull/119403

I’m seeing a series of errors when trying to run the cmake configure step on 
macOS when the cmake generator is set to Xcode. All is well if I use the Ninja 
or Unix Makefile generators. Messages are all of the form:
~~~
CMake Error at …llvm-project/clang/cmake/modules/AddClang.cmake:120 
(target_compile_definitions):
  Cannot specify compile definitions for target "obj.clangBasic" which
  is not built by this project.
Call Stack (most recent call first):
  …llvm-project/clang/lib/Basic/CMakeLists.txt:57 (add_clang_library)
~~~
The remaining errors mention targets obj.clangAPINotes, obj.clangLex, 
obj.clangParse, and so on.

The regression appears to have been introduced by commit 09fa2f012fcc (Oct 14 
2024) which added the code in this area.

My proposed solution is simply to add a test to ensure that the obj.x target 
exists before setting its compile definitions. There is precedent doing just 
this in both clang/cmake/modules/AddClang.cmake and 
clang/lib/support/CMakeLists.txt as well as in the “MSVC AND NOT 
CLANG_LINK_CLANG_DYLIB” path immediately above the offending line.

I’ve also made a couple of grammatical tweaks in the comments surrounding this 
code.

>From 7a1283573d487a3a1b499c55408448c4f667f3d0 Mon Sep 17 00:00:00 2001
From: Paul Bowen-Huggett <phugg...@keysom.io>
Date: Tue, 10 Dec 2024 16:48:34 +0100
Subject: [PATCH] Fix a cmake error when using the Xcode generator.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

I’m seeing a series of errors when trying to run the cmake configure
step when the cmake generator is set to Xcode. All is well if I use
the Ninja or Unix Makefile generators. Messages are all of the form:

  CMake Error at
  …llvm-project/clang/cmake/modules/AddClang.cmake:120 
(target_compile_definitions):
  Cannot specify compile definitions for target "obj.clangBasic" which
  is not built by this project.
  Call Stack (most recent call first):
  …llvm-project/clang/lib/Basic/CMakeLists.txt:57 (add_clang_library)

The remaining errors mention targets obj.clangAPINotes, obj.clangLex,
obj.clangParse, and so on.

The regression appears to have been introduced by commit
09fa2f012fcc (Oct 14 2024) which added the code in this area.

My proposed solution is simply to add a test to ensure that the obj.x
target exists before setting its compile definitions. There is
precedent doing just this in both clang/cmake/modules/AddClang.cmake
and clang/lib/support/CMakeLists.txt as well as in the “MSVC AND NOT
CLANG_LINK_CLANG_DYLIB” path immediately above the offending line.

I’ve also made a couple of grammatical tweaks in the comments
surrounding this code.
---
 clang/cmake/modules/AddClang.cmake | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/cmake/modules/AddClang.cmake 
b/clang/cmake/modules/AddClang.cmake
index 091aec98e93ca3..cdc8bd5cd503b4 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -109,13 +109,14 @@ macro(add_clang_library name)
   llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
 
   if(MSVC AND NOT CLANG_LINK_CLANG_DYLIB)
-    # Make sure all consumers also turn off visibility macros so there not 
trying to dllimport symbols.
+    # Make sure all consumers also turn off visibility macros so they're not
+    # trying to dllimport symbols.
     target_compile_definitions(${name} PUBLIC CLANG_BUILD_STATIC)
     if(TARGET "obj.${name}")
       target_compile_definitions("obj.${name}" PUBLIC CLANG_BUILD_STATIC)
     endif()
-  elseif(NOT ARG_SHARED AND NOT ARG_STATIC)
-    # Clang component libraries linked in to clang-cpp are declared without 
SHARED or STATIC
+  elseif(TARGET "obj.${name}" AND NOT ARG_SHARED AND NOT ARG_STATIC)
+    # Clang component libraries linked to clang-cpp are declared without 
SHARED or STATIC
     target_compile_definitions("obj.${name}" PUBLIC CLANG_EXPORTS)
   endif()
 

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to