carla/Unreal/CMakeLists.txt

551 lines
12 KiB
CMake
Raw Permalink Normal View History

project (
carla-unreal
VERSION
${CARLA_VERSION}
LANGUAGES
CXX
DESCRIPTION
"Open-source simulator for autonomous driving research."
)
carla_option (
ENABLE_DIRECTORY_CLEAN
"Enable ADDITIONAL_CLEAN_FILES on directory level"
ON
)
set (
CARLA_BUILD_PATH
${CARLA_WORKSPACE_PATH}/Build/
)
set (
CARLA_UE_PATH
2024-03-04 20:33:51 +08:00
${CARLA_WORKSPACE_PATH}/Unreal/CarlaUnreal
)
2024-03-07 00:20:13 +08:00
set (
CARLA_UE_PLUGINS_PATH
${CARLA_UE_PATH}/Plugins
)
set (
CARLA_UE_CARLA_PATH
${CARLA_UE_PLUGINS_PATH}/Carla
)
set (
CARLA_UE_CARLA_TOOLS_PATH
${CARLA_UE_PLUGINS_PATH}/CarlaTools
)
2024-05-22 22:22:45 +08:00
set (
CARLA_UE_CARLA_EXPORTER_PATH
${CARLA_UE_PLUGINS_PATH}/CarlaExporter
)
set (
CARLA_UE_PROJECT_PATH
2024-03-04 20:33:51 +08:00
${CARLA_UE_PATH}/CarlaUnreal.uproject
)
set (
CARLA_UE_CONTENT_PATH
${CARLA_UE_PATH}/Content/Carla
)
if (NOT EXISTS ${CARLA_UE_CONTENT_PATH}/.git)
carla_error ("Missing CARLA content.")
endif ()
if (ENABLE_ROS2)
set (LAUNCH_ARGS ${LAUNCH_ARGS} --ros2)
endif()
2024-05-21 19:30:13 +08:00
if (ENABLE_ROS2_DEMO)
set (LAUNCH_ARGS ${LAUNCH_ARGS} --ros2-demo)
endif()
2024-03-21 03:00:14 +08:00
set (
UNREAL_EDITOR_PATH
${CARLA_UNREAL_ENGINE_PATH}/Engine/Binaries/${UE_SYSTEM_NAME}/UnrealEditor${EXE_EXT}
)
set (CARLA_UE_CONTENT_CHECK_PATH ${CARLA_UE_PATH}/Content/Carla/Blueprints)
if (IS_DIRECTORY ${CARLA_UE_CONTENT_CHECK_PATH})
carla_message_verbose ("CARLA Unreal Content - FOUND")
else ()
carla_warning ("Could not find CARLA Content, download it or running the editor will result in a crash.")
endif ()
2024-03-07 00:20:13 +08:00
set (
UE_DEPENDENCIES
2024-03-12 18:01:37 +08:00
carla-server
libsqlite3
Boost::asio
Boost::python
Boost::geometry
Boost::gil
Eigen3::Eigen
zlibstatic
png_static
rpc
)
set (UE_DEPENDENCIES_ORDER_ONLY ${UE_DEPENDENCIES})
if (BUILD_CARLA_CLIENT)
list (APPEND UE_DEPENDENCIES_ORDER_ONLY carla-client)
endif ()
list (
APPEND
UE_DEPENDENCIES_ORDER_ONLY
RecastBuilder
)
2024-03-19 03:32:33 +08:00
set (
CARLA_UNREAL_INCLUDE_PATHS_FILE_PATH
${CMAKE_CURRENT_BINARY_DIR}/Includes.inc
)
set (
CARLA_UNREAL_LIBRARIES_PATHS_FILE_PATH
${CMAKE_CURRENT_BINARY_DIR}/Libraries.inc
)
set (
CARLA_UNREAL_OPTIONS_PATHS_FILE_PATH
${CMAKE_CURRENT_BINARY_DIR}/Options.inc
)
set (
CARLA_UNREAL_INCLUDE_PATHS
${sqlite3_SOURCE_DIR}
)
foreach (UE_DEP ${UE_DEPENDENCIES})
list (
APPEND
CARLA_UNREAL_INCLUDE_PATHS
"$<TARGET_PROPERTY:${UE_DEP},INTERFACE_INCLUDE_DIRECTORIES>"
)
endforeach ()
set (
CARLA_UNREAL_LIBRARIES
$<TARGET_FILE:libsqlite3>
)
foreach (UE_DEP ${UE_DEPENDENCIES})
get_target_property (UE_DEP_TYPE ${UE_DEP} TYPE)
if (NOT ("${UE_DEP_TYPE}" STREQUAL "INTERFACE_LIBRARY"))
list (
APPEND
CARLA_UNREAL_LIBRARIES
"$<TARGET_FILE:${UE_DEP}>"
)
endif ()
endforeach ()
set (UNREAL_PROJECT_OPTIONS)
if (ENABLE_ROS2)
list (
APPEND
CARLA_UNREAL_OPTIONS
"ROS2"
)
endif()
2024-05-21 19:30:13 +08:00
if (ENABLE_ROS2_DEMO)
list (
APPEND
CARLA_UNREAL_OPTIONS
"ROS2_DEMO"
)
endif()
if (ENABLE_OSM2ODR)
list (
APPEND
CARLA_UNREAL_OPTIONS
"OSM2ODR"
)
endif()
2024-03-21 02:38:23 +08:00
if (WIN32)
set (
CARLA_UE_GENERATE_PROJECT_FILES_COMMAND
${CARLA_UNREAL_ENGINE_PATH}/GenerateProjectFiles.bat
-project=${CARLA_UE_PROJECT_PATH}
-CMakefile
-game
-engine
)
set (
CARLA_UE_BUILD_COMMAND_PREFIX
${CARLA_UNREAL_ENGINE_PATH}/Engine/Build/BatchFiles/Build.bat
)
set (
CARLA_UE_UAT_COMMAND_PREFIX
${CARLA_UNREAL_ENGINE_PATH}/Engine/Build/BatchFiles/RunUAT.bat
)
2024-03-21 02:38:23 +08:00
else ()
set (
CARLA_UE_GENERATE_PROJECT_FILES_COMMAND
${CARLA_UNREAL_ENGINE_PATH}/GenerateProjectFiles.sh
-project=${CARLA_UE_PROJECT_PATH}
-CMakefile
-game
-engine
)
set (
CARLA_UE_BUILD_COMMAND_PREFIX
2024-03-21 03:00:14 +08:00
${CARLA_UNREAL_ENGINE_PATH}/Engine/Build/BatchFiles/${UE_SYSTEM_NAME}/Build.sh
2024-03-21 02:38:23 +08:00
)
set (
CARLA_UE_UAT_COMMAND_PREFIX
${CARLA_UNREAL_ENGINE_PATH}/Engine/Build/BatchFiles/RunUAT.sh
)
2024-03-21 02:38:23 +08:00
endif ()
if (CMAKE_TOOLCHAIN_FILE)
cmake_path (
ABSOLUTE_PATH
CMAKE_TOOLCHAIN_FILE
BASE_DIRECTORY
${CARLA_WORKSPACE_PATH}
NORMALIZE
OUTPUT_VARIABLE
TOOLCHAIN_FILE
)
set (
TOOLCHAIN_FILE_OPTION
--toolchain=${TOOLCHAIN_FILE}
)
else ()
set (TOOLCHAIN_FILE_OPTION)
endif ()
2024-03-21 03:05:54 +08:00
set (
CARLA_UNREAL_CONFIGURE_OUTPUTS
${CARLA_UNREAL_INCLUDE_PATHS_FILE_PATH}
2024-03-21 02:38:23 +08:00
${CARLA_UE_CARLA_PATH}/Includes.def
${CARLA_UE_CARLA_TOOLS_PATH}/Includes.def
${CARLA_UNREAL_LIBRARIES_PATHS_FILE_PATH}
2024-03-21 02:38:23 +08:00
${CARLA_UE_CARLA_PATH}/Libraries.def
${CARLA_UE_CARLA_TOOLS_PATH}/Libraries.def
${CARLA_UNREAL_OPTIONS_PATHS_FILE_PATH}
2024-03-21 02:38:23 +08:00
${CARLA_UE_CARLA_PATH}/Options.def
${CARLA_UE_CARLA_TOOLS_PATH}/Options.def
2024-03-21 03:05:54 +08:00
)
2024-03-21 03:18:58 +08:00
file (
GENERATE
OUTPUT
${CARLA_UNREAL_INCLUDE_PATHS_FILE_PATH}
CONTENT
"${CARLA_UNREAL_INCLUDE_PATHS}"
)
file (
GENERATE
OUTPUT
${CARLA_UNREAL_LIBRARIES_PATHS_FILE_PATH}
CONTENT
"${CARLA_UNREAL_LIBRARIES}"
)
file (
GENERATE
OUTPUT
${CARLA_UNREAL_OPTIONS_PATHS_FILE_PATH}
CONTENT
"${CARLA_UNREAL_OPTIONS}"
)
2024-03-21 03:05:54 +08:00
add_custom_command (
OUTPUT
${CARLA_UNREAL_CONFIGURE_OUTPUTS}
COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink ${CARLA_UNREAL_INCLUDE_PATHS_FILE_PATH} ${CARLA_UE_CARLA_PATH}/Includes.def
COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink ${CARLA_UNREAL_INCLUDE_PATHS_FILE_PATH} ${CARLA_UE_CARLA_TOOLS_PATH}/Includes.def
COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink ${CARLA_UNREAL_LIBRARIES_PATHS_FILE_PATH} ${CARLA_UE_CARLA_PATH}/Libraries.def
COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink ${CARLA_UNREAL_LIBRARIES_PATHS_FILE_PATH} ${CARLA_UE_CARLA_TOOLS_PATH}/Libraries.def
COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink ${CARLA_UNREAL_OPTIONS_PATHS_FILE_PATH} ${CARLA_UE_CARLA_PATH}/Options.def
COMMAND ${CMAKE_COMMAND} ARGS -E create_symlink ${CARLA_UNREAL_OPTIONS_PATHS_FILE_PATH} ${CARLA_UE_CARLA_TOOLS_PATH}/Options.def
2024-03-21 03:18:58 +08:00
USES_TERMINAL
VERBATIM
2024-03-21 02:38:23 +08:00
)
2024-03-21 02:38:23 +08:00
add_custom_target (
carla-unreal-configure
DEPENDS
2024-03-21 03:05:54 +08:00
${CARLA_UNREAL_CONFIGURE_OUTPUTS}
)
2024-03-21 02:38:23 +08:00
file (
MAKE_DIRECTORY
${CARLA_UE_PATH}/Content/Carla/ExportedMaps
2024-03-18 17:49:06 +08:00
)
carla_add_custom_target (
carla-unreal
"Build the CarlaUnreal subproject."
2024-03-11 19:30:24 +08:00
COMMAND
2024-05-22 22:22:45 +08:00
${CARLA_UE_BUILD_COMMAND_PREFIX}
2024-03-21 02:38:23 +08:00
CarlaUnreal
${UE_SYSTEM_NAME}
2024-03-21 03:41:12 +08:00
${CARLA_UNREAL_BUILD_TYPE}
2024-03-21 02:38:23 +08:00
-project=${CARLA_UE_PROJECT_PATH}
-game
-buildscw
2024-03-21 03:41:12 +08:00
DEPENDS
${CARLA_UNREAL_CONFIGURE_OUTPUTS}
2024-03-21 02:38:23 +08:00
USES_TERMINAL
VERBATIM
)
add_dependencies (
carla-unreal
${UE_DEPENDENCIES_ORDER_ONLY}
)
carla_add_custom_target (
carla-unreal-editor
"Build the CarlaUnrealEditor subproject."
2024-03-12 18:01:37 +08:00
COMMAND
2024-05-22 22:22:45 +08:00
${CARLA_UE_BUILD_COMMAND_PREFIX}
2024-03-21 02:38:23 +08:00
CarlaUnrealEditor
${UE_SYSTEM_NAME}
2024-03-21 03:41:12 +08:00
${CARLA_UNREAL_BUILD_TYPE}
2024-03-21 02:38:23 +08:00
-project=${CARLA_UE_PROJECT_PATH}
-game
-buildscw
2024-03-21 03:41:12 +08:00
DEPENDS
${CARLA_UNREAL_CONFIGURE_OUTPUTS}
2024-03-12 18:01:37 +08:00
USES_TERMINAL
VERBATIM
)
add_dependencies (
carla-unreal-editor
${UE_DEPENDENCIES_ORDER_ONLY}
)
function (
add_carla_ue_package_target
PACKAGE_CONFIGURATION
UE_BUILD_CONFIGURATION)
set (
CARLA_TARGET_PACKAGE_PATH
${CARLA_PACKAGE_PATH}/${UE_SYSTEM_NAME}
)
if (NOT "${PACKAGE_CONFIGURATION}" STREQUAL "")
set (TARGET_NAME_SUFFIX -${PACKAGE_CONFIGURATION})
string (TOLOWER "${TARGET_NAME_SUFFIX}" TARGET_NAME_SUFFIX)
else ()
set (PACKAGE_CONFIGURATION "default (shipping)")
endif ()
set (TARGET_NAME_SHORT package${TARGET_NAME_SUFFIX})
set (TARGET_NAME carla-unreal-${TARGET_NAME_SHORT})
carla_add_custom_target (
${TARGET_NAME}
"Create a CARLA package in ${PACKAGE_CONFIGURATION} mode."
COMMAND
${CARLA_UE_BUILD_COMMAND_PREFIX}
CarlaUnreal
${UE_SYSTEM_NAME}
${UE_BUILD_CONFIGURATION}
-project=${CARLA_UE_PROJECT_PATH}
-game
-buildscw
COMMAND
${CARLA_UE_UAT_COMMAND_PREFIX}
BuildCookRun
-project=${CARLA_UE_PROJECT_PATH}
-nocompileeditor
-nop4
-cook
-stage
-archive
-package
-iterate
-clientconfig=${UE_BUILD_CONFIGURATION}
-TargetPlatform=${UE_SYSTEM_NAME}
-Platform=${UE_SYSTEM_NAME}
-prereqs
-build
-archivedirectory=${CARLA_PACKAGE_PATH}
DEPENDS
${CARLA_UNREAL_CONFIGURE_OUTPUTS}
USES_TERMINAL
VERBATIM
)
add_custom_command (
TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "********** PACKAGE CREATING VERSION FILE UNREAL PACKAGE EXTRA FILES STARTED **********"
COMMAND ${CMAKE_COMMAND}
-DCARLA_SOURCE_DIR=${CARLA_SOURCE_DIR}
-DCARLA_UNREAL_ENGINE_PATH=${CARLA_UNREAL_ENGINE_PATH}
-DCARLA_PACKAGE_VERSION_FILE=${CARLA_TARGET_PACKAGE_PATH}/VERSION
-P${CMAKE_CURRENT_SOURCE_DIR}/Package/CreateCarlaVersionFile.cmake
COMMAND ${CMAKE_COMMAND} -E echo "********** PACKAGE VERSION FILE UNREAL PACKAGE EXTRA FILES COMPLETED **********"
COMMAND ${CMAKE_COMMAND} -E echo "********** PACKAGE REMOVING UNREAL PACKAGE EXTRA FILES STARTED **********"
COMMAND ${CMAKE_COMMAND}
-DCARLA_TARGET_PACKAGE_PATH=${CARLA_TARGET_PACKAGE_PATH}
-P${CMAKE_CURRENT_SOURCE_DIR}/Package/RemoveUnrealPackageExtraFiles.cmake
COMMAND ${CMAKE_COMMAND} -E echo "********** PACKAGE REMOVING UNREAL PACKAGE EXTRA FILES COMPLETED **********"
COMMAND ${CMAKE_COMMAND} -E echo "********** PACKAGE COPYING CARLA ADDITIONAL FILES STARTED **********"
COMMAND ${CMAKE_COMMAND}
-DCARLA_SOURCE_DIR=${CARLA_SOURCE_DIR}
-DCARLA_TARGET_PACKAGE_PATH=${CARLA_TARGET_PACKAGE_PATH}
-DCARLA_BINARY_DIR=${CARLA_BINARY_DIR}
-P${CMAKE_CURRENT_SOURCE_DIR}/Package/CopyCarlaAdditionalFiles.cmake
COMMAND ${CMAKE_COMMAND} -E echo "********** PACKAGE COPYING CARLA ADDITIONAL FILES COMPLETED **********"
COMMAND ${CMAKE_COMMAND} -E echo "********** COMPRESSING PACKAGE STARTED **********"
COMMAND ${CMAKE_COMMAND}
-DCARLA_PACKAGE_PATH=${CARLA_PACKAGE_PATH}
-DCARLA_TARGET_PACKAGE_PATH=${CARLA_TARGET_PACKAGE_PATH}
-DTARGET_NAME_SUFFIX=${TARGET_NAME_SUFFIX}
-P${CMAKE_CURRENT_SOURCE_DIR}/Package/Compress.cmake
COMMAND ${CMAKE_COMMAND} -E echo "********** COMPRESSING PACKAGE COMPLETED **********"
)
add_dependencies (
${TARGET_NAME}
carla-unreal-editor
)
carla_add_custom_target (
${TARGET_NAME_SHORT}
"Create a CARLA package in ${PACKAGE_CONFIGURATION} mode."
)
add_dependencies (
${TARGET_NAME_SHORT}
${TARGET_NAME}
)
endfunction()
# Docs for UE5 build configurations:
# https://docs.unrealengine.com/4.27/en-US/ProductionPipelines/DevelopmentSetup/BuildConfigurations/
add_carla_ue_package_target("" Shipping)
add_carla_ue_package_target(Shipping Shipping)
add_carla_ue_package_target(Debug Debug)
add_carla_ue_package_target(DebugGame DebugGame)
add_carla_ue_package_target(Development Development)
add_carla_ue_package_target(Test Test)
2024-03-21 03:05:54 +08:00
set (
CARLA_LAUNCH_TARGET_OPTIONS
COMMENT
"Launching Carla Unreal..."
COMMAND
2024-03-21 03:05:54 +08:00
${UNREAL_EDITOR_PATH}
${CARLA_UE_PROJECT_PATH}
-${CARLA_UNREAL_RHI}
${LAUNCH_ARGS}
USES_TERMINAL
VERBATIM
)
if (WIN32)
set (
PRELAUNCH_CONTENT_CHECK_COMMAND
if exist ${CARLA_UE_CONTENT_CHECK_PATH} (exit 0) else (exit 1)
)
else ()
set (
PRELAUNCH_CONTENT_CHECK_COMMAND
test -d ${CARLA_UE_CONTENT_CHECK_PATH}
)
endif ()
carla_add_custom_target (
check-unreal-content
"Perform some basic checks to ensure that the CARLA Unreal Editor will not open without its assets."
COMMAND
${PRELAUNCH_CONTENT_CHECK_COMMAND}
COMMENT
"Performing prelaunch check for CARLA Content presence."
USES_TERMINAL
VERBATIM
)
carla_add_custom_target (
launch-only
"Open CARLA in the Unreal Editor. This will not rebuild outdated targets."
${CARLA_LAUNCH_TARGET_OPTIONS}
)
2024-03-12 18:01:37 +08:00
add_dependencies (
launch-only
check-unreal-content
)
2024-03-21 03:05:54 +08:00
carla_add_custom_target (
launch
"Build and open CARLA in the Unreal Editor."
2024-03-21 03:05:54 +08:00
${CARLA_LAUNCH_TARGET_OPTIONS}
)
add_dependencies (
launch
carla-unreal-editor
check-unreal-content
)
set_property (
2024-05-22 22:22:45 +08:00
DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES
"${CARLA_UE_PATH}/Binaries"
"${CARLA_UE_PATH}/Build"
"${CARLA_UE_PATH}/DerivedDataCache"
"${CARLA_UE_PATH}/Intermediate"
"${CARLA_UE_PATH}/Saved"
2024-05-22 22:22:45 +08:00
"${CARLA_UE_CARLA_TOOLS_PATH}/Binaries"
"${CARLA_UE_CARLA_TOOLS_PATH}/Intermediate"
"${CARLA_UE_CARLA_TOOLS_PATH}/Saved"
2024-05-22 22:22:45 +08:00
"${CARLA_UE_CARLA_EXPORTER_PATH}/Binaries"
"${CARLA_UE_CARLA_EXPORTER_PATH}/Intermediate"
"${CARLA_UE_CARLA_EXPORTER_PATH}/Saved"
"${CARLA_UE_CARLA_PATH}/Binaries"
"${CARLA_UE_CARLA_PATH}/Intermediate"
"${CARLA_UE_CARLA_PATH}/Saved"
2024-05-22 22:22:45 +08:00
"${CARLA_UE_PLUGINS_PATH}/StreetMap/Binaries"
"${CARLA_UE_PLUGINS_PATH}/StreetMap/Intermediate"
"${CARLA_UE_PLUGINS_PATH}/StreetMap/Saved"
"${CARLA_BUILD_PATH}/Package"
2024-04-22 22:41:30 +08:00
"${CARLA_BUILD_PATH}/PythonAPI/dist"
)