Skip to content

Commit

Permalink
Use Conan Python package
Browse files Browse the repository at this point in the history
  • Loading branch information
jellespijker committed Sep 8, 2021
1 parent de29989 commit e0adc44
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 65 deletions.
10 changes: 5 additions & 5 deletions cmake/StandardProjectSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 25 additions & 48 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -34,50 +35,29 @@ 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

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):
Expand All @@ -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()

Expand Down Expand Up @@ -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":
Expand Down
14 changes: 2 additions & 12 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down

0 comments on commit e0adc44

Please sign in to comment.