Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvcloth: migrate to Conan v2 #18626

Closed
wants to merge 17 commits into from
5 changes: 1 addition & 4 deletions recipes/nvcloth/1.1.6/CMakeLists.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer use the CMake wrapper, please, use Cmaketoolchain instead: https://docs.conan.io/2/reference/tools/cmake/cmaketoolchain.html

Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup(KEEP_RPATHS)

add_subdirectory("source_subfolder/NvCloth/compiler/cmake/${TARGET_BUILD_PLATFORM}")
add_subdirectory("NvCloth/compiler/cmake/${TARGET_BUILD_PLATFORM}")
6 changes: 3 additions & 3 deletions recipes/nvcloth/1.1.6/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
url: "https://github.com/NVIDIAGameWorks/NvCloth/archive/refs/heads/1.1.6.zip"
sha256: "fe29af2e8783383d2ede8fb23a51ce9a5c59fa016e8a1d68af45a69a1828e042"
patches:
"1.1.6":
- patch_file: "patches/0001-PsAllocator-include-typeinfo.patch"
base_path: "source_subfolder"
base_path: "."

Check warning on line 8 in recipes/nvcloth/1.1.6/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/0001-PsA ... ^ (line: 7)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
base_path: "."

It's not needed anymore with new tools like apply_conandata_patch

- patch_file: "patches/0002-CallbackFix.patch"
base_path: "source_subfolder"
base_path: "."

Check warning on line 10 in recipes/nvcloth/1.1.6/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/0002-Cal ... ^ (line: 9)
- patch_file: "patches/0003-PsAllocator.patch"
base_path: "source_subfolder"
base_path: "."

Check warning on line 12 in recipes/nvcloth/1.1.6/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/0003-PsA ... ^ (line: 11)
178 changes: 96 additions & 82 deletions recipes/nvcloth/1.1.6/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import os
import shutil

from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conan.tools.microsoft import msvc_runtime_flag, is_msvc_static_runtime, is_msvc
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
from conan.tools.files import get, rmdir, copy, replace_in_file, patch, export_conandata_patches
from conan.tools.env import Environment
from conan.tools.scm import Version
from conan.tools.apple import fix_apple_shared_install_name, is_apple_os

Check warning on line 9 in recipes/nvcloth/1.1.6/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused is_apple_os imported from conan.tools.apple
from conan.errors import ConanInvalidConfiguration
from conan.tools.microsoft import is_msvc_static_runtime, is_msvc

required_conan_version = ">=1.35.0"
required_conan_version = ">=1.53.0"

class NvclothConan(ConanFile):
name = "nvcloth"
Expand All @@ -30,24 +35,62 @@
"use_dx11": False
}

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

@property
def _source_subfolder(self):
return "source_subfolder"

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

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])

