Repository: conan-io/conan-center-index

Issue:
[package] wayland/1.20.0:build fail when cross build from linux x86_64 to linux arm64
### Package and Environment Details

* Package Name/Version: **wayland/1.20.0**
* Operating System+version: **Linux Ubuntu 16.04**
* Compiler+version: **GCC 7.5 and linaro aarch64-linux-gnu-gcc 7.5**
* Docker image: **zvicii/gcc7-arm64-ubuntu16.04-jenkins(based on conanio/gcc7-ubuntu16.04-jenkins)**
* Conan version: **conan 1.49.0**
* Python version: **Python 3.7.13**


### Conan profile

```
Configuration (profile_host):
[settings]
arch=armv8
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=14
compiler.libcxx=libstdc++11
compiler.version=7
os=Linux
os_build=Linux
[options]
[build_requires]
[env]
AR=aarch64-linux-gnu-ar
AS=aarch64-linux-gnu-as
CC=aarch64-linux-gnu-gcc
CMAKE_CXX_COMPILER=aarch64-linux-gnu-g++
CMAKE_C_COMPILER=aarch64-linux-gnu-gcc
CXX=aarch64-linux-gnu-g++
FC=aarch64-linux-gnu-gfortran
LD=aarch64-linux-gnu-ld
RANLIB=aarch64-linux-gnu-ranlib
STRIP=aarch64-linux-gnu-strip
```
```
Configuration (profile_build):
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=14
compiler.libcxx=libstdc++11
compiler.version=7
os=Linux
[options]
[build_requires]
[env]
AR=ar
AS=as
CC=gcc
CMAKE_CXX_COMPILER=g++
CMAKE_C_COMPILER=gcc
CXX=g++
FC=gfortran
LD=ld
RANLIB=ranlib
STRIP=strip
```

### Steps to reproduce

My project requires qt, and build qt as static lib, so it will build wayland.
Im cross building from linux x86_64 to linux arm64, as you can see from the two profiles.

when build wayland, the log says its not cross building, and do a sanity check. and no doubt it would fail since the executable is built by aarch64-linux-gnu-gcc, so its meant for arm64 platform.
```
/home/conan/.conan/data/wayland/1.20.0/_/_/build/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb/build_subfolder/meson-private/sanitycheckc.exe: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=61f61f83a9cc22e2e73ef627ecaadef914792a27, stripped 
```

I try to make meson realize its cross building, but its beyond my knowledge.
So I turn to this community for help, many thanks.

### Logs

