Set up build system

This commit is contained in:
nsubiron 2017-07-26 16:04:39 +02:00
parent b8ea6d1f7b
commit 7d582e4b6e
20 changed files with 437 additions and 501 deletions

5
.gitignore vendored
View File

@ -8,3 +8,8 @@ Saved
# Other
Doxygen
Util/Build
Util/Install
*.log
*.pid

View File

@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "0.4.6",
"VersionName": "0.5.0",
"FriendlyName": "CARLA",
"Description": "",
"Category": "Science",

View File

@ -1,4 +1,4 @@
PROJECT_NAME = "CARLA UE4 Plugin"
PROJECT_NAME = CARLA
OUTPUT_DIRECTORY = Doxygen
CREATE_SUBDIRS = YES
FULL_PATH_NAMES = NO
@ -11,8 +11,8 @@ CASE_SENSE_NAMES = YES
SORT_BRIEF_DOCS = YES
WARN_IF_UNDOCUMENTED = NO
WARN_LOGFILE = Doxygen/warnings.log
INPUT = Source
FILE_PATTERNS = *.cpp *.h *.hpp *.cc
INPUT = Source Util/CarlaServer/source Util/PythonClient
FILE_PATTERNS = *.cpp *.h *.hpp *.cc *.py
RECURSIVE = YES
SOURCE_BROWSER = YES
STRIP_CODE_COMMENTS = NO
@ -26,7 +26,7 @@ FORMULA_FONTSIZE = 12
GENERATE_LATEX = NO
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
INCLUDE_PATH = "Source/Carla" "Source/Common" "Source/CarlaServer/source"
INCLUDE_PATH = Source Util/CarlaServer/source Util/Install/include
INCLUDE_FILE_PATTERNS = *.h *.hpp
HIDE_UNDOC_RELATIONS = NO
HAVE_DOT = YES

View File

@ -1,9 +1,81 @@
CarlaServer:
cd Source/CarlaServer && $(MAKE)
INSTALL_FOLDER=$(PWD)/Util/Install
PYTHON_CLIENT_FOLDER=$(PWD)/Util/PythonClient
BASE_BUILD_FOLDER=$(PWD)/Util/Build/carlaserver-build
MY_CMAKE_FOLDER=$(PWD)/Util/cmake
MY_CMAKE_FLAGS=-B"$(BUILD_FOLDER)" -DCMAKE_INSTALL_PREFIX="$(INSTALL_FOLDER)"
all:
cd Source/CarlaServer && $(MAKE) debug
cd Source/CarlaServer && $(MAKE) release
ifeq ($(OS),Windows_NT)
BUILD_RULE=build_windows
PROTOC_CALL=echo "Error!"
else
BUILD_RULE=build_linux
PROTOC_CALL=./Util/Protoc.sh
endif
default: release
### Build ######################################################################
debug: BUILD_FOLDER=$(BASE_BUILD_FOLDER)/debug
debug: MY_CMAKE_FLAGS+=-DCMAKE_BUILD_TYPE=Debug
debug: $(BUILD_RULE)
release: BUILD_FOLDER=$(BASE_BUILD_FOLDER)/release
release: MY_CMAKE_FLAGS+=-DCMAKE_BUILD_TYPE=Release
release: $(BUILD_RULE)
build_linux: MY_CMAKE_FLAGS+=-G "Ninja"
build_linux: call_cmake
cd $(BUILD_FOLDER) && ninja && ninja install
build_windows: MY_CMAKE_FLAGS+=-G "NMake Makefiles"
build_windows: call_cmake
cd $(BUILD_FOLDER) && nmake && nmake install
vsproject: BUILD_FOLDER=$(BASE_BUILD_FOLDER)/visualstudio
vsproject: MY_CMAKE_FLAGS+=-DCMAKE_BUILD_TYPE=Debug
vsproject: MY_CMAKE_FLAGS+=-G "Visual Studio 14 2015 Win64"
vsproject: call_cmake
call_cmake: protobuf
mkdir -p $(BUILD_FOLDER)
cd $(BUILD_FOLDER) && cmake $(MY_CMAKE_FLAGS) "$(MY_CMAKE_FOLDER)"
protobuf:
$(PROTOC_CALL)
### Docs #######################################################################
docs:
doxygen
@echo "Documentation index at ./Doxygen/html/index.html"
### Clean ######################################################################
clean:
cd Source/CarlaServer && $(MAKE) clean
rm -Rf $(BASE_BUILD_FOLDER) $(INSTALL_FOLDER) Doxygen
$(PROTOC_CALL) --clean
### Test #######################################################################
check: debug launch_test_clients run_test_debug kill_test_clients
check_release: release launch_test_clients run_test_release kill_test_clients
run_test_debug:
@-LD_LIBRARY_PATH=$(INSTALL_FOLDER)/lib $(INSTALL_FOLDER)/bin/test_carlaserverd --gtest_shuffle
run_test_release:
@-LD_LIBRARY_PATH=$(INSTALL_FOLDER)/lib $(INSTALL_FOLDER)/bin/test_carlaserver --gtest_shuffle
launch_test_clients:
@echo "Launch echo_client.py"
@python $(PYTHON_CLIENT_FOLDER)/echo_client.py -p 4000 & echo $$! > echo_client.pid
@echo "Launch carla_client.py"
@python $(PYTHON_CLIENT_FOLDER)/carla_client.py -p 2000 & echo $$! > carla_client.pid
kill_test_clients:
@echo "Kill echo_client.py"
@kill `cat echo_client.pid` && rm echo_client.pid
@echo "Kill carla_client.py"
@kill `cat carla_client.pid` && rm carla_client.pid

