Skip to content

Commit

Permalink
Rework CMakeLists for generate multiply examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Dec 2, 2024
1 parent 70fc8b2 commit 3571c98
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 34 deletions.
81 changes: 52 additions & 29 deletions examples/rpi_pico_w/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ set(ZENOH_CONFIG_LISTEN CACHE STRING "ZENOH_CONFIG_LISTEN")

message(STATUS "WIFI_SSID: ${WIFI_SSID}")
if(WIFI_PASSWORD STREQUAL "")
message(STATUS "WIFI_PASSWORD is empty")
message(STATUS "WIFI_PASSWORD is empty")
else()
message(STATUS "WIFI_PASSWORD is set")
message(STATUS "WIFI_PASSWORD is set")
endif()

message(STATUS "ZENOH_CONFIG_MODE: ${ZENOH_CONFIG_MODE}")
Expand All @@ -24,7 +24,7 @@ set(CMAKE_C_STANDARD 11)
# Include Raspberry Pico SDK
set(PICO_BOARD "pico_w")
if(NOT DEFINED ENV{PICO_SDK_PATH})
message(FATAL_ERROR "PICO_SDK_PATH environment variable is not set. Please set it to the location of the Pico SDK.")
message(FATAL_ERROR "PICO_SDK_PATH environment variable is not set. Please set it to the location of the Pico SDK.")
endif()
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)

Expand All @@ -37,12 +37,6 @@ project(zenohpico_rpi_pico_w_examples C CXX ASM)
add_compile_definitions(LWIP_TIMEVAL_PRIVATE=0)
pico_sdk_init()

add_executable(zenohpico_rpi_pico_w_examples main.c app_main.c)

#target_compile_definitions(zenohpico_rpi_pico_w_examples PRIVATE PICO_STDIO_DEBUG=1)
pico_enable_stdio_usb(zenohpico_rpi_pico_w_examples 1)
pico_enable_stdio_uart(zenohpico_rpi_pico_w_examples 1)

# Include Zenoh Pico library
include(../../cmake/helpers.cmake)
set_default_build_type(Release)
Expand All @@ -53,34 +47,63 @@ set(ZENOH_DEBUG 5)
configure_include_project(ZENOHPICO zenohpico zenohpico::lib "../.." zenohpico "https://github.com/eclipse-zenoh/zenoh-pico" "")

target_link_libraries(zenohpico_static
pico_cyw43_arch_lwip_sys_freertos
pico_stdlib
FreeRTOS-Kernel-Heap4
pico_stdlib
pico_cyw43_arch_lwip_sys_freertos
FreeRTOS-Kernel-Heap4
)

# Configure build
target_include_directories(zenohpico_static PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/..
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/..
)

target_compile_definitions(zenohpico_rpi_pico_w_examples PRIVATE
WIFI_SSID=\"${WIFI_SSID}\"
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
ZENOH_CONFIG_MODE=\"${ZENOH_CONFIG_MODE}\"
ZENOH_CONFIG_CONNECT=\"${ZENOH_CONFIG_CONNECT}\"
ZENOH_CONFIG_LISTEN=\"${ZENOH_CONFIG_LISTEN}\"
add_library(main STATIC main.c)

target_compile_definitions(main PRIVATE
WIFI_SSID=\"${WIFI_SSID}\"
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
)
target_include_directories(zenohpico_rpi_pico_w_examples PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/..
target_include_directories(main PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/..
)
target_link_libraries(zenohpico_rpi_pico_w_examples
zenohpico_static
pico_cyw43_arch_lwip_sys_freertos
pico_stdlib
FreeRTOS-Kernel-Heap4
target_link_libraries(main
pico_stdlib
pico_cyw43_arch_lwip_sys_freertos
FreeRTOS-Kernel-Heap4
)

pico_add_extra_outputs(zenohpico_rpi_pico_w_examples)
function(add_example name)
add_executable(${name} ${name}.c)
target_link_libraries(${name}
main
pico_stdlib
pico_cyw43_arch_lwip_sys_freertos
FreeRTOS-Kernel-Heap4
zenohpico::lib
)
target_compile_definitions(${name} PRIVATE
ZENOH_CONFIG_MODE=\"${ZENOH_CONFIG_MODE}\"
ZENOH_CONFIG_CONNECT=\"${ZENOH_CONFIG_CONNECT}\"
ZENOH_CONFIG_LISTEN=\"${ZENOH_CONFIG_LISTEN}\"
)
target_include_directories(${name} PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/..
)
pico_enable_stdio_usb(${name} 1)
pico_enable_stdio_uart(${name} 1)
pico_add_extra_outputs(${name})
endfunction()

add_example(app_main)

#add_example(z_get)
#add_example(z_pub)
#add_example(z_pull)
#add_example(z_put)
#add_example(z_queryable)
#add_example(z_scout)
#add_example(z_sub)

7 changes: 2 additions & 5 deletions examples/rpi_pico_w/app_main.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
#include <stdio.h>
#include <zenoh-pico.h>

#include "FreeRTOS.h"
#include "lwip/sockets.h"
#include "pico/cyw43_arch.h"
#include "pico/stdlib.h"
#include "zenoh-pico/utils/result.h"

int app_main() {
z_owned_config_t config;
z_config_default(&config);
zp_config_insert(z_loan_mut(config), Z_CONFIG_MODE_KEY, "client");
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, "tcp/192.168.0.108:7447");
// zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, "tcp/192.168.0.108:7447");
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, "tcp/192.168.21.28:7447");

printf("Opening session...\n");
z_owned_session_t s;
Expand Down

0 comments on commit 3571c98

Please sign in to comment.