-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from KIT-MRT/cmake_docker_setup
Convert to pure CMake and add Docker image
- Loading branch information
Showing
11 changed files
with
607 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build | ||
thirdparty/util_caching/build | ||
Dockerfile | ||
docker-compose* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
setup.py | ||
*.pyc | ||
CMakeLists.txt.user | ||
|
||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,107 @@ | ||
set(MRT_PKG_VERSION 4.0.0) | ||
# Modify only if you know what you are doing! | ||
cmake_minimum_required(VERSION 3.5.1) | ||
project(arbitration_graphs) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
|
||
################### | ||
## Find packages ## | ||
################### | ||
find_package(mrt_cmake_modules REQUIRED) | ||
include(UseMrtStdCompilerFlags) | ||
include(GatherDeps) | ||
|
||
# You can add a custom.cmake in order to add special handling for this package. E.g. you can do: | ||
# list(REMOVE_ITEM DEPENDEND_PACKAGES <package name 1> <package name 2> ...) | ||
# To remove libs which cannot be found automatically. You can also "find_package" other, custom dependencies there. | ||
# You can also set PROJECT_INSTALL_FILES to install files that are not installed by default. | ||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/custom.cmake") | ||
include("${CMAKE_CURRENT_SOURCE_DIR}/custom.cmake") | ||
endif() | ||
|
||
find_package(AutoDeps REQUIRED COMPONENTS ${DEPENDEND_PACKAGES}) | ||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") | ||
|
||
mrt_parse_package_xml() | ||
find_package(Glog) | ||
|
||
######################## | ||
## Add python modules ## | ||
######################## | ||
# This adds a python module if located under src/{PROJECT_NAME) | ||
mrt_python_module_setup() | ||
find_package(util_caching REQUIRED) | ||
|
||
find_package(Yaml-cpp REQUIRED) | ||
|
||
mrt_glob_files(PROJECT_PYTHON_SOURCE_FILES_SRC "python_api/*.cpp") | ||
if (PROJECT_PYTHON_SOURCE_FILES_SRC) | ||
# Add a cpp-python api library. Make sure there are no name collisions with python modules in this project | ||
mrt_add_python_api( ${PROJECT_NAME} | ||
FILES ${PROJECT_PYTHON_SOURCE_FILES_SRC} | ||
) | ||
endif() | ||
|
||
############################ | ||
## Read source code files ## | ||
############################ | ||
mrt_glob_files_recurse(PROJECT_HEADER_FILES_INC "include/*.h" "include/*.hpp" "include/*.cuh") | ||
mrt_glob_files(PROJECT_SOURCE_FILES_INC "src/*.h" "src/*.hpp" "src/*.cuh") | ||
mrt_glob_files(PROJECT_SOURCE_FILES_SRC "src/*.cpp" "src/*.cu") | ||
file(GLOB_RECURSE PROJECT_HEADER_FILES_INC "include/${PROJECT_NAME}/*.h" "include/${PROJECT_NAME}/*.hpp") | ||
|
||
|
||
########### | ||
## Build ## | ||
########### | ||
# Declare a cpp library | ||
mrt_add_library(${PROJECT_NAME} | ||
INCLUDES ${PROJECT_HEADER_FILES_INC} ${PROJECT_SOURCE_FILES_INC} | ||
SOURCES ${PROJECT_SOURCE_FILES_SRC} | ||
) | ||
add_library(${PROJECT_NAME} INTERFACE) | ||
target_include_directories(${PROJECT_NAME} INTERFACE | ||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}> | ||
$<INSTALL_INTERFACE:include/${PROJECT_NAME}> | ||
) | ||
target_link_libraries(${PROJECT_NAME} INTERFACE | ||
glog::glog | ||
util_caching | ||
${YAML_CPP_LIBRARIES} | ||
) | ||
|
||
|
||
################### | ||
## Cmake Package ## | ||
################### | ||
include(CMakePackageConfigHelpers) | ||
write_basic_package_version_file( | ||
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" | ||
VERSION 0.1 | ||
COMPATIBILITY AnyNewerVersion | ||
) | ||
include(CMakePackageConfigHelpers) | ||
configure_package_config_file( | ||
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in" | ||
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" | ||
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME} | ||
) | ||
|
||
|
||
############# | ||
## Install ## | ||
############# | ||
# Install all targets, headers by default and scripts and other files if specified (folders or files). | ||
# This command also exports libraries and config files for dependent packages and this supersedes catkin_package. | ||
mrt_install(PROGRAMS scripts FILES res data ${PROJECT_INSTALL_FILES}) | ||
|
||
|
||
install(TARGETS ${PROJECT_NAME} | ||
EXPORT ${PROJECT_NAME}Targets | ||
LIBRARY DESTINATION lib COMPONENT Runtime | ||
ARCHIVE DESTINATION lib COMPONENT Development | ||
RUNTIME DESTINATION bin COMPONENT Runtime | ||
PUBLIC_HEADER DESTINATION include COMPONENT Development | ||
BUNDLE DESTINATION bin COMPONENT Runtime | ||
) | ||
install(EXPORT ${PROJECT_NAME}Targets DESTINATION lib/cmake/${PROJECT_NAME}) | ||
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" | ||
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" | ||
DESTINATION lib/cmake/${PROJECT_NAME}) | ||
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include) | ||
|
||
|
||
############# | ||
## Testing ## | ||
############# | ||
# Add test targets for cpp and python tests | ||
if (CATKIN_ENABLE_TESTING) | ||
mrt_add_tests(test) | ||
mrt_add_nosetests(test) | ||
find_package(GTest) | ||
|
||
if(GTEST_FOUND) | ||
if(BUILD_TESTS) | ||
file(GLOB_RECURSE _tests "test/*.cpp" "test/*.cc") | ||
|
||
foreach(_test ${_tests}) | ||
get_filename_component(_test_name ${_test} NAME_WE) | ||
# make sure we add only one -test to the target | ||
string(REGEX REPLACE "-test" "" TEST_TARGET_NAME ${_test_name}) | ||
set(TEST_TARGET_NAME ${PROJECT_NAME}-gtest-${TEST_TARGET_NAME}) | ||
|
||
message(STATUS | ||
"Adding gtest unittest \"${TEST_TARGET_NAME}\" with working dir ${PROJECT_SOURCE_DIR}/${TEST_FOLDER} \n _test: ${_test}" | ||
) | ||
|
||
add_executable(${TEST_TARGET_NAME} ${_test}) | ||
|
||
target_link_libraries(${TEST_TARGET_NAME} PUBLIC | ||
${GTEST_BOTH_LIBRARIES} pthread | ||
${PROJECT_NAME} | ||
) | ||
endforeach() | ||
endif() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
FROM ubuntu:22.04 | ||
|
||
ARG DEBIAN_FRONTEND=noninteractive | ||
|
||
# Install build dependencies | ||
RUN apt-get update && \ | ||
apt-get install -y \ | ||
build-essential \ | ||
cmake \ | ||
git \ | ||
libgoogle-glog-dev \ | ||
libgtest-dev \ | ||
libyaml-cpp-dev && \ | ||
apt-get clean | ||
|
||
# Install util_caching | ||
RUN git clone https://github.com/KIT-MRT/util_caching.git /tmp/util_caching && \ | ||
mkdir /tmp/util_caching/build && \ | ||
cd /tmp/util_caching/build && \ | ||
cmake .. && \ | ||
cmake --build . && \ | ||
cmake --install . && \ | ||
rm -rf /tmp/util_caching | ||
|
||
|
||
# Install arbitration_graphs | ||
COPY . /tmp/arbitration_graphs | ||
RUN mkdir /tmp/arbitration_graphs/build && \ | ||
cd /tmp/arbitration_graphs/build && \ | ||
cmake .. && \ | ||
cmake --build . && \ | ||
cmake --install . && \ | ||
rm -rf /tmp/arbitration_graphs | ||
|
||
RUN useradd --create-home --uid 1000 blinky | ||
USER blinky | ||
|
||
WORKDIR /home/blinky/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,87 @@ | ||
# ARBITRATION GRAPHS | ||
|
||
Arbitration graphs combine simple atomic behavior blocks to more complex behaviors for decision making and behavior generation | ||
|
||
|
||
## Installation | ||
|
||
First, clone this repository, including its submodules: | ||
|
||
```bash | ||
git clone https://github.com/KIT-MRT/arbitration_graphs.git | ||
cd arbitration_graphs | ||
git submodule update --init --recursive | ||
``` | ||
|
||
|
||
### Using Docker image | ||
|
||
We provide a [`Dockerfile`](./Dockerfile) with the library already installed globally. | ||
|
||
In the source directory, build and run the docker image with `docker compose`: | ||
|
||
```bash | ||
docker compose build | ||
docker compose run --rm arbitration_graphs | ||
``` | ||
|
||
The library is installed in the Docker image under `/usr/local/include/arbitration_graphs/` and `/usr/local/lib/cmake/arbitration_graphs/`. | ||
So, it can be easily loaded with CMake: | ||
|
||
```cmake | ||
find_package(arbitration_graphs REQUIRED) | ||
``` | ||
|
||
|
||
### Building from source using CMake | ||
|
||
First make sure all dependencies are installed: | ||
- [glog](https://github.com/google/glog) | ||
- [Googletest](https://github.com/google/googletest) (only if you want to build unit tests) | ||
- [yaml-cpp](https://github.com/jbeder/yaml-cpp) | ||
- [util_caching](https://github.com/KIT-MRT/util_caching) | ||
|
||
See also the [`Dockerfile`](./Dockerfile) for how to install these packages under Debian or Ubuntu. | ||
|
||
Compile and install the project with CMake: | ||
|
||
```bash | ||
mkdir -p arbitration_graphs/build | ||
cd arbitration_graphs/build | ||
cmake .. | ||
cmake --build . | ||
sudo cmake --install . | ||
``` | ||
|
||
|
||
## Development | ||
|
||
### Using Docker image | ||
|
||
Follow the steps above to setup the Docker image. | ||
Then, run the development image. | ||
|
||
```bash | ||
docker compose -f docker-compose.devel.yaml build | ||
docker compose -f docker-compose.devel.yaml run --rm arbitration_graphs_devel | ||
``` | ||
|
||
This mounts the source into the container's `/home/blinky/arbitration_graphs` folder. | ||
There, you can edit the source code, compile and run the tests etc. | ||
|
||
|
||
### Compiling unit tests | ||
|
||
In order to compile with tests define `BUILD_TESTS=true` | ||
```bash | ||
mkdir -p arbitration_graphs/build | ||
cd arbitration_graphs/build | ||
cmake -DBUILD_TESTS=true .. | ||
cmake --build . | ||
``` | ||
|
||
Run all unit tests: | ||
|
||
```bash | ||
find -executable -type f -name '*-gtest-*' -exec {} \; | ||
``` |
Oops, something went wrong.