0

I am trying to cross compile a library with CMake. The target platform is non-standard. The library several try_compile commands. In particular, the ones inside CheckTypeSize.cmake are failing. To have the compilation succeed, I need to change the flags and link libraries that those try_compile command uses (and I do not want to modify the CMake installation). It seems as though the (undocumented) CMAKE_REQUIRED_LIBRARIES and CMAKE_REQUIRED_FLAGS are used within that module. In the toolchain file, I do:

set(CMAKE_REQUIRED_FLAGS "/DLL")

Unfortunately, I want to set a flag that starts with /D (in this case /DLL). When I do this, the variable gets translated into /D LL. Is there any way to indicate to CMake that the string shouldn't be parsed into a compile define?

MuertoExcobito
  • 9,741
  • 2
  • 37
  • 78
  • Show us some minimal code, what module are you using that has undocumented stuff? – usr1234567 Aug 24 '16 at 18:48
  • well, I just mean that CMAKE_REQUIRED_FLAGS isn't documented, in the public documentation, only at the start of those cmake (internal) module files. – MuertoExcobito Aug 24 '16 at 18:57
  • My recommendation would be to update to CMake 3.6 and add `set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)`. Also see [here](http://stackoverflow.com/questions/38700198/how-to-partially-disabling-cmake-c-c-custom-compiler-checking) and [here](http://stackoverflow.com/questions/37931068/tell-cmake-to-use-c-compiler-for-c-files-coming-from-cmake). – Florian Aug 25 '16 at 07:51
  • @Florian - solves my problem - add it as an answer and I'll accept. – MuertoExcobito Aug 25 '16 at 14:37

1 Answers1

2

Turning my comment into an answer

Please don't use internal CMake commands. My recommendation in your case - try_compile not working in cross-compiling environment and the linker is throwing errors - is to update to CMake 3.6 and add

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

Then CMake's try_compile will only try static library linking (and not an executable).

References

Community
  • 1
  • 1
Florian
  • 39,996
  • 9
  • 133
  • 149