Skip to content

Commit c381486

Browse files
authored
Improve handling of dependencies (#1012)
* Support using minitrace from conan * Support using tinyxml2 from conan * Add support for using minicoro from conan * Add support for using flatbuffers from conan * Create separate targets for each 3rdparty lib not yet supported by conan so we can avoid exposing the whole 3rdparty folder on target_include_directories Since this can create some confusion around which headers are actually being included -- the ones from that folder or the ones from conan? Also fixes the include dirs by using ${CMAKE_CURRENT_SOURCE_DIR} instead of "." * Fix builds For whatever reason including zmq.hpp before zmq_addon.hpp (which does include zmq.hpp internally) breaks builds * Do not include the whole 3rdparty folder, only link in what we need * Use the regular lexy target * Do not expose the whole 3rdparty folder as a include_directory * Add options to opt-out of vendored libraries * This was shared across both code paths, conan_build.cmake and ament_build.cmake So it is better to keep this on a single place * Keep all the find_package calls on the toplevel CMakeLists * SQLite3 is actually a dependency of cpp-sqlite * Fix include dirs of the vendored minicoro and flatbuffers * Define libzmq cmake target on FindZeroMQ to match the conan package * Improve message. This code path doesn't really mean we're using conan, it just means we're not using ament. * Use the python version of conanfile.py so we can set the CMake options needed to opt out of vendored dependencies * Address pre-commit complains * Use conanfile.py across the board * Do not look for ZeroMQ directly as it is a dependency of cppzmq Also only look for cppzmq if BTCPP_GROOT_INTERFACE * Keep a single copy of zmq.hpp This header is part of the cppzmq library so it lives on 3rdparty/cppzmq. But for whatever reason there was another version of this header here. Furthermore it was a differnt version of the library. * Leave a FIXME for posterity This target was silently being skiped, not it is explicit * Leave comment for posterity * Remove empty line * Remove unneeded line * Remove uneeded line * Remove empty line * Revert unintentional changes * Use cmake_layout to support multiconfig * Update toolchain path on cicd * Emtpy commit to re-trigger CI * Use cppzmq from conan * Use cmake presets on conan builds * It looks like in windows the preset is called conan-default * It looks like the preset is only called default for config? * Fix tests path in windows * Use lexy from conan * Force cppstd to 17, conan profile detect uses 14 * Try to fix windows builds * Remove wildcards cmake options, it has been removed on master * Update changes after cpp-sqlite removal
1 parent c0bc00b commit c381486

24 files changed

+228
-2907
lines changed

.github/workflows/cmake_ubuntu.yml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,25 @@ jobs:
3232
- name: Create default profile
3333
run: conan profile detect
3434

35-
- name: Create Build Environment
36-
# Some projects don't allow in-source building, so create a separate build directory
37-
# We'll use this as our working directory for all subsequent commands
38-
run: cmake -E make_directory ${{github.workspace}}/build
39-
4035
- name: Install conan dependencies
41-
working-directory: ${{github.workspace}}/build
42-
run: conan install ${{github.workspace}}/conanfile.txt -s build_type=${{env.BUILD_TYPE}} --build=missing
36+
run: conan install conanfile.py -s build_type=${{env.BUILD_TYPE}} --build=missing
37+
38+
- name: Normalize build type
39+
shell: bash
40+
# The build type is Capitalized, e.g. Release, but the preset is all lowercase, e.g. release.
41+
# There is no built in way to do string manipulations on GHA as far as I know.`
42+
run: echo "BUILD_TYPE_LOWERCASE=$(echo "${BUILD_TYPE}" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
4343

4444
- name: Configure CMake
4545
shell: bash
46-
working-directory: ${{github.workspace}}/build
47-
run: cmake ${{github.workspace}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake
46+
run: cmake --preset conan-${{ env.BUILD_TYPE_LOWERCASE }}
4847

4948
- name: Build
5049
shell: bash
51-
working-directory: ${{github.workspace}}/build
52-
run: cmake --build . --config ${{env.BUILD_TYPE}}
50+
run: cmake --build --preset conan-${{ env.BUILD_TYPE_LOWERCASE }}
5351

5452
- name: run test (Linux)
55-
working-directory: ${{github.workspace}}/build/tests
56-
run: ctest
53+
run: ctest --test-dir build/${{env.BUILD_TYPE}}
5754

5855
- name: Upload coverage reports to Codecov
5956
uses: codecov/codecov-action@v3

.github/workflows/cmake_windows.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,22 @@ jobs:
3232
- name: Create default profile
3333
run: conan profile detect
3434

35-
- name: Create Build Environment
36-
# Some projects don't allow in-source building, so create a separate build directory
37-
# We'll use this as our working directory for all subsequent commands
38-
run: cmake -E make_directory ${{github.workspace}}/build
39-
4035
- name: Install conan dependencies
41-
working-directory: ${{github.workspace}}/build
42-
run: conan install ${{github.workspace}}/conanfile.txt -s build_type=${{env.BUILD_TYPE}} --build=missing
36+
run: conan install conanfile.py -s build_type=${{env.BUILD_TYPE}} --build=missing --settings:host compiler.cppstd=17
37+
38+
- name: Normalize build type
39+
shell: bash
40+
# The build type is Capitalized, e.g. Release, but the preset is all lowercase, e.g. release.
41+
# There is no built in way to do string manipulations on GHA as far as I know.`
42+
run: echo "BUILD_TYPE_LOWERCASE=$(echo "${BUILD_TYPE}" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
4343

4444
- name: Configure CMake
4545
shell: bash
46-
working-directory: ${{github.workspace}}/build
47-
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake
46+
run: cmake --preset conan-default
4847

4948
- name: Build
50-
working-directory: ${{github.workspace}}/build
5149
shell: bash
52-
run: cmake --build . --config ${{env.BUILD_TYPE}}
50+
run: cmake --build --preset conan-${{ env.BUILD_TYPE_LOWERCASE }}
5351

5452
- name: run test (Windows)
5553
working-directory: ${{github.workspace}}/build

3rdparty/cppzmq/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
find_package(ZeroMQ REQUIRED)
2+
3+
add_library(cppzmq INTERFACE)
4+
5+
# This library doesn't use modern targets unfortunately.
6+
#add_library(cppzmq::cppzmq ALIAS cppzmq)
7+
8+
target_include_directories(cppzmq
9+
INTERFACE
10+
${CMAKE_CURRENT_SOURCE_DIR}
11+
)
12+
13+
if(TARGET libzmq-static)
14+
target_link_libraries(cppzmq INTERFACE libzmq-static)
15+
elseif(TARGET libzmq)
16+
target_link_libraries(cppzmq INTERFACE libzmq)
17+
else()
18+
message(FATAL_ERROR "Unknown zeromq target name")
19+
endif()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_library(flatbuffers INTERFACE)
2+
3+
add_library(flatbuffers::flatbuffers ALIAS flatbuffers)
4+
5+
target_include_directories(flatbuffers
6+
INTERFACE
7+
${CMAKE_CURRENT_SOURCE_DIR}
8+
)
File renamed without changes.

3rdparty/minicoro/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_library(minicoro INTERFACE)
2+
3+
add_library(minicoro::minicoro ALIAS minicoro)
4+
5+
target_include_directories(minicoro
6+
INTERFACE
7+
${CMAKE_CURRENT_SOURCE_DIR}
8+
)

3rdparty/minitrace/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
add_library(minitrace STATIC
2+
minitrace.cpp
3+
)
4+
5+
add_library(minitrace::minitrace ALIAS minitrace)
6+
7+
target_include_directories(minitrace
8+
PUBLIC
9+
${CMAKE_CURRENT_SOURCE_DIR}
10+
)
11+
12+
target_compile_definitions(minitrace
13+
PRIVATE
14+
MTR_ENABLED=True
15+
)
16+
17+
set_property(TARGET minitrace
18+
PROPERTY
19+
POSITION_INDEPENDENT_CODE ON
20+
)

3rdparty/tinyxml2/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
add_library(tinyxml2 STATIC
2+
tinyxml2.cpp
3+
)
4+
5+
add_library(tinyxml2::tinyxml2 ALIAS tinyxml2)
6+
7+
target_include_directories(tinyxml2
8+
PUBLIC
9+
${CMAKE_CURRENT_SOURCE_DIR}
10+
)
11+
12+
set_property(TARGET tinyxml2
13+
PROPERTY
14+
POSITION_INDEPENDENT_CODE ON
15+
)

CMakeLists.txt

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ option(USE_AFLPLUSPLUS "Use AFL++ instead of libFuzzer" OFF)
2020
option(ENABLE_DEBUG "Enable debug build with full symbols" OFF)
2121
option(FORCE_STATIC_LINKING "Force static linking of all dependencies" OFF)
2222

23+
option(USE_VENDORED_CPPZMQ "Use the bundled version of cppzmq" ON)
24+
option(USE_VENDORED_FLATBUFFERS "Use the bundled version of flatbuffers" ON)
25+
option(USE_VENDORED_LEXY "Use the bundled version of lexy" ON)
26+
option(USE_VENDORED_MINICORO "Use the bundled version of minicoro" ON)
27+
option(USE_VENDORED_MINITRACE "Use the bundled version of minitrace" ON)
28+
option(USE_VENDORED_TINYXML2 "Use the bundled version of tinyxml2" ON)
29+
30+
set(BTCPP_LIB_DESTINATION lib)
31+
set(BTCPP_INCLUDE_DESTINATION include)
32+
set(BTCPP_BIN_DESTINATION bin)
33+
2334
set(BASE_FLAGS "")
2435

2536
if(ENABLE_DEBUG)
@@ -62,12 +73,6 @@ if(USE_V3_COMPATIBLE_NAMES)
6273
add_definitions(-DUSE_BTCPP3_OLD_NAMES)
6374
endif()
6475

65-
#---- Find other packages ----
66-
find_package(Threads REQUIRED)
67-
68-
69-
set(BEHAVIOR_TREE_LIBRARY ${PROJECT_NAME})
70-
7176
# Update the policy setting to avoid an error when loading the ament_cmake package
7277
# at the current cmake version level
7378
if(POLICY CMP0057)
@@ -85,19 +90,57 @@ if ( ament_cmake_FOUND )
8590
include(cmake/ament_build.cmake)
8691
else()
8792
message(STATUS "------------------------------------------")
88-
message(STATUS "BehaviorTree is being built with conan.")
93+
message(STATUS "BehaviorTree is being built without AMENT.")
8994
message(STATUS "------------------------------------------")
9095
include(cmake/conan_build.cmake)
9196
endif()
9297

9398
#############################################################
94-
# LIBRARY
99+
# Handle dependencies
100+
101+
find_package(Threads REQUIRED)
102+
103+
if(BTCPP_GROOT_INTERFACE)
104+
if(USE_VENDORED_CPPZMQ)
105+
add_subdirectory(3rdparty/cppzmq)
106+
else()
107+
find_package(cppzmq REQUIRED)
108+
endif()
109+
endif()
110+
111+
if(BTCPP_SQLITE_LOGGING)
112+
find_package(SQLite3 REQUIRED)
113+
endif()
114+
115+
if(USE_VENDORED_FLATBUFFERS)
116+
add_subdirectory(3rdparty/flatbuffers)
117+
else()
118+
find_package(flatbuffers REQUIRED)
119+
endif()
95120

96-
add_subdirectory(3rdparty/lexy)
121+
if(USE_VENDORED_LEXY)
122+
add_subdirectory(3rdparty/lexy)
123+
else()
124+
find_package(lexy REQUIRED)
125+
endif()
97126

98-
add_library(minitrace STATIC 3rdparty/minitrace/minitrace.cpp)
99-
target_compile_definitions(minitrace PRIVATE MTR_ENABLED=True)
100-
set_property(TARGET minitrace PROPERTY POSITION_INDEPENDENT_CODE ON)
127+
if(USE_VENDORED_MINICORO)
128+
add_subdirectory(3rdparty/minicoro)
129+
else()
130+
find_package(minicoro REQUIRED)
131+
endif()
132+
133+
if(USE_VENDORED_MINITRACE)
134+
add_subdirectory(3rdparty/minitrace)
135+
else()
136+
find_package(minitrace REQUIRED)
137+
endif()
138+
139+
if(USE_VENDORED_TINYXML2)
140+
add_subdirectory(3rdparty/tinyxml2)
141+
else()
142+
find_package(tinyxml2 REQUIRED)
143+
endif()
101144

102145
list(APPEND BT_SOURCE
103146
src/action_node.cpp
@@ -141,8 +184,6 @@ list(APPEND BT_SOURCE
141184
src/loggers/bt_file_logger_v2.cpp
142185
src/loggers/bt_minitrace_logger.cpp
143186
src/loggers/bt_observer.cpp
144-
145-
3rdparty/tinyxml2/tinyxml2.cpp
146187
)
147188

148189

@@ -180,8 +221,13 @@ target_link_libraries(${BTCPP_LIBRARY}
180221
PRIVATE
181222
Threads::Threads
182223
${CMAKE_DL_LIBS}
183-
$<BUILD_INTERFACE:foonathan::lexy>
184-
$<BUILD_INTERFACE:minitrace>
224+
foonathan::lexy
225+
minitrace::minitrace
226+
tinyxml2::tinyxml2
227+
minicoro::minicoro
228+
flatbuffers::flatbuffers
229+
$<$<BOOL:${BTCPP_GROOT_INTERFACE}>:cppzmq>
230+
$<$<BOOL:${BTCPP_SQLITE_LOGGING}>:SQLite::SQLite3>
185231
PUBLIC
186232
${BTCPP_EXTRA_LIBRARIES}
187233
)
@@ -191,8 +237,6 @@ target_include_directories(${BTCPP_LIBRARY}
191237
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
192238
$<INSTALL_INTERFACE:include>
193239
PRIVATE
194-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty>
195-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/lexy/include>
196240
${BTCPP_EXTRA_INCLUDE_DIRS}
197241
)
198242

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ Three build systems are supported:
6161

6262
Compiling with [conan](https://conan.io/):
6363

64-
Assuming that you are in the **parent** directory of `BehaviorTree.CPP`:
64+
> [!NOTE]
65+
> Conan builds require CMake 3.23 or newer.
66+
67+
Assuming that you are in the **root** directory of `BehaviorTree.CPP`:
6568

6669
```
67-
mkdir build_release
68-
conan install . -of build_release -s build_type=Release
69-
cmake -S . -B build_release -DCMAKE_TOOLCHAIN_FILE="build_release/conan_toolchain.cmake"
70-
cmake --build build_release --parallel
70+
conan install . -s build_type=Release --build=missing
71+
cmake --preset conan-release
72+
cmake --build --preset conan-release
7173
```
7274

7375
If you have dependencies such as ZeroMQ and SQlite already installed and you don't want to

0 commit comments

Comments
 (0)