<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61975>61975</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
compiler-rt fails to configure for mips 32 bit due to definitions being seen as CMake options
</td>
</tr>
<tr>
<th>Labels</th>
<td>
compiler-rt,
backend:MIPS
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
DavidSpickett
</td>
</tr>
</table>
<pre>
This issue was seen in https://lab.llvm.org/staging/#/builders/214/builds/5185, info copied here for reference.
Using the following configuration:
```
cmake -G Ninja ../llvm/llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=True '-DLLVM_LIT_ARGS='"'"'-v'"'"'' -DCMAKE_INSTALL_PREFIX=../stage1.install -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_PARALLEL_LINK_JOBS=4 -DLLVM_TARGETS_TO_BUILD=Mips '-DLLVM_ENABLE_PROJECTS=llvm;clang;compiler-rt;clang-tools-extra'
```
Compiler RT tries to detect a multilib build of mips64 and mips32 and it does so using these flags:
```
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mips")
# FIXME: Ideally, we would build the N32 library too.
if("${COMPILER_RT_MIPS_EL}" AND ("${COMPILER_RT_MIPS32R6}" OR "${COMPILER_RT_MIPS64R6}"))
test_target_arch(mipsel "" "-mips32r6" "-mabi=32" "-D_LARGEFILE_SOURCE" "-D_FILE_OFFSET_BITS=64")
test_target_arch(mips64el "" "-mips64r6" "-mabi=64")
```
This is passed down to https://cmake.org/cmake/help/v3.20/module/CheckCSourceCompiles.html which then errors like this:
```
-- Performing Test COMPILER_RT_HAS_mipsel_BFLOAT16
CMake Error: Parse error in command line argument: _LARGEFILE_SOURCE
Should be: VAR:type=value
CMake Error at /usr/share/cmake-3.25/Modules/Internal/CheckSourceCompiles.cmake:94 (try_compile):
Failed to configure test project build system.
Call Stack (most recent call first):
/usr/share/cmake-3.25/Modules/CheckCSourceCompiles.cmake:76 (cmake_check_source_compiles)
/var/lib/buildbot/workers/debian-tritium-mips64el/clang-mips64el-linux/llvm/compiler-rt/lib/builtins/CMakeLists.txt:810 (check_c_source_compiles)
```
I believe this is because definitions `-D....` are passed as flags instead of using `CMAKE_REQUIRED_DEFINITIONS` to `check_c_source_compiles`.
Then somehow CMake thinks it's a CMake option not a compiler option. This may have worked in previous versions of CMake but it definitely doesn't with version 3.20.
You can reproduce this issue on another architecture by adding a `-DSOMETHING` to the architecture test flags.
The workaround for this is to build only for one architecture by adding the CMake options:
```
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON -DCMAKE_C_COMPILER_TARGET="<your target triple>"
```
(https://reviews.llvm.org/D147598 improves the error reporting in that situation but does not fix this issue overall)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMV1-TorrT_jTxpksLg6Jz4QUjsOs5_plX3VNnr6gAreRMIFYSdP32byXA7Lizs_WrmholaZLup59-umVa83ONuCDTZzKNBqwxpVSLiF15cbjw_BWNGWSyuC-OJdfAtW4QbkyDRqyB11Aac9HEDwlNCE0Ey0ZCXKuRVGdCE23Ymddnt-cTmmQNFwUqTWhCx5N-wT5Ox_MpoUvg9UlCLi8cCyhRIZykAoUnVFjnOCJeRLyw_f9N8_oMprQ2QsibfcplfeLnRjHDZW29au0Dr_tzj3nFXhGGX2DL6_8YjEbWcXGtug8YRstN-HecPn9braP0-P0lJn60R4FMIwyj9fqfTRpvw-d1nIaHQ7w_rnbbA_Gjo2oQCJ11JuvVMQ33X-wOoTNC6dv_4fWXBUJnb7eutodjuF6nL_s4Wf1L_Mj5Z5HE8YjX2jAh_uTFbtvvvoT7cL2O1-l6tf07_Wv3bLcn_e4x3H-Jj4f0uGsDJX604Rf9LoDu9Jf97q94ebQvO5T851yw-mw_ZXXhAtVQmX51aKQUeog_jGI2sN_hv-xeg_0RjOKowUgo0GBugEHVCMMFz8BxA-QJKn7RwQ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