forked from cplasberg/soem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
100 lines (85 loc) · 3.98 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
cmake_minimum_required(VERSION 2.8.12)
project(soem)
find_package(catkin REQUIRED)
message([=[
SOEM ROS Package Upgrade Announcement
=====================================
Prior, due to the code layout in soem, a workaround
has been necessary in users of this library.
This version solves this issue now by
providing proper cmake configuration files.
If you've used the workaround of specifying
`${soem_INCLUDE_DIRS}/soem` in the include_directories section
in your code/library, you should remove this now.
Also, this package has been upgraded to the upstream
SOEM release 1.4.0.
If you experience any problems, you can revert to
release v1.3.0 of this package to retrieve the old state.
]=]
)
# set-up destination variables
catkin_destinations()
# create directory during CMake build system creation step
file(MAKE_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_INCLUDE_DESTINATION})
if(WIN32)
set(OS "win32")
else()
set(OS "linux")
endif()
file(GLOB SOEM_COMMON_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/SOEM/soem/*.h")
file(GLOB SOEM_OSAL_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/SOEM/osal/${OS}/*.h")
file(GLOB SOEM_OSHW_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/SOEM/oshw/${OS}/*.h")
# Copy header to ROS-standard location in devel space to satisfy catkin_package
add_custom_target(CopyHeaders ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${SOEM_COMMON_HEADERS}
${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_INCLUDE_DESTINATION}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/SOEM/osal/osal.h
${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_INCLUDE_DESTINATION}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${SOEM_OSAL_HEADERS}
${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_INCLUDE_DESTINATION}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${SOEM_OSHW_HEADERS}
${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_INCLUDE_DESTINATION}
COMMENT "Copying SOEM headers to ROS-standard in devel space location.")
if(WIN32)
add_custom_target(CopyWpcapHeaders ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/SOEM/oshw/${OS}/wpcap/Include/
${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_INCLUDE_DESTINATION}
COMMENT "Copying Wpcap headers to ROS-standard in devel space location.")
endif()
# explicitely find pthread to be able to explicitely export the pthread dependency via catkin_package
# see https://github.com/ros/ros_comm/issues/135
set(PTHREAD_LIB "")
find_package(Threads)
if(CMAKE_THREAD_LIBS_INIT)
string(LENGTH ${CMAKE_THREAD_LIBS_INIT} _length)
if(_length GREATER 2)
string(SUBSTRING ${CMAKE_THREAD_LIBS_INIT} 0 2 _prefix)
if(${_prefix} STREQUAL "-l")
math(EXPR _rest_len "${_length} - 2")
string(SUBSTRING ${CMAKE_THREAD_LIBS_INIT} 2 ${_rest_len} PTHREAD_LIB)
endif()
endif()
endif()
# export dependencies and targets to catkin
# explicitely export pthread, as stated above
catkin_package(
CFG_EXTRAS soem-ros-extras.cmake
LIBRARIES soem ${PTHREAD_LIB}
)
# SOEM is, by default, built with position-dependent code as a static library.
# To be able to include SOEM in a dynamic library (default ROS convention),
# it needs to be built with position-independent code.
# Thus, we add -fPIC here.
# This allows us to still include this in any shared libraries we create.
add_compile_options(-fPIC)
# removed any pre-defined `WIN32_LEAN_AND_MEAN`.
# Otherwise, many symbols will be reported as missing.
remove_definitions(-DWIN32_LEAN_AND_MEAN)
#catkin_lint: ignore duplicate_cmd
#catkin_lint: ignore subproject
add_subdirectory(SOEM)