From 3ccf69e20ad9ab05f329af694226231a67c77c85 Mon Sep 17 00:00:00 2001 From: MarcelPiNacy-CVC <169088301+MarcelPiNacy-CVC@users.noreply.github.com> Date: Thu, 30 Jan 2025 16:13:30 +0100 Subject: [PATCH] Minor setup script and build system upgrade. (#8616) * Add additional python arguments + simplify toolchain cmake file. * Several CarlaSetup.sh fixes. * Remove GCC_COMPILER and GXX_COMPILER, remove gcc apt dependencies and skip python install if --python-path is passed to InstallPrerequisites. * Minor fix. * Another bash error fix. * Yet another bash mistake fix. * Fix several windows setup script errors. --- CMake/Options.cmake | 12 ---- .../{LinuxToolchain.cmake => Toolchain.cmake} | 4 ++ CMakePresets.json | 35 +-------- CarlaSetup.bat | 72 +++++++++++++------ CarlaSetup.sh | 28 ++++++-- Util/SetupUtils/InstallPrerequisites.bat | 63 +++++++++++----- Util/SetupUtils/InstallPrerequisites.sh | 42 ++++++++--- 7 files changed, 161 insertions(+), 95 deletions(-) rename CMake/{LinuxToolchain.cmake => Toolchain.cmake} (99%) diff --git a/CMake/Options.cmake b/CMake/Options.cmake index c6b13daf7..fecbeab52 100644 --- a/CMake/Options.cmake +++ b/CMake/Options.cmake @@ -128,18 +128,6 @@ carla_string_option ( "png" ) -carla_string_option ( - GXX_COMPILER - "g++ compiler used by some CARLA extensions." - /usr/bin/g++-12 -) - -carla_string_option ( - GCC_COMPILER - "gcc compiler used by some CARLA extensions." - /usr/bin/gcc-12 -) - carla_option ( VERBOSE_CONFIGURE "Whether to emit extra messages during CMake configure." diff --git a/CMake/LinuxToolchain.cmake b/CMake/Toolchain.cmake similarity index 99% rename from CMake/LinuxToolchain.cmake rename to CMake/Toolchain.cmake index 5ef37355d..5940300d5 100644 --- a/CMake/LinuxToolchain.cmake +++ b/CMake/Toolchain.cmake @@ -8,6 +8,8 @@ ]] +if (LINUX) + set (UE_ROOT $ENV{CARLA_UNREAL_ENGINE_PATH}) if (NOT UE_ROOT) @@ -204,3 +206,5 @@ set ( CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${UE_INCLUDE} ${UE_INCLUDE}/c++/v1 ) + +endif () diff --git a/CMakePresets.json b/CMakePresets.json index 3a6723180..fa342439f 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -13,11 +13,6 @@ "generator": "Ninja", "binaryDir": "${sourceDir}/Build/${presetName}", "installDir": "${sourceDir}/Install/${presetName}", - "hidden": true - }, - { - "name": "Linux-Common", - "inherits": "Common", "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/CMake/LinuxToolchain.cmake" @@ -25,7 +20,7 @@ "hidden": true }, { - "name": "Windows-Debug", + "name": "Debug", "inherits": "Common", "cacheVariables": { @@ -33,7 +28,7 @@ } }, { - "name": "Windows-Development", + "name": "Development", "inherits": "Common", "cacheVariables": { @@ -41,36 +36,12 @@ } }, { - "name": "Windows-Release", + "name": "Release", "inherits": "Common", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" } - }, - { - "name": "Linux-Debug", - "inherits": "Linux-Common", - "cacheVariables": - { - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "Linux-Development", - "inherits": "Linux-Common", - "cacheVariables": - { - "CMAKE_BUILD_TYPE": "RelWithDebInfo" - } - }, - { - "name": "Linux-Release", - "inherits": "Linux-Common", - "cacheVariables": - { - "CMAKE_BUILD_TYPE": "Release" - } } ] } diff --git a/CarlaSetup.bat b/CarlaSetup.bat index c886b1151..af7148c48 100644 --- a/CarlaSetup.bat +++ b/CarlaSetup.bat @@ -1,35 +1,62 @@ @echo off setlocal EnableDelayedExpansion -set SKIP_PREREQUISITES=false -set LAUNCH=false -set INTERACTIVE=false +set skip_prerequisites=false +set launch=false +set interactive=false +set python_path=python +set python_root= -if not "%*"=="" ( - for %%x in ("%*") do ( - if "%%~x"=="--interactive" ( - set INTERACTIVE=true - ) else if "%%~x"=="-i" ( - set INTERACTIVE=true - ) else if "%%~x"=="--skip-prerequisites" ( - set SKIP_PREREQUISITES=true - ) else if "%%~x"=="-p" ( - set SKIP_PREREQUISITES=true - ) else if "%%~x"=="--launch" ( - set LAUNCH=true - ) else if "%%~x"=="-l" ( - set LAUNCH=true +rem -- PARSE COMMAND LINE ARGUMENTS -- + +:parse + if "%1"=="" ( + goto main + ) + if "%1"=="--interactive" ( + set interactive=true + ) else if "%1"=="-i" ( + set interactive=true + ) else if "%1"=="--skip-prerequisites" ( + set skip_prerequisites=true + ) else if "%1"=="-p" ( + set skip_prerequisites=true + ) else if "%1"=="--launch" ( + set launch=true + ) else if "%1"=="-l" ( + set launch=true + ) else ( + echo %1 | findstr /B /C:"--python-root=" >nul + if not errorlevel 1 ( + set python_root="%1" + set python_root="!python_root:--python-root=!" + ) else if "%1"=="--python-root" ( + set python_root=%2 + shift + ) else if "%1"=="-pyroot" ( + set python_root=%2 + shift ) else ( - echo Unknown argument "%%~x" + echo Unknown argument "%1" + exit /b ) ) + shift + goto parse + +rem -- MAIN -- + +:main + +if not "%python_root%"=="" ( + set python_path=%python_root%\python ) rem -- PREREQUISITES INSTALL STEP -- -if %SKIP_PREREQUISITES%==false ( +if %skip_prerequisites%==false ( echo Installing prerequisites... - call Util/SetupUtils/InstallPrerequisites.bat || exit /b + call Util/SetupUtils/InstallPrerequisites.bat --python-path=%python_path% || exit /b ) else ( echo Skipping prerequisites install step. ) @@ -91,6 +118,9 @@ cmake ^ -G Ninja ^ -S . ^ -B Build ^ + --toolchain=CMake/Toolchain.cmake ^ + -DPython_ROOT_DIR=%python_root% ^ + -DPython3_ROOT_DIR=%python_root% ^ -DCMAKE_BUILD_TYPE=Release ^ -DCARLA_UNREAL_ENGINE_PATH=%CARLA_UNREAL_ENGINE_PATH% || exit /b echo Building CARLA... @@ -101,7 +131,7 @@ echo CARLA Python API build+install succeeded. rem -- POST-BUILD STEPS -- -if %LAUNCH%==true ( +if %launch%==true ( echo Launching Carla Unreal Editor... cmake --build Build --target launch || exit /b ) diff --git a/CarlaSetup.sh b/CarlaSetup.sh index 2c26a469d..1e6ed9975 100755 --- a/CarlaSetup.sh +++ b/CarlaSetup.sh @@ -5,26 +5,36 @@ set -e interactive=0 skip_prerequisites=0 launch=0 +python_root= workspace_path="$(dirname $(realpath "${BASH_SOURCE[-1]}"))" echo "workspace_path=$workspace_path" -options=$(getopt -o "i,p,l" --long "interactive,skip-prerequisites,launch" -n 'CarlaSetup.sh' -- "$@") +options=$(\ + getopt \ + -o "i,p,l,pyroot:" \ + --long "interactive,skip-prerequisites,launch,python-root:" \ + -n 'CarlaSetup.sh' -- "$@") + eval set -- "$options" while true; do case "$1" in - -i | --interactive) + -i|--interactive) interactive=1 shift ;; - -p | --skip-prerequisites) + -p|--skip-prerequisites) skip_prerequisites=1 shift ;; - -l | --launch) + -l|--launch) launch=1 shift ;; + -pyroot|--python-root) + python_root=$2 + shift 2 + ;; --) shift break @@ -61,8 +71,12 @@ fi # -- PREREQUISITES INSTALL STEP -- if [ $skip_prerequisites -eq 0 ]; then + python_path=python3 + if [ "$python_root" != "" ]; then + python_path=${python_root}/python3 + fi echo "Installing prerequisites..." - sudo -E bash -x Util/SetupUtils/InstallPrerequisites.sh + sudo -E bash -x Util/SetupUtils/InstallPrerequisites.sh --python-path=$python_path else echo "Skipping prerequisites install step." fi @@ -114,10 +128,12 @@ fi # -- BUILD CARLA -- echo "Configuring the CARLA CMake project..." cmake -G Ninja -S . -B Build \ - --toolchain=$PWD/CMake/LinuxToolchain.cmake \ + --toolchain=$PWD/CMake/Toolchain.cmake \ -DLAUNCH_ARGS="-prefernvidia" \ -DCMAKE_BUILD_TYPE=Release \ -DENABLE_ROS2=ON \ + -DPython_ROOT_DIR=${python_root} \ + -DPython3_ROOT_DIR=${python_root} \ -DCARLA_UNREAL_ENGINE_PATH=$CARLA_UNREAL_ENGINE_PATH echo "Building CARLA..." cmake --build Build diff --git a/Util/SetupUtils/InstallPrerequisites.bat b/Util/SetupUtils/InstallPrerequisites.bat index 4e7b13804..e07293ebe 100644 --- a/Util/SetupUtils/InstallPrerequisites.bat +++ b/Util/SetupUtils/InstallPrerequisites.bat @@ -1,9 +1,12 @@ @echo off -set NINJA_VERSION=1.12.1 -set PYTHON_VERSION=3.8.10 +set ninja_version=1.12.1 + +set python_path=python +set python_version_default=3.8.10 + rem https://learn.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-community?view=vs-2022&preserve-view=true -set VISUAL_STUDIO_COMPONENTS=^ +set visual_studio_components=^ Microsoft.VisualStudio.Workload.NativeDesktop ^ Microsoft.VisualStudio.Workload.NativeGame ^ Microsoft.VisualStudio.Workload.ManagedDesktop ^ @@ -14,7 +17,35 @@ set VISUAL_STUDIO_COMPONENTS=^ Microsoft.VisualStudio.Component.VC.Llvm.Clang ^ Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset ^ Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Llvm.Clang ^ - Microsoft.VisualStudio.Component.VC.14.36.17.6.x86.x64 + Microsoft.VisualStudio.Component.VC.14.36.17.6.x86.x64 ^ + Microsoft.Component.PythonTools + +rem -- PARSE COMMAND LINE ARGUMENTS -- + +:parse + if "%1"=="" ( + goto main + ) + echo %1 | findstr /B /C:"--python-path=" >nul + if not errorlevel 1 ( + set python_path="%1" + set python_path="!python_path:--python-path=!" + ) else if "%1"=="--python-path" ( + set python_path=%2 + shift + ) else if "%1"=="-pypath" ( + set python_path=%2 + shift + ) else ( + echo Unknown argument "%1" + exit /b + ) + shift + goto parse + +rem -- MAIN -- + +:main rem -- INSTALL VISUAL STUDIO -- if not exist %cd%\Temp ( @@ -23,38 +54,38 @@ if not exist %cd%\Temp ( pushd Temp curl -L -O https://aka.ms/vs/17/release/vs_community.exe || exit /b popd Temp -%cd%\Temp\vs_community.exe --add %VISUAL_STUDIO_COMPONENTS% --installWhileDownloading --passive --wait || exit /b +%cd%\Temp\vs_community.exe --add %visual_studio_components% --installWhileDownloading --passive --wait || exit /b del %cd%\Temp\vs_community.exe rmdir %cd%\Temp rem -- INSTALL NINJA -- -ninja --version 2>NUL +ninja --version >nul 2>nul if errorlevel 1 ( echo Could not find Ninja. Downloading... - curl -L -o %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\ninja-win.zip https://github.com/ninja-build/ninja/releases/download/v%NINJA_VERSION%/ninja-win.zip || exit /b + curl -L -o %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\ninja-win.zip https://github.com/ninja-build/ninja/releases/download/v%ninja_version%/ninja-win.zip || exit /b powershell -command "Expand-Archive $env:USERPROFILE\AppData\Local\Microsoft\WindowsApps\ninja-win.zip $env:USERPROFILE\AppData\Local\Microsoft\WindowsApps\ninja-win" || exit /b move %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\ninja-win\ninja.exe %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\ninja.exe || exit /b rmdir /s /q %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\ninja-win del /f %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\ninja-win.zip - echo Installed Ninja %NINJA_VERSION%. + echo Installed Ninja %ninja_version%. ) else ( echo Found Ninja. ) rem -- INSTALL PYTHON -- -python --version 2>NUL +%python_path% -V >nul 2>nul if errorlevel 1 ( echo Could not find Python. Downloading... - echo Installing Python %PYTHON_VERSION%... - curl -L -O https://www.python.org/ftp/python/%PYTHON_VERSION%/python-%PYTHON_VERSION%-amd64.exe || exit /b - python-%PYTHON_VERSION%-amd64.exe /passive PrependPath=1 || exit /b - del python-%PYTHON_VERSION%-amd64.exe + echo Installing Python %python_version_default%... + curl -L -O https://www.python.org/ftp/python/%python_version_default%/python-%python_version_default%-amd64.exe || exit /b + python-%python_version_default%-amd64.exe /passive PrependPath=1 || exit /b + del python-%python_version_default%-amd64.exe set "PATH=%LocalAppData%\Programs\Python\Python38\Scripts\;%LocalAppData%\Programs\Python\Python38\;%PATH%" - echo Python %PYTHON_VERSION% installed!!! + echo Installed Python %python_version_default%. ) else ( echo Found Python. ) rem -- INSTALL PYTHON PACKAGES -- -python -m pip install --upgrade pip || exit /b -python -m pip install -r requirements.txt || exit /b +%python_path% -m pip install --upgrade pip || exit /b +%python_path% -m pip install -r requirements.txt || exit /b diff --git a/Util/SetupUtils/InstallPrerequisites.sh b/Util/SetupUtils/InstallPrerequisites.sh index 8e274eb5d..97197a1fc 100644 --- a/Util/SetupUtils/InstallPrerequisites.sh +++ b/Util/SetupUtils/InstallPrerequisites.sh @@ -2,6 +2,31 @@ set -e +python_path_default='python3' +python_path=$python_path_default + +options=$(\ + getopt \ + -o "pypath:" \ + --long "python-path:" \ + -n 'CarlaSetup.sh' -- "$@") + +eval set -- "$options" +while true; do + case "$1" in + -pypath|--python-path) + python_path=$2 + shift 2 + ;; + --) + shift + break + ;; + *) + ;; + esac +done + if [ -z "$EUID" ]; then EUID=$(id -u) fi @@ -16,14 +41,9 @@ echo "Installing Ubuntu Packages..." apt-get update apt-get -y install \ build-essential \ - g++-12 \ - gcc-12 \ make \ ninja-build \ libvulkan1 \ - python3 \ - python3-dev \ - python3-pip \ libpng-dev \ libtiff5-dev \ libjpeg-dev \ @@ -36,13 +56,19 @@ apt-get -y install \ git \ git-lfs +if [ "$python_path" == "python3" ]; then + apt-get -y install \ + python3 \ + python3-dev \ + python3-pip +fi + # -- INSTALL PYTHON PACKAGES -- echo "Installing Python Packages..." -pip3 install --upgrade pip -pip3 install -r requirements.txt +$python_path -m pip install --upgrade pip +$python_path -m pip install -r requirements.txt # -- INSTALL CMAKE -- - check_cmake_version() { CMAKE_VERSION="$($2 --version | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')" CMAKE_MINIMUM_VERSION=$1