Porting mros2 as an Mbed library.
Dependents: mbed-os-example-mros2 example-mbed-mros2-sub-pose example-mbed-mros2-pub-twist example-mbed-mros2-mturtle-teleop
Diff: embeddedRTPS/thirdparty/Micro-CDR/CMakeLists.txt
- Revision:
- 0:580aba13d1a1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/embeddedRTPS/thirdparty/Micro-CDR/CMakeLists.txt Thu Dec 30 21:06:29 2021 +0900 @@ -0,0 +1,190 @@ +# Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +############################################################################### +# CMake build rules for Micro CDR +############################################################################### +cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) + +set(IS_TOP_LEVEL TRUE) +if(PROJECT_SOURCE_DIR) + set(IS_TOP_LEVEL FALSE) +endif() + +# Set CMAKE_BUILD_TYPE to Release by default. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to 'Release' as none was specified.") + set(CMAKE_BUILD_TYPE Release CACHE STRING + "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." + FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif() + +############################################################################### +# Product information +############################################################################### +if(CMAKE_VERSION VERSION_LESS 3.0) + project(microcdr C) + set(PROJECT_VERSION_MAJOR 2) + set(PROJECT_VERSION_MINOR 0) + set(PROJECT_VERSION_PATCH 0) + set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) +else() + cmake_policy(SET CMP0048 NEW) + project(microcdr VERSION "2.0.0" LANGUAGES C) +endif() + +############################################################################### +# eProsima build options +############################################################################### +option(EPROSIMA_BUILD "Activate internal building" OFF) +option(EPROSIMA_BUILD_TESTS "Activate the building of tests" OFF) + +if(EPROSIMA_BUILD) + set(EPROSIMA_BUILD_TESTS ON) +endif() + +############################################################################### +# Check MSVC architecture +############################################################################### +include(${PROJECT_SOURCE_DIR}/cmake/common/check_configuration.cmake) +if(MSVC OR MSVC_IDE) + check_msvc_arch() +endif() + +############################################################################### +# Targets +############################################################################### + +# Library +add_library(${PROJECT_NAME} + src/c/common.c + src/c/types/basic.c + src/c/types/string.c + src/c/types/array.c + src/c/types/sequence.c + ) + +set_common_compile_options(${PROJECT_NAME}) +set_target_properties(${PROJECT_NAME} PROPERTIES + VERSION ${PROJECT_VERSION} + C_STANDARD 99 + C_STANDARD_REQUIRED YES + ) + +# Define public headers +target_include_directories(${PROJECT_NAME} + PUBLIC + $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> + $<INSTALL_INTERFACE:include> + ) + +############################################################################### +# Config +############################################################################### + +# Install path +set(BIN_INSTALL_DIR bin/ CACHE PATH "Installation directory for binaries") +set(INCLUDE_INSTALL_DIR include/ CACHE PATH "Installation directory for C headers") +set(LIB_INSTALL_DIR lib/ CACHE PATH "Installation directory for libraries") +set(DATA_INSTALL_DIR share/ CACHE PATH "Installation directory for data") +if(WIN32) + set(LICENSE_INSTALL_DIR . CACHE PATH "Installation directory for licenses") +else() + set(LICENSE_INSTALL_DIR ${DATA_INSTALL_DIR}/${PROJECT_NAME} CACHE PATH "Installation directory for licenses") +endif() + +# Endianness configuration +include(${PROJECT_SOURCE_DIR}/cmake/common/check_configuration.cmake) + +option(CHECK_ENDIANNESS "Enable/disable endiannes checking" ON) +message(STATUS "Big Ending " __BIG_ENDIAN__) +message(STATUS "Check endianess " CHECK_ENDIANNESS) +if(__BIG_ENDIAN__) + set(CHECK_ENDIANNESS OFF) + message(STATUS "micro-CDR without check endianness using provided endianness") +elseif(CHECK_ENDIANNESS) + check_endianness() +else() + set(__BIG_ENDIAN__ 0) + message(STATUS "micro-CDR without check endianness") +endif() + +# Config.h +configure_file(${PROJECT_SOURCE_DIR}/include/ucdr/config.h.in + ${PROJECT_BINARY_DIR}/include/ucdr/config.h +) + +############################################################################### +# Compile settings +############################################################################### + +# Definitions +get_target_property(TARGET_TYPE ${PROJECT_NAME} TYPE) +if((MSVC OR MSVC_IDE) AND (TARGET_TYPE STREQUAL "SHARED_LIBRARY")) + target_compile_definitions(${PROJECT_NAME} + PUBLIC + -D${PROJECT_NAME}_SHARED + ) +endif() + +############################################################################### +# Testing +############################################################################### +if(EPROSIMA_BUILD_TESTS AND IS_TOP_LEVEL) + include(${PROJECT_SOURCE_DIR}/cmake/common/gtest.cmake) + enable_testing() + add_subdirectory(test) +endif() + +############################################################################### +# Packaging +############################################################################### + +# Install library +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}Targets + ARCHIVE DESTINATION ${LIB_INSTALL_DIR} + LIBRARY DESTINATION ${LIB_INSTALL_DIR} + RUNTIME DESTINATION ${BIN_INSTALL_DIR} + COMPONENT libraries + ) + +# Install includes +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ucdr/ + DESTINATION ${INCLUDE_INSTALL_DIR}/ucdr + FILES_MATCHING PATTERN "*.h" + ) + +# Install config.h +install(FILES ${PROJECT_BINARY_DIR}/include/ucdr/config.h + DESTINATION ${INCLUDE_INSTALL_DIR}/ucdr + ) + +# Export library +install(EXPORT ${PROJECT_NAME}Targets + DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME}/cmake + ) + +# Package configuration +include(CMakePackageConfigHelpers) +configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/packaging/Config.cmake.in + ${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}Config.cmake + INSTALL_DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME}/cmake + PATH_VARS BIN_INSTALL_DIR INCLUDE_INSTALL_DIR LIB_INSTALL_DIR DATA_INSTALL_DIR + ) +install(FILES ${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}Config.cmake + DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME}/cmake + )