328 lines
13 KiB
CMake
Executable File
328 lines
13 KiB
CMake
Executable File
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SET(_rti_gcc_arch "")
|
|
# Check if RTI_DIR is not set OR is empty (cached empty string from previous failed detection)
|
|
IF(NOT RTI_DIR OR RTI_DIR STREQUAL "")
|
|
# First check RTI_INSTALL_DIR CMake variable (set by parent CMakeLists.txt)
|
|
IF(RTI_INSTALL_DIR AND EXISTS "${RTI_INSTALL_DIR}")
|
|
SET(_RTI_DIR "${RTI_INSTALL_DIR}")
|
|
ELSE()
|
|
SET(_arch "unknown")
|
|
IF(WIN32)
|
|
SET(_RTI_DIR $ENV{DDS_PATH})
|
|
IF(NOT _RTI_DIR)
|
|
GET_FILENAME_COMPONENT(_rti_root_path "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Real-Time Innovations\\RTI Connext DDS Pro 5.2.3;Location]" ABSOLUTE)
|
|
SET(_RTI_DIR "${_rti_root_path}")
|
|
ENDIF()
|
|
IF(MSVC_VERSION EQUAL 1900)
|
|
SET(_rti_msvc_ver "VS2015")
|
|
ELSEIF(MSVC_VERSION GREATER_EQUAL 1910)
|
|
SET(_rti_msvc_ver "VS2017")
|
|
ENDIF()
|
|
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
|
SET(_rti_msvc_ver "x64Win64${_rti_msvc_ver}")
|
|
ELSE()
|
|
SET(_rti_msvc_ver "i86Win32${_rti_msvc_ver}")
|
|
ENDIF()
|
|
IF(NOT ${_rti_root_path})
|
|
SET(_RTI_DIR $ENV{KDEROOT})
|
|
FILE(TO_CMAKE_PATH "${_RTI_DIR}" _RTI_DIR)
|
|
IF(NOT EXISTS "${_RTI_DIR}" OR NOT IS_DIRECTORY "${_RTI_DIR}")
|
|
SET(_RTI_DIR $ENV{WORKSPACE})
|
|
FILE(TO_CMAKE_PATH "${_RTI_DIR}" _RTI_DIR)
|
|
ENDIF()
|
|
IF(NOT EXISTS "${_RTI_DIR}" OR NOT IS_DIRECTORY "${_RTI_DIR}")
|
|
SET(_RTI_DIR ${EXTERNAL_LIBRARY_DIR})
|
|
FILE(TO_CMAKE_PATH "${_RTI_DIR}" _RTI_DIR)
|
|
ENDIF()
|
|
ENDIF()
|
|
SET(_arch "${_rti_msvc_ver}")
|
|
ELSE(WIN32)
|
|
SET(_RTI_DIR $ENV{DDS_PATH})
|
|
IF(NOT _RTI_DIR)
|
|
# Try local external directory first (check multiple levels for different repo structures)
|
|
# Check container path first (/workspace/external), then host-relative paths
|
|
IF(EXISTS "${CMAKE_SOURCE_DIR}/external/rti_connext_dds-7.7.0")
|
|
SET(_RTI_DIR "${CMAKE_SOURCE_DIR}/external/rti_connext_dds-7.7.0")
|
|
ELSEIF(EXISTS "${CMAKE_SOURCE_DIR}/../external/rti_connext_dds-7.7.0")
|
|
SET(_RTI_DIR "${CMAKE_SOURCE_DIR}/../external/rti_connext_dds-7.7.0")
|
|
ELSEIF(EXISTS "${CMAKE_SOURCE_DIR}/../../../external/rti_connext_dds-7.7.0")
|
|
SET(_RTI_DIR "${CMAKE_SOURCE_DIR}/../../../external/rti_connext_dds-7.7.0")
|
|
ELSE()
|
|
SET(_RTI_DIR "/opt/RTI")
|
|
ENDIF()
|
|
ENDIF()
|
|
IF(NOT EXISTS "${_RTI_DIR}" OR NOT IS_DIRECTORY "${_RTI_DIR}")
|
|
MESSAGE(WARNING "RTI directory ${_RTI_DIR} not found; continuing without RTI. Set DDS_PATH to RTI installation to enable RTI features.")
|
|
# mark as not available
|
|
set(_RTI_DIR_NOT_FOUND TRUE)
|
|
set(_RTI_DIR "")
|
|
ENDIF()
|
|
SET(_rti_gcc_arch "x64Linux3gcc4.8.2")
|
|
IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
IF(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0.0)
|
|
# Prefer newer gcc-based RTI builds; try a sequence then fall back to any x64Linux4gcc* dir found under RTI lib
|
|
SET(_preferred_archs "x64Linux4gcc8.5.0;x64Linux4gcc7.3.0;x64Linux3gcc5.4.0")
|
|
SET(_found_arch "")
|
|
foreach(_cand IN LISTS _preferred_archs)
|
|
if(EXISTS "${_RTI_DIR}/lib/${_cand}")
|
|
SET(_found_arch "${_cand}")
|
|
break()
|
|
endif()
|
|
endforeach()
|
|
if(_found_arch STREQUAL "")
|
|
# fallback: pick any x64Linux* directory under lib
|
|
file(GLOB _rti_arch_dirs RELATIVE "${_RTI_DIR}/lib" "${_RTI_DIR}/lib/x64Linux*")
|
|
list(LENGTH _rti_arch_dirs _rti_arch_dirs_len)
|
|
if(_rti_arch_dirs_len GREATER 0)
|
|
list(GET _rti_arch_dirs 0 _found_arch)
|
|
endif()
|
|
endif()
|
|
if(NOT _found_arch STREQUAL "")
|
|
SET(_rti_gcc_arch "${_found_arch}")
|
|
else()
|
|
# final fallbacks
|
|
SET(_rti_gcc_arch "x64Linux4gcc7.3.0")
|
|
endif()
|
|
ENDIF()
|
|
ENDIF()
|
|
SET(_arch "${_rti_gcc_arch}")
|
|
ENDIF()
|
|
ENDIF()
|
|
SET(RTI_DIR "${_RTI_DIR}" CACHE STRING "RTI base path" FORCE)
|
|
MESSAGE(STATUS "Trying to use RTI from ${RTI_DIR} with arch ${_arch}")
|
|
ELSE()
|
|
# RTI_DIR was provided externally - auto-detect architecture
|
|
SET(_rti_gcc_arch "x64Linux3gcc4.8.2")
|
|
IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
IF(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0.0)
|
|
# Prefer newer gcc-based RTI builds; try a sequence then fall back to any x64Linux4gcc* dir found under RTI lib
|
|
SET(_preferred_archs "x64Linux4gcc8.5.0;x64Linux4gcc7.3.0;x64Linux3gcc5.4.0")
|
|
SET(_found_arch "")
|
|
foreach(_cand IN LISTS _preferred_archs)
|
|
if(EXISTS "${RTI_DIR}/lib/${_cand}")
|
|
SET(_found_arch "${_cand}")
|
|
break()
|
|
endif()
|
|
endforeach()
|
|
if(_found_arch STREQUAL "")
|
|
# fallback: pick any x64Linux* directory under lib
|
|
file(GLOB _rti_arch_dirs RELATIVE "${RTI_DIR}/lib" "${RTI_DIR}/lib/x64Linux*")
|
|
list(LENGTH _rti_arch_dirs _rti_arch_dirs_len)
|
|
if(_rti_arch_dirs_len GREATER 0)
|
|
list(GET _rti_arch_dirs 0 _found_arch)
|
|
endif()
|
|
endif()
|
|
if(NOT _found_arch STREQUAL "")
|
|
SET(_rti_gcc_arch "${_found_arch}")
|
|
else()
|
|
# final fallbacks
|
|
SET(_rti_gcc_arch "x64Linux4gcc7.3.0")
|
|
endif()
|
|
ENDIF()
|
|
ENDIF()
|
|
MESSAGE(STATUS "Using externally provided RTI from ${RTI_DIR} with arch ${_rti_gcc_arch}")
|
|
ENDIF()
|
|
IF(WIN32)
|
|
SET(_rti_include_hint "${RTI_DIR}/include/")
|
|
SET(_rti_library_hint "${RTI_DIR}/lib/${_rti_msvc_ver}/")
|
|
ELSE()
|
|
SET(_rti_include_hint "${RTI_DIR}/include/")
|
|
SET(_rti_library_hint "${RTI_DIR}/lib/")
|
|
ENDIF()
|
|
|
|
|
|
IF(NOT RTI_INCLUDE_DIR)
|
|
if(DEFINED _RTI_DIR_NOT_FOUND AND _RTI_DIR STREQUAL "")
|
|
# RTI directory was not found earlier; skip searching for includes and create empty placeholder
|
|
message(WARNING "Skipping RTI include search because RTI installation was not found")
|
|
set(RTI_INCLUDE_DIR "")
|
|
set(RTI_INCLUDE_DIRS "" CACHE STRING "RTI include directories" FORCE)
|
|
|
|
# Create placeholder INTERFACE targets for all RTI libraries when RTI is not installed
|
|
# These allow configuration to succeed but will cause link errors if actually used
|
|
SET(_RTI_LIBS nddscore nddsc nddscpp2 rtiroutingservice)
|
|
FOREACH(_lib ${_RTI_LIBS})
|
|
SET(_tgt_name RTI::${_lib})
|
|
IF(NOT TARGET ${_tgt_name})
|
|
ADD_LIBRARY(${_tgt_name} INTERFACE IMPORTED)
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY INTERFACE_INCLUDE_DIRECTORIES "")
|
|
# Set dummy library variables to satisfy Ninja dependency tracking
|
|
SET(RTI_${_lib}_LIBRARY "" CACHE STRING "RTI ${_lib} library (placeholder)" FORCE)
|
|
SET(RTI_${_lib}_LIBRARY_RELEASE "" CACHE STRING "RTI ${_lib} library release (placeholder)" FORCE)
|
|
SET(RTI_${_lib}_LIBRARY_DEBUG "" CACHE STRING "RTI ${_lib} library debug (placeholder)" FORCE)
|
|
ENDIF()
|
|
ENDFOREACH()
|
|
SET(RTI_LIBRARIES "" CACHE STRING "All rti libraries (placeholder)" FORCE)
|
|
SET(RTI_FOUND FALSE CACHE BOOL "RTI not found" FORCE)
|
|
# Force BUILD_RTI to OFF when RTI is not actually installed
|
|
SET(BUILD_RTI OFF CACHE BOOL "Build with RTI support" FORCE)
|
|
MESSAGE(WARNING "RTI not found - disabling BUILD_RTI. Set DDS_PATH to RTI installation to enable RTI features.")
|
|
return()
|
|
else()
|
|
# Use PATHS instead of HINTS for more reliable path resolution
|
|
FIND_PATH(RTI_INCLUDE_DIR ndds/ndds_cpp.h PATHS ${_rti_include_hint} NO_DEFAULT_PATH)
|
|
IF(RTI_INCLUDE_DIR)
|
|
SET(RTI_INCLUDE_DIRS "${RTI_INCLUDE_DIR}" "${RTI_INCLUDE_DIR}/ndds" "${RTI_INCLUDE_DIR}/ndds/hpp" CACHE STRING "RTI include directories" FORCE)
|
|
MARK_AS_ADVANCED(RTI_INCLUDE_DIRS)
|
|
ELSE()
|
|
MESSAGE(FATAL "Could not find RTI include directory at ${_rti_include_hint}")
|
|
ENDIF()
|
|
endif()
|
|
ENDIF()
|
|
|
|
|
|
IF(NOT RTI_DDSGEN_EXECUTABLE)
|
|
FIND_PROGRAM(RTI_DDSGEN_EXECUTABLE NAMES rtiddsgen rtiddsgen.bat HINTS ${RTI_DIR}/scripts ${RTI_DIR}/bin)
|
|
ENDIF()
|
|
IF(NOT RTI_VERSION_MAJOR)
|
|
EXEC_PROGRAM(${RTI_DDSGEN_EXECUTABLE} ARGS -version OUTPUT_VARIABLE _dds_version_output)
|
|
STRING(REGEX REPLACE ".* ([0-9]\\.[0-9]\\.[0-9]).*" "\\1" _dds_version_output ${_dds_version_output})
|
|
SET(_rti_version_major 5)
|
|
IF(_dds_version_output VERSION_GREATER 2.9.9)
|
|
SET(_rti_version_major 6)
|
|
ENDIF()
|
|
SET(RTI_VERSION_MAJOR ${_rti_version_major} CACHE STRING "RTI version" FORCE)
|
|
ENDIF()
|
|
|
|
INCLUDE(FindPackageHandleStandardArgs)
|
|
|
|
# Set policy for imported target library requirements
|
|
if(POLICY CMP0111)
|
|
cmake_policy(SET CMP0111 NEW)
|
|
endif()
|
|
|
|
SET(_RTI_LIBS nddscore nddsc nddscpp2 rtiroutingservice)
|
|
SET(_libs "")
|
|
SET(_lib_vars "")
|
|
|
|
# Build list of library search paths including arch-specific subdirs
|
|
set(_rti_lib_search_paths "${RTI_DIR}/lib" "${RTI_DIR}/lib/${_rti_gcc_arch}")
|
|
# Also scan for any arch subdirs under lib/
|
|
file(GLOB _rti_arch_dirs "${RTI_DIR}/lib/*")
|
|
foreach(_arch_dir IN LISTS _rti_arch_dirs)
|
|
if(IS_DIRECTORY "${_arch_dir}")
|
|
list(APPEND _rti_lib_search_paths "${_arch_dir}")
|
|
endif()
|
|
endforeach()
|
|
|
|
FOREACH(_lib ${_RTI_LIBS})
|
|
SET(_libname "RTI_${_lib}_LIBRARY")
|
|
SET(_libname_release "RTI_${_lib}_LIBRARY_RELEASE")
|
|
SET(_libname_debug "RTI_${_lib}_LIBRARY_DEBUG")
|
|
|
|
# Build explicit search paths for this library
|
|
set(_lib_search_paths
|
|
"${RTI_DIR}/lib/${_rti_gcc_arch}"
|
|
"${RTI_DIR}/lib"
|
|
)
|
|
|
|
# Find release library (no suffix)
|
|
FIND_LIBRARY(${_libname_release}
|
|
NAMES ${_lib}
|
|
PATHS ${_lib_search_paths}
|
|
NO_DEFAULT_PATH)
|
|
|
|
# Find debug library (d suffix on Linux)
|
|
FIND_LIBRARY(${_libname_debug}
|
|
NAMES ${_lib}d
|
|
PATHS ${_lib_search_paths}
|
|
NO_DEFAULT_PATH)
|
|
|
|
# Set combined library variable
|
|
IF(${_libname_release})
|
|
SET(${_libname} "${${_libname_release}}" CACHE STRING "RTI ${_lib} library" FORCE)
|
|
ELSEIF(${_libname_debug})
|
|
SET(${_libname} "${${_libname_debug}}" CACHE STRING "RTI ${_lib} library" FORCE)
|
|
ENDIF()
|
|
SET(_tgt_name RTI::${_lib})
|
|
|
|
IF(NOT TARGET ${_tgt_name})
|
|
ADD_LIBRARY(${_tgt_name} UNKNOWN IMPORTED)
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${RTI_INCLUDE_DIRS}")
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${RTI_INCLUDE_DIRS}")
|
|
|
|
IF(UNIX)
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY INTERFACE_COMPILE_DEFINITIONS "RTI_UNIX;RTI_LINUX;RTI_64BIT" )
|
|
ENDIF()
|
|
IF(WIN32)
|
|
IF("${_lib}" STREQUAL "rtiroutingservice")
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY INTERFACE_COMPILE_DEFINITIONS "RTI_WIN32;RTI_routingservice_DLL_VARIABLE" )
|
|
ELSE()
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY INTERFACE_COMPILE_DEFINITIONS "RTI_WIN32;NDDS_DLL_VARIABLE" )
|
|
ENDIF()
|
|
ENDIF()
|
|
|
|
# Set library locations - use release for both configs if debug not found
|
|
IF(${_libname}_RELEASE AND ${_libname}_DEBUG)
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY IMPORTED_CONFIGURATIONS RELEASE DEBUG)
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY IMPORTED_LOCATION_RELEASE "${${_libname}_RELEASE}")
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY IMPORTED_LOCATION_DEBUG "${${_libname}_DEBUG}")
|
|
# Set default IMPORTED_LOCATION for non-configured builds
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY IMPORTED_LOCATION "${${_libname}_RELEASE}")
|
|
ELSEIF(${_libname}_RELEASE)
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY IMPORTED_CONFIGURATIONS RELEASE DEBUG)
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY IMPORTED_LOCATION_RELEASE "${${_libname}_RELEASE}")
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY IMPORTED_LOCATION_DEBUG "${${_libname}_RELEASE}")
|
|
# Set default IMPORTED_LOCATION for non-configured builds
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY IMPORTED_LOCATION "${${_libname}_RELEASE}")
|
|
ELSEIF(${_libname}_DEBUG)
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY IMPORTED_CONFIGURATIONS RELEASE DEBUG)
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY IMPORTED_LOCATION_RELEASE "${${_libname}_DEBUG}")
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY IMPORTED_LOCATION_DEBUG "${${_libname}_DEBUG}")
|
|
# Set default IMPORTED_LOCATION for non-configured builds
|
|
SET_PROPERTY(TARGET ${_tgt_name} PROPERTY IMPORTED_LOCATION "${${_libname}_DEBUG}")
|
|
ELSE()
|
|
# No library found - skip creating this target
|
|
MESSAGE(WARNING "RTI library ${_lib} not found in ${RTI_DIR}")
|
|
SET(${_libname} "" CACHE STRING "RTI ${_lib} library (not found)" FORCE)
|
|
CONTINUE()
|
|
ENDIF()
|
|
ENDIF()
|
|
|
|
LIST(APPEND _libs "${${_libname}}")
|
|
# rtiroutingservice is optional - only add required libs to _lib_vars for FIND_PACKAGE_HANDLE_STANDARD_ARGS
|
|
IF(NOT "${_lib}" STREQUAL "rtiroutingservice")
|
|
LIST(APPEND _lib_vars "${_libname}")
|
|
ENDIF()
|
|
ENDFOREACH()
|
|
|
|
IF(TARGET RTI::nddscore AND UNIX)
|
|
SET_PROPERTY(TARGET RTI::nddscore PROPERTY INTERFACE_LINK_LIBRARIES "dl" )
|
|
ENDIF()
|
|
|
|
SET(RTI_LIBRARIES ${_libs} CACHE STRING "All rti libraries" FORCE)
|
|
MARK_AS_ADVANCED(RTI_LIBRARIES)
|
|
|
|
INCLUDE(FindPackageHandleStandardArgs)
|
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(RTI DEFAULT_MSG RTI_DIR RTI_INCLUDE_DIR RTI_DDSGEN_EXECUTABLE ${_lib_vars})
|
|
|