-
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.
djinni-support-lib: migrate to Conan v2
- Loading branch information
Showing
15 changed files
with
274 additions
and
202 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,145 +1,169 @@ | ||
import os | ||
|
||
from conans import ConanFile, CMake, tools | ||
from conans.errors import ConanInvalidConfiguration | ||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.apple import is_apple_os | ||
from conan.tools.build import check_min_cppstd | ||
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout | ||
from conan.tools.env import VirtualBuildEnv | ||
from conan.tools.files import collect_libs, copy, get | ||
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime | ||
from conan.tools.scm import Version | ||
|
||
required_conan_version = ">=1.53.0" | ||
|
||
|
||
class DjinniSuppotLib(ConanFile): | ||
name = "djinni-support-lib" | ||
homepage = "https://djinni.xlcpp.dev" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
description = "Djinni is a tool for generating cross-language type declarations and interface bindings" | ||
topics = ("java", "Objective-C", "Android", "iOS") | ||
license = "Apache-2.0" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://djinni.xlcpp.dev" | ||
topics = ("java", "Objective-C", "Android", "iOS") | ||
|
||
package_type = "library" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = {"shared": [True, False], | ||
"fPIC": [True, False], | ||
"target": ["jni", "objc", "python", "cppcli", "auto", "deprecated"], | ||
"with_jni": [True, False, "auto"], | ||
"with_objc": [True, False, "auto"], | ||
"with_python": [True, False, "auto"], | ||
"with_cppcli": [True, False, "auto"], | ||
"system_java": [True, False] | ||
} | ||
default_options = {"shared": False, | ||
"fPIC": True, | ||
"target": "deprecated", | ||
"with_jni": "auto", | ||
"with_objc": "auto", | ||
"with_python": "auto", | ||
"with_cppcli": "auto", | ||
"system_java": False, | ||
} | ||
exports_sources = ["CMakeLists.txt"] | ||
generators = "cmake", "cmake_find_package" | ||
|
||
_cmake = None | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
"with_jni": [True, False, "auto"], | ||
"with_objc": [True, False, "auto"], | ||
"with_python": [True, False, "auto"], | ||
"with_cppcli": [True, False, "auto"], | ||
"system_java": [True, False], | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": True, | ||
"with_jni": "auto", | ||
"with_objc": "auto", | ||
"with_python": "auto", | ||
"with_cppcli": "auto", | ||
"system_java": False, | ||
} | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
elif self.settings.os == "Android": | ||
self.options.system_java = True | ||
|
||
@property | ||
def _objc_support(self): | ||
if self.options.with_objc == "auto" or self.options.target == "auto": | ||
return tools.is_apple_os(self.settings.os) | ||
if self.options.with_objc == "auto": | ||
return is_apple_os(self) | ||
else: | ||
return self.options.with_objc == True or self.options.target == "objc" | ||
return self.options.with_objc | ||
|
||
@property | ||
def _jni_support(self): | ||
if self.options.with_jni == "auto" or self.options.target == "auto": | ||
if self.options.with_jni == "auto": | ||
return self.settings.os == "Android" | ||
else: | ||
return self.options.with_jni == True or self.options.target == "jni" | ||
return self.options.with_jni | ||
|
||
@property | ||
def _python_support(self): | ||
return self.options.with_python == True or self.options.target == "python" | ||
return self.options.with_python | ||
|
||
@property | ||
def _cppcli_support(self): | ||
if self.options.with_cppcli == "auto" or self.options.target == "auto": | ||
if self.options.with_cppcli == "auto": | ||
return self.settings.os == "Windows" | ||
else: | ||
return self.options.with_cppcli == True or self.options.target == "cppcli" | ||
|
||
def configure(self): | ||
if self.settings.compiler == "Visual Studio" or self.options.shared: | ||
del self.options.fPIC | ||
|
||
@property | ||
def _source_subfolder(self): | ||
return "source_subfolder" | ||
|
||
def build_requirements(self): | ||
if not self.options.system_java and self._jni_support: | ||
self.build_requires("zulu-openjdk/11.0.12@") | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
elif self.settings.os == "Android": | ||
self.options.system_java = True | ||
return self.options.with_cppcli | ||
|
||
@property | ||
def _supported_compilers(self): | ||
return { | ||
"gcc": "8", | ||
"clang": "7", | ||
"Visual Studio": "15", | ||
"apple-clang": "10", | ||
"msvc": "191", | ||
"Visual Studio": "15", | ||
} | ||
|
||
def configure(self): | ||
if is_msvc(self) or self.options.shared: | ||
self.options.rm_safe("fPIC") | ||
|
||
def layout(self): | ||
cmake_layout(self, src_folder="src") | ||
|
||
def validate(self): | ||
if self.options.target != "deprecated": | ||
self.output.warn("The 'target' option is deprecated and will be removed soon. Use 'with_jni', 'with_objc', 'with_python' or 'with_cppcli' options instead.") | ||
if not (self._objc_support or self._jni_support or self._python_support or self._cppcli_support): | ||
raise ConanInvalidConfiguration("Target language could not be determined automatically. Set at least one of 'with_jni', 'with_objc', 'with_python' or 'with_cppcli' options to `True`.") | ||
raise ConanInvalidConfiguration( | ||
"Target language could not be determined automatically. Set at least one of 'with_jni'," | ||
" 'with_objc', 'with_python' or 'with_cppcli' options to `True`." | ||
) | ||
if self._cppcli_support: | ||
if self.settings.os != "Windows": | ||
raise ConanInvalidConfiguration("C++/CLI has been enabled on a non-Windows operating system. This is not supported.") | ||
raise ConanInvalidConfiguration( | ||
"C++/CLI has been enabled on a non-Windows operating system. This is not supported." | ||
) | ||
if self.options.shared: | ||
raise ConanInvalidConfiguration("C++/CLI does not support building as shared library") | ||
if self.settings.compiler.runtime == "MT" or self.settings.compiler.runtime == "MTd": | ||
if is_msvc_static_runtime(self): | ||
raise ConanInvalidConfiguration("'/clr' and '/MT' command-line options are incompatible") | ||
if self._objc_support or self._jni_support or self._python_support: | ||
raise ConanInvalidConfiguration( | ||
"C++/CLI is not yet supported with other languages enabled as well. Disable 'with_jni', 'with_objc' and 'with_python' options for a valid configuration.") | ||
"C++/CLI is not yet supported with other languages enabled as well. " | ||
"Disable 'with_jni', 'with_objc' and 'with_python' options for a valid configuration." | ||
) | ||
if self._python_support: | ||
if self.settings.os == "Windows": | ||
raise ConanInvalidConfiguration("Python on Windows is not fully yet supported, please see https://github.com/cross-language-cpp/djinni-support-lib/issues.") | ||
raise ConanInvalidConfiguration( | ||
"Python on Windows is not fully yet supported, please see" | ||
" https://github.com/cross-language-cpp/djinni-support-lib/issues." | ||
) | ||
if self.settings.get_safe("compiler.cppstd"): | ||
tools.check_min_cppstd(self, "17") | ||
check_min_cppstd(self, "17") | ||
try: | ||
minimum_required_compiler_version = self._supported_compilers[str(self.settings.compiler)] | ||
if tools.Version(self.settings.compiler.version) < minimum_required_compiler_version: | ||
raise ConanInvalidConfiguration("This package requires c++17 support. The current compiler does not support it.") | ||
if Version(self.settings.compiler.version) < minimum_required_compiler_version: | ||
raise ConanInvalidConfiguration( | ||
"This package requires c++17 support. The current compiler does not support it." | ||
) | ||
except KeyError: | ||
self.output.warn("This recipe has no support for the current compiler. Please consider adding it.") | ||
self.output.warning( | ||
"This recipe has no support for the current compiler. Please consider adding it." | ||
) | ||
|
||
def build_requirements(self): | ||
if not self.options.system_java and self._jni_support: | ||
self.build_requires("zulu-openjdk/11.0.19") | ||
|
||
def source(self): | ||
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder) | ||
|
||
def _configure_cmake(self): | ||
if self._cmake: | ||
return self._cmake | ||
self._cmake = CMake(self) | ||
self._cmake.definitions["DJINNI_WITH_OBJC"] = self._objc_support | ||
self._cmake.definitions["DJINNI_WITH_JNI"] = self._jni_support | ||
self._cmake.definitions["DJINNI_WITH_PYTHON"] = self._python_support | ||
self._cmake.definitions["DJINNI_WITH_CPPCLI"] = self._cppcli_support | ||
self._cmake.definitions["BUILD_TESTING"] = False | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = self.options.shared | ||
tc.variables["DJINNI_WITH_OBJC"] = self._objc_support | ||
tc.variables["DJINNI_WITH_JNI"] = self._jni_support | ||
tc.variables["DJINNI_WITH_PYTHON"] = self._python_support | ||
tc.variables["DJINNI_WITH_CPPCLI"] = self._cppcli_support | ||
tc.variables["BUILD_TESTING"] = False | ||
if self._jni_support: | ||
self._cmake.definitions["JAVA_AWT_LIBRARY"] = "NotNeeded" | ||
self._cmake.definitions["JAVA_AWT_INCLUDE_PATH"] = "NotNeeded" | ||
self._cmake.configure() | ||
return self._cmake | ||
tc.variables["JAVA_AWT_LIBRARY"] = "NotNeeded" | ||
tc.variables["JAVA_AWT_INCLUDE_PATH"] = "NotNeeded" | ||
tc.generate() | ||
tc = CMakeDeps(self) | ||
tc.generate() | ||
tc = VirtualBuildEnv(self) | ||
tc.generate(scope="build") | ||
|
||
def build(self): | ||
cmake = self._configure_cmake() | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def package(self): | ||
cmake = self._configure_cmake() | ||
cmake = CMake(self) | ||
cmake.install() | ||
self.copy("LICENSE", dst="licenses", src=self._source_subfolder) | ||
copy(self, "LICENSE", | ||
dst=os.path.join(self.package_folder, "licenses"), | ||
src=self.source_folder) | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = tools.collect_libs(self) | ||
self.cpp_info.libs = collect_libs(self) |
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,9 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package) | ||
cmake_minimum_required(VERSION 3.15) | ||
project(test_package LANGUAGES CXX) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
find_package(djinni-support-lib REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE djinni-support-lib::djinni-support-lib) | ||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17) |
29 changes: 18 additions & 11 deletions
29
recipes/djinni-support-lib/1.x.x/test_package/conanfile.py
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,19 +1,26 @@ | ||
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" | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeDeps", "CMakeToolchain" | ||
test_type = "explicit" | ||
|
||
def _configure_cmake(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
return cmake | ||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def build(self): | ||
cmake = self._configure_cmake() | ||
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") |
8 changes: 3 additions & 5 deletions
8
recipes/djinni-support-lib/1.x.x/test_package/test_package.cpp
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,11 +1,9 @@ | ||
#include <djinni/djinni_common.hpp> | ||
|
||
#include <cstdlib> | ||
|
||
// since we would either need objective C++ or Java (jni) there is not a lot to test | ||
// just that we have the hearders and can link | ||
// just that we have the headers and can link | ||
int main() { | ||
return EXIT_SUCCESS ; | ||
return EXIT_SUCCESS; | ||
} | ||
|
||
|
||
|
8 changes: 8 additions & 0 deletions
8
recipes/djinni-support-lib/1.x.x/test_v1_package/CMakeLists.txt
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,8 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(test_package) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
|
||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ | ||
${CMAKE_CURRENT_BINARY_DIR}/test_package/) |
19 changes: 19 additions & 0 deletions
19
recipes/djinni-support-lib/1.x.x/test_v1_package/conanfile.py
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,19 @@ | ||
from conans import ConanFile, CMake, tools | ||
import os | ||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake", "cmake_find_package_multi" | ||
|
||
def _configure_cmake(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
return cmake | ||
|
||
def build(self): | ||
cmake = self._configure_cmake() | ||
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) |
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 |
---|---|---|
|
@@ -5,5 +5,4 @@ sources: | |
patches: | ||
"0.0.1": | ||
- patch_file: "patches/cmake_install.patch" | ||
base_path: "source_subfolder" | ||
|
Oops, something went wrong.