From 0989aae70b599340c699c4e8410f53d81c975f76 Mon Sep 17 00:00:00 2001 From: Axel1092 Date: Thu, 18 Feb 2021 15:59:26 +0100 Subject: [PATCH] Added PROJ library dependencies in windows. Imrpoved PythonAPI compilation speed in windows. Disabled boost RTTI checks. --- PythonAPI/carla/setup.py | 5 +- PythonAPI/util/config.py | 2 +- Util/BuildTools/BuildOSM2ODR.bat | 2 + Util/BuildTools/Setup.bat | 25 +++- Util/InstallersWin/install_proj.bat | 161 +++++++++++++++++++++++++ Util/InstallersWin/install_sqlite3.bat | 151 +++++++++++++++++++++++ 6 files changed, 340 insertions(+), 6 deletions(-) create mode 100644 Util/InstallersWin/install_proj.bat create mode 100644 Util/InstallersWin/install_sqlite3.bat diff --git a/PythonAPI/carla/setup.py b/PythonAPI/carla/setup.py index abe3712c7..2dd2889a5 100755 --- a/PythonAPI/carla/setup.py +++ b/PythonAPI/carla/setup.py @@ -105,14 +105,15 @@ def get_libcarla_extensions(): sys.version_info.major, sys.version_info.minor) - extra_link_args = ['shlwapi.lib', 'Advapi32.lib'] + extra_link_args = ['shlwapi.lib', 'Advapi32.lib', 'ole32.lib', 'shell32.lib'] required_libs = [ pylib, 'libboost_filesystem', 'rpc.lib', 'carla_client.lib', 'libpng.lib', 'zlib.lib', 'Recast.lib', 'Detour.lib', 'DetourCrowd.lib', - 'osm2odr.lib', 'xerces-c_3.lib'] + 'xerces-c_3.lib', 'sqlite3.lib', + 'proj.lib', 'osm2odr.lib'] # Search for files in 'PythonAPI\carla\dependencies\lib' that contains # the names listed in required_libs in it's file name diff --git a/PythonAPI/util/config.py b/PythonAPI/util/config.py index 9d61a9d5a..90e915822 100755 --- a/PythonAPI/util/config.py +++ b/PythonAPI/util/config.py @@ -229,7 +229,7 @@ def main(): print('file not found.') elif args.osm_path is not None: if os.path.exists(args.osm_path): - with open(args.osm_path) as od_file: + with open(args.osm_path, encoding='utf-8') as od_file: try: data = od_file.read() except OSError: diff --git a/Util/BuildTools/BuildOSM2ODR.bat b/Util/BuildTools/BuildOSM2ODR.bat index fe8ae5f77..8c8a51568 100644 --- a/Util/BuildTools/BuildOSM2ODR.bat +++ b/Util/BuildTools/BuildOSM2ODR.bat @@ -82,6 +82,8 @@ if %BUILD_OSM2ODR% == true ( cmake -G "Visual Studio 15 2017 Win64"^ -DCMAKE_CXX_FLAGS_RELEASE="/MD /MP"^ -DCMAKE_INSTALL_PREFIX="%OSM2ODR_INSTALL_PATH:\=/%"^ + -DPROJ_INCLUDE_DIR=%INSTALLATION_DIR:/=\%\proj-install\include^ + -DPROJ_LIBRARY=%INSTALLATION_DIR:/=\%\proj-install/lib\proj.lib^ "%ROOT_PATH%\Util\OSM2ODR" if %errorlevel% neq 0 goto error_cmake diff --git a/Util/BuildTools/Setup.bat b/Util/BuildTools/Setup.bat index 6c64eb478..6806e5598 100644 --- a/Util/BuildTools/Setup.bat +++ b/Util/BuildTools/Setup.bat @@ -30,6 +30,7 @@ set VERSION_FILE=%ROOT_PATH:/=\%Util\ContentVersions.txt set CONTENT_DIR=%ROOT_PATH:/=\%Unreal\CarlaUE4\Content\Carla\ set CARLA_DEPENDENCIES_FOLDER=%ROOT_PATH:/=\%Unreal\CarlaUE4\Plugins\Carla\CarlaDependencies\ set CARLA_BINARIES_FOLDER=%ROOT_PATH:/=\%Unreal\CarlaUE4\Plugins\Carla\Binaries\Win64 +set CARLA_PYTHON_DEPENDENCIES=%ROOT_PATH:/=\%PythonAPI\carla\dependencies\ set USE_CHRONO=false :arg-parse @@ -185,13 +186,31 @@ copy /Y "%INSTALLATION_DIR%..\Util\BoostFiles\rational.hpp" "%INSTALLATION_DIR%b copy /Y "%INSTALLATION_DIR%..\Util\BoostFiles\read.hpp" "%INSTALLATION_DIR%boost-%BOOST_VERSION%-install\include\boost\geometry\io\wkt\read.hpp" rem ============================================================================ -rem -- Download and install Xercesc ---------------------------------------------- +rem -- Download and install Xercesc -------------------------------------------- rem ============================================================================ echo %FILE_N% Installing Xercesc... call "%INSTALLERS_DIR%install_xercesc.bat"^ --build-dir "%INSTALLATION_DIR%" +rem ============================================================================ +rem -- Download and install Sqlite3 -------------------------------------------- +rem ============================================================================ + +echo %FILE_N% Installing Sqlite3 +call "%INSTALLERS_DIR%install_sqlite3.bat"^ + --build-dir "%INSTALLATION_DIR%" +copy %INSTALLATION_DIR%\sqlite3-install\lib\sqlite3.lib %CARLA_PYTHON_DEPENDENCIES%\lib + +rem ============================================================================ +rem -- Download and install PROJ -------------------------------------------- +rem ============================================================================ + +echo %FILE_N% Installing PROJ +call "%INSTALLERS_DIR%install_proj.bat"^ + --build-dir "%INSTALLATION_DIR%" +copy %INSTALLATION_DIR%\proj-install\lib\proj.lib %CARLA_PYTHON_DEPENDENCIES%\lib + rem ============================================================================ rem -- Download and install Chrono ---------------------------------------------- rem ============================================================================ @@ -223,7 +242,7 @@ if %USE_CHRONO% == true ( xcopy /Y /S /I "%INSTALLATION_DIR%eigen-install\include\*" "%CARLA_DEPENDENCIES_FOLDER%include\*" > NUL rem Workaround for unreal not finding the .dll files copy "%INSTALLATION_DIR%chrono-install\bin\*.dll" "%CARLA_BINARIES_FOLDER%\*.dll" > NUL - + ) rem ============================================================================ @@ -268,7 +287,7 @@ set CMAKE_CONFIG_FILE=%INSTALLATION_DIR%CMakeLists.txt.in >>"%CMAKE_CONFIG_FILE%" echo. >>"%CMAKE_CONFIG_FILE%" echo if (CMAKE_BUILD_TYPE STREQUAL "Server") >>"%CMAKE_CONFIG_FILE%" echo # Prevent exceptions ->>"%CMAKE_CONFIG_FILE%" echo add_definitions(-DBOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY) +>>"%CMAKE_CONFIG_FILE%" echo add_definitions(-DBOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY) >>"%CMAKE_CONFIG_FILE%" echo add_compile_options(/EHsc) >>"%CMAKE_CONFIG_FILE%" echo add_definitions(-DASIO_NO_EXCEPTIONS) >>"%CMAKE_CONFIG_FILE%" echo add_definitions(-DBOOST_NO_EXCEPTIONS) diff --git a/Util/InstallersWin/install_proj.bat b/Util/InstallersWin/install_proj.bat new file mode 100644 index 000000000..027fef804 --- /dev/null +++ b/Util/InstallersWin/install_proj.bat @@ -0,0 +1,161 @@ +REM @echo off +setlocal + +rem BAT script that downloads and installs a ready to use +rem x64 xerces-c build for CARLA (carla.org). +rem Run it through a cmd with the x64 Visual C++ Toolset enabled. + +set LOCAL_PATH=%~dp0 +set FILE_N= -[%~n0]: + +rem Print batch params (debug purpose) +echo %FILE_N% [Batch params]: %* + +rem ============================================================================ +rem -- Parse arguments --------------------------------------------------------- +rem ============================================================================ + +:arg-parse +if not "%1"=="" ( + if "%1"=="--build-dir" ( + set BUILD_DIR=%~dpn2 + shift + ) + if "%1"=="-h" ( + goto help + ) + if "%1"=="--help" ( + goto help + ) + shift + goto :arg-parse +) + +rem If not set set the build dir to the current dir +if "%BUILD_DIR%" == "" set BUILD_DIR=%~dp0 +if not "%BUILD_DIR:~-1%"=="\" set BUILD_DIR=%BUILD_DIR%\ + +rem ============================================================================ +rem -- Local Variables --------------------------------------------------------- +rem ============================================================================ + +set PROJ_BASE_NAME=proj-7.2.1 +set PROJ_ZIP=%PROJ_BASE_NAME%.tar.gz +set PROJ_ZIP_DIR=%BUILD_DIR%%PROJ_ZIP% +set PROJ_REPO=https://download.osgeo.org/proj/%PROJ_ZIP% + +set SQLITE_INSTALL_DIR=%BUILD_DIR%sqlite3-install +set SQLITE_INCLUDE_DIR=%SQLITE_INSTALL_DIR%\include +set SQLITE_BIN=%SQLITE_INSTALL_DIR%\bin\sqlite.exe +set SQLITE_LIB=%SQLITE_INSTALL_DIR%\lib\sqlite3.lib + +set PROJ_SRC_DIR=%BUILD_DIR%proj-src +set PROJ_BUILD_DIR=%PROJ_SRC_DIR%\build +set PROJ_INSTALL_DIR=%BUILD_DIR%proj-install + +set PROJ_INCLUDE_DIR=%PROJ_INSTALL_DIR%\include +set PROJ_BIN_DIR=%PROJ_INSTALL_DIR%\bin +set PROJ_LIB_DIR=%PROJ_INSTALL_DIR%\lib + +if exist "%PROJ_INSTALL_DIR%" ( + goto already_build +) + +echo %FILE_N% Retrieving %PROJ_BASE_NAME%. +powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%PROJ_REPO%', '%PROJ_ZIP_DIR%')" +if %errorlevel% neq 0 goto error_download + +cd %BUILD_DIR% +echo %FILE_N% Extracting PROJ from "%PROJ_ZIP%". +call tar -xzf %PROJ_ZIP% +move %BUILD_DIR%%PROJ_BASE_NAME% %PROJ_SRC_DIR% + +mkdir %PROJ_BUILD_DIR% +cd %PROJ_BUILD_DIR% + +cmake -G "Visual Studio 15 2017 Win64" .. ^ + -DCMAKE_CXX_FLAGS_RELEASE="/MD /MP"^ + -DCMAKE_CXX_FLAGS="/MD /MP"^ + -DSQLITE3_INCLUDE_DIR=%SQLITE_INCLUDE_DIR% -DSQLITE3_LIBRARY=%SQLITE_LIB%^ + -DEXE_SQLITE3=%SQLITE_BIN%^ + -DENABLE_TIFF=OFF -DENABLE_CURL=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_PROJSYNC=OFF^ + -DCMAKE_BUILD_TYPE=Release -DBUILD_PROJINFO=OFF^ + -DBUILD_CCT=OFF -DBUILD_CS2CS=OFF -DBUILD_GEOD=OFF -DBUILD_GIE=OFF^ + -DBUILD_PROJ=OFF -DBUILD_TESTING=OFF^ + -DCMAKE_INSTALL_PREFIX=%PROJ_INSTALL_DIR% +if %errorlevel% neq 0 goto error_cmake + +cmake --build . --config Release --target install + +del %PROJ_ZIP_DIR% + +goto success + +rem ============================================================================ +rem -- Messages and Errors ----------------------------------------------------- +rem ============================================================================ + +:help + echo %FILE_N% Download and install a PROJ. + echo "Usage: %FILE_N% [-h^|--help] [--build-dir] [--zlib-install-dir]" + goto eof + +:success + echo. + echo %FILE_N% PROJ has been successfully installed in "%PROJ_INSTALL_DIR%"! + goto good_exit + +:already_build + echo %FILE_N% A PROJ installation already exists. + echo %FILE_N% Delete "%PROJ_INSTALL_DIR%" if you want to force a rebuild. + goto good_exit + +:error_download + echo. + echo %FILE_N% [DOWNLOAD ERROR] An error ocurred while downloading PROJ. + echo %FILE_N% [DOWNLOAD ERROR] Possible causes: + echo %FILE_N% - Make sure that the following url is valid: + echo %FILE_N% "%PROJ_REPO%" + echo %FILE_N% [DOWNLOAD ERROR] Workaround: + echo %FILE_N% - Download the PROJ's source code and + echo %FILE_N% extract the content in + echo %FILE_N% "%PROJ_SRC_DIR%" + echo %FILE_N% And re-run the setup script. + goto bad_exit + +:error_extracting + echo. + echo %FILE_N% [EXTRACTING ERROR] An error ocurred while extracting the zip. + echo %FILE_N% [EXTRACTING ERROR] Workaround: + echo %FILE_N% - Download the PROJ's source code and + echo %FILE_N% extract the content manually in + echo %FILE_N% "%PROJ_SRC_DIR%" + echo %FILE_N% And re-run the setup script. + goto bad_exit + +:error_compiling + echo. + echo %FILE_N% [COMPILING ERROR] An error ocurred while compiling with cl.exe. + echo %FILE_N% Possible causes: + echo %FILE_N% - Make sure you have Visual Studio installed. + echo %FILE_N% - Make sure you have the "x64 Visual C++ Toolset" in your path. + echo %FILE_N% For example, using the "Visual Studio x64 Native Tools Command Prompt", + echo %FILE_N% or the "vcvarsall.bat". + goto bad_exit + +:error_generating_lib + echo. + echo %FILE_N% [NMAKE ERROR] An error ocurred while compiling and installing using nmake. + goto bad_exit + +:good_exit + echo %FILE_N% Exiting... + rem A return value used for checking for errors + endlocal & set install_proj=%PROJ_INSTALL_DIR% + exit /b 0 + +:bad_exit + if exist "%PROJ_INSTALL_DIR%" rd /s /q "%PROJ_INSTALL_DIR%" + echo %FILE_N% Exiting with error... + endlocal + exit /b %errorlevel% diff --git a/Util/InstallersWin/install_sqlite3.bat b/Util/InstallersWin/install_sqlite3.bat new file mode 100644 index 000000000..00c8007db --- /dev/null +++ b/Util/InstallersWin/install_sqlite3.bat @@ -0,0 +1,151 @@ +REM @echo off +setlocal + +rem BAT script that downloads and installs a ready to use +rem x64 xerces-c build for CARLA (carla.org). +rem Run it through a cmd with the x64 Visual C++ Toolset enabled. + +set LOCAL_PATH=%~dp0 +set FILE_N= -[%~n0]: + +rem Print batch params (debug purpose) +echo %FILE_N% [Batch params]: %* + +rem ============================================================================ +rem -- Parse arguments --------------------------------------------------------- +rem ============================================================================ + +:arg-parse +if not "%1"=="" ( + if "%1"=="--build-dir" ( + set BUILD_DIR=%~dpn2 + shift + ) + if "%1"=="-h" ( + goto help + ) + if "%1"=="--help" ( + goto help + ) + shift + goto :arg-parse +) + +rem If not set set the build dir to the current dir +if "%BUILD_DIR%" == "" set BUILD_DIR=%~dp0 +if not "%BUILD_DIR:~-1%"=="\" set BUILD_DIR=%BUILD_DIR%\ + +rem ============================================================================ +rem -- Local Variables --------------------------------------------------------- +rem ============================================================================ + +set SQLITE_BASE_NAME=sqlite-amalgamation-3340100 +set SQLITE_ZIP=%SQLITE_BASE_NAME%.zip +set SQLITE_ZIP_DIR=%BUILD_DIR%%SQLITE_ZIP% +set SQLITE_REPO=https://www.sqlite.org/2021/%SQLITE_ZIP% + +set SQLITE_SRC_DIR=%BUILD_DIR%sqlite3-src +set SQLITE_INSTALL_DIR=%BUILD_DIR%sqlite3-install + +set SQLITE_INCLUDE_DIR=%SQLITE_INSTALL_DIR%\include +set SQLITE_BIN_DIR=%SQLITE_INSTALL_DIR%\bin +set SQLITE_LIB_DIR=%SQLITE_INSTALL_DIR%\lib + +if exist "%SQLITE_INSTALL_DIR%" ( + goto already_build +) + +echo %FILE_N% Retrieving %SQLITE_BASE_NAME%. +powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%SQLITE_REPO%', '%SQLITE_ZIP_DIR%')" +if %errorlevel% neq 0 goto error_download + +echo %FILE_N% Extracting Sqlite3 from "%SQLITE_ZIP%". +powershell -Command "Expand-Archive '%SQLITE_ZIP_DIR%' -DestinationPath '%BUILD_DIR%'" +move %BUILD_DIR%%SQLITE_BASE_NAME% %SQLITE_SRC_DIR% + +cd %SQLITE_SRC_DIR% + +call cl /MD /MP sqlite3.c shell.c -Fesqlite.exe +call cl /MD /MP /c /EHsc sqlite3.c +call lib sqlite3.obj + +mkdir %SQLITE_INCLUDE_DIR% +mkdir %SQLITE_BIN_DIR% +mkdir %SQLITE_LIB_DIR% + +move sqlite.exe %SQLITE_BIN_DIR% +move sqlite3.h %SQLITE_INCLUDE_DIR% +move sqlite3.lib %SQLITE_LIB_DIR% + +del %SQLITE_ZIP_DIR% + +goto success + +rem ============================================================================ +rem -- Messages and Errors ----------------------------------------------------- +rem ============================================================================ + +:help + echo %FILE_N% Download and install a Sqlite3. + echo "Usage: %FILE_N% [-h^|--help] [--build-dir] [--zlib-install-dir]" + goto eof + +:success + echo. + echo %FILE_N% Sqlite3 has been successfully installed in "%SQLITE_INSTALL_DIR%"! + goto good_exit + +:already_build + echo %FILE_N% A Sqlite3 installation already exists. + echo %FILE_N% Delete "%SQLITE_INSTALL_DIR%" if you want to force a rebuild. + goto good_exit + +:error_download + echo. + echo %FILE_N% [DOWNLOAD ERROR] An error ocurred while downloading Sqlite3. + echo %FILE_N% [DOWNLOAD ERROR] Possible causes: + echo %FILE_N% - Make sure that the following url is valid: + echo %FILE_N% "%SQLITE_REPO%" + echo %FILE_N% [DOWNLOAD ERROR] Workaround: + echo %FILE_N% - Download the Sqlite3's source code and + echo %FILE_N% extract the content in + echo %FILE_N% "%SQLITE_SRC_DIR%" + echo %FILE_N% And re-run the setup script. + goto bad_exit + +:error_extracting + echo. + echo %FILE_N% [EXTRACTING ERROR] An error ocurred while extracting the zip. + echo %FILE_N% [EXTRACTING ERROR] Workaround: + echo %FILE_N% - Download the Sqlite3's source code and + echo %FILE_N% extract the content manually in + echo %FILE_N% "%SQLITE_SRC_DIR%" + echo %FILE_N% And re-run the setup script. + goto bad_exit + +:error_compiling + echo. + echo %FILE_N% [COMPILING ERROR] An error ocurred while compiling with cl.exe. + echo %FILE_N% Possible causes: + echo %FILE_N% - Make sure you have Visual Studio installed. + echo %FILE_N% - Make sure you have the "x64 Visual C++ Toolset" in your path. + echo %FILE_N% For example, using the "Visual Studio x64 Native Tools Command Prompt", + echo %FILE_N% or the "vcvarsall.bat". + goto bad_exit + +:error_generating_lib + echo. + echo %FILE_N% [NMAKE ERROR] An error ocurred while compiling and installing using nmake. + goto bad_exit + +:good_exit + echo %FILE_N% Exiting... + rem A return value used for checking for errors + endlocal & set install_Sqlite3=%SQLITE_INSTALL_DIR% + exit /b 0 + +:bad_exit + if exist "%SQLITE_INSTALL_DIR%" rd /s /q "%SQLITE_INSTALL_DIR%" + echo %FILE_N% Exiting with error... + endlocal + exit /b %errorlevel%