158
Setup.sh Executable file
View File

@ -0,0 +1,158 @@
#! /bin/bash
################################################################################
# CARLA Util Setup
#
# This downloads and compiles libc++. So we can build and compile our
# dependencies with libc++ for linking against Unreal.
#
# Thanks to the people at https://github.com/Microsoft/AirSim for providing the
# important parts of this script.
################################################################################
# set -x
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
pushd "$SCRIPT_DIR" >/dev/null
mkdir -p Util/Build
pushd Util/Build >/dev/null
# Require clang 3.9
command -v clang++-3.9 >/dev/null 2>&1 || {
echo >&2 "clang 3.9 is required, but it's not installed.";
echo >&2 "make sure you build Unreal Engine with clang 3.9 too.";
exit 1;
}
# ==============================================================================
# -- Get and compile libc++ ----------------------------------------------------
# ==============================================================================
# Get libc++ source
if [[ ! -d "llvm-source" ]]; then
echo "Retrieving libc++..."
git clone --depth=1 -b release_39 https://github.com/llvm-mirror/llvm.git llvm-source
git clone --depth=1 -b release_39 https://github.com/llvm-mirror/libcxx.git llvm-source/projects/libcxx
git clone --depth=1 -b release_39 https://github.com/llvm-mirror/libcxxabi.git llvm-source/projects/libcxxabi
else
echo "Folder llvm-source already exists, skipping git clone..."
fi
# Build libc++
rm -rf llvm-build
mkdir -p llvm-build
pushd llvm-build >/dev/null
export C_COMPILER=clang-3.9
export COMPILER=clang++-3.9
cmake -DCMAKE_C_COMPILER=${C_COMPILER} -DCMAKE_CXX_COMPILER=${COMPILER} \
-LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF -DLIBCXX_INSTALL_EXPERIMENTAL_LIBRARY=OFF \
-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX="../llvm-install" \
../llvm-source
make cxx
#install libc++ locally in llvm-install folder
make install-libcxx install-libcxxabi
popd >/dev/null
# ==============================================================================
# -- Get Boost and compile it with libc++ --------------------------------------
# ==============================================================================
# Get boost source
if [[ ! -d "boost-source" ]]; then
echo "Retrieving boost..."
wget https://dl.bintray.com/boostorg/release/1.64.0/source/boost_1_64_0.tar.gz
tar -xvzf boost_1_64_0.tar.gz
rm boost_1_64_0.tar.gz
mv boost_1_64_0 boost-source
else
echo "Folder boost-source already exists, skipping download..."
fi
pushd boost-source >/dev/null
BOOST_TOOLSET="clang-3.9"
BOOST_CFLAGS="-fPIC -std=c++1y -stdlib=libc++ -I../llvm-install/include/c++/v1"
BOOST_LFLAGS="-stdlib=libc++ -L../llvm-install/lib"
./bootstrap.sh --with-toolset=clang --prefix=../boost-install
./b2 clean
./b2 toolset="${BOOST_TOOLSET}" cxxflags="${BOOST_CFLAGS}" linkflags="${BOOST_LFLAGS}" --prefix="../boost-install" -j 4 stage release
./b2 install toolset="${BOOST_TOOLSET}" cxxflags="${BOOST_CFLAGS}" linkflags="${BOOST_LFLAGS}" --prefix="../boost-install"
popd >/dev/null
# ==============================================================================
# -- Get Protobuf and compile it with libc++ -----------------------------------
# ==============================================================================
# Get protobuf source
if [[ ! -d "protobuf-source" ]]; then
echo "Retrieving protobuf..."
git clone --depth=1 -b v3.3.0 https://github.com/google/protobuf.git protobuf-source
else
echo "Folder protobuf-source already exists, skipping git clone..."
fi
pushd protobuf-source >/dev/null
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PWD/../llvm-install/lib/"
./autogen.sh
./configure \
CC="clang-3.9" \
CXX="clang++-3.9" \
CXXFLAGS="-fPIC -stdlib=libc++ -I$PWD/../llvm-install/include/c++/v1" \
LDFLAGS="-stdlib=libc++ -L$PWD/../llvm-install/lib/" \
--prefix="$PWD/../protobuf-install"
make
make install
popd >/dev/null
# ==============================================================================
# -- Get GTest and compile it with libc++ --------------------------------------
# ==============================================================================
# Get googletest source
if [[ ! -d "googletest-source" ]]; then
echo "Retrieving googletest..."
git clone --depth=1 -b release-1.8.0 https://github.com/google/googletest.git googletest-source
else
echo "Folder googletest-source already exists, skipping git clone..."
fi
pushd googletest-source >/dev/null
cmake -H. -B./build \
-DCMAKE_C_COMPILER=${C_COMPILER} -DCMAKE_CXX_COMPILER=${COMPILER} \
-DCMAKE_CXX_FLAGS="-stdlib=libc++ -I$PWD/../llvm-install/include/c++/v1 -Wl,-L$PWD/../llvm-install/lib" \
-DCMAKE_INSTALL_PREFIX="../googletest-install" \
-G "Ninja"
pushd build >/dev/null
ninja
ninja install
popd >/dev/null
popd >/dev/null
# ==============================================================================
# -- ...and we are done --------------------------------------------------------
# ==============================================================================
popd >/dev/null
popd >/dev/null
set +x
echo ""
echo "****************"
echo "*** Success! ***"
echo "****************"

