conan-io / conan-center-index

Recipes for the ConanCenter repository
https://conan.io/center
MIT License
958 stars 1.76k forks source link

[package] sdl_image/2.6.3#52a97d235594273a10267a0ca5b3f9ec: MinGW cross compiling static library not create preset #24695

Open radiofan opened 3 months ago

radiofan commented 3 months ago

Description

Hello. I try build program with static sdl_image/2.6.3 by MinGW on Arch Linux for Windows. Conan packets are installed successfully, but cmake preset failed. CMake try find sdl_image-static, because Conan think that my OS is Windows. https://github.com/conan-io/conan-center-index/blob/4f3d305b303c56e4c8537f620c6a9b4e6437783c/recipes/sdl_image/all/conanfile.py#L203-L204

Correcting self.settings.os == "Windows" to self.settings_build.os == "Windows" solves the problem. This work with MinGW and MSVC.

Package and Environment Details

Conan profile

Build profile:

[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=14
os=Linux

win-mingw.jinja:

[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=20
compiler.libcxx=libstdc++11
compiler.version=13
os=Windows
[options]
BOARD=HOST
[conf]
tools.cmake.cmaketoolchain:user_toolchain=['win-mingw.cmake']
[buildenv]
CMAKE_TOOLCHAIN_FILE=win-mingw.cmake

win-mingw.cmake:

set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
set(CMAKE_RANLIB x86_64-w64-mingw32-ranlib)

add_compile_options(-static)
add_link_options(-static)

conanfile.py:

from conan import ConanFile
from conan.tools.cmake import cmake_layout, CMakeToolchain

class Project(ConanFile):
    name = "project"
    description = ""
    author = ""
    settings = "os", "arch", "compiler", "build_type"
    generators = "CMakeDeps"
    options = {
        "BOARD": ["HOST", "GD32", "WEB"],
    }
    default_options = {
        "BOARD": "GD32",
    }

    def requirements(self):
        if self.options.BOARD != "WEB":
            self.requires("boost/1.84.0")
            if self.options.BOARD == "HOST":
                self.requires("libiconv/1.17#9d9082101394d053c67e95d3bc9f1e78")
                self.requires("sdl/2.28.5", force=True)
                self.requires("sdl_image/2.6.3")

    def configure(self):
        self.options["boost"].header_only = True
        self.options["boost"].multithreading = False
        self.options["boost"].numa = False
        self.options["boost"].zlib = False
        self.options["boost"].bzip2 = False
        self.options["boost"].lzma = False
        self.options["boost"].zstd = False
        self.options["boost"].debug_level = 0
        self.options["boost"].without_locale = True
        self.options["boost"].without_coroutine = True
        self.options["boost"].without_wave = True
        self.options["boost"].without_type_erasure = True
        self.options["boost"].without_fiber = True
        self.options["boost"].without_thread = True
        self.options["boost"].without_context = True
        self.options["boost"].without_atomic = True
        self.options["boost"].without_contract = True
        self.options["boost"].without_filesystem = True
        self.options["boost"].without_log = True
        self.options["boost"].without_nowide = True

        if self.settings.os == "Linux":
            self.options["sdl"].alsa = False
            self.options["sdl"].arts = False
            self.options["sdl"].directfb = False
            self.options["sdl"].esd = False
            self.options["sdl"].fPIC = False
            self.options["sdl"].iconv = False
            self.options["sdl"].jack = False
            self.options["sdl"].libunwind = False
            self.options["sdl"].nas = False
            self.options["sdl"].opengl = True
            self.options["sdl"].opengles = False
            self.options["sdl"].pulse = False
            self.options["sdl"].sdl2main = True
            self.options["sdl"].shared = False
            self.options["sdl"].sndio = False
            self.options["sdl"].video_rpi = False
            self.options["sdl"].vulkan = False
            self.options["sdl"].wayland = False
            self.options["sdl"].x11 = True
            self.options["sdl"].xcursor = False
            self.options["sdl"].xinerama = False
            self.options["sdl"].xinput = True
            self.options["sdl"].xrandr = False
            self.options["sdl"].xscrnsaver = False
            self.options["sdl"].xshape = False
            self.options["sdl"].xvm = False
        else:
            self.options["sdl"].shared = False
            self.options["sdl"].directx = False
            self.options["sdl"].opengl = True
            self.options["sdl"].opengles = False
            self.options["sdl"].sdl2main = True
            self.options["sdl"].vulkan = False

        self.options["sdl_image"].xv = False # XV thumbnails
        self.options["sdl_image"].bmp = False
        self.options["sdl_image"].gif = False
        self.options["sdl_image"].lbm = False # Interleaved Bitmap FORM : ILBM or PBM(packed bitmap) HAM6, HAM8, and 24bit types are not supported.
        self.options["sdl_image"].pcx = False # ZSoft IBM PC Paintbrush
        self.options["sdl_image"].pnm = False # Portable Anymap
        self.options["sdl_image"].qoi = False # Quite OK Image Format
        self.options["sdl_image"].svg = False
        self.options["sdl_image"].tga = False
        self.options["sdl_image"].xcf = False # GIMP native
        self.options["sdl_image"].xpm = False # X11 Pixmap
        self.options["sdl_image"].shared = False
        self.options["sdl_image"].fPIC = False
        self.options["sdl_image"].with_jxl = False
        self.options["sdl_image"].with_avif = False
        self.options["sdl_image"].with_libpng = True
        self.options["sdl_image"].with_libjpeg = False
        self.options["sdl_image"].with_libtiff = False
        self.options["sdl_image"].with_libwebp = False

        #self.options["png"].shared = False
        #self.options["png"].fPIC = False
        #self.options["zlib"].shared = False
        #self.options["zlib"].fPIC = False

    def layout(self):
        cmake_layout(self)

    def generate(self):
        tc = CMakeToolchain(self, "Ninja")
        tc.variables["BOARD"] = self.options.BOARD
        tc.generate()

Steps to reproduce

$ conan install -b missing . -pr:h win-mingw.jinja -s build_type=Release
$ cmake --preset conan-release

Logs

Conan install log ``` WARN: legacy: Unscoped option definition is ambiguous. Use '&:BOARD=HOST' to refer to the current package. Use '*:BOARD=HOST' or other pattern if the intent was to apply to dependencies ======== Input profiles ======== Profile host: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=20 compiler.libcxx=libstdc++11 compiler.version=13 os=Windows [options] BOARD=HOST [conf] tools.cmake.cmaketoolchain:user_toolchain=['win-mingw.cmake'] [buildenv] CMAKE_TOOLCHAIN_FILE=win-mingw.cmake Profile build: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu17 compiler.libcxx=libstdc++11 compiler.version=14 os=Linux ======== Computing dependency graph ======== boost/1.84.0: Not found in local cache, looking in remotes... boost/1.84.0: Checking remote: conancenter boost/1.84.0: Downloaded recipe revision 85fab16ba3b744074ca9733d2ed5fe5a libiconv/1.17: Not found in local cache, looking in remotes... libiconv/1.17: Checking remote: conancenter libiconv/1.17: Downloaded recipe revision 9d9082101394d053c67e95d3bc9f1e78 sdl/2.28.5: Not found in local cache, looking in remotes... sdl/2.28.5: Checking remote: conancenter sdl/2.28.5: Downloaded recipe revision e1be2b96f805dd72b290e34727b86428 cmake/3.30.0: Not found in local cache, looking in remotes... cmake/3.30.0: Checking remote: conancenter cmake/3.30.0: Downloaded recipe revision b93985853f6298c398c76dd4c2ac02a2 sdl_image/2.6.3: Not found in local cache, looking in remotes... sdl_image/2.6.3: Checking remote: conancenter sdl_image/2.6.3: Downloaded recipe revision 52a97d235594273a10267a0ca5b3f9ec libpng/1.6.43: Not found in local cache, looking in remotes... libpng/1.6.43: Checking remote: conancenter libpng/1.6.43: Downloaded recipe revision c219d8f01983bac10c404fc613605eef zlib/1.3.1: Not found in local cache, looking in remotes... zlib/1.3.1: Checking remote: conancenter zlib/1.3.1: Downloaded recipe revision f52e03ae3d251dec704634230cd806a2 Graph root conanfile.py (project/None): /conanfile.py Requirements boost/1.84.0#85fab16ba3b744074ca9733d2ed5fe5a - Downloaded (conancenter) libiconv/1.17#9d9082101394d053c67e95d3bc9f1e78 - Downloaded (conancenter) libpng/1.6.43#c219d8f01983bac10c404fc613605eef - Downloaded (conancenter) sdl/2.28.5#e1be2b96f805dd72b290e34727b86428 - Downloaded (conancenter) sdl_image/2.6.3#52a97d235594273a10267a0ca5b3f9ec - Downloaded (conancenter) zlib/1.3.1#f52e03ae3d251dec704634230cd806a2 - Downloaded (conancenter) Build requirements cmake/3.30.0#b93985853f6298c398c76dd4c2ac02a2 - Downloaded (conancenter) Resolved version ranges cmake/[>3.27 <4]: cmake/3.30.0 cmake/[>=3.16 <4]: cmake/3.30.0 libpng/[>=1.6 <2]: libpng/1.6.43 zlib/[>=1.2.11 <2]: zlib/1.3.1 Overrides sdl/2.28.3: ['sdl/2.28.5'] ======== Computing necessary packages ======== Requirements boost/1.84.0#85fab16ba3b744074ca9733d2ed5fe5a:da39a3ee5e6b4b0d3255bfef95601890afd80709#4d8e4eaa714ea2a7038d012658db0946 - Download (conancenter) libiconv/1.17#9d9082101394d053c67e95d3bc9f1e78:74fce2c720f804facc619f996bab77ff99796c4d - Build libpng/1.6.43#c219d8f01983bac10c404fc613605eef:cf51190da154c41f82d86a4f8b509d2cd71c2952 - Build sdl/2.28.5#e1be2b96f805dd72b290e34727b86428:e0cfb1d31a8ee3e04d68bd0fec7a1c85c8459b0c - Build sdl_image/2.6.3#52a97d235594273a10267a0ca5b3f9ec:27acdfab78522b010a679b10b58ccac2d8119b6d - Build zlib/1.3.1#f52e03ae3d251dec704634230cd806a2:74fce2c720f804facc619f996bab77ff99796c4d - Build Build requirements cmake/3.30.0#b93985853f6298c398c76dd4c2ac02a2:63fead0844576fc02943e16909f08fcdddd6f44b#d7d754a5f57bf0f76caef273545cfd89 - Download (conancenter) ======== Installing packages ======== -------- Downloading 2 packages -------- ... ======== Finalizing install (deploy, generators) ======== conanfile.py (project/None): Writing generators to /build/Release/generators conanfile.py (project/None): Generator 'CMakeDeps' calling 'generate()' conanfile.py (project/None): CMakeDeps necessary find_package() and targets for your CMakeLists.txt find_package(Boost) find_package(SDL2_image) find_package(SDL2) find_package(Iconv) target_link_libraries(... boost::boost SDL2_image::SDL2_image SDL2::SDL2main Iconv::Iconv) conanfile.py (project/None): Calling generate() conanfile.py (project/None): Generators folder: /build/Release/generators conanfile.py (project/None): CMakeToolchain generated: conan_toolchain.cmake conanfile.py (project/None): CMakeToolchain: Preset 'conan-release' added to CMakePresets.json. (cmake>=3.23) cmake --preset conan-release (cmake<3.23) cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release conanfile.py (project/None): CMakeToolchain generated: /build/Release/generators/CMakePresets.json conanfile.py (project/None): CMakeToolchain generated: /CMakeUserPresets.json conanfile.py (project/None): Generating aggregated env files conanfile.py (project/None): Generated aggregated env files: ['conanbuild.sh', 'conanrun.bat'] Install finished successfully ```
cmake preset log ``` Preset CMake variables: CMAKE_BUILD_TYPE="Release" CMAKE_POLICY_DEFAULT_CMP0091="NEW" CMAKE_TOOLCHAIN_FILE:FILEPATH="generators/conan_toolchain.cmake" Preset environment variables: CMAKE_TOOLCHAIN_FILE="win-mingw.cmake" -- Using Conan toolchain: /build/Release/generators/conan_toolchain.cmake -- Conan toolchain: C++ Standard 20 with extensions OFF -- Conan: Component target declared 'Boost::headers' -- Conan: Component target declared 'Boost::boost' -- Conan: Target declared 'boost::boost' -- Conan: Component target declared 'SDL2::SDL2' -- Conan: Component target declared 'SDL2::SDL2main' -- Conan: Target declared 'Iconv::Iconv' -- Conan: Component target declared 'SDL2_image::SDL2_image' CMake Error at build/Release/generators/cmakedeps_macros.cmake:67 (message): Library 'SDL2_image-static' not found in package. If 'SDL2_image-static' is a system library, declare it with 'cpp_info.system_libs' property Call Stack (most recent call first): build/Release/generators/SDL2_image-Target-release.cmake:23 (conan_package_library_targets) build/Release/generators/SDL2_imageTargets.cmake:28 (include) build/Release/generators/SDL2_imageConfig.cmake:16 (include) CMakeLists.txt:28 (find_package) -- Configuring incomplete, errors occurred! ```
perseoGI commented 2 months ago

Hi @radiofan, I've just opened https://github.com/conan-io/conan-center-index/pull/24962 When this gets merged this problem should be solved.

Thank you, good catch!

radiofan commented 2 months ago

You are cool, but it's a pity they rejected the fix

uilianries commented 2 months ago

@radiofan I guess there is a misconfiguration in your case, I don't see the need to using a cmake user preset injected to your profile to this case. For instance the recommended profile for mingw on Windows is different from yours: https://docs.conan.io/2/examples/dev_flow/tool_requires/mingw.html

So, adapting it to use in Linux, the host profile should look:

[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.exception=sjlj
compiler.libcxx=libstdc++11
compiler.threads=posix
compiler.version=10
os=Windows
[conf]
tools.build:compiler_executables={'c': '/usr/bin/x86_64-w64-mingw32-gcc-10', 'cpp': '/usr/bin/x86_64-w64-mingw32-g++'}

I can build without errors: https://gist.github.com/uilianries/f55896b641abbafc16b1c2d2eb2f4895

Then, in order to run cmake --preset conan-release, you need a CMakeLists.txt (not listed in this issue).

If you need to inject more variables, you could use Conan config directly in your profile as well.

https://docs.conan.io/2/reference/config_files/global_conf.html

tools.build:cflags=["-static"]
tools.build:cxxflags=["-static"]

Could you please check if this solution fits your case?

radiofan commented 1 month ago

Sorry, I dropped out of work a little bit. Thank you, i check this solution as soon as I can.

radiofan commented 1 month ago

Hello, @uilianries , thank you for your answer. I tried to use your configuration, it not help to build. I get same error when cmake --preset:

CMake Error at build/Release/generators/cmakedeps_macros.cmake:67 (message):
  Library 'SDL2_image-static' not found in package.  If 'SDL2_image-static'
  is a system library, declare it with 'cpp_info.system_libs' property
Call Stack (most recent call first):
  build/Release/generators/SDL2_image-Target-release.cmake:23 (conan_package_library_targets)
  build/Release/generators/SDL2_imageTargets.cmake:28 (include)
  build/Release/generators/SDL2_imageConfig.cmake:16 (include)
  CMakeLists.txt:28 (find_package)
uilianries commented 1 month ago

@RADIOFAN, could you please share your entire build using the solution that I proposed before? Including profiles and CMakeLists.txt (partially) if possible. As I commented before, it's working for me™, but there is a difference between our environments for sure that's resulting in your error, probably a small detail that we are missing.