# (c) 2018 Copyright, Real-Time Innovations, Inc. All rights reserved. # No duplications, whole or partial, manual or electronic, may be made # without express written permission. Any such copies, or revisions thereof, # must display this notice unaltered. # This code contains trade secrets of Real-Time Innovations, Inc. #[[.rst: .. _connextdds_create_imported_target: Imported targets ---------------- :: connextdds_create_imported_target( TARGET name BASENAME name STATIC|SHARED|UNKNOWN|INTERFACE LANGUAGES lang1 [...] CPE cpe_string LICENSE license_name PURL purl_string [INCLUDE_DIRS ...] [COMPILE_DEFINITIONS ...] [COMPILE_OPTIONS ...] [MD5_HASH hash] [SHA1_HASH hash] ) Create a virtual imported target. By Linking against these targets, it will use its include directories and compile definitions. This is recommended instead of using variables defined in find modules. Arguments: ``TARGET`` (mandatory) Name of the target to create. ``BASENAME`` (mandatory) Prefix of the variables containing the libraries. The variables to search are: ``{BASENAME}_LIBRARY`` with the debug and/or release version of the libraries, ``{BASENAME}_LIBRARY_DEBUG`` with the debug version and ``{BASENAME}_LIBRARY_RELEASE`` for the release version. ``STATIC``, ``SHARED``, ``UNKNOWN``, ``INTERFACE`` (mandatory) Specify the configuration of the target libraries. Use ``UNKNOWN`` if you don't know if it's static or dynamic and ``INTERFACE`` for header-only targets. ``LANGUAGES`` (mandatory) List of languages supporting this library. Usually this is just C. ``CPE`` (mandatory) Common Platform Enumeration string identifying the software component. ``LICENSE`` (mandatory) License name for the software component. ``PURL`` (mandatory) Package URL string identifying the software component package. ``INCLUDE_DIRS`` (optional) List of additional include directories to use with this target. ``COMPILE_DEFINITIONS`` (optional) List of additional compile definitions to use with this target. ``COMPILE_OPTIONS`` (optional) List of additional compile options to use with this target. ``MD5_HASH`` (optional) Pre-computed MD5 hash to use instead of calculating from library file. If not provided, the hash will be computed from the library file or basename. ``SHA1_HASH`` (optional) Pre-computed SHA1 hash to use instead of calculating from library file. If not provided, the hash will be computed from the library file or basename. #]] include(CMakeParseArguments) include(ConnextDdsArgumentChecks) function(connextdds_create_imported_target) set(options STATIC SHARED UNKNOWN INTERFACE) set(single_value_args TARGET BASENAME CPE LICENSE PURL MD5_HASH SHA1_HASH) set(multi_value_args LANGUAGES INCLUDE_DIRS COMPILE_DEFINITIONS COMPILE_OPTIONS) cmake_parse_arguments( _IMPORTED "${options}" "${single_value_args}" "${multi_value_args}" ${ARGN} ) connextdds_check_required_arguments( _IMPORTED_TARGET _IMPORTED_BASENAME _IMPORTED_LANGUAGES _IMPORTED_CPE _IMPORTED_LICENSE _IMPORTED_PURL ) if(NOT _IMPORTED_STATIC AND NOT _IMPORTED_SHARED AND NOT _IMPORTED_UNKNOWN AND NOT _IMPORTED_INTERFACE) connextdds_log_message(FATAL_ERROR "Missing library type: static / shared / unknown / interface" ) endif() if(NOT ${_IMPORTED_BASENAME}_LIBRARY AND NOT _IMPORTED_INCLUDE_DIRS) connextdds_log_message(FATAL_ERROR "Missing libraries/headers for imported target ${_IMPORTED_TARGET}" ) endif() # If it already exists, nothing to do. if(TARGET ${_IMPORTED_TARGET}) return() endif() if(_IMPORTED_INTERFACE) # If there aren't libraries, it's a header-only so we need INTERFACE, # otherwise it will complain about missing libraries. set(library_type INTERFACE) elseif(_IMPORTED_STATIC) set(library_type STATIC) elseif(_IMPORTED_SHARED) set(library_type SHARED) elseif(_IMPORTED_UNKNOWN) # UNKNOWN reprents that we don't know if it's static or shared. set(library_type UNKNOWN) else() connextdds_log_message(FATAL_ERROR "Missing library type for '${_IMPORTED_TARGET}'. " "Valid types are: STATIC, SHARED, UNKNOWN or INTERFACE" ) endif() # Create the library add_library(${_IMPORTED_TARGET} ${library_type} IMPORTED) # Set the include directory and the default library set_target_properties(${_IMPORTED_TARGET} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_IMPORTED_INCLUDE_DIRS}" INTERFACE_COMPILE_DEFINITIONS "${_IMPORTED_COMPILE_DEFINITIONS}" INTERFACE_COMPILE_OPTIONS "${_IMPORTED_COMPILE_OPTIONS}" ) if(WIN32 AND _IMPORTED_SHARED) # For Windows shared libraries, IMPORTED_LOCATION must contain the # path to the DLL file. Since for linking we only need the .lib file # which is the one found by add_library, we only need to set # IMPORTED_IMPLIB. set(location_property IMPORTED_IMPLIB) else() set(location_property IMPORTED_LOCATION) endif() # Set the library if(EXISTS "${${_IMPORTED_BASENAME}_LIBRARY}") set_target_properties(${_IMPORTED_TARGET} PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "${_IMPORTED_LANGUAGES}" ${location_property} "${${_IMPORTED_BASENAME}_LIBRARY}" ) # Use provided hash values if available, otherwise calculate them if(_IMPORTED_MD5_HASH) set(_md5 "${_IMPORTED_MD5_HASH}") else() file(MD5 "${${_IMPORTED_BASENAME}_LIBRARY}" _md5) endif() if(_IMPORTED_SHA1_HASH) set(_sha1 "${_IMPORTED_SHA1_HASH}") else() file(SHA1 "${${_IMPORTED_BASENAME}_LIBRARY}" _sha1) endif() else() # Use provided hash values if available, otherwise calculate from basename if(_IMPORTED_MD5_HASH) set(_md5 "${_IMPORTED_MD5_HASH}") else() string(MD5 _md5 ${_IMPORTED_BASENAME}) endif() if(_IMPORTED_SHA1_HASH) set(_sha1 "${_IMPORTED_SHA1_HASH}") else() string(SHA1 _sha1 ${_IMPORTED_BASENAME}) endif() endif() # Set the debug library if(EXISTS ${${_IMPORTED_BASENAME}_LIBRARY_DEBUG}) set_property(TARGET ${_IMPORTED_TARGET} APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG ) set_target_properties(${_IMPORTED_TARGET} PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "${_IMPORTED_LANGUAGES}" ${location_property}_DEBUG "${${_IMPORTED_BASENAME}_LIBRARY_DEBUG}" ) endif() # Set the release library if(EXISTS ${${_IMPORTED_BASENAME}_LIBRARY_RELEASE}) set_property(TARGET ${_IMPORTED_TARGET} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE ) set_target_properties(${_IMPORTED_TARGET} PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "${_IMPORTED_LANGUAGES}" ${location_property}_RELEASE "${${_IMPORTED_BASENAME}_LIBRARY_RELEASE}" ) endif() if(_IMPORTED_INTERFACE) # Set Third-Party metadata set_target_properties( ${_IMPORTED_TARGET} PROPERTIES INTERFACE_CPE "${_IMPORTED_CPE}#${_md5}#${_sha1}" INTERFACE_LICENSE ${_IMPORTED_LICENSE} INTERFACE_PURL "${_IMPORTED_PURL}" ) else() set_target_properties( ${_IMPORTED_TARGET} PROPERTIES CPE "${_IMPORTED_CPE}#${_md5}#${_sha1}" LICENSE ${_IMPORTED_LICENSE} PURL "${_IMPORTED_PURL}" ) endif() endfunction()