Skip to content

Commit 7a12835

Browse files
author
Paul Bowen-Huggett
committed
Fix a cmake error when using the Xcode generator.
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 09fa2f0 (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.
1 parent 97ff961 commit 7a12835

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

clang/cmake/modules/AddClang.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@ macro(add_clang_library name)
109109
llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
110110

111111
if(MSVC AND NOT CLANG_LINK_CLANG_DYLIB)
112-
# Make sure all consumers also turn off visibility macros so there not trying to dllimport symbols.
112+
# Make sure all consumers also turn off visibility macros so they're not
113+
# trying to dllimport symbols.
113114
target_compile_definitions(${name} PUBLIC CLANG_BUILD_STATIC)
114115
if(TARGET "obj.${name}")
115116
target_compile_definitions("obj.${name}" PUBLIC CLANG_BUILD_STATIC)
116117
endif()
117-
elseif(NOT ARG_SHARED AND NOT ARG_STATIC)
118-
# Clang component libraries linked in to clang-cpp are declared without SHARED or STATIC
118+
elseif(TARGET "obj.${name}" AND NOT ARG_SHARED AND NOT ARG_STATIC)
119+
# Clang component libraries linked to clang-cpp are declared without SHARED or STATIC
119120
target_compile_definitions("obj.${name}" PUBLIC CLANG_EXPORTS)
120121
endif()
121122

0 commit comments

Comments
 (0)