-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
105 lines (83 loc) · 2.95 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved.
# This software may be modified and distributed under the terms of the
# GNU Lesser General Public License v2.1 or any later version.
cmake_minimum_required(VERSION 3.7)
project(ExampleRosToolbox LANGUAGES CXX VERSION 0.1)
# C++ standard
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Build type
if(NOT CMAKE_CONFIGURATION_TYPES)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build" FORCE)
endif()
set(ROS_BUILD_TYPES "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${ROS_BUILD_TYPES})
endif()
# Export all symbols in Windows
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# Utility for defining install folders
include(GNUInstallDirs)
# Tweak linker flags in Linux.
# Matlab is very strict on missing symbols and by default ld do not warn if
# something is missing.
if(UNIX AND NOT APPLE AND NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Release")
get_filename_component(LINKER_BIN ${CMAKE_LINKER} NAME)
if(${LINKER_BIN} STREQUAL "ld")
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--unresolved-symbols=report-all")
endif()
endif()
# ===========
# C++ LIBRARY
# ===========
# Find the needed BlockFactory components:
# - "Core" contains the core classes such as Block and Signal
# - "Simulink" is required at runtime for loading the library from Simulink
find_package(BlockFactory
REQUIRED COMPONENTS Core
OPTIONAL_COMPONENTS Simulink)
# Find the C++ ROS libraries
find_package(roscpp REQUIRED)
# Include CMake helpers provided by BlockFactory
include(BlockFactoryPlugin)
register_blockfactory_block(
BLOCK_NAME RosTopicPublisher
PLUGIN_NAME RosToolbox
SOURCES src/RosTopicPublisher.cpp
HEADERS include/RosTopicPublisher.h)
register_blockfactory_block(
BLOCK_NAME RosTopicSubscriber
PLUGIN_NAME RosToolbox
SOURCES src/RosTopicSubscriber.cpp
HEADERS include/RosTopicSubscriber.h)
# Create the plugin library
add_blockfactory_plugin(RosToolbox
EXTRA_SOURCES src/Factory.cpp)
# Link the library with the external dependencies
target_link_libraries(RosToolbox PRIVATE ${roscpp_LIBRARIES})
# Setup the include directories
target_include_directories(RosToolbox PRIVATE
${roscpp_INCLUDE_DIRS}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
if(WIN32)
target_compile_definitions(RosToolbox PRIVATE ROS_BUILD_SHARED_LIBS=1)
endif()
# ==================
# AUTOGENERATED CODE
# ==================
find_package(Matlab COMPONENTS
MX_LIBRARY
ENG_LIBRARY
MAIN_PROGRAM
SIMULINK)
if(${Matlab_SIMULINK_FOUND})
# Build the autogenerated class
add_subdirectory(matlab)
# Create the executable
add_executable(main src/main.cpp)
target_link_libraries(main RosPubSubExample)
endif()
# ==========================
# INSTALL THE PLUGIN LIBRARY
# ==========================
install_blockfactory_plugin(RosToolbox)