diff --git a/recipes/nvcloth/1.1.6/CMakeLists.txt b/recipes/nvcloth/1.1.6/CMakeLists.txt index a236130272a84..c3bf938133a82 100644 --- a/recipes/nvcloth/1.1.6/CMakeLists.txt +++ b/recipes/nvcloth/1.1.6/CMakeLists.txt @@ -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}") diff --git a/recipes/nvcloth/1.1.6/conandata.yml b/recipes/nvcloth/1.1.6/conandata.yml index c37596cc7f7b6..83ebca606340b 100644 --- a/recipes/nvcloth/1.1.6/conandata.yml +++ b/recipes/nvcloth/1.1.6/conandata.yml @@ -5,8 +5,8 @@ sources: patches: "1.1.6": - patch_file: "patches/0001-PsAllocator-include-typeinfo.patch" - base_path: "source_subfolder" + base_path: "." - patch_file: "patches/0002-CallbackFix.patch" - base_path: "source_subfolder" + base_path: "." - patch_file: "patches/0003-PsAllocator.patch" - base_path: "source_subfolder" + base_path: "." diff --git a/recipes/nvcloth/1.1.6/conanfile.py b/recipes/nvcloth/1.1.6/conanfile.py index c303576ad28c2..af2e23828ec98 100644 --- a/recipes/nvcloth/1.1.6/conanfile.py +++ b/recipes/nvcloth/1.1.6/conanfile.py @@ -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 +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" @@ -30,24 +35,62 @@ class NvclothConan(ConanFile): "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")) + 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") + self.package_type = "shared-library" + elif self.settings.os in ["iOS", "Android"]: + # shared builds are not supported + self.options.rm_safe("shared") + self.package_type = "static-library" + + 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)) + 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") @@ -56,74 +99,44 @@ def validate(self): 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", @@ -136,26 +149,23 @@ def _get_target_build_platform(self): 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: @@ -170,6 +180,10 @@ def package_info(self): 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'] + + if self.options.get_safe("shared") == False: if self.settings.os in ("FreeBSD", "Linux"): self.cpp_info.system_libs.append("m") diff --git a/recipes/nvcloth/1.1.6/test_package/CMakeLists.txt b/recipes/nvcloth/1.1.6/test_package/CMakeLists.txt index e0165aeedb7a2..c8c4b1d83adb3 100644 --- a/recipes/nvcloth/1.1.6/test_package/CMakeLists.txt +++ b/recipes/nvcloth/1.1.6/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/nvcloth/1.1.6/test_package/conanfile.py b/recipes/nvcloth/1.1.6/test_package/conanfile.py index e290e81a631fa..fc34f5d5c4f26 100644 --- a/recipes/nvcloth/1.1.6/test_package/conanfile.py +++ b/recipes/nvcloth/1.1.6/test_package/conanfile.py @@ -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")