forked from phamelin/orocos-rtt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UseOROCOS-RTT-helpers.cmake
156 lines (140 loc) · 6.32 KB
/
UseOROCOS-RTT-helpers.cmake
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#
# Parses the manifest.xml file and stores the dependencies in RESULT.
# Relies on xpath.
#
# Usage: orocos_get_manifest_deps DEPS)
#
macro( orocos_get_manifest_deps RESULT)
find_program(XPATH_EXE xpath )
if (NOT XPATH_EXE)
message("Warning: xpath not found. Can't read dependencies in manifest.xml file.")
else(NOT XPATH_EXE)
IF (APPLE)
execute_process(COMMAND ${XPATH_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/manifest.xml "package/depend/@package" RESULT_VARIABLE RES OUTPUT_VARIABLE DEPS)
SET(REGEX_STR " package=\"([^\"]+)\"")
ELSE (APPLE)
execute_process(COMMAND ${XPATH_EXE} -q -e "package/depend/@package" ${CMAKE_CURRENT_SOURCE_DIR}/manifest.xml RESULT_VARIABLE RES OUTPUT_VARIABLE DEPS)
SET(REGEX_STR " package=\"([^\"]+)\"\n")
ENDIF (APPLE)
if (NOT RES EQUAL 0)
message(SEND_ERROR "Error: xpath found but returned non-zero:${DEPS}")
endif (NOT RES EQUAL 0)
string(REGEX REPLACE "${REGEX_STR}" "\\1;" RR_RESULT ${DEPS})
#message("Deps are: '${DEPS}'")
#message("Dependencies are: '${RR_RESULT}'")
set(${RESULT} ${RR_RESULT})
endif (NOT XPATH_EXE)
endmacro( orocos_get_manifest_deps RESULT)
#
# Find a package, pick up its include dirs and link with its libraries.
# It does this by locating and reading the .pc file generated by that package.
# In case no such .pc file exists (or is not found), tt is assumed that no
# flags are necessary.
#
# This macro is called for you by UseOrocos-RTT.cmake
# for each dependency listed in your manifest.xml file.
#
# sets these variables:
# ${PACKAGE}_LIBRARIES The fully resolved link libraries for this package.
# ${PACKAGE}_<LIB>_LIBRARIES Each fully resolved link library <LIB> in the above list.
#
# Usage: orocos_use_package( myrobot )
#
function( orocos_use_package PACKAGE )
if (PACKAGE STREQUAL "rtt")
return()
endif (PACKAGE STREQUAL "rtt")
if (ROS_ROOT)
if (NOT USE_FOUND_${PACKAGE}_PACKAGE_PATH)
# use rospack to find package directories of *all* dependencies.
# We need these because a .pc file may depend on another .pc file in another package.
# This package + the packages this package depends on:
rosbuild_find_ros_package(${PACKAGE})
if (${PACKAGE}_PACKAGE_PATH)
rosbuild_invoke_rospack(${PACKAGE} ${PACKAGE}_prefix DEPS depends)
string(REGEX REPLACE "\n" ";" ${PACKAGE}_prefix_DEPS2 "${${PACKAGE}_prefix_DEPS}" )
foreach(ROSDEP ${${PACKAGE}_prefix_DEPS2} ${PACKAGE})
# Skip previously found packages
if (NOT USE_FOUND_${ROSDEP}_PACKAGE_PATH)
rosbuild_find_ros_package( ${ROSDEP} )
# We prefer looking in the install directory above the package's own directory:
set( ENV{PKG_CONFIG_PATH} "${${ROSDEP}_PACKAGE_PATH}/install/lib/pkgconfig:${${ROSDEP}_PACKAGE_PATH}:$ENV{PKG_CONFIG_PATH}" )
set( USE_FOUND_${ROSDEP}_PACKAGE_PATH 1 ) # mark we don't need to find it again.
endif (NOT USE_FOUND_${ROSDEP}_PACKAGE_PATH)
endforeach(ROSDEP ${${PACKAGE}_prefix_DEPS2} ${PACKAGE})
endif (${PACKAGE}_PACKAGE_PATH)
#message("Searching for ${PACKAGE} in ${${ROSDEP}_PACKAGE_PATH}.")
else (NOT USE_FOUND_${PACKAGE}_PACKAGE_PATH)
if (VERBOSE)
message("[UseOrocos] Note: '${PACKAGE}' is not a ROS package. Trying .pc file...")
endif (VERBOSE)
endif (NOT USE_FOUND_${PACKAGE}_PACKAGE_PATH)
else(ROS_ROOT)
#Use default pkg-config path
#message("Searching for ${PACKAGE} in env PKG_CONFIG_PATH.")
endif(ROS_ROOT)
# Now we are ready to get the flags from the .pc files:
#pkg_check_modules(${PACKAGE}_COMP ${PACKAGE}-${OROCOS_TARGET})
pkg_search_module(${PACKAGE}_COMP ${PACKAGE} ${PACKAGE}-${OROCOS_TARGET})
if (${PACKAGE}_COMP_FOUND)
include_directories(${${PACKAGE}_COMP_INCLUDE_DIRS})
# Use find_libraries to find each library:
foreach(COMP_LIB ${${PACKAGE}_COMP_LIBRARIES})
find_library(${PACKAGE}_${COMP_LIB}_LIBRARY NAMES ${COMP_LIB} HINTS ${${PACKAGE}_COMP_LIBRARY_DIRS})
if(${PACKAGE}_${COMP_LIB}_LIBRARY)
else(${PACKAGE}_${COMP_LIB}_LIBRARY)
message(SEND_ERROR "Could not find library ${COMP_LIB} in ${${PACKAGE}_COMP_LIBRARY_DIRS}, although its .pc file says it should be there.")
endif(${PACKAGE}_${COMP_LIB}_LIBRARY)
list(APPEND ${PACKAGE}_LIBRARIES ${${PACKAGE}_${COMP_LIB}_LIBRARY})
endforeach(COMP_LIB ${${PACKAGE}_COMP_LIBRARIES})
# Only link in case there is something *and* the user didn't opt-out:
if (NOT OROCOS_NO_AUTO_LINKING AND ${PACKAGE}_COMP_LIBRARIES)
link_libraries( ${${PACKAGE}_LIBRARIES} )
message("[UseOrocos] Linking all targets with libraries from package '${PACKAGE}'.")
#message("Linking with ${PACKAGE}: ${${PACKAGE}_LIBRARIES}")
endif (NOT OROCOS_NO_AUTO_LINKING AND ${PACKAGE}_COMP_LIBRARIES)
else (${PACKAGE}_COMP_FOUND)
if (VERBOSE)
message("[UseOrocos] ${PACKAGE} does not provide a .pc file for exporting its build/link flags (or one of it 'Requires' dependencies was not found).")
endif (VERBOSE)
endif (${PACKAGE}_COMP_FOUND)
endfunction( orocos_use_package PACKAGE )
macro(_orocos_list_to_string _string _list)
set(${_string})
foreach(_item ${_list})
string(LENGTH "${${_string}}" _len)
if(${_len} GREATER 0)
set(${_string} "${${_string}} ${_item}")
else(${_len} GREATER 0)
set(${_string} "${_item}")
endif(${_len} GREATER 0)
endforeach(_item)
endmacro(_orocos_list_to_string)
macro(orocos_add_compile_flags target)
set(args ${ARGN})
separate_arguments(args)
get_target_property(_flags ${target} COMPILE_FLAGS)
if(NOT _flags)
set(_flags ${ARGN})
else(NOT _flags)
separate_arguments(_flags)
list(APPEND _flags "${args}")
endif(NOT _flags)
_orocos_list_to_string(_flags_str "${_flags}")
set_target_properties(${target} PROPERTIES
COMPILE_FLAGS "${_flags_str}")
endmacro(orocos_add_compile_flags)
macro(orocos_add_link_flags target)
set(args ${ARGN})
separate_arguments(args)
get_target_property(_flags ${target} LINK_FLAGS)
if(NOT _flags)
set(_flags ${ARGN})
else(NOT _flags)
separate_arguments(_flags)
list(APPEND _flags "${args}")
endif(NOT _flags)
_orocos_list_to_string(_flags_str "${_flags}")
set_target_properties(${target} PROPERTIES
LINK_FLAGS "${_flags_str}")
endmacro(orocos_add_link_flags)