View File

@ -1,5 +1,6 @@
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
using System;
using System.IO;
using UnrealBuildTool;
@ -47,16 +48,7 @@ public class Carla : ModuleRules
}
);
AddBoostDependency(Target);
AddProtobufDependency(Target);
AddLibPNGDependency(Target);
AddCarlaServerDependency(Target);
if (Target.Platform == UnrealTargetPlatform.Linux)
{
// Fails to link the std libraries.
PublicAdditionalLibraries.Add("stdc++");
}
}
private bool IsWindows(TargetInfo Target)
@ -75,118 +67,46 @@ public class Carla : ModuleRules
}
else
{
// On Linux on the other hand, we need to use the version of the libraries
// without optimizations due to the crash in the std::string destructor.
return true;
}
}
private void AddBoostDependency(TargetInfo Target)
{
if (IsWindows(Target))
{
string BoostRoot = System.Environment.GetEnvironmentVariable("BOOST_ROOT");
if (string.IsNullOrEmpty(BoostRoot) || !System.IO.Directory.Exists(BoostRoot))
{
throw new System.Exception("BOOST_ROOT is not defined, or points to a non-existant directory, please set this environment variable.");
}
PrivateIncludePaths.Add(BoostRoot);
string BoostLib = Path.Combine(BoostRoot, "stage", "lib");
if (!System.IO.Directory.Exists(BoostLib))
{
throw new System.Exception("Please build boost and make sure the libraries are at " + BoostLib + ". ");
}
bool found = System.IO.Directory.GetFiles(BoostLib, "libboost_system-*.lib").Length > 0;
if (!found)
{
throw new System.Exception("Not finding libboost_system-*.lib in " + BoostLib + ".");
}
PublicLibraryPaths.Add(Path.Combine(BoostLib));
}
else
{
PublicAdditionalLibraries.Add("boost_system");
}
}
private void AddProtobufDependency(TargetInfo Target)
{
if (IsWindows(Target))
{
string ProtobufRoot = System.Environment.GetEnvironmentVariable("PROTOBUF_ROOT");
string ProtobufLib;
if (UseDebugLibs(Target))
{
ProtobufRoot = Path.Combine(ProtobufRoot, "Debug");
ProtobufLib = "libprotobufd.lib";
}
else
{
ProtobufRoot = Path.Combine(ProtobufRoot, "Release");
ProtobufLib = "libprotobuf.lib";
}
if (string.IsNullOrEmpty(ProtobufRoot) || !System.IO.Directory.Exists(ProtobufRoot))
{
throw new System.Exception("PROTOBUF_ROOT is not defined, or points to a non-existant directory, please set this environment variable.");
}
PrivateIncludePaths.Add(Path.Combine(ProtobufRoot, "include"));
PublicAdditionalLibraries.Add(Path.Combine(ProtobufRoot, "lib", ProtobufLib));
}
else
{
PublicAdditionalLibraries.Add("protobuf");
}
}
private void AddLibPNGDependency(TargetInfo Target)
{
if (Target.Platform == UnrealTargetPlatform.Linux)
{
string UE4Root = System.Environment.GetEnvironmentVariable("UE4_ROOT");
if (string.IsNullOrEmpty(UE4Root))
{
PublicAdditionalLibraries.Add("png");
}
else
{
if (!System.IO.Directory.Exists(UE4Root))
{
throw new System.Exception("UE4_ROOT points to a non-existant directory, please correct this environment variable.");
}
PublicAdditionalLibraries.Add("ThirdParty/libPNG/libPNG-1.5.2/lib/Linux/x86_64-unknown-linux-gnu/libpng.a");
PublicAdditionalLibraries.Add("ThirdParty/zlib/v1.2.8/lib/Linux/x86_64-unknown-linux-gnu/libz_fPIC.a");
}
}
}
delegate string ADelegate(string s);
private void AddCarlaServerDependency(TargetInfo Target)
{
string CarlaServerIncludePath = Path.Combine(ModuleDirectory, "..", "CarlaServer/include");
string CarlaServerLibPath = Path.Combine(ModuleDirectory, "..", "CarlaServer/lib");
string CarlaServerLibBaseName;
if (UseDebugLibs(Target))
{
CarlaServerLibBaseName = "carlaserverd";
}
else
{
CarlaServerLibBaseName = "carlaserver";
}
string CarlaServerInstallPath = Path.GetFullPath(Path.Combine(ModuleDirectory, "../../Util/Install"));
Console.WriteLine("CarlaServer install path = " + CarlaServerInstallPath);
string CarlaServerLib;
if (IsWindows(Target))
if (UseDebugLibs(Target))
{
CarlaServerLib = Path.Combine(CarlaServerLibPath, CarlaServerLibBaseName + ".lib");
CarlaServerLib = "carlaserverd";
}
else
{
CarlaServerLib = Path.Combine(CarlaServerLibPath, "lib" + CarlaServerLibBaseName + ".a");
CarlaServerLib = "carlaserver";
}
ADelegate GetSharedLibName = (string BaseName) => {
if (IsWindows(Target))
{
return BaseName + ".dll";
}
else
{
return "lib" + BaseName + ".so";
}
};
// Link dependencies.
PublicAdditionalLibraries.Add(Path.Combine(CarlaServerInstallPath, "lib", GetSharedLibName("boost_system")));
PublicAdditionalLibraries.Add(Path.Combine(CarlaServerInstallPath, "lib", GetSharedLibName("protobuf")));
PublicAdditionalLibraries.Add(Path.Combine(CarlaServerInstallPath, "lib", GetSharedLibName(CarlaServerLib)));
// Include path.
string CarlaServerIncludePath = Path.Combine(CarlaServerInstallPath, "include");
PublicIncludePaths.Add(CarlaServerIncludePath);
PrivateIncludePaths.Add(CarlaServerIncludePath);
PublicAdditionalLibraries.Add(CarlaServerLib);
}
}

