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

Allow cppunit to be compiled without msys2 #11030

Closed
wants to merge 1 commit into from
Closed
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
77 changes: 28 additions & 49 deletions recipes/cppunit/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from conans import AutoToolsBuildEnvironment, ConanFile, tools
import contextlib
import shutil
from conans import AutoToolsBuildEnvironment, ConanFile, tools, MSBuild
import os

required_conan_version = ">=1.33.0"

required_conan_version = ">=1.40.0"

class CppunitConan(ConanFile):
name = "cppunit"
Expand All @@ -22,8 +21,6 @@ class CppunitConan(ConanFile):
"fPIC": True,
}

generators = "pkg_config"

_autotools = None

@property
Expand All @@ -42,43 +39,13 @@ def configure(self):
if self.options.shared:
del self.options.fPIC

def build_requirements(self):
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")
if self.settings.compiler == "Visual Studio":
self.build_requires("automake/1.16.3")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

@contextlib.contextmanager
def _build_context(self):
if self.settings.compiler == "Visual Studio":
with tools.vcvars(self):
env = {
"AR": "{} lib".format(tools.unix_path(self.deps_user_info["automake"].ar_lib)),
"CC": "{} cl -nologo".format(tools.unix_path(self.deps_user_info["automake"].compile)),
"CXX": "{} cl -nologo".format(tools.unix_path(self.deps_user_info["automake"].compile)),
"NM": "dumpbin -symbols",
"OBJDUMP": ":",
"RANLIB": ":",
"STRIP": ":",
}
with tools.environment_append(env):
yield
else:
yield
tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True)

def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
if self.settings.os == "Windows" and self.options.shared:
self._autotools.defines.append("CPPUNIT_BUILD_DLL")
if self.settings.compiler == "Visual Studio":
self._autotools.flags.append("-FS")
self._autotools.cxx_flags.append("-EHsc")
self._autotools = AutoToolsBuildEnvironment(self)
yes_no = lambda v: "yes" if v else "no"
conf_args = [
"--enable-shared={}".format(yes_no(self.options.shared)),
Expand All @@ -93,26 +60,38 @@ def _configure_autotools(self):
return self._autotools

def build(self):
with self._build_context():
if self.settings.compiler == "Visual Studio":
project = "cppunit_dll.vcxproj" if self.options.shared else "cppunit.vcxproj"
msvc_arch = {
'x86': 'x86',
'x86_64': 'x64',
'armv7': 'ARM',
'armv8': 'ARM64'
}
msbuild = MSBuild(self)
msbuild.build(os.path.join(self._source_subfolder, "src", "cppunit", project), use_env=False)
else:
autotools = self._configure_autotools()
autotools.make()

def package(self):
self.copy("COPYING", src=self._source_subfolder, dst="licenses")
with self._build_context():
if self.settings.compiler == "Visual Studio":
shutil.copytree(src=os.path.join(self._source_subfolder, "lib"), dst=os.path.join(self.package_folder, "lib"))
shutil.copytree(src=os.path.join(self._source_subfolder, "include"), dst=os.path.join(self.package_folder, "include"))
else:
autotools = self._configure_autotools()
autotools.install()

if self.settings.compiler == "Visual Studio" and self.options.shared:
os.rename(os.path.join(self.package_folder, "lib", "cppunit.dll.lib"),
os.path.join(self.package_folder, "lib", "cppunit.lib"))

tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.libs = ["cppunit"]
libsuffix = "d" if self.settings.compiler == "Visual Studio" and self.settings.build_type == "Debug" else ""
if self.settings.compiler == "Visual Studio" and self.options.shared:
self.cpp_info.libs = ["cppunit_dll" + libsuffix]
else:
self.cpp_info.libs = ["cppunit" + libsuffix]
if not self.options.shared:
stdlib = tools.stdcpp_library(self)
if stdlib:
Expand Down