Skip to content

Commit

Permalink
Migration to ConanV2
Browse files Browse the repository at this point in the history
  • Loading branch information
madduci committed Dec 30, 2023
1 parent f4fe501 commit 7fc9246
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 46 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ build/
tmp/
bin/*
.devcontainer/
.vscode/
.vscode/

test_package/CMakeUserPresets.json
55 changes: 29 additions & 26 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from conans import ConanFile, tools, CMake
from conan.tools.microsoft import msvc_runtime_flag
from conans.errors import ConanInvalidConfiguration
import os

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, export_conandata_patches, get, replace_in_file
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
from conan.tools.scm import Version

required_conan_version = ">=2.0.0"

class Opene57Conan(ConanFile):
name = "opene57"
version = "1.6.5"
Expand All @@ -25,8 +32,6 @@ class Opene57Conan(ConanFile):
"shared": False,
"fPIC": True
}
generators = "cmake", "cmake_find_package"
_cmake = None

@property
def _source_subfolder(self):
Expand Down Expand Up @@ -61,12 +66,12 @@ def validate(self):
raise ConanInvalidConfiguration("OpenE57 cannot be built as shared library yet")

if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 17)
check_min_cppstd(self, 17)

minimum_version = self._minimum_compilers_version.get(str(self.settings.compiler), False)
if not minimum_version:
self.output.warn("C++17 support required. Your compiler is unknown. Assuming it supports C++17.")
elif tools.Version(self.settings.compiler.version) < minimum_version:
elif Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration("C++17 support required, which your compiler does not support.")

def requirements(self):
Expand All @@ -81,32 +86,30 @@ def requirements(self):

self.requires("xerces-c/3.2.4")

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["PROJECT_VERSION"] = self.version
self._cmake.definitions["BUILD_EXAMPLES"] = False
self._cmake.definitions["BUILD_TOOLS"] = self.options.with_tools
self._cmake.definitions["BUILD_TESTS"] = False
if self.settings.compiler == "Visual Studio":
self._cmake.definitions["BUILD_WITH_MT"] = "MT" in msvc_runtime_flag(self)
else:
self._cmake.definitions["CMAKE_POSITION_INDEPENDENT_CODE"] = self.options.get_safe("fPIC", True)
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
def generate(self):
tc = CMakeToolchain(self)
tc.variables["PROJECT_VERSION"] = self.version
tc.variables["BUILD_EXAMPLES"] = False
tc.variables["BUILD_TOOLS"] = self.options.with_tools
tc.variables["BUILD_TESTS"] = False
if is_msvc(self):
tc.variables["BUILD_WITH_MT"] = is_msvc_static_runtime(self)
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = self.options.shared
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def build(self):
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
self.copy(pattern="LICENSE.libE57", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
copy(self, "LICENSE.libE57", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()
os.remove(os.path.join(self.package_folder, "CHANGELOG.md"))
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.dll")

def package_info(self):
if self.options.with_tools:
Expand Down
8 changes: 2 additions & 6 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
cmake_minimum_required(VERSION 3.15.0 FATAL_ERROR)
project(opene57_example CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(opene57 REQUIRED)
find_package(opene57 REQUIRED CONFIG)

add_executable(${PROJECT_NAME} example.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE opene57::opene57)
target_include_directories(${PROJECT_NAME} PRIVATE ${opene57_INCLUDE_DIRS})
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
34 changes: 21 additions & 13 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import shutil,os
from conan.tools.microsoft import msvc_runtime_flag
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 TestOpene57Conan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"

class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
if not tools.cross_building(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "opene57_example")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "opene57_example")
self.run(bin_path, env="conanrun")

0 comments on commit 7fc9246

Please sign in to comment.