View File

@ -1,7 +1,2 @@
*.log
*.pid
*.sublime-workspace
bin
bin_debug
build
lib
*.pb.cc
*.pb.h

View File

@ -1,158 +0,0 @@
cmake_minimum_required (VERSION 3.4.2)
project (CarlaServer)
# ==============================================================================
# -- Compiler config -----------------------------------------------------------
# ==============================================================================
if (UNIX)
set(CMAKE_CXX_COMPILER /usr/bin/clang++)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++14 -Werror -Wall -Wextra -Wno-unused-parameter")
find_package(Threads)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_DEBUG -O0")
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG -O3")
endif (CMAKE_BUILD_TYPE STREQUAL "Debug")
endif (UNIX)
# ==============================================================================
# -- Suppress windows warning --------------------------------------------------
# ==============================================================================
# http://stackoverflow.com/a/40217291
if (WIN32)
macro(get_WIN32_WINNT version)
if (CMAKE_SYSTEM_VERSION)
set(ver ${CMAKE_SYSTEM_VERSION})
string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver})
string(REGEX MATCH "^([0-9]+)" verMajor ${ver})
# Check for Windows 10, b/c we'll need to convert to hex 'A'.
if ("${verMajor}" MATCHES "10")
set(verMajor "A")
string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver})
endif ("${verMajor}" MATCHES "10")
# Remove all remaining '.' characters.
string(REPLACE "." "" ver ${ver})
# Prepend each digit with a zero.
string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver})
set(${version} "0x${ver}")
endif(CMAKE_SYSTEM_VERSION)
endmacro(get_WIN32_WINNT)
get_WIN32_WINNT(ver)
add_definitions(-D_WIN32_WINNT=${ver})
endif(WIN32)
# ==============================================================================
# -- Boost ---------------------------------------------------------------------
# ==============================================================================
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost REQUIRED system date_time regex)
include_directories(${Boost_INCLUDE_DIRS})
# ==============================================================================
# -- Protobuf ------------------------------------------------------------------
# ==============================================================================
if (UNIX)
include(FindProtobuf)
find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIR})
set(Protobuf_LIBRARIES protobuf)
elseif (WIN32)
if (CMAKE_BUILD_TYPE MATCHES Debug)
if (EXISTS $ENV{PROTOBUF_ROOT}/Debug)
message(STATUS "Using Protobuf DEBUG at " $ENV{PROTOBUF_ROOT}/Debug)
include_directories($ENV{PROTOBUF_ROOT}/Debug/include)
link_directories($ENV{PROTOBUF_ROOT}/Debug/lib)
set(Protobuf_LIBRARIES libprotobufd.lib)
else (EXISTS $ENV{PROTOBUF_ROOT}/Debug)
message(FATAL_ERROR "Cannot find PROTOBUF_ROOT/Debug")
endif (EXISTS $ENV{PROTOBUF_ROOT}/Debug)
else (CMAKE_BUILD_TYPE MATCHES Release)
if (EXISTS $ENV{PROTOBUF_ROOT}/Release)
message(STATUS "Using Protobuf RELEASE at " $ENV{PROTOBUF_ROOT}/Release)
include_directories($ENV{PROTOBUF_ROOT}/Release/include)
link_directories($ENV{PROTOBUF_ROOT}/Release/lib)
set(Protobuf_LIBRARIES libprotobuf.lib)
else (EXISTS $ENV{PROTOBUF_ROOT}/Release)
message(FATAL_ERROR "Cannot find PROTOBUF_ROOT/Release")
endif (EXISTS $ENV{PROTOBUF_ROOT}/Release)
endif (CMAKE_BUILD_TYPE MATCHES Debug)
endif (UNIX)
# ==============================================================================
# -- GTest ---------------------------------------------------------------------
# ==============================================================================
# Download and unpack googletest at configure time.
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# Prevent overriding the parent project's compiler/linker
# settings on Windows.
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build)
# The gtest/gtest_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
endif()
set(GTest_LIBRARIES gtest_main)
# ==============================================================================
# -- Project config ------------------------------------------------------------
# ==============================================================================
set(CarlaServer_Deps_LIBRARIES
${Protobuf_LIBRARIES}
${GTest_LIBRARIES}
${Boost_DATE_TIME_LIBRARY}
${Boost_REGEX_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${CMAKE_THREAD_LIBS_INIT})
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin_debug)
set(CarlaServer_LIBRARIES carlaserverd ${CarlaServer_Deps_LIBRARIES})
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(CarlaServer_LIBRARIES carlaserver ${CarlaServer_Deps_LIBRARIES})
endif (CMAKE_BUILD_TYPE STREQUAL "Debug")
include_directories("${PROJECT_SOURCE_DIR}/source")
include_directories("${PROJECT_SOURCE_DIR}/include")
add_subdirectory(source/carla/server)
add_subdirectory(source/test)

