From b50448cc8b214471911ef4f6408469afd92283e1 Mon Sep 17 00:00:00 2001 From: gaopeng1 Date: Thu, 31 Aug 2023 14:41:53 +0800 Subject: [PATCH] feat: support 3.11 --- CMakeLists.txt | 20 +++++++++++-------- cmake/external/pybind11.cmake | 9 +++------ setup.py | 37 ++++++++++++++++++++++++----------- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4567a09..77b6c4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,8 +14,12 @@ project(${META_PROJECT_NAME} VERSION ${META_VERSION} LANGUAGES C CXX) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_C_FLAGS "-static-libgcc") - set(CMAKE_CXX_FLAGS "-static-libgcc -static-libstdc++") + set(CMAKE_C_FLAGS + "${CMAKE_C_FLAGS} -static-libgcc -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive" + ) + set(CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++ -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive" + ) endif() endif() @@ -38,18 +42,18 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Setup dependencies library, when first run # option(3RT_FROM_LOCAL - "Dependencies library will be built or find in local host." OFF + "Dependencies library will be built or find in local host." OFF ) option(3RT_FROM_CONAN - "Dependencies library will be download from openxrlab conan remote" OFF + "Dependencies library will be download from openxrlab conan remote" OFF ) # set external project install prefix set(STAGED_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/3rdparty CACHE - STRING - "dependencies install directory, if not exist, need setup You need to get the dependencies first" + STRING + "dependencies install directory, if not exist, need setup You need to get the dependencies first" ) # add cmake prefix path for find external project, find_package() @@ -64,11 +68,11 @@ endif() install(DIRECTORY ${STAGED_INSTALL_PREFIX}/ DESTINATION 3rdparty/) if(NOT EXISTS ${STAGED_INSTALL_PREFIX} AND NOT 3RT_FROM_LOCAL - AND NOT 3RT_FROM_CONAN + AND NOT 3RT_FROM_CONAN ) message( FATAL_ERROR - " + " --------------------------------------------------------------------------- You need to get the dependencies first, Configure cmake with `-D3RT_FROM_LOCAL=ON` OR `-D3RT_FROM_CONAN=ON` and cmake --build diff --git a/cmake/external/pybind11.cmake b/cmake/external/pybind11.cmake index 8ae7cc0..c5dd5e8 100644 --- a/cmake/external/pybind11.cmake +++ b/cmake/external/pybind11.cmake @@ -4,13 +4,10 @@ if(NOT IOS) externalproject_add( ext_pybind11 PREFIX pybind11 - URL https://github.com/pybind/pybind11/archive/refs/tags/v2.6.2.tar.gz - URL_HASH - SHA256=8ff2fff22df038f5cd02cea8af56622bc67f5b64534f1b83b9f133b8366acff2 + URL https://github.com/pybind/pybind11/archive/refs/tags/v2.10.4.tar.gz CMAKE_ARGS ${ExternalProject_CMAKE_ARGS_hidden} - -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}/pybind11 - -DBUILD_TESTING=OFF - -DPYBIND11_USE_STATIC_PYTHON=ON + -DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}/pybind11 + -DBUILD_TESTING=OFF -DPYBIND11_USE_STATIC_PYTHON=ON ) else() message(STATUS "[XRPrimer] Disable pybind11 on IOS") diff --git a/setup.py b/setup.py index 7f5bc84..f39d43a 100644 --- a/setup.py +++ b/setup.py @@ -148,7 +148,10 @@ def build_extension(self, ext): # Specify the arch if using MSVC generator, but only if it doesn't # contain a backward-compatibility arch spec already in the # generator name. - if not single_config and not contains_arch: + + # skip this if on windows + if (not single_config and not contains_arch + and not self.plat_name.startswith('win')): cmake_args += ['-A', PLAT_TO_CMAKE[self.plat_name]] # Multi-config generators have a different way to specify configs @@ -190,20 +193,29 @@ def build_extension(self, ext): clean_cmake(folders=['build_deps', self.build_temp]) # Build external from pre-built libs by default - ret = os.system('conan remote list | grep xrlab') - if ret == 0: # remote exists - prebuilt_args = '-D3RT_FROM_CONAN=ON' - else: - prebuilt_args = '-D3RT_FROM_LOCAL=ON' + # ret = os.system('conan remote list | findstr xrlab') + # if ret == 0: # remote exists + # prebuilt_args = '-D3RT_FROM_CONAN=ON' + # else: + # prebuilt_args = '-D3RT_FROM_LOCAL=ON' + # always build from local + prebuilt_args = '-D3RT_FROM_LOCAL=ON' + + platform_args = [] + if self.plat_name.startswith('win'): + platform_args = ['-G', 'MinGW Makefiles'] # Ensure temp dir exists os.makedirs(build_temp, exist_ok=True) # get external - subprocess.check_call( - ['cmake', '-S.', '-B', 'build_deps', prebuilt_args] + cmake_args) + subprocess.check_call(['cmake'] + platform_args + + ['-S.', '-B', 'build_deps', prebuilt_args] + + cmake_args) subprocess.check_call(['cmake', '--build', 'build_deps']) + # build project - subprocess.check_call(['cmake', '-S.', '-B', build_temp] + cmake_args) + subprocess.check_call(['cmake'] + platform_args + + ['-S.', '-B', build_temp] + cmake_args) subprocess.check_call(['cmake', '--build', build_temp] + build_args) # Move from build temp to final position for ext in self.extensions: @@ -215,6 +227,9 @@ def copy_output(self, ext): dst_path = os.path.join(self.build_lib, self.get_ext_filename(ext.name)) # Ensure dst dir exists + if not os.path.exists(src_path): + return + os.makedirs(self.build_lib, exist_ok=True) self.copy_file(src_path, dst_path) @@ -318,14 +333,14 @@ def gen_packages_items(): 'License :: OSI Approved :: Apache Software License', 'Operating System :: OS Independent', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', ], license='Apache License 2.0', - python_requires='>=3.6, <3.11', + python_requires='>=3.7, <3.12', tests_require=parse_requirements('requirements/test.txt'), install_requires=parse_requirements('requirements/runtime.txt'), ext_modules=[CMakeExtension(name='xrprimer_cpp', )],