intel / intel/intel-graphics-compiler
cmake variable errors
- Dominant language
- C++
- Stars
- 718
- Forks
- 191
- PR merge metrics
- No merged PRs in 30d
Description
While trying to build in-tree using stock llvm-project sources I noted the following things:
1. `IGC_OPTION__lld_SOURCES_DIR` variable name
2. `libunwind` dependency to `DEFAULT_IGC_LLVM_SOURCES_DIR`
3. `IGC_OPTION__*_SOURCES_DIR:UNINITIALIZED=` variable declared as `UNITIALIZED` instead of `PATH`
4. `DEFAULT_IGC_LLVM_SOURCES_DIR` declared as `DEFAULT_IGC_LLVM_SOURCES_DIR-NOTFOUND` by default
5. `This is allowed only when policy CMP0079 is set to NEW` error
6. And multiple others...
I was able to navigate around all of the issues found. For others that may be in a similar scenario and affected by this feel free to have a look at my resulting configuration at https://github.com/SynoCommunity/spksrc/pull/6166/files#diff-23723854ab26778948b751518e7e79cfd297e803ce1cdb8ba97732e235457170 - note that I've left as many comments as I could to get the gist of the issues found.
## Details
### 1. `lld` source variables uses a mixture of uppercase and lowercase:
```
CMAKE_ARGS += -DIGC_OPTION__LLD_MODE='Source'
CMAKE_ARGS += -DIGC_OPTION__lld_SOURCES_DIR=$(WORK_DIR)/llvm-project/lld
```
Note here the mandatory lowercase of `lld` in `IGC_OPTION__lld_SOURCES_DIR` variable. If using it with uppercase it won't find it resulting in inhability to copy files over. Also note that enforcing `DEFAULT_IGC_LLVM_SOURCES_DIR` somehow fixes this although the appropriate thing to do is to use the lowercase `IGC_OPTION__lld_SOURCES_DIR`. Here is the error otherwise (either using uppercase variable name or not enforcing `DEFAULT_IGC_LLVM_SOURCES_DIR`):
```
-- [lld] lld will be built from sources
-- [lld] Copying stock lld sources to /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/intel-graphics-compiler-igc-1.0.17384.9/build/IGC/llvm-deps-14.0.5/src/lld
CMake Error: cmake version 3.25.1
Usage: /usr/bin/cmake -E [arguments...]
Available commands:
capabilities - Report capabilities built into cmake in JSON format
cat [--] ... - concat the files and print them to the standard output
chdir dir cmd [args...] - run command in a given directory
compare_files [--ignore-eol] file1 file2
- check if file1 is same as file2
copy ... destination - copy files to destination (either file or directory)
copy_directory ... destination - copy content of ... directories to 'destination' directory
copy_if_different ... destination - copy files if it has changed
echo [...] - displays arguments as text
echo_append [...] - displays arguments as text but no new line
env [--unset=NAME ...] [NAME=VALUE ...] [--] [...]
- run command in a modified environment
environment - display the current environment
make_directory ... - create parent and directories
md5sum ... - create MD5 checksum of files
sha1sum ... - create SHA1 checksum of files
sha224sum ... - create SHA224 checksum of files
sha256sum ... - create SHA256 checksum of files
sha384sum ... - create SHA384 checksum of files
sha512sum ... - create SHA512 checksum of files
remove [-f] ... - remove the file(s), use -f to force it (deprecated: use rm instead)
remove_directory ... - remove directories and their contents (deprecated: use rm instead)
rename oldname newname - rename a file or directory (on one volume)
rm [-rRf] [--] ... - remove files or directories, use -f to force it, r or R to remove directories and their contents recursively
sleep ... - sleep for given number of seconds
tar [cxt][vf][zjJ] file.tar [file/dir1 file/dir2 ...]
- create or extract a tar or zip archive
time command [args...] - run command and display elapsed time
touch ... - touch a .
touch_nocreate ... - touch a but do not create it.
create_symlink old new - create a symbolic link new -> old
create_hardlink old new - create a hard link new -> old
true - do nothing with an exit code of 0
false - do nothing with an exit code of 1
```
Notice the output in the `CMakeCache.txt`:
```
$ grep _SOURCES_DIR build/CMakeCache.txt DEFAULT_IGC_LLVM_SOURCES_DIR:PATH=DEFAULT_IGC_LLVM_SOURCES_DIR-NOTFOUND
IGC_OPTION__CLANG_SOURCES_DIR:UNINITIALIZED=/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/clang
IGC_OPTION__LLD_SOURCES_DIR:UNINITIALIZED=/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/lld
IGC_OPTION__LLVM_SOURCES_DIR:PATH=/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project
IGC_OPTION__VC_INTRINSICS_SOURCES_DIR:UNINITIALIZED=/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/vc-intrinsics
IGC_OPTION__lld_SOURCES_DIR:PATH=
```
Work-around:
a. Use lowercase such as `-DIGC_OPTION__lld_SOURCES_DIR:PATH=`
b. Only define `-DIGC_OPTION__LLD_MODE='Source'` and let IGC build auto-detect remaining.
### 2. `libunwind` has no associated variables (its not even mentionned in the doc). It is rather somehow associated to `lld` resulting in the following error:
```
^[[31mCMake Error at external/llvm/llvm_lld_source_hook.cmake:56 (file):
file COPY cannot find
"/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/intel-graphics-compiler-igc-1.0.17384.9/IGC/DEFAULT_IGC_LLVM_SOURCES_DIR-NOTFOUND/libunwind/include/mach-o/compact_unwind_encoding.h":
No such file or directory.
Call Stack (most recent call first):
external/llvm/llvm_deps.cmake:52 (include)
IGC/CMakeLists.txt:1327 (include)
```
Work-around:
- Again, enforcing `-DDEFAULT_IGC_LLVM_SOURCES_DIR=$(WORK_DIR)/llvm-project` somehow fixes this. Suggesting instead to have a `IGC_OPTION__LIBUNWIND_SOURCES_DIR` to avoid depending on `DEFAULT_IGC_LLVM_SOURCES_DIR`
### 3. `_SOURCES_DIR` are captured as `UNINITIALIZED` rather than `PATH`.
Work-around:
- Enforcing `:PATH` when setting the variables solves that. Here's the `CMakeCache.txt` with and without:
With:
```
$ grep _SOURCES_DIR build/CMakeCache.txt DEFAULT_IGC_LLVM_SOURCES_DIR:PATH=DEFAULT_IGC_LLVM_SOURCES_DIR-NOTFOUND
IGC_OPTION__CLANG_SOURCES_DIR:PATH=/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/clang
IGC_OPTION__LLVM_SOURCES_DIR:PATH=/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project
IGC_OPTION__VC_INTRINSICS_SOURCES_DIR:PATH=/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/vc-intrinsics
IGC_OPTION__lld_SOURCES_DIR:PATH=/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/lld
```
Without:
```
$ grep _SOURCES_DIR build/CMakeCache.txt
DEFAULT_IGC_LLVM_SOURCES_DIR:PATH=DEFAULT_IGC_LLVM_SOURCES_DIR-NOTFOUND
IGC_OPTION__CLANG_SOURCES_DIR:UNINITIALIZED=/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/clang
IGC_OPTION__LLVM_SOURCES_DIR:PATH=/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project
IGC_OPTION__VC_INTRINSICS_SOURCES_DIR:UNINITIALIZED=/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/vc-intrinsics
IGC_OPTION__lld_SOURCES_DIR:UNINITIALIZED=/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/lld
```
### 4. `DEFAULT_IGC_LLVM_SOURCES_DIR` always being undefined by default such as:
```
DEFAULT_IGC_LLVM_SOURCES_DIR:PATH=DEFAULT_IGC_LLVM_SOURCES_DIR-NOTFOUND
```
Interestingly due to the `libunwind` issue I ended-up needing to define that anyway.
### 5. Lastly, I'm getting the following errors at the end of the configuration process
Work-around:
a. The first issue is that I was combining symlinks under `llvm/projects` pointing to `opencl-clang` and `llvm-spirv` in conjunction with:
```
-DLLVM_EXTERNAL_PROJECTS='llvm-spirv;opencl-clang'
-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR=$(WORK_DIR)/SPIRV-LLVM-Translator
-DLLVM_EXTERNAL_OPENCL_CLANG_SOURCE_DIR=$(WORK_DIR)/opencl-clang
```
But really this has to be either one or the other. It hapens that IGC does not behave well with `-DLLVM_EXTERNAL_` definitions so removing them and only keeping symlinks solved that.
b. Relatively to `See documentation for policy CMP0* for more details.`, I've tried multiple conbinations of `-DCMAKE_POLICY_DEFAULT_CMP0*='OLD|NEW'` as even if configuration would complete, it would still fail at build time. At the end of it the only method to I've found to solve that was to stop using `Ninja` and rely on `CMake` for the build process. Using that it now works.
Logs details:
```
-- Found Python3: /usr/bin/python3 (found suitable version "3.11.2", minimum required is "3.0") found components: Interpreter
-- Linker detection: GNU ld
-- Setting native build dir to /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/intel-graphics-compiler-igc-1.0.17384.9/build/IGC/llvm-deps-14.0.5/build/src/NATIVE
-- Performing Test HAS_WERROR_GLOBAL_CTORS
-- Performing Test HAS_WERROR_GLOBAL_CTORS - Failed
-- Found Git: /usr/bin/git (found version "2.39.2")
-- Targeting X86
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.1")
-- Using SPIR-V Headers from
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/SPIRV-Headers
-- Checking for one of the modules 'SPIRV-Tools'
-- [OPENCL-CLANG] Using Clang source code direcotry: /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/intel-graphics-compiler-igc-1.0.17384.9/build/IGC/llvm-deps-14.0.5/src/clang
-- [OPENCL-CLANG] Using SPIRV-LLVM-Translator source code directory: /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/SPIRV-LLVM-Translator
-- APPLY_PATCHES is disabled, skip patch apply process.
-- Looking for sys/resource.h
-- Looking for sys/resource.h - found
-- Clang version: 14.0.5
-- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG
-- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG - Failed
-- Looking for include file sys/inotify.h
-- Looking for include file sys/inotify.h - found
-- Not building amdgpu-arch: hsa-runtime64 not found
-- LLD version: 14.0.5
-- Using SPIR-V Headers from
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/SPIRV-Headers
CMake Error at /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/cmake/modules/AddLLVM.cmake:552 (add_library):
add_library cannot create target "LLVMSPIRVLib" because another target with
the same name already exists. The existing target is a static library
created in source directory
"/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/projects/llvm-spirv/lib/SPIRV".
See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/cmake/modules/AddLLVM.cmake:812 (llvm_add_library)
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/SPIRV-LLVM-Translator/lib/SPIRV/CMakeLists.txt:1 (add_llvm_library)
CMake Error at /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/cmake/modules/AddLLVM.cmake:676 (target_link_libraries):
Attempt to add link library "LLVMAnalysis" to target "LLVMSPIRVLib" which
is not built in this directory.
This is allowed only when policy CMP0079 is set to NEW.
Call Stack (most recent call first):
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/cmake/modules/AddLLVM.cmake:812 (llvm_add_library)
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/SPIRV-LLVM-Translator/lib/SPIRV/CMakeLists.txt:1 (add_llvm_library)
CMake Error at /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/cmake/modules/AddLLVM.cmake:728 (add_custom_target):
add_custom_target cannot create target "install-LLVMSPIRVLib" because
another target with the same name already exists. The existing target is a
custom target created in source directory
"/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/projects/llvm-spirv/lib/SPIRV".
See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/cmake/modules/AddLLVM.cmake:846 (add_llvm_install_targets)
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/SPIRV-LLVM-Translator/lib/SPIRV/CMakeLists.txt:1 (add_llvm_library)
CMake Error at /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/cmake/modules/AddLLVM.cmake:893 (add_executable):
add_executable cannot create target "llvm-spirv" because another target
with the same name already exists. The existing target is an executable
created in source directory
"/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/projects/llvm-spirv/tools/llvm-spirv".
See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/cmake/modules/AddLLVM.cmake:1248 (add_llvm_executable)
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/SPIRV-LLVM-Translator/tools/llvm-spirv/CMakeLists.txt:12 (add_llvm_tool)
CMake Error at /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/cmake/modules/LLVM-Config.cmake:107 (target_link_libraries):
Attempt to add link library "LLVMSPIRVLib" to target "llvm-spirv" which is
not built in this directory.
This is allowed only when policy CMP0079 is set to NEW.
Call Stack (most recent call first):
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/cmake/modules/LLVM-Config.cmake:95 (explicit_llvm_config)
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/cmake/modules/AddLLVM.cmake:942 (llvm_config)
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/cmake/modules/AddLLVM.cmake:1248 (add_llvm_executable)
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/SPIRV-LLVM-Translator/tools/llvm-spirv/CMakeLists.txt:12 (add_llvm_tool)
CMake Error at /home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/cmake/modules/AddLLVM.cmake:954 (target_link_libraries):
Attempt to add link library "-lpthread" to target "llvm-spirv" which is not
built in this directory.
This is allowed only when policy CMP0079 is set to NEW.
Call Stack (most recent call first):
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/llvm-project/llvm/cmake/modules/AddLLVM.cmake:1248 (add_llvm_executable)
/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/SPIRV-LLVM-Translator/tools/llvm-spirv/CMakeLists.txt:12 (add_llvm_tool)
CMake Error at external/llvm/CMakeLists.txt:53 (get_directory_property):
get_directory_property DIRECTORY argument provided but requested directory
not found. This could be because the directory argument was invalid or, it
is valid but has not been processed yet.
CMake Error at external/llvm/CMakeLists.txt:55 (message):
Found LLVM version: ; however preferred was: 14.0.5
Please set IGC_OPTION__LLVM_PREFERRED_VERSION to or pass
IGC_OPTION__LLVM_SOURCES_DIR with preferred version
-- Configuring incomplete, errors occurred!
See also "/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/intel-graphics-compiler-igc-1.0.17384.9/build/CMakeFiles/CMakeOutput.log".
See also "/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler/work-x64-7.1/intel-graphics-compiler-igc-1.0.17384.9/build/CMakeFiles/CMakeError.log".
make[2]: *** [../../mk/spksrc.cross-cmake.mk:150: cmake_configure_target] Error 1
make[2]: Leaving directory '/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler'
make[1]: *** [../../mk/spksrc.supported.mk:71: build-arch-x64-7.1] Error 1
make[1]: Leaving directory '/home/spksrc/ffmpeg-opencl-140/spksrc/cross/intel-graphics-compiler'
```
Contributor guide
Assessment
This issue has not been assessed yet.