View File

@ -1,15 +0,0 @@
cmake_minimum_required (VERSION 3.0.2)
project(googletest-download NONE)
include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)

View File

@ -1,52 +0,0 @@
{
"folders":
[
{
"folder_exclude_patterns": ["build"],
"path": "."
}
],
"build_systems":
[
{
"file_regex": "^../../(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"name": "make - CarlaServer",
"shell_cmd": "make",
"syntax": "Packages/Makefile/Make Output.sublime-syntax",
"variants":
[
{
"name": "All",
"shell_cmd": "make all"
},
{
"name": "Check",
"shell_cmd": "make check"
},
{
"name": "Clean",
"shell_cmd": "make clean"
},
{
"name": "Doxygen Documentation",
"shell_cmd": "doxygen"
}
],
"working_dir": "${project_path}"
}
],
"SublimeLinter":
{
"linters":
{
"clang":
{
"extra_flags": "-std=c++14 -Wno-pragma-once-outside-header",
"include_dirs":
[
"${project_folder}/source"
]
}
}
}
}

View File

@ -1,38 +0,0 @@
PROJECT_NAME = "CARLA UE4 Plugin"
OUTPUT_DIRECTORY = Doxygen
CREATE_SUBDIRS = YES
FULL_PATH_NAMES = NO
JAVADOC_AUTOBRIEF = YES
LOOKUP_CACHE_SIZE = 3
EXTRACT_ALL = YES
EXTRACT_PRIVATE = YES
EXTRACT_STATIC = YES
CASE_SENSE_NAMES = YES
SORT_BRIEF_DOCS = YES
WARN_IF_UNDOCUMENTED = NO
WARN_LOGFILE = Doxygen/warnings.log
INPUT = Source
FILE_PATTERNS = *.cpp *.h *.hpp *.cc
RECURSIVE = YES
SOURCE_BROWSER = YES
STRIP_CODE_COMMENTS = NO
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
ALPHABETICAL_INDEX = NO
HTML_DYNAMIC_SECTIONS = YES
DISABLE_INDEX = YES
GENERATE_TREEVIEW = NO
FORMULA_FONTSIZE = 12
GENERATE_LATEX = NO
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
INCLUDE_PATH = "Source/Carla" "Source/Common" "Source/CarlaServer/source"
INCLUDE_FILE_PATTERNS = *.h *.hpp
HIDE_UNDOC_RELATIONS = NO
HAVE_DOT = YES
TEMPLATE_RELATIONS = YES
CALL_GRAPH = YES
CALLER_GRAPH = YES
DOT_IMAGE_FORMAT = svg
INTERACTIVE_SVG = YES
DOT_MULTI_TARGETS = YES

