Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CMake for C and C++ examples #443

Merged
merged 2 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 39 additions & 34 deletions examples/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,42 @@ cmake_minimum_required(VERSION 3.1)

project(lcm_c_example)

# Import LCM via pkgconfig.
find_package(PkgConfig REQUIRED)
pkg_check_modules(LCM REQUIRED lcm)

# Use lcm-gen to generate headers and sources.
find_program(LCM_GEN_EXECUTABLE lcm-gen)
add_custom_target(exlcm
COMMAND ${LCM_GEN_EXECUTABLE} -c ../../types/example_t.lcm
BYPRODUCTS exlcm_example_t.c)
include_directories("${lcm_c_example_BINARY_DIR}")

# Everything from here on needs these flags.
include_directories(${LCM_INCLUDE_DIRS})
link_libraries(${LCM_LDFLAGS})

# Create executables for the example programs.

add_executable(listener "listener.c" "exlcm_example_t.c")
add_dependencies(listener exlcm)

add_executable(listener-async "listener-async.c" "exlcm_example_t.c")
add_dependencies(listener-async exlcm)

add_executable(listener-glib "listener-glib.c" "exlcm_example_t.c")
add_dependencies(listener-glib exlcm)
pkg_check_modules(GLIB REQUIRED glib-2.0)
target_link_libraries(listener-glib ${GLIB_LIBRARIES})
target_include_directories(listener-glib PRIVATE ${GLIB_INCLUDE_DIRS})

add_executable(send_message "send_message.c" "exlcm_example_t.c")
add_dependencies(send_message exlcm)

add_executable(read_log "read_log.c" "exlcm_example_t.c")
add_dependencies(read_log exlcm)
find_package(lcm REQUIRED)
include(${LCM_USE_FILE})

# Include this directory for finding GLib2, using the file FindGLib2.cmake.
# **WARNING** If you want to reuse this example, you will need to copy
# FindGLib2.cmake to your new project and adjust your CMAKE_MODULE_PATH.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../../cmake")

find_package(GLib2 REQUIRED)

# Put all message definition files in the type directory in one list
FILE(GLOB example_message_definitions "${CMAKE_CURRENT_LIST_DIR}/../types/*.lcm")

# Generate headers and source from message definition
lcm_wrap_types(C_SOURCES c_sources C_HEADERS c_headers
${example_message_definitions})

# Create library from all the messages
lcm_add_library(example_messages-c C STATIC ${c_sources} ${c_headers})
target_include_directories(example_messages-c INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)

# Create executables for the three example programs, linking all of them to our
# messages library and lcm

add_executable(listener "listener.c")
lcm_target_link_libraries(listener example_messages-c ${LCM_NAMESPACE}lcm)

add_executable(listener-async "listener-async.c")
lcm_target_link_libraries(listener-async example_messages-c ${LCM_NAMESPACE}lcm)

add_executable(listener-glib "listener-glib.c")
lcm_target_link_libraries(listener-glib example_messages-c ${LCM_NAMESPACE}lcm GLib2::glib)

add_executable(send_message "send_message.c")
lcm_target_link_libraries(send_message example_messages-c ${LCM_NAMESPACE}lcm)

add_executable(read_log "read_log.c")
lcm_target_link_libraries(read_log example_messages-c ${LCM_NAMESPACE}lcm)
34 changes: 18 additions & 16 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@ cmake_minimum_required(VERSION 3.1)

project(lcm_cpp_example)

# Import LCM via pkgconfig.
find_package(PkgConfig REQUIRED)
pkg_check_modules(LCM REQUIRED lcm)
find_package(lcm REQUIRED)
include(${LCM_USE_FILE})

# Use lcm-gen to generate headers.
find_program(LCM_GEN_EXECUTABLE lcm-gen)
add_custom_target(exlcm
COMMAND ${LCM_GEN_EXECUTABLE} -x ../../types/*.lcm)
include_directories("${lcm_cpp_example_BINARY_DIR}")
# Put all message definition files in the type directory in one list
FILE(GLOB example_message_definitions "${CMAKE_CURRENT_LIST_DIR}/../types/*.lcm")

# Everything from here on needs these flags.
include_directories(${LCM_INCLUDE_DIRS})
link_libraries(${LCM_LDFLAGS})
# Generate headers from message definition
lcm_wrap_types(CPP_HEADERS cpp_headers
${example_message_definitions})

# Create executables for the example programs.
# Create library from all the messages
lcm_add_library(example_messages-cpp CPP ${cpp_headers})
target_include_directories(example_messages-cpp INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)

# Create executables for the three example programs, linking all of them to our
# messages library and lcm

add_executable(listener "listener.cpp")
add_dependencies(listener exlcm)
lcm_target_link_libraries(listener example_messages-cpp ${LCM_NAMESPACE}lcm)

add_executable(send_message "send_message.cpp")
add_dependencies(send_message exlcm)
lcm_target_link_libraries(send_message example_messages-cpp ${LCM_NAMESPACE}lcm)

add_executable(read_log "read_log.cpp")
add_dependencies(read_log exlcm)
lcm_target_link_libraries(read_log example_messages-cpp ${LCM_NAMESPACE}lcm)
24 changes: 14 additions & 10 deletions examples/cpp/lcm_log_writer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
project(lcm_log_writer)
cmake_minimum_required(VERSION 3.1)

add_compile_options("-std=c++11")
set(CMAKE_BUILD_TYPE "Release")
project(lcm_log_writer)

find_package(lcm REQUIRED)
include(${LCM_USE_FILE})

# Import LCM via pkgconfig.
find_package(PkgConfig REQUIRED)
pkg_check_modules(LCM REQUIRED lcm)
include_directories(${LCM_INCLUDE_DIRS})
link_libraries(${LCM_LDFLAGS})
# Generate header from message definition
lcm_wrap_types(CPP_HEADERS pjs_cpp_headers
pronto_joint_state_t.lcm)

include_directories("${PROJECT_SOURCE_DIR}/include")
# Create library from the message
lcm_add_library(pjs_messages-cpp CPP ${pjs_cpp_headers})
target_include_directories(pjs_messages-cpp INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)

add_executable(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/main.cpp)
# Create executable
add_executable(lcm_log_writer "main.cpp")
lcm_target_link_libraries(lcm_log_writer pjs_messages-cpp ${LCM_NAMESPACE}lcm)
Loading