Rearrange and fixup abstraction layer
- Replace os_result by dds_retcode_t and move DDS return code defines down. Eliminates the need to convert between different return code types. - Move dds_time_t down and remove os_time. Eliminates the need to convert between different time representations and reduces code duplication. - Remove use of Microsoft source-code annotation language (SAL). SAL annotations are Microsoft specific and not very well documented. This makes it very difficult for contributers to write. - Rearrange the abstraction layer to be feature-based. The previous layout falsely assumed that the operating system dictates which implementation is best suited. For general purpose operating systems this is mostly true, but embedded targets require a slightly different approach and may not even offer all features. The new layout makes it possible to mix-and-match feature implementations and allows for features to not be implemented at all. - Replace the os prefix by ddsrt to avoid name collisions. - Remove various portions of unused and unwanted code. - Export thread names on all supported platforms. - Return native thread identifier on POSIX compatible platforms. - Add timed wait for condition variables that takes an absolute time. - Remove system abstraction for errno. The os_getErrno and os_setErrno were incorrect. Functions that might fail now simply return a DDS return code instead. - Remove thread-specific memory abstraction. os_threadMemGet and accompanying functions were a mess and their use has been eliminated by other changes in this commit. - Replace attribute (re)defines by ddsrt_ prefixed equivalents to avoid name collisions and problems with faulty __nonnull__ attributes. Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
		
							parent
							
								
									318968f40f
								
							
						
					
					
						commit
						cd6742ee12
					
				
					 439 changed files with 22117 additions and 28782 deletions
				
			
		
							
								
								
									
										210
									
								
								src/ddsrt/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										210
									
								
								src/ddsrt/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,210 @@
 | 
			
		|||
#
 | 
			
		||||
# Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
 | 
			
		||||
#
 | 
			
		||||
# This program and the accompanying materials are made available under the
 | 
			
		||||
# terms of the Eclipse Public License v. 2.0 which is available at
 | 
			
		||||
# http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
 | 
			
		||||
# v. 1.0 which is available at
 | 
			
		||||
# http://www.eclipse.org/org/documents/edl-v10.php.
 | 
			
		||||
#
 | 
			
		||||
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 | 
			
		||||
#
 | 
			
		||||
include(CheckCSourceCompiles)
 | 
			
		||||
include(CheckLibraryExists)
 | 
			
		||||
 | 
			
		||||
function(check_runtime_feature SOURCE_FILE)
 | 
			
		||||
  set(expr "cmake_([_a-zA-Z0-9]+)=([_a-zA-Z0-9]+)")
 | 
			
		||||
  try_compile(
 | 
			
		||||
    foo "${CMAKE_BINARY_DIR}"
 | 
			
		||||
    SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE}"
 | 
			
		||||
    OUTPUT_VARIABLE output)
 | 
			
		||||
  string(REGEX MATCHALL "${expr}" matches "${output}")
 | 
			
		||||
  foreach(match ${matches})
 | 
			
		||||
    string(REGEX REPLACE "${expr}" "\\1" option "${match}")
 | 
			
		||||
    string(REGEX REPLACE "${expr}" "\\2" value "${match}")
 | 
			
		||||
    set(${option} ${value} PARENT_SCOPE)
 | 
			
		||||
  endforeach()
 | 
			
		||||
endfunction()
 | 
			
		||||
 | 
			
		||||
if(APPLE)
 | 
			
		||||
  set(system_name darwin)
 | 
			
		||||
else()
 | 
			
		||||
  string(TOLOWER ${CMAKE_SYSTEM_NAME} system_name)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
# A better choice is to use a so-called object library for ddsrt, but it was
 | 
			
		||||
# not possible to use target_link_libraries with object libraries until CMake
 | 
			
		||||
# 3.12. At the time of this writing most long-term stable distributions still
 | 
			
		||||
# ship an older version, so an interface library with public sources is used
 | 
			
		||||
# as a workaround for now.
 | 
			
		||||
add_library(ddsrt INTERFACE)
 | 
			
		||||