View File

@ -1,78 +0,0 @@
PROTOBUF_SRC_DIR=source/carla
PROTOBUF_CPP_OUT_DIR=source/carla/server
PROTOBUF_PY_OUT_DIR=source/carla/client
PROTOBUF_FILES= \
$(PROTOBUF_CPP_OUT_DIR)/carla_protocol.pb.h \
$(PROTOBUF_CPP_OUT_DIR)/carla_protocol.pb.cc \
$(PROTOBUF_PY_OUT_DIR)/carla_protocol.pb2.py
MY_CMAKE_FLAGS=-H. -B$(BUILD_FOLDER)
ifeq ($(OS),Windows_NT)
DEFAULT_RULE=release
BUILD_RULE=build_windows
else
DEFAULT_RULE=debug
BUILD_RULE=build_linux
endif
default: $(DEFAULT_RULE)
### Build ######################################################################
debug: BUILD_FOLDER=build/debug
debug: MY_CMAKE_FLAGS+=-DCMAKE_BUILD_TYPE=Debug
debug: $(BUILD_RULE)
release: BUILD_FOLDER=build/release
release: MY_CMAKE_FLAGS+=-DCMAKE_BUILD_TYPE=Release
release: $(BUILD_RULE)
build_linux: protobuf
cmake $(MY_CMAKE_FLAGS) -G "Ninja"
cd $(BUILD_FOLDER) && ninja
build_windows: protobuf
cmake $(MY_CMAKE_FLAGS) -G "NMake Makefiles"
cd $(BUILD_FOLDER) && nmake
vsproject: BUILD_FOLDER=build/visualstudio
vsproject: MY_CMAKE_FLAGS+=-DCMAKE_BUILD_TYPE=Debug
vsproject: protobuf
cmake $(MY_CMAKE_FLAGS) -G "Visual Studio 14 2015 Win64"
protobuf: $(PROTOBUF_FILES)
$(PROTOBUF_FILES): $(PROTOBUF_SRC_DIR)/carla_protocol.proto
protoc -I=$(PROTOBUF_SRC_DIR) --cpp_out=$(PROTOBUF_CPP_OUT_DIR) --python_out=$(PROTOBUF_PY_OUT_DIR) $<
### Clean ######################################################################
clean:
rm -f $(PROTOBUF_FILES)
rm -Rf build CMakeFiles bin bin_debug lib
### Test #######################################################################
check: debug launch_test_clients run_test_debug kill_test_clients
check_release: release launch_test_clients run_test_release kill_test_clients
run_test_debug:
@-./bin_debug/test_carla_server --gtest_shuffle
run_test_release:
@-./bin/test_carla_server --gtest_shuffle
launch_test_clients:
@echo "Launch echo_client.py"
@python source/carla/client/echo_client.py -p 4000 & echo $$! > echo_client.pid
@echo "Launch carla_client.py"
@python source/carla/client/carla_client.py -p 2000 & echo $$! > carla_client.pid
kill_test_clients:
@echo "Kill echo_client.py"
@kill `cat echo_client.pid` && rm echo_client.pid
@echo "Kill carla_client.py"
@kill `cat carla_client.pid` && rm carla_client.pid

View File

@ -1,15 +0,0 @@
file(GLOB carlaserver_SRC
"*.h"
"*.cpp"
"*.pb.h"
"*.pb.cc"
)
set(carlaserver_SRC ${carlaserver_SRC})
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_library(carlaserverd SHARED ${carlaserver_SRC})
# target_link_libraries(carlaserverd ${CarlaServer_LIBRARIES})
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
add_library(carlaserver SHARED ${carlaserver_SRC})
# target_link_libraries(carlaserver ${CarlaServer_LIBRARIES})
endif (CMAKE_BUILD_TYPE STREQUAL "Debug")

View File

