Hi, I am scratching my head trying to find out why checks with if(CMAKE_CROSSCOMPILING)
return false (running cmake version 3.18.2).
I am trying to cross compile pieces of the llvm-project with the following command-line in clean build folders:
cmake -GNinja \
"-H$LLVM_SRC_DIR/llvm" \
"-B$build_dir$suffix" \
-DCMAKE_INSTALL_PREFIX=$install_dir$suffix \
-DMLIR_TABLEGEN=$mlir_tablegen \
-DLLVM_INSTALL_UTILS=OFF \
-DLLVM_ENABLE_LLD=OFF \
-DLLVM_ENABLE_PROJECTS="mlir" \
-DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc-7 \
-DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++-7 \
-DCMAKE_CXX_FLAGS='-fcompare-debug-second' \
-DCMAKE_CROSSCOMPILING:BOOL=ON \
-DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabihf \
-DLLVM_TARGET_ARCH=ARM \
-DLLVM_TARGETS_TO_BUILD=ARM \
-DLLVM_BUILD_TOOLS=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
-DMLIR_INCLUDE_TESTS=OFF \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_BUILD_EXAMPLES=OFF
cmake --build "$build_dir$suffix" --target mlir_c_runner_utils mlir_runner_utils
Note the -DCMAKE_CROSSCOMPILING:BOOL=ON
option. This is correctly shown in CMakeCache.txt:
$ cat CMakeCache.txt | grep CROSS
CMAKE_CROSSCOMPILING:BOOL=ON
But when I try to message
or test the variable, it evaluates to FALSE
message (STATUS "!!! CMAKE_CROSSCOMPILING flag value: ${CMAKE_CROSSCOMPILING}")
if(CMAKE_CROSSCOMPILING)
message (STATUS "!!! Crosscompiling, SystemC api libraries are disabed")
else()
message (STATUS "!!! Not Crosscompiling, SystemC api libraries are enabled")
endif()
endif()
[0/1] Re-running CMake...
...
-- Targeting ARM
-- !!! CMAKE_CROSSCOMPILING flag value: FALSE
-- !!! Not Crosscompiling, SystemC api libraries are enabled
...
Should I be using a different approach to set and check CMAKE_CROSSCOMPILING?
It appears that some internal logic is overriding my variable.
I appreciate any help.
ps.: I was redirected here from this issue https://gitlab.kitware.com/cmake/cmake/-/issues/21744
ps.: Others have pointed similar problems (cmake - How do I detect that I am cross-compiling in CMakeLists.txt? - Stack Overflow). Their solution was to change it in CMakeLists.txt file, but I was trying to avoid this approach, favoring the usage of the -DCMAKE_CROSSCOMPILING option.