How to partially disabling cmake C/C++ custom compiler checking

谁说我不能喝 提交于 2019-12-17 19:55:32

问题


I am trying to do some crosscompilation using cmake. Some are easy with all the examples on Internet, I managed to crosscompile my library on Linux (x86 and ARM), Windows and Android. But now I would like to do it on a custom platform.

The process I need to achieve:

  1. Sourcing my environment (this destroy all previous bash classic environment)
  2. Compile with cmake
  3. Execute what I want

But Cmake is testing for symbols in my custom C/C++ libraries which make my library unable to compile. The errors I have are that cmake some versions of GLIBCXX and CXXABI (no C issues) but not all of them.

Is there a way to make cmake ok with it ?

EDIT:

I tried using:

set(CMAKE_C_COMPILER_WORKS TRUE)
set(CMAKE_CXX_COMPILER_WORKS TRUE)

And with:

include(CMakeForceCompiler)
...
cmake_force_c_compiler(${ENV_PATH}/bin/${CC})
cmake_force_cxx_compiler(${ENV_PATH}/bin/${CXX})

But cmake is still checking for symbols.


回答1:


Without having your environment nor the error message it's not easy to tell the actual root cause but here are two of the common causes and respective fixes:

  1. If you don't have a complete toolchain file created for your custom environment - so CMake can't link a simple test program - you can try the relatively new (version 3.6) global CMake variable named CMAKE_TRY_COMPILE_TARGET_TYPE.

    So just add the following:

    set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
    

    Then CMake would just try to build a static library.

  2. To have only the most common GCC compiler variables set and have only some basic checks, try:

    SET(CMAKE_SYSTEM_NAME Generic)
    

    See CMake Cross Compiling: Setting up the system and toolchain:

    If your target is an embedded system without OS set CMAKE_SYSTEM_NAME to "Generic"

References

  • CMake AMRCC + custom linker
  • cmake cross-compile with specific linker doesn't pass arguments to armlink



回答2:


Commandline:

    cmake ... \
    -DCMAKE_C_COMPILER_FORCED=TRUE \
    -DCMAKE_CXX_COMPILER_FORCED=TRUE

or

CMakeLists.txt

    ...
    set(CMAKE_C_COMPILER_FORCED TRUE)
    set(CMAKE_CXX_COMPILER_FORCED TRUE)
    ...

Works for me.



来源:https://stackoverflow.com/questions/38700198/how-to-partially-disabling-cmake-c-c-custom-compiler-checking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!