@ -7,13 +7,15 @@
#include "carla/Debug.h"
#include "carla/Logging.h"
#include "carla/server/carla_protocol.pb.h"
#include "carla/server/carla_server.pb.h"
namespace cs = carla_server;
namespace carla {
namespace server {
std::string CarlaEncoder::Encode(const carla_scene_description &values) {
auto *message = _protobuf.CreateMessage<carla_protocol::SceneDescription>();
auto *message = _protobuf.CreateMessage<cs::SceneDescription>();
DEBUG_ASSERT(message != nullptr);
message->set_player_start_locations(
values.player_start_locations,
@ -22,13 +24,13 @@ namespace server {
}
std::string CarlaEncoder::Encode(const carla_episode_ready &values) {
auto *message = _protobuf.CreateMessage<carla_protocol::EpisodeReady>();
auto *message = _protobuf.CreateMessage<cs::EpisodeReady>();
DEBUG_ASSERT(message != nullptr);
message->set_ready(values.ready);
return Protobuf::Encode(*message);
}
static void SetVector3D(carla_protocol::Vector3D *lhs, const carla_vector3d &rhs) {
static void SetVector3D(cs::Vector3D *lhs, const carla_vector3d &rhs) {
DEBUG_ASSERT(lhs != nullptr);
lhs->set_x(rhs.x);
lhs->set_y(rhs.y);
@ -36,7 +38,7 @@ namespace server {
}
std::string CarlaEncoder::Encode(const carla_measurements &values) {
static thread_local auto *message = _protobuf.CreateMessage<carla_protocol::Measurements>();
static thread_local auto *message = _protobuf.CreateMessage<cs::Measurements>();
DEBUG_ASSERT(message != nullptr);
message->set_platform_timestamp(values.platform_timestamp);
message->set_game_timestamp(values.game_timestamp);
@ -55,7 +57,7 @@ namespace server {
}
bool CarlaEncoder::Decode(const std::string &str, RequestNewEpisode &values) {
auto *message = _protobuf.CreateMessage<carla_protocol::RequestNewEpisode>();
auto *message = _protobuf.CreateMessage<cs::RequestNewEpisode>();
DEBUG_ASSERT(message != nullptr);
message->ParseFromString(str);
if (message->IsInitialized()) {
@ -73,7 +75,7 @@ namespace server {
}
bool CarlaEncoder::Decode(const std::string &str, carla_episode_start &values) {
auto *message = _protobuf.CreateMessage<carla_protocol::EpisodeStart>();
auto *message = _protobuf.CreateMessage<cs::EpisodeStart>();
DEBUG_ASSERT(message != nullptr);
message->ParseFromString(str);
if (message->IsInitialized()) {
@ -86,7 +88,7 @@ namespace server {
}
bool CarlaEncoder::Decode(const std::string &str, carla_control &values) {
static thread_local auto *message = _protobuf.CreateMessage<carla_protocol::Control>();
static thread_local auto *message = _protobuf.CreateMessage<cs::Control>();
DEBUG_ASSERT(message != nullptr);
message->ParseFromString(str);
if (message->IsInitialized()) {

View File

@ -1,10 +0,0 @@
file(GLOB test_carla_server_SRC
"*.h"
"*.cpp"
)
set(test_carla_server_SRC ${test_carla_server_SRC})
add_executable(test_carla_server ${test_carla_server_SRC})
target_link_libraries(test_carla_server ${CarlaServer_LIBRARIES})
add_test(carla_server test_carla_server)

View File

@ -1,6 +1,6 @@
syntax = "proto3";
package carla_protocol;
package carla_server;
option cc_enable_arenas = true;

38
Util/Protoc.sh Executable file
View File

@ -0,0 +1,38 @@
#! /bin/bash
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
pushd "$SCRIPT_DIR" >/dev/null
PROTOBUF_SRC_DIR=Proto
PROTOBUF_CPP_OUT_DIR=CarlaServer/source/carla/server
PROTOBUF_PY_OUT_DIR=PythonClient
PROTO_BASENAME=carla_server
if [ "$1" == "--clean" ]; then
# Delete existing ones.
rm -f ${PROTOBUF_CPP_OUT_DIR}/*.pb.h ${PROTOBUF_CPP_OUT_DIR}/*.pb.cc
rm -f ${PROTOBUF_PY_OUT_DIR}/*_pb2.py
exit 0
fi
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./Build/llvm-install/lib
PROTOC=./Build/protobuf-install/bin/protoc
if [[ ! -f $PROTOC ]]; then
echo >&2 "ERROR: Missing protobuf compiler."
echo >&2 "Did you forget to run Setup.sh?"
exit 1
fi
echo "Compiling ${PROTO_BASENAME}.proto..."
${PROTOC} \
-I=${PROTOBUF_SRC_DIR} \
--cpp_out=${PROTOBUF_CPP_OUT_DIR} \
--python_out=${PROTOBUF_PY_OUT_DIR} \
${PROTOBUF_SRC_DIR}/${PROTO_BASENAME}.proto
popd >/dev/null
echo "done."

View File

@ -176,9 +176,9 @@ def test_carla_client():
data = client.read_images()
logging.info('received %d bytes of images', len(data) if data is not None else 0)
if (x+1) % 10 == 0:
logging.info('Taking a nap...')
time.sleep(2)
# if (x+1) % 10 == 0:
# logging.info('Taking a nap...')
# time.sleep(2)
logging.info('sending control')
client.write_control(steer=-2.3, throttle=1.0, reverse=True)

11
Util/cmake/CMakeLists.txt Normal file
View File

@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.5.0)
project(CARLA)
set(CARLA_UTIL_PATH "${PROJECT_SOURCE_DIR}/..")
set(CARLA_LIBCXX_INSTALL_PATH "${CARLA_UTIL_PATH}/Build/llvm-install")
set(CARLA_BOOST_INSTALL_PATH "${CARLA_UTIL_PATH}/Build/boost-install")
set(CARLA_PROTOBUF_INSTALL_PATH "${CARLA_UTIL_PATH}/Build/protobuf-install")
set(CARLA_GOOGLETEST_INSTALL_PATH "${CARLA_UTIL_PATH}/Build/googletest-install")
add_subdirectory("CarlaServer")

View File

@ -0,0 +1,101 @@
cmake_minimum_required (VERSION 3.5.0)
project (CarlaServer)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CarlaServer_Lib_Target carlaserverd)
set(CarlaServer_Test_Target test_carlaserverd)
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
set(CarlaServer_Lib_Target carlaserver)
set(CarlaServer_Test_Target test_carlaserver)
endif (CMAKE_BUILD_TYPE STREQUAL "Debug")
# ==============================================================================
# -- Compiler and dependencies -------------------------------------------------
# ==============================================================================
if (UNIX)
find_package(Threads)
set(CMAKE_CXX_COMPILER /usr/bin/clang++-3.9)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Wno-unused-parameter")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -D_DEBUG -O0")
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG -O3")
endif (CMAKE_BUILD_TYPE STREQUAL "Debug")
# Setup libc++.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
include_directories("${CARLA_LIBCXX_INSTALL_PATH}/include/c++/v1")
link_directories("${CARLA_LIBCXX_INSTALL_PATH}/lib")
file(GLOB LibCXX_Shared_Libraries "${CARLA_LIBCXX_INSTALL_PATH}/lib/libc++*.so*")
# Setup boost.
include_directories("${CARLA_BOOST_INSTALL_PATH}/include")
set(Boost_Static_Libraries "${CARLA_BOOST_INSTALL_PATH}/lib/libboost_system.a")
file(GLOB Boost_Shared_Libraries "${CARLA_BOOST_INSTALL_PATH}/lib/libboost_system.so*")
# Setup protobuf.
include_directories("${CARLA_PROTOBUF_INSTALL_PATH}/include")
set(Protobuf_Static_Libraries "${CARLA_PROTOBUF_INSTALL_PATH}/lib/libprotobuf.a")
file(GLOB Protobuf_Shared_Libraries "${CARLA_PROTOBUF_INSTALL_PATH}/lib/libprotobuf.so*")
# Setup googletest.
include_directories("${CARLA_GOOGLETEST_INSTALL_PATH}/include")
set(GTest_Static_Libraries "${CARLA_GOOGLETEST_INSTALL_PATH}/lib/libgtest.a")
install(FILES
${LibCXX_Shared_Libraries}
${Boost_Shared_Libraries}
${Protobuf_Shared_Libraries}
DESTINATION lib)
else (UNIX)
message(FATAL_ERROR "Build configuration not yet available for this platform")
endif (UNIX)
# ==============================================================================
# -- Project config ------------------------------------------------------------
# ==============================================================================
set(CarlaServer_Path "${CARLA_UTIL_PATH}/CarlaServer")
include_directories("${CarlaServer_Path}/source")
include_directories("${CarlaServer_Path}/include")
# libcarlaserver
file(GLOB carlaserver_SRC
"${CarlaServer_Path}/include/carla/carla_server.h"
"${CarlaServer_Path}/source/carla/*.h"
"${CarlaServer_Path}/source/carla/*.cpp"
"${CarlaServer_Path}/source/carla/server/*.h"
"${CarlaServer_Path}/source/carla/server/*.cpp"
"${CarlaServer_Path}/source/carla/server/*.pb.h"
"${CarlaServer_Path}/source/carla/server/*.pb.cc")
add_library(${CarlaServer_Lib_Target} SHARED ${carlaserver_SRC})
install(DIRECTORY "${CarlaServer_Path}/include/carla" DESTINATION include)
install(TARGETS ${CarlaServer_Lib_Target} DESTINATION lib)
# unit tests
file(GLOB test_carlaserver_SRC
"${CarlaServer_Path}/source/test/*.h"
"${CarlaServer_Path}/source/test/*.cpp")
set(CarlaServer_Static_LIBRARIES
${CarlaServer_Lib_Target}
${GTest_Static_Libraries}
${Protobuf_Static_Libraries}
${Boost_Static_Libraries}
${CMAKE_THREAD_LIBS_INIT})
add_executable(${CarlaServer_Test_Target} ${test_carlaserver_SRC})
target_link_libraries(${CarlaServer_Test_Target} ${CarlaServer_Static_LIBRARIES})
install(TARGETS ${CarlaServer_Test_Target} DESTINATION bin)