```
wayland/1.20.0: Applying build-requirement: meson/0.59.3
wayland/1.20.0: Applying build-requirement: ninja/1.10.2
wayland/1.20.0: Copying sources to build folder
wayland/1.20.0: Building your package in /home/conan/.conan/data/wayland/1.20.0/_/_/build/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb
wayland/1.20.0: Generator pkg_config created libffi.pc
wayland/1.20.0: Generator pkg_config created libxml-2.0.pc
wayland/1.20.0: Generator pkg_config created expat.pc
wayland/1.20.0: Generator pkg_config created zlib.pc
wayland/1.20.0: Generator pkg_config created libiconv.pc
wayland/1.20.0: Aggregating env generators
wayland/1.20.0: Calling build()
The Meson build system
Version: 0.59.3
Source dir: /home/conan/.conan/data/wayland/1.20.0/_/_/build/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb/source_subfolder
Build dir: /home/conan/.conan/data/wayland/1.20.0/_/_/build/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb/build_subfolder
Build type: native build
Project name: wayland
Project version: 1.20.0

source_subfolder/meson.build:1:0: ERROR: Could not invoke sanity test executable: [Errno 8] Exec format error: '/home/conan/.conan/data/wayland/1.20.0/_/_/build/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb/build_subfolder/meson-private/sanitycheckc.exe'.

A full log can be found at /home/conan/.conan/data/wayland/1.20.0/_/_/build/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb/build_subfolder/meson-logs/meson-log.txt
wayland/1.20.0: 
WARN: qt/5.15.4: requirement openssl/1.1.1o overridden by nim/None to openssl/1.1.1n 
WARN: qt/5.15.4: requirement icu/71.1 overridden by nim/None to icu/71.1 
WARN: fontconfig/2.13.93: requirement freetype/2.12.1 overridden by qt/5.15.4 to freetype/2.11.1 
WARN: xkbcommon/1.4.1: requirement wayland/1.20.0 overridden by qt/5.15.4 to wayland/1.20.0 
WARN: wayland/1.20.0: requirement libxml2/2.9.12 overridden by xkbcommon/1.4.1 to libxml2/2.9.14 
WARN: wayland/1.20.0: requirement expat/2.4.2 overridden by xkbcommon/1.4.1 to expat/2.4.8 
WARN: nim_tools_http/1.1.0-19-g98c6d593@yunxin/testing: requirement nebase/v3.7.0-159-gacc5dd86@yunxin/testing overridden by nim/None to nebase/v3.7.0-171-gc92da913@yunxin/testing 
WARN: nebase/v3.7.0-171-gc92da913@yunxin/testing: requirement zlib/1.2.11 overridden by nim_tools_http/1.1.0-19-g98c6d593@yunxin/testing to zlib/1.2.12 
WARN: libevent/2.1.12: requirement openssl/1.1.1m overridden by nebase/v3.7.0-171-gc92da913@yunxin/testing to openssl/1.1.1n 
WARN: libcurl/7.80.0: requirement openssl/1.1.1o overridden by nebase/v3.7.0-171-gc92da913@yunxin/testing to openssl/1.1.1n 
WARN: ne_phoenix/0.1.0-44-gc4880ff7@yunxin/testing: requirement zlib/1.2.11 overridden by h_available/1.5.1-4-gdf0190a1@yunxin/testing to zlib/1.2.12 
WARN: aws-sdk-cpp/1.9.234: requirement aws-c-common/0.6.19 overridden by h_available/1.5.1-4-gdf0190a1@yunxin/testing to aws-c-common/0.7.4 
WARN: aws-c-cal/0.5.13: requirement aws-c-common/0.6.19 overridden by aws-sdk-cpp/1.9.234 to aws-c-common/0.7.4 
WARN: aws-c-http/0.6.13: requirement aws-c-common/0.6.19 overridden by aws-sdk-cpp/1.9.234 to aws-c-common/0.7.4 
WARN: aws-c-compression/0.2.14: requirement aws-c-common/0.6.19 overridden by aws-c-http/0.6.13 to aws-c-common/0.7.4 
WARN: aws-c-io/0.10.20: requirement aws-c-common/0.6.19 overridden by aws-c-http/0.6.13 to aws-c-common/0.7.4 
WARN: aws-crt-cpp/0.17.23: requirement aws-c-common/0.6.19 overridden by aws-sdk-cpp/1.9.234 to aws-c-common/0.7.4 
WARN: aws-c-event-stream/0.2.7: requirement aws-c-common/0.6.19 overridden by aws-crt-cpp/0.17.23 to aws-c-common/0.7.4 
WARN: aws-c-event-stream/0.2.7: requirement aws-c-io/0.11.2 overridden by aws-crt-cpp/0.17.23 to aws-c-io/0.10.20 
WARN: aws-checksums/0.1.12: requirement aws-c-common/0.6.19 overridden by aws-c-event-stream/0.2.7 to aws-c-common/0.7.4 
WARN: aws-c-auth/0.6.11: requirement aws-c-common/0.6.19 overridden by aws-crt-cpp/0.17.23 to aws-c-common/0.7.4 
WARN: aws-c-sdkutils/0.1.2: requirement aws-c-common/0.6.19 overridden by aws-c-auth/0.6.11 to aws-c-common/0.7.4 
WARN: aws-c-mqtt/0.7.10: requirement aws-c-common/0.6.19 overridden by aws-crt-cpp/0.17.23 to aws-c-common/0.7.4 
WARN: aws-c-s3/0.1.37: requirement aws-c-common/0.6.19 overridden by aws-crt-cpp/0.17.23 to aws-c-common/0.7.4 
wayland/1.20.0: WARN: Package binary is corrupted, removing: e7fe6d00c2e8fadd056c0ec4c294fa6925173acb
wayland/1.20.0: WARN: Build folder is dirty, removing it: /home/conan/.conan/data/wayland/1.20.0/_/_/build/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb
wayland/1.20.0: ERROR: Package 'e7fe6d00c2e8fadd056c0ec4c294fa6925173acb' build failed
wayland/1.20.0: WARN: Build folder /home/conan/.conan/data/wayland/1.20.0/_/_/build/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb
ERROR: wayland/1.20.0: Error in build() method, line 89
        meson = self._configure_meson()
while calling '_configure_meson', line 83
        args=["--datadir={}".format(os.path.join(self.package_folder, "res"))]
        ConanException: Error 1 while executing meson "/home/conan/.conan/data/wayland/1.20.0/_/_/build/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb/source_subfolder" "/home/conan/.conan/data/wayland/1.20.0/_/_/build/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb/build_subfolder" --backend=ninja -Dprefix="/home/conan/.conan/data/wayland/1.20.0/_/_/package/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb" -Dlibdir="lib" -Dbindir="bin" -Dsbindir="bin" -Dlibexecdir="bin" -Dincludedir="include" -Ddefault_library="static" -Db_staticpic="true" -Dlibraries="true" -Ddtd_validation="true" -Ddocumentation="false" -Dtests="false" -Dscanner="true" '--datadir=/home/conan/.conan/data/wayland/1.20.0/_/_/package/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb/res' --buildtype=release
CMake Error at build/conan.cmake:651 (message):
  Conan install failed='1'
Call Stack (most recent call first):
  CMakeLists.txt:88 (conan_cmake_install)


-- Configuring incomplete, errors occurred!
See also "/home/conan/workspace/nim-cross-platform-sdk/build/CMakeFiles/CMakeOutput.log".
```
```
Build started at 2022-06-23T04:23:51.757696
Main binary: /opt/pyenv/versions/3.7.13/bin/python3
Build Options: -Dprefix=/home/conan/.conan/data/wayland/1.20.0/_/_/package/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb -Dlibdir=lib -Dbindir=bin -Dsbindir=bin -Dlibexecdir=bin -Dincludedir=include -Ddefault_library=static -Db_staticpic=true -Dlibraries=true -Ddtd_validation=true -Ddocumentation=false -Dtests=false -Dscanner=true -Ddatadir=/home/conan/.conan/data/wayland/1.20.0/_/_/package/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb/res -Dbackend=ninja -Dbuildtype=release
Python system: Linux
The Meson build system
Version: 0.59.3
Source dir: /home/conan/.conan/data/wayland/1.20.0/_/_/build/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb/source_subfolder
Build dir: /home/conan/.conan/data/wayland/1.20.0/_/_/build/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb/build_subfolder
Build type: native build
Project name: wayland
Project version: 1.20.0
Sanity testing C compiler: aarch64-linux-gnu-gcc
Is cross compiler: False.
Sanity check compiler command line: aarch64-linux-gnu-gcc sanitycheckc.c -o sanitycheckc.exe -O3 -s -fPIC -I/home/conan/.conan/data/libffi/3.4.2/_/_/package/8fd38d381db52e2495321ce060b9f457656f6c8f/include -I/home/conan/.conan/data/libxml2/2.9.14/_/_/package/567a33571ec0f7e332612d29d3ba19e5b4564386/include -I/home/conan/.conan/data/libxml2/2.9.14/_/_/package/567a33571ec0f7e332612d29d3ba19e5b4564386/include/libxml2 -I/home/conan/.conan/data/expat/2.4.8/_/_/package/8ca280ee2b2069bbe2754a427afd38b56aff1751/include -I/home/conan/.conan/data/zlib/1.2.12/_/_/package/8fd38d381db52e2495321ce060b9f457656f6c8f/include -I/home/conan/.conan/data/libiconv/1.16/_/_/package/8fd38d381db52e2495321ce060b9f457656f6c8f/include -DXML_STATIC -DLIBXML_STATIC -DFFI_BUILDING -DNDEBUG -D_FILE_OFFSET_BITS=64 -L/home/conan/.conan/data/libffi/3.4.2/_/_/package/8fd38d381db52e2495321ce060b9f457656f6c8f/lib -L/home/conan/.conan/data/libxml2/2.9.14/_/_/package/567a33571ec0f7e332612d29d3ba19e5b4564386/lib -L/home/conan/.conan/data/expat/2.4.8/_/_/package/8ca280ee2b2069bbe2754a427afd38b56aff1751/lib -L/home/conan/.conan/data/zlib/1.2.12/_/_/package/8fd38d381db52e2495321ce060b9f457656f6c8f/lib -L/home/conan/.conan/data/libiconv/1.16/_/_/package/8fd38d381db52e2495321ce060b9f457656f6c8f/lib
Sanity check compile stdout:

-----
Sanity check compile stderr:

-----
Running test binary command: /home/conan/.conan/data/wayland/1.20.0/_/_/build/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb/build_subfolder/meson-private/sanitycheckc.exe

source_subfolder/meson.build:1:0: ERROR: Could not invoke sanity test executable: [Errno 8] Exec format error: '/home/conan/.conan/data/wayland/1.20.0/_/_/build/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb/build_subfolder/meson-private/sanitycheckc.exe'.

```


