From 36ff4e16e4537c816876acb2e61b995edca9010e Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 7 Dec 2022 14:41:52 +0200 Subject: [PATCH] Export defines, add use_rmm option --- CMakeLists.txt | 15 ++++++++++++--- conanfile.py | 42 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d60a435..e365d49d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") option(BUILD_UNIT_TESTS "Build the Cupoch unit tests" ON) +option(BUILD_EXAMPLES "Build the Cupoch examples" ON) option(BUILD_PYTHON_MODULE "Build the python module" ON) option(USE_RMM "Use rmm library(fast memory allocator)" ON) option(STATIC_WINDOWS_RUNTIME "Use static (MT/MTd) Windows runtime" OFF) @@ -101,11 +102,16 @@ elseif (APPLE) endif (NOT BUILD_SHARED_LIBS) # In Release build -O3 will be added automatically by CMake # We still enable -O3 at Debug build to optimize performance + string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") - add_definitions(-O3) + add_compile_options(-O3) endif() elseif (UNIX) add_definitions(-DUNIX) + # TODO: replace these with CMake properties: + # - POSITION_INDEPENDENT_CODE + # - CXX_STANDARD + # - CMAKE_CXX_VISIBILITY_PRESET # enable c++17 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fPIC") @@ -115,8 +121,9 @@ elseif (UNIX) add_compile_options(-Wno-deprecated-declarations) # In Release build -O3 will be added automatically by CMake # We still enable -O3 at debug build to optimize performance + string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) if (uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") - add_definitions(-O3) + add_compile_options(-O3) endif() # disable BUILD_LIBREALSENSE since it is not fully supported on Linux message(STATUS "Compiling on Unix") @@ -176,4 +183,6 @@ add_subdirectory(third_party) include_directories(src) add_subdirectory(src) -add_subdirectory(examples) +if (BUILD_EXAMPLES) + add_subdirectory(examples) +endif() \ No newline at end of file diff --git a/conanfile.py b/conanfile.py index d74c3c8d..52e98d3c 100644 --- a/conanfile.py +++ b/conanfile.py @@ -19,11 +19,19 @@ class CupochConan(ConanFile): description = "Rapid 3D data processing for robotics using CUDA." settings = "os", "compiler", "build_type", "arch" - options = {"shared": [True, False], "fPIC": [True, False]} - default_options = {"shared": False, "fPIC": True} + options = {"shared": [True, False], "fPIC": [True, False], "use_rmm": [True, False]} + default_options = {"shared": False, "fPIC": True, "use_rmm": True} build_policy = "missing" - exports_sources = ["include/*", "src/*", "cmake/*", "examples/*", "scripts/*", "third_party/*", "CMakeLists.txt"] + exports_sources = [ + "include/*", + "src/*", + "cmake/*", + "examples/*", + "scripts/*", + "third_party/*", + "CMakeLists.txt", + ] @property def _with_unit_tests(self): @@ -35,6 +43,15 @@ def _with_unit_tests(self): def _skip_build(self): return os.environ.get("SKIP_BUILD", "0") != "0" + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + del self.options.use_rmm + + def configure(self): + if self.options.shared: + del self.options.fPIC + def requirements(self): self.requires("eigen/3.4.0", headers=True, transitive_headers=True) self.requires("spdlog/1.8.5", headers=True, libs=True) @@ -57,7 +74,9 @@ def layout(self): def generate(self): imgui_paths = self.dependencies["imgui/1.89.1"].cpp_info.srcdirs backends_dir = next(path for path in imgui_paths if path.endswith("bindings")) - output_dir = os.path.join(self.source_folder, "src/cupoch/visualization/visualizer/imgui/backends") + output_dir = os.path.join( + self.source_folder, "src/cupoch/visualization/visualizer/imgui/backends" + ) for backend_file in [ "imgui_impl_glfw.h", "imgui_impl_glfw.cpp", @@ -70,7 +89,10 @@ def generate(self): tc = CMakeToolchain(self) # Do not set CXX, C flags from Conan to avoid adding -stdlib=libstdc++ tc.blocks.remove("cmake_flags_init") - tc.cache_variables["BUILD_TESTING"] = self._with_unit_tests + tc.cache_variables["BUILD_UNIT_TESTS"] = self._with_unit_tests + tc.cache_variables["BUILD_EXAMPLES"] = False + tc.cache_variables["BUILD_PYTHON_MODULE"] = False + tc.cache_variables["USE_RMM"] = "use_rmm" in self.options and self.options.use_rmm tc.generate() CMakeDeps(self).generate() @@ -116,6 +138,16 @@ def package_info(self): "urdfdom", "sgm", ] + self.cpp_info.defines.append("FLANN_USE_CUDA") + if self.settings.os == "Windows": + self.cpp_info.append("WINDOWS") + self.cpp_info.append("_CRT_SECURE_NO_DEPRECATE") + self.cpp_info.append("_CRT_NONSTDC_NO_DEPRECATE") + self.cpp_info.append("_SCL_SECURE_NO_WARNINGS") + self.cpp_info.append("GLEW_STATIC") + self.cpp_info.append("THRUST_CPP11_REQUIRED_NO_ERROR") + self.cpp_info.append("NOMINMAX") + self.cpp_info.append("_USE_MATH_DEFINES") # Make the system dependencies easier to install by default in Conan 2.0 self.conf_info.define("tools.system.package_manager:mode", "install") self.conf_info.define("tools.system.package_manager:sudo", True)