zproject icon indicating copy to clipboard operation
zproject copied to clipboard

CMake relocation / cross compile support is broken

Open herbrechtsmeier opened this issue 6 years ago • 7 comments

The current CMake implementation doesn’t support cross compile via Yocto. CMake supports the relocation of its installation by default. The generated CMake build files breaks this feature because they contaminate the CMake targets with absolute paths. The find package modules should provide targets to forward the include directories and libraries to the CMake build targets. The CMake build targets should use these imported targets and the CMake package config should call find package on all required external libraries to provide all needed targets.

  • Create imported libraries in ‘Find$(use.project:c).cmake’ files
  • Add ‘find_package($(use.project) REQUIRED)’ calls for all ‘use’ items to the ‘Config.cmake.in’ file guarded by ‘@$(PROJECT.PREFIX)WITH$(USE.PROJECT)@’ if ‘use.optional’ is not 0
  • Use targets inside OPTIONAL_LIBRARIES variable

herbrechtsmeier avatar Jun 25 '19 09:06 herbrechtsmeier

Could you please send a PR to fix it?

bluca avatar Jun 25 '19 10:06 bluca

@bluca Could we update CMake minimum required version to 3.6 or higher? Many distributions have a higher version as 3.6. This version will allow use to use the IMPORTED_TARGET argument of pkg_check_modules to create a target per dependency.

herbrechtsmeier avatar Aug 26 '19 18:08 herbrechtsmeier

that's quite a big jump from 2.8 - can it be made optional by checking which version of cmake is being used? Then users with old versions won't have support removed

bluca avatar Aug 26 '19 18:08 bluca

The list of not supported distributions between 3.0 and 3.5 isn't that big. The 3.6 is a problem and CentOS is restricted to 2.8.12.

We have to check the code from the FindPkgConfig module and try to backport it.

herbrechtsmeier avatar Aug 26 '19 20:08 herbrechtsmeier

couldn't there simply be a check for the CMAKE version to use that feature? if it's new enough use it, if not don't

bluca avatar Aug 26 '19 20:08 bluca

Do you mean we should fix the issue only for newer CMake versions and otherwise fall back to the current behaviour?

herbrechtsmeier avatar Aug 27 '19 16:08 herbrechtsmeier

Yes - the problem in Yocto will be fixed, and we avoid breaking compatibility with CentOS/RHEL

bluca avatar Aug 27 '19 16:08 bluca