Added C++ client to be compiled with other targets

This commit is contained in:
Blyron 2024-07-02 13:23:19 +02:00 committed by Blyron
parent e9fdf846d0
commit b29456719c
6 changed files with 73 additions and 173 deletions

View File

@ -1 +1,73 @@
add_subdirectory (CppClient)
set (
CARLA_EXAMPLE_CPP_CLIENT_SOURCE_PATH
${CARLA_WORKSPACE_PATH}/Examples/CppClient
)
set (
CARLA_EXAMPLE_CPP_DEPENDENCIES
carla-client
rpc
png_static
zlibstatic
Boost::asio
Boost::python
Boost::geometry
Boost::gil
RecastNavigation::Recast
RecastNavigation::Detour
RecastNavigation::DetourCrowd
)
if (BUILD_EXAMPLES)
carla_message ("CARLA Building C++ EXAMPLE CLIENT")
project (
carla-example-cpp-client
LANGUAGES
CXX
VERSION
${CARLA_VERSION}
)
file (
GLOB_RECURSE
CARLA_EXAMPLE_CPP_SOURCES
CONFIGURE_DEPENDS
${CARLA_EXAMPLE_CPP_CLIENT_SOURCE_PATH}/*.cpp
)
file (
GLOB_RECURSE
CARLA_EXAMPLE_CPP_HEADERS
CONFIGURE_DEPENDS
${CARLA_EXAMPLE_CPP_CLIENT_SOURCE_PATH}/*.h
)
carla_add_executable (
carla-example-client
"Build the CARLA C++ client example."
${CARLA_EXAMPLE_CPP_SOURCES}
)
add_dependencies (
carla-example-client
${CARLA_EXAMPLE_CPP_DEPENDENCIES}
)
target_link_libraries (
carla-example-client PUBLIC
carla-client
Boost::asio
Boost::python
Boost::algorithm
Boost::geometry
Boost::assert
Boost::gil
RecastNavigation::Recast
RecastNavigation::Detour
RecastNavigation::DetourCrowd
png_static
zlibstatic
rpc
)
endif ()

View File

@ -1,5 +0,0 @@
/ToolChain.cmake
/bin
/build
/libcarla-install
_*

View File

@ -1,12 +0,0 @@
project (carla-example-cpp-client)
carla_add_executable (
carla-example-cpp-client
"Build the CARLA C++ client example."
main.cpp
)
target_link_libraries (
carla-example-cpp-client PRIVATE
carla-client
)

View File

@ -1,64 +0,0 @@
CARLADIR=$(CURDIR)/../..
BUILDDIR=$(CURDIR)/build
BINDIR=$(CURDIR)/bin
INSTALLDIR=$(CURDIR)/libcarla-install
TOOLCHAIN=$(CURDIR)/ToolChain.cmake
CC=/usr/bin/gcc-7
CXX=/usr/bin/g++-7
CXXFLAGS=-std=c++14 -pthread -fPIC -O3 -DNDEBUG -Werror -Wall -Wextra
define log
@echo "\033[1;35m$(1)\033[0m"
endef
default: build
clean:
@rm -rf $(BUILDDIR) $(INSTALLDIR)
@rm -f ToolChain.cmake
run: build
$(call log,Running C++ Client...)
@$(BINDIR)/cpp_client $(ARGS)
run.only:
$(call log,Running C++ Client...)
@$(BINDIR)/cpp_client $(ARGS)
build: $(BINDIR)/cpp_client
$(BINDIR)/cpp_client: | build_libcarla
$(call log,Compiling C++ Client...)
@mkdir -p $(BINDIR)
@$(CXX) $(CXXFLAGS) -I$(INSTALLDIR)/include -isystem $(INSTALLDIR)/include/system -L$(INSTALLDIR)/lib \
-o $(BINDIR)/cpp_client main.cpp \
-Wl,-Bstatic -lcarla_client -lrpc -lboost_filesystem -Wl,-Bdynamic \
-lpng -ltiff -ljpeg -lRecast -lDetour -lDetourCrowd
build_libcarla: $(TOOLCHAIN)
@cd $(CARLADIR); make setup
@mkdir -p $(BUILDDIR)
$(call log,Compiling LibCarla.client...)
@{ \
cd $(BUILDDIR); \
if [ ! -f "build.ninja" ]; then \
cmake \
-G "Ninja" \
-DCMAKE_BUILD_TYPE=Client \
-DLIBCARLA_BUILD_RELEASE=ON \
-DLIBCARLA_BUILD_DEBUG=OFF \
-DLIBCARLA_BUILD_TEST=OFF \
-DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN) \
-DCMAKE_INSTALL_PREFIX=$(INSTALLDIR) \
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
$(CARLADIR); \
fi; \
ninja; \
ninja install | grep -v "Up-to-date:"; \
}
$(TOOLCHAIN):
@echo "set(CMAKE_C_COMPILER $(CC))" > $(TOOLCHAIN)
@echo "set(CMAKE_CXX_COMPILER $(CXX))" >> $(TOOLCHAIN)
@echo "set(CMAKE_CXX_FLAGS \"\$${CMAKE_CXX_FLAGS} $(CXXFLAGS)\" CACHE STRING \"\" FORCE)" >> $(TOOLCHAIN)

View File

@ -1,80 +0,0 @@
C++ Client Example
==================
This example creates an application using CARLA's C++ API to connect and control
the simulator from C++.
Compile and run
---------------
Use the Makefile provided (Linux only), to compile and run the example. Note
that it expects to have a simulator running at port 2000.
```
make run
```
How it works
------------
In order to link our application against LibCarla, we need to compile LibCarla
with the same compiler and configuration we are using with our application. To
do so, we generate a CMake tool-chain file specifying the compiler and flags we
want
```cmake
# Example ToolChain.cmake
set(CMAKE_C_COMPILER /usr/bin/clang-8)
set(CMAKE_CXX_COMPILER /usr/bin/clang++-8)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -O3 -DNDEBUG" CACHE STRING "" FORCE)
```
We pass this file to CMake when compiling LibCarla.client
```sh
cd /path/to/carla-root-folder
make setup
cd /path/to/build-folder
cmake \
-G "Ninja" \
-DCMAKE_BUILD_TYPE=Client \
-DLIBCARLA_BUILD_RELEASE=ON \
-DLIBCARLA_BUILD_DEBUG=OFF \
-DLIBCARLA_BUILD_TEST=OFF \
-DCMAKE_TOOLCHAIN_FILE=/path/to/ToolChain.cmake \
-DCMAKE_INSTALL_PREFIX=/path/to/install-folder \
/path/to/carla-root-folder
ninja
ninja install
```
This will generate the following structure at the provided install path
```
libcarla-install
├── include
│   ├── carla
│   ├── cephes
│   ├── pugixml
| ├── ...
│   └── system
│   ├── boost
│   ├── recast
│   └── rpc
└── lib
├── libcarla_client.a
├── librpc.a
├── libboost_filesystem.a
└── ...
```
Our application needs to be linked at minimum against `libcarla_client.a`,
`librpc.a`, `libRecast.a`, and `libDetour*.a`. If we make use of IO
functionality and/or image processing we would need to link against
`boost_filesystem`, `png`, `tiff`, and/or `jpeg`.
For more details take a look at the Makefile provided.

View File

@ -1,11 +0,0 @@
message("Hello world!")
set(CC, "$ENV{UE4_ROOT}/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v17_clang-10.0.1-centos7/x86_64-unknown-linux-gnu/bin/clang")
set(CXX, "$ENV{UE4_ROOT}/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v17_clang-10.0.1-centos7/x86_64-unknown-linux-gnu/bin/clang++")
message(STATUS "COMBINED_PATH: ${CC}")
message(STATUS "COMBINED_PATH: ${CXX}")
set(CMAKE_C_COMPILER ${CC})
set(CMAKE_CXX_COMPILER ${CXX})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread -fPIC -O3 -DNDEBUG" CACHE STRING "" FORCE)