Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nativefiledialog: migrate to Conan v2 #21152

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 117 additions & 49 deletions recipes/nativefiledialog/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,76 +1,144 @@
import os
from conans import ConanFile, MSBuild, AutoToolsBuildEnvironment, tools
from conans.errors import ConanInvalidConfiguration

from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import chdir, copy, get, save, replace_in_file
from conan.tools.gnu import Autotools, AutotoolsToolchain, PkgConfigDeps, GnuToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import MSBuild, MSBuildToolchain, is_msvc

required_conan_version = ">=1.53.0"


class NativefiledialogConan(ConanFile):
name = "nativefiledialog"
description = "A tiny, neat C library that portably invokes native file open and save dialogs."
license = "Zlib"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/mlabbe/nativefiledialog"
description = "A tiny, neat C library that portably invokes native file open and save dialogs."
topics = ("conan", "dialog", "gui")
settings = "os", "compiler", "build_type", "arch"
generators = "pkg_config",

@property
def _source_subfolder(self):
return "source_subfolder"
topics = ("dialog", "gui")

def requirements(self):
if self.settings.os == "Linux":
self.requires("gtk/3.24.24")
package_type = "static-library"
settings = "os", "arch", "compiler", "build_type"
options = {
"fPIC": [True, False],
}
default_options = {
"fPIC": True,
}

def build_requirements(self):
self.build_requires("premake/5.0.0-alpha15")
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

if self.settings.arch not in ["x86", "x86_64"]:
raise ConanInvalidConfiguration("architecture %s is not supported" % self.settings.arch)
def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
if self.settings.os in ["Linux", "FreeBSD"]:
self.requires("gtk/3.24.43")

def build_requirements(self):
self.tool_requires("premake/5.0.0-alpha15")
if not is_msvc(self) and not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str):
self.tool_requires("pkgconf/[>=2.2 <3]")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-release_" + self.version
os.rename(extracted_dir, self._source_subfolder)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def build(self):
if self.settings.compiler == "Visual Studio":
generator = "vs" + {"16": "2019",
"15": "2017",
"14": "2015",
"12": "2013",
"11": "2012",
"10": "2010",
"9": "2008",
"8": "2005"}.get(str(self.settings.compiler.version))
@property
def _vs_ide_year(self):
compiler_version = str(self.settings.compiler.version)
return {
"180": "2013",
"190": "2015",
"191": "2017",
"192": "2019",
"193": "2022",
"194": "2022",
}[compiler_version]

@property
def _build_subdir(self):
return os.path.join(self.source_folder, "build", "subdir")

@property
def _arch(self):
return {
"x86": "x86",
"x86_64": "x86_64",
"armv5": "ARM",
"armv7": "ARM",
"armv8": "ARM64",
"mips": "MIPS",
"mips64": "MIPS64",
}[str(self.settings.arch)]

def generate(self):
venv = VirtualBuildEnv(self)
venv.generate()

if is_msvc(self):
tc = MSBuildToolchain(self)
tc.generate()
else:
generator = "gmake2"
subdir = os.path.join(self._source_subfolder, "build", "subdir")
os.makedirs(subdir)
with tools.chdir(subdir):
os.rename(os.path.join("..", "premake5.lua"), "premake5.lua")
self.run("premake5 %s" % generator)

if self.settings.compiler == "Visual Studio":
tc = AutotoolsToolchain(self)
tc.generate()
tc = PkgConfigDeps(self)
tc.generate()

system = [f'architecture ("{self._arch}")']
if cross_building(self):
gnu_vars = GnuToolchain(self).extra_env.vars(self)
prefix = gnu_vars["STRIP"].replace("-strip", "-")
system.append(f'gccprefix ("{prefix}")')
save(self, os.path.join(self.generators_folder, "system.lua"), "\n".join(system))

copy(self, "premake5.lua", os.path.join(self.source_folder, "build"), self._build_subdir)

def build(self):
with chdir(self, self._build_subdir):
# Use the correct pkg-config executable
replace_in_file(self, "premake5.lua", "pkg-config", self.conf.get("tools.gnu:pkg_config", default="pkgconf", check_type=str))

if is_msvc(self):
ide_year = self._vs_ide_year
# 2022 is not directly supported as of v116
ide_year = "2019" if ide_year == "2022" else ide_year
generator = f"vs{ide_year}"
else:
generator = "gmake2"
sys = os.path.join(self.generators_folder, "system.lua")
self.run(f"premake5 {generator} --systemscript={sys}")

if is_msvc(self):
msbuild = MSBuild(self)
msbuild.build("NativeFileDialog.sln")
else:
config = "debug" if self.settings.build_type == "Debug" else "release"
config += "_x86" if self.settings.arch == "x86" else "_x64"
env_build = AutoToolsBuildEnvironment(self)
env_build.make(args=["config=%s" % config])
autotools = Autotools(self)
autotools.make(args=[f"config={config}", "-j1"], target="nfd")

@property
def _lib_name(self):
suffix = "_d" if self.settings.build_type == "Debug" else ""
return "nfd" + suffix

def package(self):
libname = "nfd_d" if self.settings.build_type == "Debug" else "nfd"
if self.settings.compiler == "Visual Studio":
self.copy("*%s.lib" % libname, dst="lib", src=self._source_subfolder, keep_path=False)
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
copy(self, "*nfd.h", self.source_folder, os.path.join(self.package_folder, "include"), keep_path=False)
if is_msvc(self):
copy(self, f"*{self._lib_name}.lib", self.source_folder, os.path.join(self.package_folder, "lib"), keep_path=False)
else:
self.copy("*%s.a" % libname, dst="lib", src=self._source_subfolder, keep_path=False)
self.copy("*nfd.h", dst="include", src=self._source_subfolder, keep_path=False)
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
copy(self, f"*{self._lib_name}.a", self.source_folder, os.path.join(self.package_folder, "lib"), keep_path=False)

def package_info(self):
self.cpp_info.libs = ["nfd_d" if self.settings.build_type == "Debug" else "nfd"]
self.cpp_info.libs = [self._lib_name]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.requires = ["gtk::gtk+-3.0"]
9 changes: 4 additions & 5 deletions recipes/nativefiledialog/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(nativefiledialog REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE nativefiledialog::nativefiledialog)
20 changes: 14 additions & 6 deletions recipes/nativefiledialog/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
4 changes: 2 additions & 2 deletions recipes/nativefiledialog/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <nfd.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
Expand Down