Skip to content

Commit

Permalink
feat: support 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
gaopeng1 committed Aug 31, 2023
1 parent d94a211 commit b50448c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
20 changes: 12 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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(<xxx>)
Expand All @@ -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 <build_path>
Expand Down
9 changes: 3 additions & 6 deletions cmake/external/pybind11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
37 changes: 26 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down Expand Up @@ -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', )],
Expand Down

0 comments on commit b50448c

Please sign in to comment.