[libclc] [CMake][libclc] Improve dependencies to avoid build errors (PR #95018)

Tim Creech via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 11 09:35:51 PDT 2024


tcreech-intel wrote:

Yes, the article you link to is highly relevant. Without this PR we're hitting the problem described in example <span>#</span>4.

We can promote the issue to a build failure by choosing a custom command which can't run concurrently with itself:
```cmake
cmake_minimum_required(VERSION 3.2)

add_custom_command(
    OUTPUT gen
    # Try to grab a lock and fail immediately if we can't:
    COMMAND flock -x -n gen.lock sleep 1
    COMMAND cmake -E echo Hello > gen
    )

add_custom_target(
    my-all-1 ALL DEPENDS gen
    )

add_custom_target(
    my-all-2 ALL DEPENDS gen
    )
```

With the above `make` will succeed, but `make -j2` will fail. The issue is not exposed with Ninja.
This is the same behavior I see in libclc today, except more jobs are needed.
Adding an intermediate target and depending on both the new target and the file does seem to fix all of our problems.

I've added the file dependencies back in b707fc7dea2e, and I think it fixes the build issue while preserving the incremental build behavior you described.
Could you please give it a try?


https://github.com/llvm/llvm-project/pull/95018


More information about the cfe-commits mailing list