-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
226 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,9 @@ | ||
cmake_minimum_required(VERSION 3.1.0) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
|
||
project(test_package) | ||
|
||
cmake_policy(SET CMP0020 NEW) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_set_vs_runtime() | ||
conan_set_libcxx() | ||
conan_output_dirs_setup() | ||
cmake_minimum_required(VERSION 3.8) | ||
project(test_package LANGUAGES CXX) | ||
|
||
find_package(Qt5 COMPONENTS Core Network Sql Concurrent Xml REQUIRED CONFIG) | ||
|
||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
|
||
set(SOURCES test_package.cpp greeter.h example.qrc) | ||
|
||
add_executable(${PROJECT_NAME} WIN32 ${SOURCES}) | ||
|
||
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Network Qt5::Sql Qt5::Concurrent Qt5::Xml) | ||
add_executable(${PROJECT_NAME} WIN32 test_package.cpp greeter.h example.qrc) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network Qt5::Sql Qt5::Concurrent Qt5::Xml) | ||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES AUTOMOC ON AUTORCC ON) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,145 +1,58 @@ | ||
import os | ||
import shutil | ||
import textwrap | ||
|
||
from conan import ConanFile | ||
from conans import tools, Meson, RunEnvironment, CMake | ||
from conan.tools.build import cross_building | ||
from conan.tools.files import save | ||
from conan.errors import ConanInvalidConfiguration | ||
|
||
from conan.tools.build import can_run | ||
from conan.tools.cmake import CMake, cmake_layout | ||
from conan.tools.env import VirtualRunEnv | ||
from conan.tools.files import copy, save | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake", "cmake_find_package_multi", "qmake" | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeDeps", "CMakeToolchain", "VirtualBuildEnv" | ||
test_type = "explicit" | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
@property | ||
def _settings_build(self): | ||
return getattr(self, "settings_build", self.settings) | ||
def requirements(self): | ||
self.requires(self.tested_reference_str, run=can_run(self)) | ||
|
||
def build_requirements(self): | ||
if self._settings_build.os == "Windows" and self.settings.compiler == "Visual Studio": | ||
self.build_requires("jom/1.1.3") | ||
if self._meson_supported(): | ||
self.build_requires("meson/1.0.1") | ||
if not can_run(self): | ||
self.tool_requires(self.tested_reference_str) | ||
|
||
def generate(self): | ||
save(self, "qt.conf", """[Paths] | ||
Prefix = {} | ||
ArchData = bin/archdatadir | ||
HostData = bin/archdatadir | ||
Data = bin/datadir | ||
Sysconf = bin/sysconfdir | ||
LibraryExecutables = bin/archdatadir/bin | ||
Plugins = bin/archdatadir/plugins | ||
Imports = bin/archdatadir/imports | ||
Qml2Imports = bin/archdatadir/qml | ||
Translations = bin/datadir/translations | ||
Documentation = bin/datadir/doc | ||
Examples = bin/datadir/examples""".format(self.dependencies["qt"].package_folder.replace('\\', '/'))) | ||
|
||
def _is_mingw(self): | ||
return self.settings.os == "Windows" and self.settings.compiler == "gcc" | ||
|
||
def _meson_supported(self): | ||
return self.options["qt"].shared and\ | ||
not cross_building(self) and\ | ||
not tools.os_info.is_macos and\ | ||
not self._is_mingw() | ||
|
||
def _qmake_supported(self): | ||
return self.options["qt"].shared | ||
|
||
def _build_with_qmake(self): | ||
if not self._qmake_supported(): | ||
return | ||
tools.mkdir("qmake_folder") | ||
with tools.chdir("qmake_folder"): | ||
self.output.info("Building with qmake") | ||
|
||
with tools.vcvars(self.settings) if self.settings.compiler == "Visual Studio" else tools.no_op(): | ||
args = [self.source_folder, "DESTDIR=bin"] | ||
|
||
def _getenvpath(var): | ||
val = os.getenv(var) | ||
if val and tools.os_info.is_windows: | ||
val = val.replace("\\", "/") | ||
os.environ[var] = val | ||
return val | ||
|
||
value = _getenvpath("CC") | ||
if value: | ||
args += ['QMAKE_CC="' + value + '"', | ||
'QMAKE_LINK_C="' + value + '"', | ||
'QMAKE_LINK_C_SHLIB="' + value + '"'] | ||
|
||
value = _getenvpath('CXX') | ||
if value: | ||
args += ['QMAKE_CXX="' + value + '"', | ||
'QMAKE_LINK="' + value + '"', | ||
'QMAKE_LINK_SHLIB="' + value + '"'] | ||
|
||
self.run("qmake %s" % " ".join(args), run_environment=True) | ||
if tools.os_info.is_windows: | ||
if self.settings.compiler == "Visual Studio": | ||
self.run("jom", run_environment=True) | ||
else: | ||
self.run("mingw32-make", run_environment=True) | ||
else: | ||
self.run("make", run_environment=True) | ||
|
||
def _build_with_meson(self): | ||
if self._meson_supported(): | ||
self.output.info("Building with Meson") | ||
tools.mkdir("meson_folder") | ||
with tools.environment_append(RunEnvironment(self).vars): | ||
meson = Meson(self) | ||
try: | ||
meson.configure(build_folder="meson_folder", defs={"cpp_std": "c++11"}) | ||
except ConanInvalidConfiguration: | ||
self.output.info(open("meson_folder/meson-logs/meson-log.txt", 'r').read()) | ||
raise | ||
meson.build() | ||
|
||
def _build_with_cmake_find_package_multi(self): | ||
self.output.info("Building with cmake_find_package_multi") | ||
env_build = RunEnvironment(self) | ||
with tools.environment_append(env_build.vars): | ||
cmake = CMake(self, set_cmake_flags=True) | ||
if self.settings.os == "Macos": | ||
cmake.definitions['CMAKE_OSX_DEPLOYMENT_TARGET'] = '10.14' | ||
|
||
cmake.configure() | ||
cmake.build() | ||
qt_install_prefix = self.dependencies["qt"].package_folder.replace("\\", "/") | ||
qt_conf = textwrap.dedent(f"""\ | ||
[Paths] | ||
Prefix = {qt_install_prefix} | ||
ArchData = bin/archdatadir | ||
HostData = bin/archdatadir | ||
Data = bin/datadir | ||
Sysconf = bin/sysconfdir | ||
LibraryExecutables = bin/archdatadir/bin | ||
Plugins = bin/archdatadir/plugins | ||
Imports = bin/archdatadir/imports | ||
Qml2Imports = bin/archdatadir/qml | ||
Translations = bin/datadir/translations | ||
Documentation = bin/datadir/doc | ||
Examples = bin/datadir/examples | ||
""") | ||
save(self, "qt.conf", qt_conf) | ||
|
||
VirtualRunEnv(self).generate() | ||
if can_run(self): | ||
VirtualRunEnv(self).generate(scope="build") | ||
|
||
def build(self): | ||
self._build_with_qmake() | ||
self._build_with_meson() | ||
self._build_with_cmake_find_package_multi() | ||
|
||
def _test_with_qmake(self): | ||
if not self._qmake_supported(): | ||
return | ||
self.output.info("Testing qmake") | ||
bin_path = os.path.join("qmake_folder", "bin") | ||
if tools.os_info.is_macos: | ||
bin_path = os.path.join(bin_path, "test_package.app", "Contents", "MacOS") | ||
shutil.copy(os.path.join(self.generators_folder, "qt.conf"), bin_path) | ||
self.run(os.path.join(bin_path, "test_package"), run_environment=True) | ||
|
||
def _test_with_meson(self): | ||
if self._meson_supported(): | ||
self.output.info("Testing Meson") | ||
shutil.copy(os.path.join(self.generators_folder, "qt.conf"), "meson_folder") | ||
self.run(os.path.join("meson_folder", "test_package"), run_environment=True) | ||
|
||
def _test_with_cmake_find_package_multi(self): | ||
self.output.info("Testing CMake_find_package_multi") | ||
shutil.copy(os.path.join(self.generators_folder, "qt.conf"), "bin") | ||
self.run(os.path.join("bin", "test_package"), run_environment=True) | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not cross_building(self, skip_x64_x86=True): | ||
self._test_with_qmake() | ||
self._test_with_meson() | ||
self._test_with_cmake_find_package_multi() | ||
if can_run(self): | ||
copy(self, "qt.conf", src=self.generators_folder, dst=os.path.join(self.cpp.build.bindirs[0])) | ||
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") | ||
self.run(bin_path, env="conanrun") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
cmake_minimum_required(VERSION 3.1.0) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
|
||
project(test_package) | ||
|
||
cmake_policy(SET CMP0020 NEW) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_set_vs_runtime() | ||
conan_set_libcxx() | ||
conan_output_dirs_setup() | ||
|
||
find_package(Qt5 COMPONENTS Core Network Sql Concurrent Xml REQUIRED CONFIG) | ||
|
||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
|
||
set(SOURCES ../test_package/test_package.cpp ../test_package/greeter.h ../test_package/example.qrc) | ||
|
||
add_executable(${PROJECT_NAME} WIN32 ${SOURCES}) | ||
|
||
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Network Qt5::Sql Qt5::Concurrent Qt5::Xml) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import os | ||
import shutil | ||
|
||
from conan import ConanFile | ||
from conans import tools, Meson, RunEnvironment, CMake | ||
from conan.tools.build import cross_building | ||
from conan.tools.files import save | ||
from conan.errors import ConanInvalidConfiguration | ||
|
||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake", "cmake_find_package_multi", "qmake" | ||
|
||
@property | ||
def _settings_build(self): | ||
return getattr(self, "settings_build", self.settings) | ||
|
||
def build_requirements(self): | ||
if self._settings_build.os == "Windows" and self.settings.compiler == "Visual Studio": | ||
self.build_requires("jom/1.1.3") | ||
if self._meson_supported(): | ||
self.build_requires("meson/1.1.0") | ||
|
||
def generate(self): | ||
save(self, "qt.conf", """[Paths] | ||
Prefix = {} | ||
ArchData = bin/archdatadir | ||
HostData = bin/archdatadir | ||
Data = bin/datadir | ||
Sysconf = bin/sysconfdir | ||
LibraryExecutables = bin/archdatadir/bin | ||
Plugins = bin/archdatadir/plugins | ||
Imports = bin/archdatadir/imports | ||
Qml2Imports = bin/archdatadir/qml | ||
Translations = bin/datadir/translations | ||
Documentation = bin/datadir/doc | ||
Examples = bin/datadir/examples""".format(self.dependencies["qt"].package_folder.replace('\\', '/'))) | ||
|
||
def _is_mingw(self): | ||
return self.settings.os == "Windows" and self.settings.compiler == "gcc" | ||
|
||
def _meson_supported(self): | ||
return self.options["qt"].shared and\ | ||
not cross_building(self) and\ | ||
not tools.os_info.is_macos and\ | ||
not self._is_mingw() | ||
|
||
def _qmake_supported(self): | ||
return self.options["qt"].shared | ||
|
||
def _build_with_qmake(self): | ||
if not self._qmake_supported(): | ||
return | ||
tools.mkdir("qmake_folder") | ||
with tools.chdir("qmake_folder"): | ||
self.output.info("Building with qmake") | ||
|
||
with tools.vcvars(self.settings) if self.settings.compiler == "Visual Studio" else tools.no_op(): | ||
args = [self.source_folder, "DESTDIR=bin"] | ||
|
||
def _getenvpath(var): | ||
val = os.getenv(var) | ||
if val and tools.os_info.is_windows: | ||
val = val.replace("\\", "/") | ||
os.environ[var] = val | ||
return val | ||
|
||
value = _getenvpath("CC") | ||
if value: | ||
args += ['QMAKE_CC="' + value + '"', | ||
'QMAKE_LINK_C="' + value + '"', | ||
'QMAKE_LINK_C_SHLIB="' + value + '"'] | ||
|
||
value = _getenvpath('CXX') | ||
if value: | ||
args += ['QMAKE_CXX="' + value + '"', | ||
'QMAKE_LINK="' + value + '"', | ||
'QMAKE_LINK_SHLIB="' + value + '"'] | ||
|
||
self.run("qmake %s" % " ".join(args), run_environment=True) | ||
if tools.os_info.is_windows: | ||
if self.settings.compiler == "Visual Studio": | ||
self.run("jom", run_environment=True) | ||
else: | ||
self.run("mingw32-make", run_environment=True) | ||
else: | ||
self.run("make", run_environment=True) | ||
|
||
def _build_with_meson(self): | ||
if self._meson_supported(): | ||
self.output.info("Building with Meson") | ||
tools.mkdir("meson_folder") | ||
with tools.environment_append(RunEnvironment(self).vars): | ||
meson = Meson(self) | ||
try: | ||
meson.configure(build_folder="meson_folder", defs={"cpp_std": "c++11"}) | ||
except ConanInvalidConfiguration: | ||
self.output.info(open("meson_folder/meson-logs/meson-log.txt", 'r').read()) | ||
raise | ||
meson.build() | ||
|
||
def _build_with_cmake_find_package_multi(self): | ||
self.output.info("Building with cmake_find_package_multi") | ||
env_build = RunEnvironment(self) | ||
with tools.environment_append(env_build.vars): | ||
cmake = CMake(self, set_cmake_flags=True) | ||
if self.settings.os == "Macos": | ||
cmake.definitions['CMAKE_OSX_DEPLOYMENT_TARGET'] = '10.14' | ||
|
||
cmake.configure() | ||
cmake.build() | ||
|
||
def build(self): | ||
self._build_with_qmake() | ||
self._build_with_meson() | ||
self._build_with_cmake_find_package_multi() | ||
|
||
def _test_with_qmake(self): | ||
if not self._qmake_supported(): | ||
return | ||
self.output.info("Testing qmake") | ||
bin_path = os.path.join("qmake_folder", "bin") | ||
if tools.os_info.is_macos: | ||
bin_path = os.path.join(bin_path, "test_package.app", "Contents", "MacOS") | ||
shutil.copy(os.path.join(self.generators_folder, "qt.conf"), bin_path) | ||
self.run(os.path.join(bin_path, "test_package"), run_environment=True) | ||
|
||
def _test_with_meson(self): | ||
if self._meson_supported(): | ||
self.output.info("Testing Meson") | ||
shutil.copy(os.path.join(self.generators_folder, "qt.conf"), "meson_folder") | ||
self.run(os.path.join("meson_folder", "test_package"), run_environment=True) | ||
|
||
def _test_with_cmake_find_package_multi(self): | ||
self.output.info("Testing CMake_find_package_multi") | ||
shutil.copy(os.path.join(self.generators_folder, "qt.conf"), "bin") | ||
self.run(os.path.join("bin", "test_package"), run_environment=True) | ||
|
||
def test(self): | ||
if not cross_building(self, skip_x64_x86=True): | ||
self._test_with_qmake() | ||
self._test_with_meson() | ||
self._test_with_cmake_find_package_multi() |
Oops, something went wrong.