copy(self, "CMakeLists.txt", self.recipe_folder, os.path.join(self.export_sources_folder, "src"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
copy(self, "CMakeLists.txt", self.recipe_folder, os.path.join(self.export_sources_folder, "src"))

export_conandata_patches(self)

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

def configure(self):
if self.settings.os in ["Windows", "Macos"]:
# static builds are not supported
self.options.rm_safe("shared")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear how is it not supported. I see the default option was shared by default, but where can I find an evidence of this breaking change?

self.package_type = "shared-library"

Check warning on line 56 in recipes/nvcloth/1.1.6/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Attribute 'package_type' defined outside __init__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.package_type = "shared-library"

Please, do not change the package-type in case both type are supported in any OS.

elif self.settings.os in ["iOS", "Android"]:
# shared builds are not supported
self.options.rm_safe("shared")
self.package_type = "static-library"

Check warning on line 60 in recipes/nvcloth/1.1.6/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Attribute 'package_type' defined outside __init__

if self.options.get_safe("shared"):
self.options.rm_safe("fPIC")

def generate(self):
tc = CMakeToolchain(self)

if self.options.get_safe("shared") is not None:
if not self.options.get_safe("shared"):
tc.variables["PX_STATIC_LIBRARIES"] = 1
tc.variables["STATIC_WINCRT"] = is_msvc_static_runtime(self)

tc.variables["NV_CLOTH_ENABLE_CUDA"] = self.options.use_cuda
tc.variables["NV_CLOTH_ENABLE_DX11"] = self.options.use_dx11

tc.variables["TARGET_BUILD_PLATFORM"] = self._get_target_build_platform()

tc.generate()
cmake = CMakeDeps(self)
cmake.generate()

def build(self):
self._patch_sources()
self._remove_samples()

env = Environment()
env.define("GW_DEPS_ROOT", os.path.abspath(self.source_folder))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why cant you pass it directly to CMake as a variable?

envvars = env.vars(self, scope="build")
with envvars.apply():
cmake = CMake(self)
cmake.configure()
cmake.build()

def validate(self):
if self.settings.os not in ["Windows", "Linux", "Macos", "Android", "iOS"]:
raise ConanInvalidConfiguration("Current os is not supported")
Expand All @@ -56,74 +99,44 @@
if build_type not in ["Debug", "RelWithDebInfo", "Release"]:
raise ConanInvalidConfiguration("Current build_type is not supported")

if is_msvc(self) and tools.Version(self.settings.compiler.version) < 9:
if is_msvc(self) and Version(self.settings.compiler.version) < 9:
raise ConanInvalidConfiguration("Visual Studio versions < 9 are not supported")

def _configure_cmake(self):
cmake = CMake(self)
if not self.options.shared:
cmake.definitions["PX_STATIC_LIBRARIES"] = 1
cmake.definitions["STATIC_WINCRT"] = is_msvc_static_runtime(self)

cmake.definitions["NV_CLOTH_ENABLE_CUDA"] = self.options.use_cuda
cmake.definitions["NV_CLOTH_ENABLE_DX11"] = self.options.use_dx11

cmake.definitions["TARGET_BUILD_PLATFORM"] = self._get_target_build_platform()

cmake.configure(
build_folder=os.path.join(self.build_folder, self._build_subfolder)
)
return cmake

def _remove_samples(self):
tools.rmdir(os.path.join(self._source_subfolder, "NvCloth", "samples"))
rmdir(self, os.path.join(self.source_folder, "NvCloth", "samples"))

def _patch_sources(self):
# There is no reason to force consumer of PhysX public headers to use one of
# NDEBUG or _DEBUG, since none of them relies on NDEBUG or _DEBUG
tools.replace_in_file(os.path.join(self.build_folder, self._source_subfolder, "PxShared", "include", "foundation", "PxPreprocessor.h"),
replace_in_file(self, os.path.join(self.source_folder, "PxShared", "include", "foundation", "PxPreprocessor.h"),
"#error Exactly one of NDEBUG and _DEBUG needs to be defined!",
"// #error Exactly one of NDEBUG and _DEBUG needs to be defined!")
shutil.copy(
os.path.join(self.build_folder, self._source_subfolder, "NvCloth/include/NvCloth/Callbacks.h"),
os.path.join(self.build_folder, self._source_subfolder, "NvCloth/include/NvCloth/Callbacks.h.origin")
os.path.join(self.source_folder, "NvCloth/include/NvCloth/Callbacks.h"),
os.path.join(self.source_folder, "NvCloth/include/NvCloth/Callbacks.h.origin")
)
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)
for each_patch in self.conan_data["patches"][self.version]:
patch(self, **each_patch)

if self.settings.build_type == "Debug":
shutil.copy(
os.path.join(self.build_folder, self._source_subfolder, "NvCloth/include/NvCloth/Callbacks.h"),
os.path.join(self.build_folder, self._source_subfolder, "NvCloth/include/NvCloth/Callbacks.h.patched")
os.path.join(self.source_folder, "NvCloth/include/NvCloth/Callbacks.h"),
os.path.join(self.source_folder, "NvCloth/include/NvCloth/Callbacks.h.patched")
)
shutil.copy(
os.path.join(self.build_folder, self._source_subfolder, "NvCloth/include/NvCloth/Callbacks.h.origin"),
os.path.join(self.build_folder, self._source_subfolder, "NvCloth/include/NvCloth/Callbacks.h")
os.path.join(self.source_folder, "NvCloth/include/NvCloth/Callbacks.h.origin"),
os.path.join(self.source_folder, "NvCloth/include/NvCloth/Callbacks.h")
)

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

def configure(self):
if self.options.shared:
del self.options.fPIC

def build(self):
with tools.environment_append({"GW_DEPS_ROOT": os.path.abspath(self._source_subfolder)}):
self._patch_sources()
self._remove_samples()
cmake = self._configure_cmake()
cmake.build()

def _get_build_type(self):
if self.settings.build_type == "Debug":
return "debug"
elif self.settings.build_type == "RelWithDebInfo":
if self.settings.build_type == "RelWithDebInfo":
return "checked"
elif self.settings.build_type == "Release":
if self.settings.build_type == "Release":
return "release"

raise ConanInvalidConfiguration("Invalid build type")

def _get_target_build_platform(self):
return {
"Windows" : "windows",
Expand All @@ -136,26 +149,23 @@
def package(self):
if self.settings.build_type == "Debug":
shutil.copy(
os.path.join(self._source_subfolder, "NvCloth/include/NvCloth/Callbacks.h.patched"),
os.path.join(self._source_subfolder, "NvCloth/include/NvCloth/Callbacks.h")
os.path.join(self.source_folder, "NvCloth/include/NvCloth/Callbacks.h.patched"),
os.path.join(self.source_folder, "NvCloth/include/NvCloth/Callbacks.h")
)
nvcloth_source_subfolder = os.path.join(self.build_folder, self._source_subfolder)
nvcloth_build_subfolder = os.path.join(self.build_folder, self._build_subfolder)

self.copy(pattern="NvCloth/license.txt", dst="licenses", src=nvcloth_source_subfolder, keep_path=False)
self.copy("*.h", dst="include", src=os.path.join(nvcloth_source_subfolder, "NvCloth", "include"))
self.copy("*.h", dst="include", src=os.path.join(nvcloth_source_subfolder, "NvCloth", "extensions", "include"))
self.copy("*.h", dst="include", src=os.path.join(nvcloth_source_subfolder, "PxShared", "include"))
self.copy("*.a", dst="lib", src=nvcloth_build_subfolder, keep_path=False)
self.copy("*.lib", dst="lib", src=nvcloth_build_subfolder, keep_path=False)
self.copy("*.dylib*", dst="lib", src=nvcloth_build_subfolder, keep_path=False)
self.copy("*.dll", dst="bin", src=nvcloth_build_subfolder, keep_path=False)
self.copy("*.so", dst="lib", src=nvcloth_build_subfolder, keep_path=False)
nvcloth_source_subfolder = self.source_folder
nvcloth_build_subfolder = self.build_folder
copy(self, pattern="NvCloth/license.txt", dst=os.path.join(self.package_folder, "licenses"), src=nvcloth_source_subfolder, keep_path=False)
copy(self, "*.h", dst=os.path.join(self.package_folder, "include"), src=os.path.join(nvcloth_source_subfolder, "NvCloth", "include"))
copy(self, "*.h", dst=os.path.join(self.package_folder, "include"), src=os.path.join(nvcloth_source_subfolder, "NvCloth", "extensions", "include"))
copy(self, "*.h", dst=os.path.join(self.package_folder, "include"), src=os.path.join(nvcloth_source_subfolder, "PxShared", "include"))
copy(self, "*.a", dst=os.path.join(self.package_folder, "lib"), src=nvcloth_build_subfolder, keep_path=False)
copy(self, "*.lib", dst=os.path.join(self.package_folder, "lib"), src=nvcloth_build_subfolder, keep_path=False)
copy(self, "*.dylib*", dst=os.path.join(self.package_folder, "lib"), src=nvcloth_build_subfolder, keep_path=False)
copy(self, "*.dll", dst=os.path.join(self.package_folder, "bin"), src=nvcloth_build_subfolder, keep_path=False)
copy(self, "*.so", dst=os.path.join(self.package_folder, "lib"), src=nvcloth_build_subfolder, keep_path=False)
fix_apple_shared_install_name(self)

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "nvcloth"
self.cpp_info.names["cmake_find_package_multi"] = "nvcloth"

if self.settings.build_type == "Debug":
debug_suffix = "DEBUG"
else:
Expand All @@ -170,6 +180,10 @@
else:
self.cpp_info.libs = ["NvCloth{}".format(debug_suffix)]

if not self.options.shared:
self.cpp_info.includedirs = ['include']
self.cpp_info.libdirs = ['lib']
self.cpp_info.bindirs = ['bin']

Comment on lines +183 to +186
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.cpp_info.includedirs = ['include']
self.cpp_info.libdirs = ['lib']
self.cpp_info.bindirs = ['bin']

These are configured already by default: https://docs.conan.io/2/reference/conanfile/methods/package_info.html#cpp-info-library-and-build-information

if self.options.get_safe("shared") == False:
if self.settings.os in ("FreeBSD", "Linux"):
self.cpp_info.system_libs.append("m")
7 changes: 2 additions & 5 deletions recipes/nvcloth/1.1.6/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

find_package(nvcloth REQUIRED nvcloth CONFIG)
find_package(nvcloth REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} nvcloth::nvcloth)
target_link_libraries(${PROJECT_NAME} PRIVATE nvcloth::nvcloth)
19 changes: 14 additions & 5 deletions recipes/nvcloth/1.1.6/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import os
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout

class NvClothTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
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):
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")