Skip to content

Commit 6ecda61

Browse files
author
Liuchuan Yu
committed
Check pybind11 first and copy the dll file
1 parent e534c42 commit 6ecda61

File tree

1 file changed

+79
-39
lines changed

1 file changed

+79
-39
lines changed

setup_windows.bat

Lines changed: 79 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ set "PXREAROBOTSDK_LIB_DIR=%XROBOTKIT_CLONED_REPO_PATH%\RoboticsService\SDK\win\
1717
:: Define destination directories
1818
set "LIB_DEST_DIR=%SCRIPT_ROOT%\lib"
1919
set "INCLUDE_DEST_DIR=%SCRIPT_ROOT%\include"
20+
2021
:: Create destination directories
2122
echo Creating destination directories...
2223
mkdir "%LIB_DEST_DIR%" 2>NUL
@@ -33,6 +34,46 @@ if not exist "%INCLUDE_DEST_DIR%" (
3334

3435
echo Destination directories created successfully.
3536

37+
:: --- Check for pybind11 and install if not found ---
38+
echo.
39+
echo Checking for pybind11...
40+
pip show pybind11 >NUL 2>&1
41+
if %errorlevel% neq 0 (
42+
echo Error: pybind11 not found. Please run `pip install pybind11` first. Exiting.
43+
exit /b 1
44+
)
45+
46+
:: --- Set PYBIND11_DIR for CMake ---
47+
echo.
48+
echo Setting PYBIND11_DIR environment variable...
49+
for /f "usebackq" %%i in (`python -c "import sys; print(sys.prefix)"`) do set PYTHON_PREFIX=%%i
50+
if not defined PYTHON_PREFIX (
51+
echo Error: Could not determine Python installation prefix.
52+
echo Please ensure Python is correctly installed and in your PATH. Exiting.
53+
exit /b 1
54+
)
55+
56+
set "PYBIND11_DIR=%PYTHON_PREFIX%\Lib\site-packages\pybind11\share\cmake\pybind11"
57+
echo Attempting to set PYBIND11_DIR to: %PYBIND11_DIR%
58+
set PYBIND11_DIR=%PYBIND11_DIR%
59+
if not exist "%PYBIND11_DIR%\pybind11Config.cmake" (
60+
echo Warning: pybind11Config.cmake not found at expected PYBIND11_DIR: "%PYBIND11_DIR%"
61+
echo This might indicate a problem with the pybind11 installation or its path.
62+
:: Attempting to find another common path if the standard one doesn't work.
63+
for /d %%d in ("%PYTHON_PREFIX%\Lib\site-packages\pybind11\share\cmake\*") do (
64+
if exist "%%d\pybind11Config.cmake" (
65+
set "PYBIND11_DIR=%%d"
66+
echo Found pybind11Config.cmake in "%%d". Using this path.
67+
goto :pybind11_dir_found
68+
)
69+
)
70+
echo Critical Error: pybind11Config.cmake could not be found after pybind11 installation.
71+
echo Please check your pybind11 installation. Exiting.
72+
exit /b 1
73+
)
74+
:pybind11_dir_found
75+
echo PYBIND11_DIR set to: %PYBIND11_DIR%
76+
3677
set "DLL_NAME=PXREARobotSDK.dll"
3778
set "LIB_NAME=PXREARobotSDK.lib"
3879

@@ -139,58 +180,57 @@ if %errorlevel% neq 0 (
139180

140181
echo Libraries copied successfully.
141182

142-
:: --- Check for pybind11 and install if not found ---
183+
:: Build and install the Python project
143184
echo.
144-
echo Checking for pybind11...
145-
pip show pybind11 >NUL 2>&1
185+
echo Building and installing the Python project...
186+
python setup.py install
146187
if %errorlevel% neq 0 (
147-
echo Error: pybind11 not found. Please install pybind11 first. Exiting.
188+
echo Error: Python setup.py install failed. Exiting.
148189
goto :cleanup_and_exit
149190
)
150191

151-
:: --- Set PYBIND11_DIR for CMake ---
152-
:: This helps CMake find pybind11's configuration files during setup.py build.
192+
:: Copy DLL to the installed package location
153193
echo.
154-
echo Setting PYBIND11_DIR environment variable...
155-
for /f "usebackq" %%i in (`python -c "import sys; print(sys.prefix)"`) do set PYTHON_PREFIX=%%i
156-
if not defined PYTHON_PREFIX (
157-
echo Error: Could not determine Python installation prefix.
158-
echo Please ensure Python is correctly installed and in your PATH. Exiting.
194+
echo Copying DLL to the installed package location...
195+
for /f "usebackq" %%i in (`python -c "import site; print(site.getsitepackages()[0])"`) do set SITE_PACKAGES=%%i
196+
if not defined SITE_PACKAGES (
197+
echo Warning: Could not determine site-packages directory.
198+
echo DLL not copied to package location. You may need to do this manually.
159199
goto :cleanup_and_exit
160200
)
161201

162-
set "PYBIND11_DIR=%PYTHON_PREFIX%\Lib\site-packages\pybind11\share\cmake\pybind11"
163-
echo Attempting to set PYBIND11_DIR to: %PYBIND11_DIR%
164-
set PYBIND11_DIR=%PYBIND11_DIR%
165-
if not exist "%PYBIND11_DIR%\pybind11Config.cmake" (
166-
echo Warning: pybind11Config.cmake not found at expected PYBIND11_DIR: "%PYBIND11_DIR%"
167-
echo This might indicate a problem with the pybind11 installation or its path.
168-
:: Attempting to find another common path if the standard one doesn't work.
169-
for /d %%d in ("%PYTHON_PREFIX%\Lib\site-packages\pybind11\share\cmake\*") do (
170-
if exist "%%d\pybind11Config.cmake" (
171-
set "PYBIND11_DIR=%%d"
172-
echo Found pybind11Config.cmake in "%%d". Using this path.
173-
goto :pybind11_dir_found
174-
)
202+
:: Find the egg directory
203+
set "FOUND_EGG="
204+
for /d %%d in ("%SITE_PACKAGES%\Lib\site-packages\xrobotoolkit_sdk-*") do (
205+
set "FOUND_EGG=%%d"
206+
goto :egg_found
207+
)
208+
:egg_found
209+
210+
if not defined FOUND_EGG (
211+
echo Warning: Could not find xrobotoolkit_sdk egg directory in %SITE_PACKAGES%
212+
echo Looking in easy-install.pth...
213+
if exist "%SITE_PACKAGES%\easy-install.pth" (
214+
for /f "usebackq tokens=*" %%i in (`findstr /i "xrobotoolkit_sdk" "%SITE_PACKAGES%\easy-install.pth"`) do set "FOUND_EGG=%%i"
175215
)
176-
echo Critical Error: pybind11Config.cmake could not be found after pybind11 installation.
177-
echo Please check your pybind11 installation. Exiting.
178-
goto :cleanup_and_exit
179216
)
180-
:pybind11_dir_found
181-
echo PYBIND11_DIR set to: %PYBIND11_DIR%
182217

183-
:: Build and install the Python project
184-
echo.
185-
echo Building and installing the Python project...
186-
python setup.py install
187-
echo.
188-
echo Setup completed successfully!
189-
if %errorlevel% neq 0 (
190-
echo Error: Python setup.py install failed. Exiting.
191-
goto :cleanup_and_exit
218+
if not defined FOUND_EGG (
219+
echo Warning: Could not find xrobotoolkit_sdk egg directory.
220+
echo DLL not copied to package location. You may need to do this manually.
221+
) else (
222+
echo Found egg directory: %FOUND_EGG%
223+
echo Copying %DLL_NAME% to %FOUND_EGG%
224+
copy "%LIB_DEST_DIR%\%DLL_NAME%" "%FOUND_EGG%\"
225+
if %errorlevel% neq 0 (
226+
echo Warning: Failed to copy DLL to egg directory.
227+
) else (
228+
echo DLL successfully copied to package location.
229+
)
192230
)
193231

232+
echo Setup completed successfully!
233+
194234
:cleanup_and_exit
195235
:: Remove the temporary directory
196236
echo Cleaning up temporary directory: %TEMP_DIR%
@@ -199,4 +239,4 @@ if %errorlevel% neq 0 (
199239
echo Warning: Failed to remove temporary directory "%SCRIPT_ROOT%\%TEMP_DIR%". Please remove it manually.
200240
)
201241

202-
endlocal
242+
endlocal

0 commit comments

Comments
 (0)