target_include_directories(
 | 
			
		||||
  ddsrt INTERFACE
 | 
			
		||||
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
 | 
			
		||||
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>")
 | 
			
		||||
 | 
			
		||||
# Generate version header.
 | 
			
		||||
configure_file("include/dds/version.h.in" "include/dds/version.h")
 | 
			
		||||
target_sources(
 | 
			
		||||
  ddsrt INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/include/dds/version.h")
 | 
			
		||||
 | 
			
		||||
if(WIN32)
 | 
			
		||||
  configure_file("include/getopt.h.in" "include/getopt.h" COPYONLY)
 | 
			
		||||
  list(APPEND headers "${CMAKE_CURRENT_BINARY_DIR}/include/getopt.h")
 | 
			
		||||
  list(APPEND sources "${CMAKE_CURRENT_SOURCE_DIR}/src/getopt.c")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include")
 | 
			
		||||
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/src")
 | 
			
		||||
 | 
			
		||||
list(APPEND headers
 | 
			
		||||
  "${include_path}/dds/ddsrt/log.h"
 | 
			
		||||
  "${include_path}/dds/ddsrt/retcode.h"
 | 
			
		||||
  "${include_path}/dds/ddsrt/attributes.h"
 | 
			
		||||
  "${include_path}/dds/ddsrt/endian.h"
 | 
			
		||||
  "${include_path}/dds/ddsrt/arch.h"
 | 
			
		||||
  "${include_path}/dds/ddsrt/misc.h"
 | 
			
		||||
  "${include_path}/dds/ddsrt/io.h"
 | 
			
		||||
  "${include_path}/dds/ddsrt/process.h"
 | 
			
		||||
  "${include_path}/dds/ddsrt/strtod.h"
 | 
			
		||||
  "${include_path}/dds/ddsrt/strtol.h"
 | 
			
		||||
  "${include_path}/dds/ddsrt/types.h")
 | 
			
		||||
 | 
			
		||||
list(APPEND sources
 | 
			
		||||
  "${source_path}/io.c"
 | 
			
		||||
  "${source_path}/log.c"
 | 
			
		||||
  "${source_path}/retcode.c"
 | 
			
		||||
  "${source_path}/process.c"
 | 
			
		||||
  "${source_path}/strtod.c"
 | 
			
		||||
  "${source_path}/strtol.c")
 | 
			
		||||
 | 
			
		||||
# Not every target offers the same set of features. For embedded targets the
 | 
			
		||||
# set of features may even be different between builds. e.g. a FreeRTOS build
 | 
			
		||||
# could use the lightweight IP stack, but later change to FreeRTOS+TCP.
 | 
			
		||||
#
 | 
			
		||||
# Most features and target specific settings can be determined at compile time
 | 
			
		||||
# by a combination of pre-defined macros. However, some features require input
 | 
			
		||||
# from the build system. e.g. that the target operating system is FreeRTOS or
 | 
			
		||||
# that the network stack to be used is lwIP as opposed to the target native
 | 
			
		||||
# network stack. In order to mix-and-match various compilers, architectures,
 | 
			
		||||
# operating systems, etc input from the build system is required.
 | 
			
		||||
foreach(feature atomics cdtors environ heap ifaddrs random rusage
 | 
			
		||||
                sockets string sync threads time)
 | 
			
		||||
  if(EXISTS "${include_path}/dds/ddsrt/${feature}.h")
 | 
			
		||||
    list(APPEND headers "${include_path}/dds/ddsrt/${feature}.h")
 | 
			
		||||
    file(GLOB
 | 
			
		||||
           files
 | 
			
		||||
         CONFIGURE_DEPENDS
 | 
			
		||||
           "${include_path}/dds/ddsrt/${feature}/**.h")
 | 
			
		||||
    list(APPEND headers ${files})
 | 
			
		||||
 | 
			
		||||
    # Do not add any sources if a feature is not offered by the target. The
 | 
			
		||||
    # headers will define any macros needed by the source code by combining
 | 
			
		||||
    # build system exports and pre-defined macros. To determine if a certain
 | 
			
		||||
    # feature is offered by the target and whether or not to compile any
 | 
			
		||||
    # source files, that information must be made available to CMake.
 | 
			
		||||
    #
 | 
			
		||||
    # Tests that export the required information can be written in
 | 
			
		||||
    # cmake/${feature}.c. A test consists of a source file that includes the
 | 
			
		||||
    # required header files and results in a specifically crafted compiler
 | 
			
		||||
    # error that is picked up by CMake. By default, if a file named after the
 | 
			
		||||
    # feature does not exist in cmake, the feature is expected to be
 | 
			
		||||
    # implemented for all targets.
 | 
			
		||||
    string(TOUPPER "${feature}" feature_uc)
 | 
			
		||||
    if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${feature}.c")
 | 
			
		||||
      check_runtime_feature(cmake/${feature}.c)
 | 
			
		||||
    else()
 | 
			
		||||
      set(HAVE_${feature_uc} TRUE)
 | 
			
		||||
    endif()
 | 
			
		||||
 | 
			
		||||
    if(HAVE_${feature_uc})
 | 
			
		||||
      # Code that is more-or-less the same for all targets can placed in
 | 
			
		||||
      # src/<feature>.c. An example would be ddsrt_freeifaddrs.
 | 
			
		||||
      if(EXISTS "${source_path}/${feature}.c")
 | 
			
		||||
        list(APPEND sources "${source_path}/${feature}.c")
 | 
			
		||||
      endif()
 | 
			
		||||
      set(system_exists FALSE)
 | 
			
		||||
      foreach(system ${system_name} posix)
 | 
			
		||||
        # Headers that must remain private but are required by other runtime
 | 
			
		||||
        # source files must be located in src/<feature>/dds/ddsrt.
 | 
			
		||||
        if(IS_DIRECTORY "${source_path}/${feature}/include")
 | 
			
		||||
          file(GLOB
 | 
			
		||||
                 files
 | 
			
		||||
               CONFIGURE_DEPENDS
 | 
			
		||||
                 "${source_path}/${feature}/include/**.h")
 | 
			
		||||
          list(APPEND sources ${files})
 | 
			
		||||
          target_include_directories(
 | 
			
		||||
            ddsrt INTERFACE
 | 
			
		||||
              "$<BUILD_INTERFACE:${source_path}/${feature}/include/>")
 | 
			
		||||
        endif()
 | 
			
		||||
        if(IS_DIRECTORY "${source_path}/${feature}/${system}")
 | 
			
		||||
          file(GLOB
 | 
			
		||||
                 files
 | 
			
		||||
               CONFIGURE_DEPENDS
 | 
			
		||||
                 "${source_path}/${feature}/${system}/**.c")
 | 
			
		||||
          list(APPEND sources ${files})
 | 
			
		||||
          set(system_exists TRUE)
 | 
			
		||||
        endif()
 | 
			
		||||
        # Break as soon a system-specific headers or sources are found.
 | 
			
		||||
        if(system_exists)
 | 
			
		||||
          break()
 | 
			
		||||
        endif()
 | 
			
		||||
      endforeach()
 | 
			
		||||
    else()
 | 
			
		||||
      message(STATUS "Feature ${feature} disabled")
 | 
			
		||||
    endif()
 | 
			
		||||
  else()
 | 
			
		||||
    message(FATAL_ERROR "Feature ${feature} does not exist")
 | 
			
		||||
  endif()
 | 
			
		||||
endforeach()
 | 
			
		||||
 | 
			
		||||
target_sources(ddsrt INTERFACE ${sources})
 | 
			
		||||
 | 
			
		||||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
 | 
			
		||||
find_package(Threads REQUIRED)
 | 
			
		||||
target_link_libraries(ddsrt INTERFACE Threads::Threads)
 | 
			
		||||
 | 
			
		||||
if(WIN32)
 | 
			
		||||
  target_link_libraries(ddsrt INTERFACE wsock32 ws2_32 iphlpapi)
 | 
			
		||||
elseif(UNIX)
 | 
			
		||||
  check_library_exists(c clock_gettime "" HAVE_CLOCK_GETTIME)
 | 
			
		||||
  if(NOT HAVE_CLOCK_GETTIME)
 | 
			
		||||
    # Before glibc 2.17, clock_gettime was in librt.
 | 
			
		||||
    check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME_RT)
 | 
			
		||||
    if(HAVE_CLOCK_GETTIME_RT)
 | 
			
		||||
      set(HAVE_CLOCK_GETTIME TRUE)
 | 
			
		||||
      target_link_libraries(ddsrt INTERFACE rt)
 | 
			
		||||
    endif()
 | 
			
		||||
  endif()
 | 
			
		||||
 | 
			
		||||
  if(NOT HAVE_CLOCK_GETTIME)
 | 
			
		||||
    message(FATAL_ERROR "clock_gettime is not available")
 | 
			
		||||
  endif()
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
if(${CMAKE_C_COMPILER_ID} STREQUAL "SunPro")
 | 
			
		||||
  target_link_libraries(ddsrt INTERFACE socket nsl)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
if(BUILD_TESTING)
 | 
			
		||||
  add_subdirectory(tests)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
install(
 | 
			
		||||
  DIRECTORY "include/dds"
 | 
			
		||||
  DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 | 
			
		||||
  COMPONENT dev
 | 
			
		||||
  FILES_MATCHING PATTERN "*.h")
 | 
			
		||||
 | 
			
		||||
install(
 | 
			
		||||
  FILES "${CMAKE_CURRENT_BINARY_DIR}/include/dds/version.h"
 | 
			
		||||
  DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/dds"
 | 
			
		||||
  COMPONENT dev)
 | 
			
		||||
 | 
			
		||||
if(WIN32)
 | 
			
		||||
  install(
 | 
			
		||||
    FILES "${CMAKE_CURRENT_BINARY_DIR}/include/getopt.h"
 | 
			
		||||
    DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 | 
			
		||||
    COMPONENT dev)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue