diff --git a/cmake/StandardProjectSettings.cmake b/cmake/StandardProjectSettings.cmake index cf20b1b4..0d5dedea 100644 --- a/cmake/StandardProjectSettings.cmake +++ b/cmake/StandardProjectSettings.cmake @@ -104,12 +104,12 @@ function(use_python project_name) message(STATUS "Setting Python version to ${Python_VERSION}. Set Python_VERSION if you want to compile against an other version.") endif() if(APPLE) - set(Python3_FIND_FRAMEWORK NEVER) + set(Python_FIND_FRAMEWORK NEVER) endif() - find_package(Python3 ${Python_VERSION} EXACT REQUIRED COMPONENTS ${COMPONENTS}) - target_link_libraries(${project_name} PRIVATE ${Python3_LIBRARIES}) - target_include_directories(${project_name} PUBLIC ${Python3_INCLUDE_DIRS}) - message(STATUS "Linking and building ${project_name} against Python ${Python3_VERSION}") + find_package(Python ${Python_VERSION} EXACT REQUIRED COMPONENTS ${COMPONENTS}) + target_link_libraries(${project_name} PRIVATE Python::Python) + target_include_directories(${project_name} PUBLIC ${Python_INCLUDE_DIRS}) + message(STATUS "Linking and building ${project_name} against Python ${Python_VERSION}") endfunction() # Ultimaker uniform Thread linking method diff --git a/conanfile.py b/conanfile.py index 78870a18..6199b929 100644 --- a/conanfile.py +++ b/conanfile.py @@ -3,29 +3,30 @@ from conans import ConanFile, tools from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake -from conan.tools.layout import LayoutPackager, clion_layout class ArcusConan(ConanFile): name = "Arcus" - version = "4.10.0" + version = "4.11.0" license = "LGPL-3.0" author = "Ultimaker B.V." url = "https://github.com/Ultimaker/libArcus" description = "Communication library between internal components for Ultimaker software" topics = ("conan", "python", "binding", "sip", "cura", "protobuf", "c++") settings = "os", "compiler", "build_type", "arch" + revision_mode = "scm" + build_policy = "missing" exports = "LICENSE" options = { + "build_python": [True, False], "shared": [True, False], "fPIC": [True, False], - "examples": [True, False], - "python_version": "ANY" + "examples": [True, False] } default_options = { + "build_python": True, "shared": True, "fPIC": True, - "examples": False, - "python_version": "3.8" + "examples": False } scm = { "type": "git", @@ -34,42 +35,19 @@ class ArcusConan(ConanFile): "revision": "auto" } - _ext = None - - @property - def ext(self): - if self._ext: - return self._ext - self._ext = "lib" if self.settings.os == "Windows" else "a" - if self.options.shared: - if self.settings.os == "Windows": - self._ext = "dll" - elif self.settings.os == "Macos": - self._ext = "dylib" - else: - self._ext = "so" - return self._ext - - # TODO: Move lib naming logic to python_requires project - _lib_name = None - - @property - def lib_name(self): - if self._lib_name: - return self._lib_name - pre = "" if self.settings.os == "Windows" else "lib" - ext = "" if self.settings.os == "Windows" else f".{self.ext}" - self._lib_name = f"{pre}{self.name}{ext}" - return self._lib_name - def config_options(self): - if self.settings.os == "Windows" and self.settings.compiler == "gcc": - self.options.python = False - self.options["protobuf"].shared = False if self.settings.os == "Macos" else self.options.shared + if self.settings.os == "Windows": + self.options.shared = False + if self.settings.compiler == "gcc": + self.options.build_python = False + if self.settings.os == "Macos": + self.options["protobuf"].shared = False + else: + self.options["protobuf"].shared = self.options.shared def configure(self): - self.options["SIP"].python_version = self.options.python_version - self.options["SIP"].shared = self.options.shared + if self.options.build_python: + self.options["SIP"].shared = self.options.shared if self.options.shared or self.settings.compiler == "Visual Studio": del self.options.fPIC @@ -77,7 +55,9 @@ def build_requirements(self): self.build_requires("cmake/[>=3.16.2]") def requirements(self): - self.requires("SIP/[>=4.19.24]@riverbankcomputing/testing") + if self.options.build_python: + self.requires("Python/3.8.10@python/testing") + self.requires("SIP/[>=4.19.24]@riverbankcomputing/testing") self.requires("protobuf/3.17.1") def validate(self): @@ -94,16 +74,15 @@ def generate(self): if self.settings.compiler == "Visual Studio": tc.blocks["generic_system"].values["generator_platform"] = None tc.blocks["generic_system"].values["toolset"] = None - tc.blocks["shared"].values["shared_libs"] = False # FIXME: Otherwise it throws: error LNK2001: unresolved external symbol "__declspec(dllimport) tc.variables["ALLOW_IN_SOURCE_BUILD"] = True - tc.variables["BUILD_PYTHON"] = True tc.variables["BUILD_EXAMPLES"] = self.options.examples - tc.variables["Python_VERSION"] = self.options.python_version - tc.variables["SIP_MODULE_SITE_PATH"] = "site-packages" + tc.variables["BUILD_PYTHON"] = self.options.build_python + if self.options.build_python: + tc.variables["Python_VERSION"] = self.deps_cpp_info["Python"].version + tc.variables["SIP_MODULE_SITE_PATH"] = "site-packages" - # FIXME: Otherwise it throws: error LNK2001: unresolved external symbol "__declspec(dllimport) - tc.variables["BUILD_STATIC"] = not self.options.shared if self.settings.os != "Windows" else True + tc.variables["BUILD_STATIC"] = not self.options.shared tc.generate() @@ -140,8 +119,6 @@ def package_info(self): self.cpp_info.defines.append("ARCUS") if self.settings.build_type == "Debug": self.cpp_info.defines.append("ARCUS_DEBUG") - self.cpp_info.names["cmake_find_package"] = self.name - self.cpp_info.names["cmake_find_package_multi"] = self.name if self.settings.os in ["Linux", "FreeBSD", "Macos"]: self.cpp_info.system_libs.append("pthread") elif self.settings.os == "Windows": diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 5960e712..8b8eb284 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -1,25 +1,15 @@ -import os -from conans import ConanFile, CMake, tools +from conans import ConanFile, CMake from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake class ArcusTestConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - options = { - "python_version": "ANY" - } - default_options = { - "python_version": "3.9" - } - - def configure(self): - self.options["Arcus"].python_version = self.options.python_version def build_requirements(self): self.build_requires("cmake/3.15.7") def requirements(self): - self.requires(f"Arcus/4.10.0@ultimaker/testing") + self.requires("Arcus/4.11.0@ultimaker/testing") self.requires("protobuf/3.17.1") def generate(self):