Discussion:
In case it helps, I have been able to cross-compile the `wayland` package using the `MesonToolchain` generator in [my fork](https://github.com/jwillikers/conan-center-index/tree/wayland-tool-requires-wayland). FYI it requires Conan 1.50.0.
Can you now cross-compile the `wayland` package?
unfortunately it failed with following error
```
Found pkg-config: /usr/bin/pkg-config (0.29.1)
Found CMake: /opt/pyenv/versions/3.7.13/bin/cmake (3.22.5)
Build-time dependency wayland-scanner found: NO (tried cmake)

../src/meson.build:73:1: ERROR: Could not generate cargs for wayland-scanner:
Package expat was not found in the pkg-config search path.
Perhaps you should add the directory containing `expat.pc'
to the PKG_CONFIG_PATH environment variable
Package 'expat', required by 'wayland-scanner', not found
```

I tried add env variable, still no luck
```
export PKG_CONFIG_PATH="/home/conan/.conan/data/wayland/1.20.0/_/_/build/e7fe6d00c2e8fadd056c0ec4c294fa6925173acb/build-release/conan"
```
I get a similar issue when trying to use `sdl/2.0.20`. My setup (not cross-compiling) is described in https://github.com/conan-io/conan-center-index/issues/11889. NOTE: sdl depends on wayland which depends on expat.

Now I get an error when linking with SDL:
```CMake Error at CMakeLists.txt:73 (add_executable):
  Target "EpicFreeGames" links to target "EXPAT::EXPAT" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?
```

My CMake code looks like this:
```cmake
# Unrelated stuff...
find_package(SDL2 REQUIRED)
add_executable(EpicFreeGames WIN32) # Line 73
target_link_libraries(EpicFreeGames PRIVATE SDL2::SDL2)
target_sources(EpicFreeGames PRIVATE src/main.cc)
```

The issue seems to be (this is a guess) that wayland specifies it depends on `expat::expat` (https://github.com/conan-io/conan-center-index/blob/master/recipes/wayland/all/conanfile.py#L112) but expat defines its target name as `EXPAT::EXPAT`. Well, kinda, it looks like it depends on the specific generator being used: https://github.com/conan-io/conan-center-index/blob/master/recipes/expat/all/conanfile.py#L94-L102

In my case I'm using `cmake_find_package` (not `_multi`)
Shouldn't it be `EXPAT::EXPAT` to match the built-in `FindEXPAT` CMake find module?
Soo I'm not too sure, maybe? I simply link to SDL, which then brings wayland which depends on expat, I'm not sure what exactly goes wrong here 😕
(I updated my last comment to add slightly more context)
@andoalon What happens if you use the CMakeDeps / CMakeToolchain generators? I bet this is a problem with the deprecated `cmake` generators.
I'm not familiar with the CMakeDeps / CMakeToolchain generators? Can I easily switch to them? How are they different from cmake_find_package / cmake_find_package_multi (the generators I'm using)?
@andoalon please, read https://docs.conan.io/en/latest/migrating_to_2.0/recipes.html#the-generate-method and https://docs.conan.io/en/latest/reference/conanfile/tools/cmake/cmaketoolchain.html

Basically, `CMakeToolchain` generates a toolchain cmake file, with all settings and `CMakeDeps` generates Findxxx.cmake files. So you no longer need to `conan_basic_setup` or inject any stuff to your CMakeLists.txt 
Thank you, I'm quite busy these days, I'll take a look when I have time 😅

I do have a kinda unrelated question though: so far I've been using `conan.cmake` (+some wrappers of mine) so that cmake drives the build, and I only need to directly interact with cmake (not conan). My question is: is such a setup posible using `CMakeDeps` and `CMakeToolchain` generators? Is it possible to maybe `include(...)` a cmake toolchain file directly from cmake, instead of using `-DCMAKE_TOOLCHAIN_FILE=...`? Otherwise the setup would no longer be viable 🤔

From what I understand the goal of these generators is for conan to be the one driving the build (being on top of cmake, not the other way around), is that correct?
No, it's not possible to combine `conan.cmake` with those new generators. There is more information about the support on the project's readme: https://github.com/conan-io/cmake-conan/blob/develop/README.md

In short, probably there will be, but it will take time (months).
I'm trying to reproduce this bug, but the first thing which does not match:

wayland/1.20.0 requires expat/2.4.8, which depends on Conan 1.50.0. However, the description says you are running Conan 1.49.0. How is it? 

Resolving patch:
diff --git a/recipes/wayland/all/conanfile.py b/recipes/wayland/all/conanfile.py
--- a/recipes/wayland/all/conanfile.py
+++ b/recipes/wayland/all/conanfile.py
@@ -56,7 +56,7 @@ def build_requirements(self):
         self.tool_requires("meson/0.63.0")
         self.tool_requires("pkgconf/1.7.4")
         if cross_building(self):
-            self.tool_requires(f"wayland/{self.version}")
+            self.tool_requires(self.ref)
 
     def layout(self):
         basic_layout(self)
@@ -82,8 +82,9 @@ def generate(self):
             if cross_building(self):
                 native_generators_folder = os.path.join(self.generators_folder, "native")
                 mkdir(self, native_generators_folder)
-                for pc_name, pc_content in get_pc_files_and_content(self, self.dependencies.build["wayland"]).items():
-                    save(self, os.path.join(native_generators_folder, pc_name), pc_content)
+                for target in ["wayland", "expat", "libxml2", "libiconv"]:
+                    for pc_name, pc_content in get_pc_files_and_content(self, self.dependencies.build[target]).items():
+                        save(self, os.path.join(native_generators_folder, pc_name), pc_content)
                 tc.project_options["build.pkg_config_path"] = native_generators_folder
         tc.generate()
 
@@ -165,7 +166,7 @@ def package_info(self):
             # todo Remove in Conan version 1.50.0 where these are set by default for the PkgConfigDeps generator.
             self.cpp_info.components["wayland-client"].includedirs = ["include"]
             self.cpp_info.components["wayland-client"].libdirs = ["lib"]
-            
+
             pkgconfig_variables = {
                 'datarootdir': '${prefix}/res',
                 'pkgdatadir': '${datarootdir}/wayland',
@@ -201,3 +202,7 @@ def package_info(self):
             # todo Remove in Conan version 1.50.0 where these are set by default for the PkgConfigDeps generator.
             self.cpp_info.components["wayland-egl-backend"].includedirs = ["include"]
             self.cpp_info.components["wayland-egl-backend"].libdirs = ["lib"]
+
+            bindir = os.path.join(self.package_folder, "bin")
+            self.output.info("Appending PATH environment variable: {}".format(bindir))
+            self.env_info.PATH.append(bindir)


Test patch:
diff --git a/recipes/wayland/all/test_package/CMakeLists.txt b/recipes/wayland/all/test_package/CMakeLists.txt
--- a/recipes/wayland/all/test_package/CMakeLists.txt
+++ b/recipes/wayland/all/test_package/CMakeLists.txt
@@ -1,11 +1,7 @@
 cmake_minimum_required(VERSION 3.15)
-project(test_package)
+project(test_package C)
 
 find_package(wayland COMPONENTS wayland-client REQUIRED)
-find_program(WAYLAND_SCANNER wayland-scanner)
-if (NOT WAYLAND_SCANNER)
-    message(FATAL_ERROR "Could not find wayland-scanner executable")
-endif()
 
 add_executable(test_package test_package.c)
 target_link_libraries(test_package PRIVATE wayland::wayland-client)
diff --git a/recipes/wayland/all/test_package/conanfile.py b/recipes/wayland/all/test_package/conanfile.py
--- a/recipes/wayland/all/test_package/conanfile.py
+++ b/recipes/wayland/all/test_package/conanfile.py
@@ -9,16 +9,16 @@
 
 class TestPackageConan(ConanFile):
     settings = "os", "compiler", "build_type", "arch"
-    generators = "CMakeToolchain", "CMakeDeps", "PkgConfigDeps", "VirtualBuildEnv", "VirtualRunEnv"
+    generators = "CMakeToolchain", "CMakeDeps", "PkgConfigDeps", "VirtualRunEnv"
 
     def layout(self):
         cmake_layout(self)
 
     def build(self):
-        cmake = CMake(self)
-        cmake.configure()
-        cmake.build()
         if not cross_building(self):
+            cmake = CMake(self)
+            cmake.configure()
+            cmake.build()
             pkg_config = PkgConfig(self, "wayland-scanner", self.generators_folder)
             self.run('%s --version' % pkg_config.variables["wayland_scanner"], env="conanrun")
 
diff --git a/recipes/wayland/all/test_v1_package/CMakeLists.txt b/recipes/wayland/all/test_v1_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/wayland/all/test_v1_package/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.15)
+project(test_package C)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup(TARGETS)
+
+find_package(wayland REQUIRED CONFIG)
+
+add_executable(test_package ../test_package/test_package.c)
+target_link_libraries(test_package PRIVATE wayland::wayland-client)
diff --git a/recipes/wayland/all/test_v1_package/conanfile.py b/recipes/wayland/all/test_v1_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/wayland/all/test_v1_package/conanfile.py
@@ -0,0 +1,21 @@
+import os
+
+from conan import ConanFile
+from conan.tools.build import cross_building
+from conans import CMake
+
+
+class TestPackageConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake", "cmake_find_package_multi"
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def test(self):
+        if not cross_building(self):
+            self.run("wayland-scanner --version", run_environment=True)
+            cmd = os.path.join(self.build_folder, "bin", "test_package")
+            self.run(cmd, run_environment=True)