Skip to content

Commit

Permalink
(#13879) recastnavigation: conan v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm authored Nov 3, 2022
1 parent e50aa14 commit db2c751
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 62 deletions.
7 changes: 0 additions & 7 deletions recipes/recastnavigation/all/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion recipes/recastnavigation/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ sources:
patches:
"cci.20200511":
- patch_file: "patches/001_fix_shared_option.patch"
base_path: "source_subfolder"
99 changes: 55 additions & 44 deletions recipes/recastnavigation/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get
import os
from conans import ConanFile, CMake, tools

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.52.0"


class RecastNavigationConan(ConanFile):
name = "recastnavigation"
homepage = "https://github.com/recastnavigation/recastnavigation"
description = " Navigation-mesh Toolset for Games"
topics = ("conan", "navmesh", "recast", "navigation", "crowd")
topics = ("navmesh", "recast", "navigation", "crowd")
url = "https://github.com/conan-io/conan-center-index"
license = "Zlib"
exports_sources = ["CMakeLists.txt", "patches/*"]
generators = "cmake"
settings = "os", "compiler", "build_type", "arch"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
Expand All @@ -22,72 +23,82 @@ class RecastNavigationConan(ConanFile):
"shared": False,
"fPIC": True,
}
short_paths = True

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"
short_paths = True

@property
def _build_subfolder(self):
return "build_subfolder"
def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
try:
del self.options.fPIC
except Exception:
pass

def layout(self):
cmake_layout(self, src_folder="src")

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["RECASTNAVIGATION_DEMO"] = False
self._cmake.definitions["RECASTNAVIGATION_TESTS"] = False
self._cmake.definitions["RECASTNAVIGATION_EXAMPLES"] = False
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["RECASTNAVIGATION_DEMO"] = False
tc.variables["RECASTNAVIGATION_TESTS"] = False
tc.variables["RECASTNAVIGATION_EXAMPLES"] = False
tc.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("License.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "License.txt", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "recastnavigation"
self.cpp_info.names["cmake_find_package_multi"] = "recastnavigation"
self.cpp_info.components["Recast"].names["cmake_find_package"] = "Recast"
self.cpp_info.components["Recast"].names["cmake_find_package_multi"] = "Recast"
self.cpp_info.set_property("cmake_file_name", "recastnavigation")
self.cpp_info.set_property("pkg_config_name", "recastnavigation")

self.cpp_info.components["Recast"].set_property("cmake_target_name", "RecastNavigation::Recast")
self.cpp_info.components["Recast"].libs = ["Recast"]

self.cpp_info.components["Detour"].names["cmake_find_package"] = "Detour"
self.cpp_info.components["Detour"].names["cmake_find_package_multi"] = "Detour"
self.cpp_info.components["Detour"].set_property("cmake_target_name", "RecastNavigation::Detour")
self.cpp_info.components["Detour"].libs = ["Detour"]

self.cpp_info.components["DetourCrowd"].names["cmake_find_package"] = "DetourCrowd"
self.cpp_info.components["DetourCrowd"].names["cmake_find_package_multi"] = "DetourCrowd"
self.cpp_info.components["DetourCrowd"].set_property("cmake_target_name", "RecastNavigation::DetourCrowd")
self.cpp_info.components["DetourCrowd"].libs = ["DetourCrowd"]
self.cpp_info.components["DetourCrowd"].requires = ["Detour"]

self.cpp_info.components["DetourTileCache"].names["cmake_find_package"] = "DetourTileCache"
self.cpp_info.components["DetourTileCache"].names["cmake_find_package_multi"] = "DetourTileCache"
self.cpp_info.components["DetourTileCache"].set_property("cmake_target_name", "RecastNavigation::DetourTileCache")
self.cpp_info.components["DetourTileCache"].libs = ["DetourTileCache"]
self.cpp_info.components["DetourTileCache"].requires = ["Detour"]

self.cpp_info.components["DebugUtils"].names["cmake_find_package"] = "DebugUtils"
self.cpp_info.components["DebugUtils"].names["cmake_find_package_multi"] = "DebugUtils"
self.cpp_info.components["DebugUtils"].set_property("cmake_target_name", "RecastNavigation::DebugUtils")
self.cpp_info.components["DebugUtils"].libs = ["DebugUtils"]
self.cpp_info.components["DebugUtils"].requires = ["Recast", "Detour", "DetourTileCache"]

# TODO: to remove in conan v2
self.cpp_info.filenames["cmake_find_package"] = "recastnavigation"
self.cpp_info.filenames["cmake_find_package_multi"] = "recastnavigation"
self.cpp_info.names["cmake_find_package"] = "RecastNavigation"
self.cpp_info.names["cmake_find_package_multi"] = "RecastNavigation"
self.cpp_info.components["Recast"].names["cmake_find_package"] = "Recast"
self.cpp_info.components["Recast"].names["cmake_find_package_multi"] = "Recast"
self.cpp_info.components["Detour"].names["cmake_find_package"] = "Detour"
self.cpp_info.components["Detour"].names["cmake_find_package_multi"] = "Detour"
self.cpp_info.components["DetourCrowd"].names["cmake_find_package"] = "DetourCrowd"
self.cpp_info.components["DetourCrowd"].names["cmake_find_package_multi"] = "DetourCrowd"
self.cpp_info.components["DetourTileCache"].names["cmake_find_package"] = "DetourTileCache"
self.cpp_info.components["DetourTileCache"].names["cmake_find_package_multi"] = "DetourTileCache"
self.cpp_info.components["DebugUtils"].names["cmake_find_package"] = "DebugUtils"
self.cpp_info.components["DebugUtils"].names["cmake_find_package_multi"] = "DebugUtils"
7 changes: 3 additions & 4 deletions recipes/recastnavigation/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(recastnavigation REQUIRED CONFIG)

add_executable(${CMAKE_PROJECT_NAME} test_package.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE RecastNavigation::Recast)
21 changes: 15 additions & 6 deletions recipes/recastnavigation/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os
from conans import ConanFile, CMake, tools


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

def layout(self):
cmake_layout(self)

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

def build(self):
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.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/recastnavigation/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
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)
17 changes: 17 additions & 0 deletions recipes/recastnavigation/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

0 comments on commit db2c751

Please sign in to comment.