Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-os-example-mros2 example-mbed-mros2-sub-pose example-mbed-mros2-pub-twist example-mbed-mros2-mturtle-teleop
embeddedRTPS/thirdparty/Micro-CDR/CMakeLists.txt@7:c80f65422d99, 2022-03-19 (annotated)
- Committer:
- smoritaemb
- Date:
- Sat Mar 19 09:23:37 2022 +0900
- Revision:
- 7:c80f65422d99
- Parent:
- 0:580aba13d1a1
Merge test_assortment_of_msgs branch.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| smoritaemb | 0:580aba13d1a1 | 1 | # Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
| smoritaemb | 0:580aba13d1a1 | 2 | # |
| smoritaemb | 0:580aba13d1a1 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| smoritaemb | 0:580aba13d1a1 | 4 | # you may not use this file except in compliance with the License. |
| smoritaemb | 0:580aba13d1a1 | 5 | # You may obtain a copy of the License at |
| smoritaemb | 0:580aba13d1a1 | 6 | # |
| smoritaemb | 0:580aba13d1a1 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| smoritaemb | 0:580aba13d1a1 | 8 | # |
| smoritaemb | 0:580aba13d1a1 | 9 | # Unless required by applicable law or agreed to in writing, software |
| smoritaemb | 0:580aba13d1a1 | 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| smoritaemb | 0:580aba13d1a1 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| smoritaemb | 0:580aba13d1a1 | 12 | # See the License for the specific language governing permissions and |
| smoritaemb | 0:580aba13d1a1 | 13 | # limitations under the License. |
| smoritaemb | 0:580aba13d1a1 | 14 | |
| smoritaemb | 0:580aba13d1a1 | 15 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 16 | # CMake build rules for Micro CDR |
| smoritaemb | 0:580aba13d1a1 | 17 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 18 | cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) |
| smoritaemb | 0:580aba13d1a1 | 19 | |
| smoritaemb | 0:580aba13d1a1 | 20 | set(IS_TOP_LEVEL TRUE) |
| smoritaemb | 0:580aba13d1a1 | 21 | if(PROJECT_SOURCE_DIR) |
| smoritaemb | 0:580aba13d1a1 | 22 | set(IS_TOP_LEVEL FALSE) |
| smoritaemb | 0:580aba13d1a1 | 23 | endif() |
| smoritaemb | 0:580aba13d1a1 | 24 | |
| smoritaemb | 0:580aba13d1a1 | 25 | # Set CMAKE_BUILD_TYPE to Release by default. |
| smoritaemb | 0:580aba13d1a1 | 26 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
| smoritaemb | 0:580aba13d1a1 | 27 | message(STATUS "Setting build type to 'Release' as none was specified.") |
| smoritaemb | 0:580aba13d1a1 | 28 | set(CMAKE_BUILD_TYPE Release CACHE STRING |
| smoritaemb | 0:580aba13d1a1 | 29 | "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." |
| smoritaemb | 0:580aba13d1a1 | 30 | FORCE) |
| smoritaemb | 0:580aba13d1a1 | 31 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") |
| smoritaemb | 0:580aba13d1a1 | 32 | endif() |
| smoritaemb | 0:580aba13d1a1 | 33 | |
| smoritaemb | 0:580aba13d1a1 | 34 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 35 | # Product information |
| smoritaemb | 0:580aba13d1a1 | 36 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 37 | if(CMAKE_VERSION VERSION_LESS 3.0) |
| smoritaemb | 0:580aba13d1a1 | 38 | project(microcdr C) |
| smoritaemb | 0:580aba13d1a1 | 39 | set(PROJECT_VERSION_MAJOR 2) |
| smoritaemb | 0:580aba13d1a1 | 40 | set(PROJECT_VERSION_MINOR 0) |
| smoritaemb | 0:580aba13d1a1 | 41 | set(PROJECT_VERSION_PATCH 0) |
| smoritaemb | 0:580aba13d1a1 | 42 | set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) |
| smoritaemb | 0:580aba13d1a1 | 43 | else() |
| smoritaemb | 0:580aba13d1a1 | 44 | cmake_policy(SET CMP0048 NEW) |
| smoritaemb | 0:580aba13d1a1 | 45 | project(microcdr VERSION "2.0.0" LANGUAGES C) |
| smoritaemb | 0:580aba13d1a1 | 46 | endif() |
| smoritaemb | 0:580aba13d1a1 | 47 | |
| smoritaemb | 0:580aba13d1a1 | 48 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 49 | # eProsima build options |
| smoritaemb | 0:580aba13d1a1 | 50 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 51 | option(EPROSIMA_BUILD "Activate internal building" OFF) |
| smoritaemb | 0:580aba13d1a1 | 52 | option(EPROSIMA_BUILD_TESTS "Activate the building of tests" OFF) |
| smoritaemb | 0:580aba13d1a1 | 53 | |
| smoritaemb | 0:580aba13d1a1 | 54 | if(EPROSIMA_BUILD) |
| smoritaemb | 0:580aba13d1a1 | 55 | set(EPROSIMA_BUILD_TESTS ON) |
| smoritaemb | 0:580aba13d1a1 | 56 | endif() |
| smoritaemb | 0:580aba13d1a1 | 57 | |
| smoritaemb | 0:580aba13d1a1 | 58 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 59 | # Check MSVC architecture |
| smoritaemb | 0:580aba13d1a1 | 60 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 61 | include(${PROJECT_SOURCE_DIR}/cmake/common/check_configuration.cmake) |
| smoritaemb | 0:580aba13d1a1 | 62 | if(MSVC OR MSVC_IDE) |
| smoritaemb | 0:580aba13d1a1 | 63 | check_msvc_arch() |
| smoritaemb | 0:580aba13d1a1 | 64 | endif() |
| smoritaemb | 0:580aba13d1a1 | 65 | |
| smoritaemb | 0:580aba13d1a1 | 66 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 67 | # Targets |
| smoritaemb | 0:580aba13d1a1 | 68 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 69 | |
| smoritaemb | 0:580aba13d1a1 | 70 | # Library |
| smoritaemb | 0:580aba13d1a1 | 71 | add_library(${PROJECT_NAME} |
| smoritaemb | 0:580aba13d1a1 | 72 | src/c/common.c |
| smoritaemb | 0:580aba13d1a1 | 73 | src/c/types/basic.c |
| smoritaemb | 0:580aba13d1a1 | 74 | src/c/types/string.c |
| smoritaemb | 0:580aba13d1a1 | 75 | src/c/types/array.c |
| smoritaemb | 0:580aba13d1a1 | 76 | src/c/types/sequence.c |
| smoritaemb | 0:580aba13d1a1 | 77 | ) |
| smoritaemb | 0:580aba13d1a1 | 78 | |
| smoritaemb | 0:580aba13d1a1 | 79 | set_common_compile_options(${PROJECT_NAME}) |
| smoritaemb | 0:580aba13d1a1 | 80 | set_target_properties(${PROJECT_NAME} PROPERTIES |
| smoritaemb | 0:580aba13d1a1 | 81 | VERSION ${PROJECT_VERSION} |
| smoritaemb | 0:580aba13d1a1 | 82 | C_STANDARD 99 |
| smoritaemb | 0:580aba13d1a1 | 83 | C_STANDARD_REQUIRED YES |
| smoritaemb | 0:580aba13d1a1 | 84 | ) |
| smoritaemb | 0:580aba13d1a1 | 85 | |
| smoritaemb | 0:580aba13d1a1 | 86 | # Define public headers |
| smoritaemb | 0:580aba13d1a1 | 87 | target_include_directories(${PROJECT_NAME} |
| smoritaemb | 0:580aba13d1a1 | 88 | PUBLIC |
| smoritaemb | 0:580aba13d1a1 | 89 | $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> |
| smoritaemb | 0:580aba13d1a1 | 90 | $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> |
| smoritaemb | 0:580aba13d1a1 | 91 | $<INSTALL_INTERFACE:include> |
| smoritaemb | 0:580aba13d1a1 | 92 | ) |
| smoritaemb | 0:580aba13d1a1 | 93 | |
| smoritaemb | 0:580aba13d1a1 | 94 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 95 | # Config |
| smoritaemb | 0:580aba13d1a1 | 96 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 97 | |
| smoritaemb | 0:580aba13d1a1 | 98 | # Install path |
| smoritaemb | 0:580aba13d1a1 | 99 | set(BIN_INSTALL_DIR bin/ CACHE PATH "Installation directory for binaries") |
| smoritaemb | 0:580aba13d1a1 | 100 | set(INCLUDE_INSTALL_DIR include/ CACHE PATH "Installation directory for C headers") |
| smoritaemb | 0:580aba13d1a1 | 101 | set(LIB_INSTALL_DIR lib/ CACHE PATH "Installation directory for libraries") |
| smoritaemb | 0:580aba13d1a1 | 102 | set(DATA_INSTALL_DIR share/ CACHE PATH "Installation directory for data") |
| smoritaemb | 0:580aba13d1a1 | 103 | if(WIN32) |
| smoritaemb | 0:580aba13d1a1 | 104 | set(LICENSE_INSTALL_DIR . CACHE PATH "Installation directory for licenses") |
| smoritaemb | 0:580aba13d1a1 | 105 | else() |
| smoritaemb | 0:580aba13d1a1 | 106 | set(LICENSE_INSTALL_DIR ${DATA_INSTALL_DIR}/${PROJECT_NAME} CACHE PATH "Installation directory for licenses") |
| smoritaemb | 0:580aba13d1a1 | 107 | endif() |
| smoritaemb | 0:580aba13d1a1 | 108 | |
| smoritaemb | 0:580aba13d1a1 | 109 | # Endianness configuration |
| smoritaemb | 0:580aba13d1a1 | 110 | include(${PROJECT_SOURCE_DIR}/cmake/common/check_configuration.cmake) |
| smoritaemb | 0:580aba13d1a1 | 111 | |
| smoritaemb | 0:580aba13d1a1 | 112 | option(CHECK_ENDIANNESS "Enable/disable endiannes checking" ON) |
| smoritaemb | 0:580aba13d1a1 | 113 | message(STATUS "Big Ending " __BIG_ENDIAN__) |
| smoritaemb | 0:580aba13d1a1 | 114 | message(STATUS "Check endianess " CHECK_ENDIANNESS) |
| smoritaemb | 0:580aba13d1a1 | 115 | if(__BIG_ENDIAN__) |
| smoritaemb | 0:580aba13d1a1 | 116 | set(CHECK_ENDIANNESS OFF) |
| smoritaemb | 0:580aba13d1a1 | 117 | message(STATUS "micro-CDR without check endianness using provided endianness") |
| smoritaemb | 0:580aba13d1a1 | 118 | elseif(CHECK_ENDIANNESS) |
| smoritaemb | 0:580aba13d1a1 | 119 | check_endianness() |
| smoritaemb | 0:580aba13d1a1 | 120 | else() |
| smoritaemb | 0:580aba13d1a1 | 121 | set(__BIG_ENDIAN__ 0) |
| smoritaemb | 0:580aba13d1a1 | 122 | message(STATUS "micro-CDR without check endianness") |
| smoritaemb | 0:580aba13d1a1 | 123 | endif() |
| smoritaemb | 0:580aba13d1a1 | 124 | |
| smoritaemb | 0:580aba13d1a1 | 125 | # Config.h |
| smoritaemb | 0:580aba13d1a1 | 126 | configure_file(${PROJECT_SOURCE_DIR}/include/ucdr/config.h.in |
| smoritaemb | 0:580aba13d1a1 | 127 | ${PROJECT_BINARY_DIR}/include/ucdr/config.h |
| smoritaemb | 0:580aba13d1a1 | 128 | ) |
| smoritaemb | 0:580aba13d1a1 | 129 | |
| smoritaemb | 0:580aba13d1a1 | 130 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 131 | # Compile settings |
| smoritaemb | 0:580aba13d1a1 | 132 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 133 | |
| smoritaemb | 0:580aba13d1a1 | 134 | # Definitions |
| smoritaemb | 0:580aba13d1a1 | 135 | get_target_property(TARGET_TYPE ${PROJECT_NAME} TYPE) |
| smoritaemb | 0:580aba13d1a1 | 136 | if((MSVC OR MSVC_IDE) AND (TARGET_TYPE STREQUAL "SHARED_LIBRARY")) |
| smoritaemb | 0:580aba13d1a1 | 137 | target_compile_definitions(${PROJECT_NAME} |
| smoritaemb | 0:580aba13d1a1 | 138 | PUBLIC |
| smoritaemb | 0:580aba13d1a1 | 139 | -D${PROJECT_NAME}_SHARED |
| smoritaemb | 0:580aba13d1a1 | 140 | ) |
| smoritaemb | 0:580aba13d1a1 | 141 | endif() |
| smoritaemb | 0:580aba13d1a1 | 142 | |
| smoritaemb | 0:580aba13d1a1 | 143 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 144 | # Testing |
| smoritaemb | 0:580aba13d1a1 | 145 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 146 | if(EPROSIMA_BUILD_TESTS AND IS_TOP_LEVEL) |
| smoritaemb | 0:580aba13d1a1 | 147 | include(${PROJECT_SOURCE_DIR}/cmake/common/gtest.cmake) |
| smoritaemb | 0:580aba13d1a1 | 148 | enable_testing() |
| smoritaemb | 0:580aba13d1a1 | 149 | add_subdirectory(test) |
| smoritaemb | 0:580aba13d1a1 | 150 | endif() |
| smoritaemb | 0:580aba13d1a1 | 151 | |
| smoritaemb | 0:580aba13d1a1 | 152 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 153 | # Packaging |
| smoritaemb | 0:580aba13d1a1 | 154 | ############################################################################### |
| smoritaemb | 0:580aba13d1a1 | 155 | |
| smoritaemb | 0:580aba13d1a1 | 156 | # Install library |
| smoritaemb | 0:580aba13d1a1 | 157 | install(TARGETS ${PROJECT_NAME} |
| smoritaemb | 0:580aba13d1a1 | 158 | EXPORT ${PROJECT_NAME}Targets |
| smoritaemb | 0:580aba13d1a1 | 159 | ARCHIVE DESTINATION ${LIB_INSTALL_DIR} |
| smoritaemb | 0:580aba13d1a1 | 160 | LIBRARY DESTINATION ${LIB_INSTALL_DIR} |
| smoritaemb | 0:580aba13d1a1 | 161 | RUNTIME DESTINATION ${BIN_INSTALL_DIR} |
| smoritaemb | 0:580aba13d1a1 | 162 | COMPONENT libraries |
| smoritaemb | 0:580aba13d1a1 | 163 | ) |
| smoritaemb | 0:580aba13d1a1 | 164 | |
| smoritaemb | 0:580aba13d1a1 | 165 | # Install includes |
| smoritaemb | 0:580aba13d1a1 | 166 | install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ucdr/ |
| smoritaemb | 0:580aba13d1a1 | 167 | DESTINATION ${INCLUDE_INSTALL_DIR}/ucdr |
| smoritaemb | 0:580aba13d1a1 | 168 | FILES_MATCHING PATTERN "*.h" |
| smoritaemb | 0:580aba13d1a1 | 169 | ) |
| smoritaemb | 0:580aba13d1a1 | 170 | |
| smoritaemb | 0:580aba13d1a1 | 171 | # Install config.h |
| smoritaemb | 0:580aba13d1a1 | 172 | install(FILES ${PROJECT_BINARY_DIR}/include/ucdr/config.h |
| smoritaemb | 0:580aba13d1a1 | 173 | DESTINATION ${INCLUDE_INSTALL_DIR}/ucdr |
| smoritaemb | 0:580aba13d1a1 | 174 | ) |
| smoritaemb | 0:580aba13d1a1 | 175 | |
| smoritaemb | 0:580aba13d1a1 | 176 | # Export library |
| smoritaemb | 0:580aba13d1a1 | 177 | install(EXPORT ${PROJECT_NAME}Targets |
| smoritaemb | 0:580aba13d1a1 | 178 | DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME}/cmake |
| smoritaemb | 0:580aba13d1a1 | 179 | ) |
| smoritaemb | 0:580aba13d1a1 | 180 | |
| smoritaemb | 0:580aba13d1a1 | 181 | # Package configuration |
| smoritaemb | 0:580aba13d1a1 | 182 | include(CMakePackageConfigHelpers) |
| smoritaemb | 0:580aba13d1a1 | 183 | configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/packaging/Config.cmake.in |
| smoritaemb | 0:580aba13d1a1 | 184 | ${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}Config.cmake |
| smoritaemb | 0:580aba13d1a1 | 185 | INSTALL_DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME}/cmake |
| smoritaemb | 0:580aba13d1a1 | 186 | PATH_VARS BIN_INSTALL_DIR INCLUDE_INSTALL_DIR LIB_INSTALL_DIR DATA_INSTALL_DIR |
| smoritaemb | 0:580aba13d1a1 | 187 | ) |
| smoritaemb | 0:580aba13d1a1 | 188 | install(FILES ${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}Config.cmake |
| smoritaemb | 0:580aba13d1a1 | 189 | DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME}/cmake |
| smoritaemb | 0:580aba13d1a1 | 190 | ) |