Skip to content

Commit

Permalink
use only find_package when building examples as a root project
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Oct 29, 2024
1 parent b6b9f0e commit bef16ef
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 31 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,11 @@ jobs:
cd build
cmake --build . --target examples
- name: Build examples with zenoh-c as subbroject and static library and in debug mode and in separate directory
shell: bash
run: |
mkdir -p ../build_examples
cmake -S examples -B ../build_examples -DZENOHC_TREAT_WARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF
cmake --build ../build_examples --config Debug
rm -rf ../build_examples
- name: Build examples with zenoh-c as installed package
shell: bash
run: |
mkdir -p build_examples && cd build_examples
cmake ../examples -DZENOHC_TREAT_WARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/local -DZENOHC_SOURCE=PACKAGE
cmake ../examples -DZENOHC_TREAT_WARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/local
cmake --build . --config Release
cd .. && rm -rf build_examples
Expand Down
22 changes: 2 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,36 +130,18 @@ cmake ../zenoh-c/examples
cmake --build .
```

In this case, the examples executables will be built in the current directory.

As a root project the `examples` project links `zenoh-c` with CMake's [add_subdirectory] command by default. There are also other ways to link `zenoh-c` - with [find_package] or [FetchContent]:

[add_subdirectory]: https://cmake.org/cmake/help/latest/command/add_subdirectory.html
[find_package]: https://cmake.org/cmake/help/latest/command/find_package.html
[FetchContent]: https://cmake.org/cmake/help/latest/module/FetchContent.html

Link with `zenoh-c` installed into default location in the system (with [find_package]):

```bash
cmake ../zenoh-c/examples -DZENOHC_SOURCE=PACKAGE
cmake ../zenoh-c/examples
```

Link with `zenoh-c` installed in `~/.local` directory:

```bash
cmake ../zenoh-c/examples -DZENOHC_SOURCE=PACKAGE -DCMAKE_INSTALL_PREFIX=~/.local
```

Download specific `zenoh-c` version from git with [FetchContent]:

```bash
cmake ../zenoh-c/examples -DZENOHC_SOURCE=GIT_URL -DZENOHC_GIT_TAG=0.11.0-rc
cmake ../zenoh-c/examples -DCMAKE_INSTALL_PREFIX=~/.local
```

See also `configure_include_project` function in [helpers.cmake] for more information

[helpers.cmake]: cmake/helpers.cmake

## Running the Examples

### Basic Pub/Sub Example
Expand Down
3 changes: 1 addition & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
project(zenohc_examples LANGUAGES C)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake" ${CMAKE_MODULE_PATH})
include(helpers)
set_default_build_type(Release)
configure_include_project(ZENOHC zenohc zenohc::lib ".." zenohc "https://github.com/eclipse-zenoh/zenoh-c" "")
find_package(zenohc REQUIRED)
add_custom_target(examples ALL)
else()
message(STATUS "zenoh-c examples")
Expand Down

0 comments on commit bef16ef

Please sign in to comment.