cmake_minimum_required(VERSION 3.5)
# Read version from the package.xml file.
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/package.xml package_xml_str)
if(NOT package_xml_str MATCHES "([0-9]+.[0-9]+.[0-9]+)")
message(FATAL_ERROR "Could not parse project version from package.xml. Aborting.")
endif()
# At this point we either have a proper version string, or we've errored
# out with a FATAL_ERROR above. So assume CMAKE_MATCH_1 contains our
# package's version.
project(abb_libegm VERSION ${CMAKE_MATCH_1} LANGUAGES CXX)
include(GNUInstallDirs)
if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()
#########################
## Boost C++ Libraries ##
#########################
find_package(Boost REQUIRED COMPONENTS regex system thread)
#############################
## Google Protocol Buffers ##
#############################
# Temporary workaround for https://github.com/ms-iot/ROSOnWindows/issues/218
if(WIN32)
foreach(prefix IN ITEMS $ENV{CMAKE_PREFIX_PATH})
if(${prefix} STREQUAL "C:/opt/rosdeps/x64")
list(APPEND CMAKE_PROGRAM_PATH "C:/opt/rosdeps/x64/tools/protobuf")
endif()
endforeach()
endif()
find_package(Protobuf REQUIRED)
# Make sure protoc is present, as apparently the above find_package() doesn't check that.
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
message(FATAL_ERROR "Cannot find required 'protoc', cannot process Protobuf files without it. Aborting.")
endif()
# Generate C++ for protocol classes (headers and sources
# get written to the CMAKE_CURRENT_BINARY_DIR location).
set(EgmProtoFiles proto/egm.proto proto/egm_wrapper.proto proto/egm_wrapper_trajectory.proto)
if(NOT QUIET)
message(STATUS "Generating protobuf C++ for: ${EgmProtoFiles}")
endif()
if(MSVC)
# Add export macro when using Microsoft Visual C++ compiler.
protobuf_generate_cpp(EgmProtoSources EgmProtoHeaders EXPORT_MACRO ABB_LIBEGM_EXPORT ${EgmProtoFiles})
else()
protobuf_generate_cpp(EgmProtoSources EgmProtoHeaders ${EgmProtoFiles})
endif()
#############
## Threads ##
#############
find_package(Threads REQUIRED)
# Work around Protobuf exporting 'lpthread' as a library: we let the
# previous find_package(...) determine the system's thread library.
list(REMOVE_ITEM PROTOBUF_LIBRARIES "-lpthread")
###########
## Build ##
###########
if(NOT DEFINED BUILD_SHARED_LIBS)
option(BUILD_SHARED_LIBS "Build dynamically-linked binaries" ON)
endif()
set(
SRC_FILES
src/egm_base_interface.cpp
src/egm_common.cpp
src/egm_common_auxiliary.cpp
src/egm_controller_interface.cpp
src/egm_interpolator.cpp
src/egm_logger.cpp
src/egm_udp_server.cpp
src/egm_trajectory_interface.cpp
${EgmProtoSources}
)
add_library(${PROJECT_NAME} ${SRC_FILES})
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
include(GenerateExportHeader)
generate_export_header(${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC
"$"
$/include>
${PROTOBUF_INCLUDE_DIRS}
)
target_link_libraries(${PROJECT_NAME} PUBLIC
Boost::regex
Boost::system
Boost::thread
${PROTOBUF_LIBRARIES}
Threads::Threads
)
if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(${PROJECT_NAME} PUBLIC "ABB_LIBEGM_STATIC_DEFINE")
endif()
if(MSVC)
# Force include the export header when using Microsoft Visual C++ compiler.
target_compile_options(${PROJECT_NAME} PUBLIC "/FI${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_export.h")
endif()
#############
## Install ##
#############
install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES
${EgmProtoFiles}
${EgmProtoHeaders}
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)
install(
TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
include(CMakePackageConfigHelpers)
# Create the ${PROJECT_NAME}Config.cmake.
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
"${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake" @ONLY
)
# Create the ${PROJECT_NAME}ConfigVersion.cmake.
write_basic_package_version_file(
${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
COMPATIBILITY AnyNewerVersion
)
install(
FILES
"${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/package.xml"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}
)
# Export targets.
set(export_targets ${export_targets};${PROJECT_NAME})
export(
EXPORT export_${PROJECT_NAME}
FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake"
NAMESPACE ${PROJECT_NAME}::
)
install(
EXPORT export_${PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
)