CMakeLists.txt 12.5 KB
#=============================================================================
# CMakeLists.txt - Rules for sns-components target.
#
# Generated by coolbot-bundle version 1.0.0
#=============================================================================

MESSAGE("")
MESSAGE(STATUS "Generating sns-components target")

#
# NOTE: You have a file called cmake_targets.cmake in the directory resources/cmake
# Check to see that in this file, you have the following entry:
#
# ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/sns-components)
#
# In the event that the entry is not available, add the line in this file or in
# the main CMakeLists.txt file.
#

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/sns-components)

#
# NOTE: It is preferable not to use the AUX_SOURCE_DIRECTORY command. It is
# recommended to manually specify the source files and header. For example:
#
# SET(SNS_COMPONENTS_SRCS
#     src/source.cpp
#     src/source1.cpp
#     ...
#     src/sourceN.cpp
# )
#
# SET(SNS_COMPONENTS_HDRS
#     src/header.h
#     src/header1.h
#     ...
#     src/headerN.h
# )
#
# SET(SNS_COMPONENTS_MAIN_SOURCE_FILES
#     ${SNS_COMPONENTS_SRCS}
#     ${SNS_COMPONENTS_HDRS})
#
AUX_SOURCE_DIRECTORY("${PROJECT_SOURCE_DIR}/sns-components"
                    SNS_COMPONENTS_MAIN_SOURCE_FILES)

IF(SHOW_DEBUG_INFO)
  MESSAGE(STATUS "Source code of sns-components target:")
  MESSAGE("${SNS_COMPONENTS_MAIN_SOURCE_FILES}")
ENDIF(SHOW_DEBUG_INFO)

#
# Flags for the construction of the target sns-components.
# By default, sets the CoolBOT framework flags.
# Here, you should add the flags you need. You can use the RUN_PKGCONFIG macro:
#
#     RUN_PKGCONFIG( <pkg-config option>
#                    <pkg-config file>
#                    <result of the execution>
#                    <output variable with the flags> )
#
# By default, searches for the file in the path established by the tool
# pkg-config.
#
# NOTE: The RUN_PKGCONFIG macro accepts an optional parameter that indicates
# the path where the file pkg-config:
#
#     RUN_PKGCONFIG( <pkg-config option>
#                    <pkg-config file>
#                    <result of the execution>
#                    <output variable with the flags>
#                    <pkg-config file path> )
#
# In this case, the pkg-config file must be extension ".pc".
#
# In addition, you can use the following macros:
#
#     FIND_PKGCONFIG_MODULE( <pkg-config module file name>
#                            <pkg-config module file is within bundle>
#                            <output variable with linker flags>
#                            <output variable with compiler flags>
#                            <output variable  with the result of the operation>
#                            <pkg-config file path> )
#
# This macro searches if the pkg-config module file exists. If the module exists
# gets flags for compiling and linked.
#
#     MY_FIND_PACKAGE( <CMake package name>
#                      <pkg-config module file name>
#                      <output variable with linker flags>
#                      <output variable with compiler flags> )
#
# This macro searches if the CMake module file exists. If the CMake module exists
# gets flags for compiling and linked.
#
#     LOAD_PKGCONFIG_MODULE( module_name
#                            module_is_within_bundle
#                            result
#                            output_module_linker_flags
#                            output_module_compiler_flags
#                            pkgconfig_directory_path )
#
# This macro calls the macro: FIND_PKGCONFIG_MODULE and displays messages about
# the operation performed.
#
#     LOAD_CMAKE_MODULE( module_name
#                        pkgconfig_module_name
#                        output_module_linker_flags
#                        output_module_compiler_flags )
#
# This macro calls the macro: MY_FIND_PACKAGE and displays messages about the
# operation performed.
#
# The SNS_COMPONENTS_TARGET_DEPENDENCIES variable indicates if the target
# dependencies are resolved:
#
# - TRUE: The target dependencies are resolved.
#
# - FALSE: Some of the dependencies could not be resolved.
#
# This variable is created in cmake_global_variables.cmake file with the FALSE
# value. It's a variable cache type. You can modify the cache value as follows:
#
# SET(SNS_COMPONENTS_TARGET_DEPENDENCIES <value> CACHE INTERNAL "")
#
# where <value> is the value to set.
#

#
# Here you must perform dependencies checking.
#
# NOTE: You have to ask if software dependencies have been resolved and, if so,
# assign the SNS_COMPONENTS_TARGET_DEPENDENCIES variable the value TRUE.
#
# For example: This CoolBOT module depends on the software A and B (both external
# bundle) and we have the pkg-config files. Also, this module has a internal
# dependency with C module. In this case, being an internal dependency, we have
# the variable: C_TARGET_DEPENDENCIES. Then:
#
# IF( C_TARGET_DEPENDENCIES )
#
#   SET(PKGCONFIG_FILE_IS_WITHIN_BUNDLE FALSE)
#
#   LOAD_PKGCONFIG_MODULE( "A"
#                          PKGCONFIG_FILE_IS_WITHIN_BUNDLE
#                          A_DEPENDENCIES_RESOLVED
#                          A_LINKER_FLAGS
#                          A_COMPILER_FLAGS
#                          "" )
#
#   LOAD_PKGCONFIG_MODULE( "B"
#                          PKGCONFIG_FILE_IS_WITHIN_BUNDLE
#                          B_DEPENDENCIES_RESOLVED
#                          B_LINKER_FLAGS
#                          B_COMPILER_FLAGS
#                          "" )
#
#   SET(PKGCONFIG_FILE_IS_WITHIN_BUNDLE TRUE)
#
#   LOAD_PKGCONFIG_MODULE( "C"
#                          PKGCONFIG_FILE_IS_WITHIN_BUNDLE
#                          C_DEPENDENCIES_RESOLVED
#                          C_LINKER_FLAGS
#                          C_COMPILER_FLAGS
#                          ${PKG_DIR} )
#
#   IF( A_DEPENDENCIES_RESOLVED AND B_DEPENDENCIES_RESOLVED AND C_DEPENDENCIES_RESOLVED )
#       SET(SNS_COMPONENTS_TARGET_DEPENDENCIES TRUE CACHE INTERNAL "")
#   ENDIF( A_DEPENDENCIES_RESOLVED AND B_DEPENDENCIES_RESOLVED AND C_DEPENDENCIES_RESOLVED )
#
# ENDIF( C_TARGET_DEPENDENCIES )
#

IF( 
  PLAYER_ROBOT_TARGET_DEPENDENCIES AND GRID_MAP_TARGET_DEPENDENCIES AND ND_TARGET_DEPENDENCIES AND PLANNER_TARGET_DEPENDENCIES
)

  SET(PKGCONFIG_FILE_IS_WITHIN_BUNDLE TRUE)
  LOAD_PKGCONFIG_MODULE( "player-robot"
                        PKGCONFIG_FILE_IS_WITHIN_BUNDLE
                        PLAYER_ROBOT_FOUND
                        PLAYER_ROBOT_LINKER_FLAGS
                        PLAYER_ROBOT_COMPILER_FLAGS
                        ${PKG_DIR} )

  SET(PKGCONFIG_FILE_IS_WITHIN_BUNDLE TRUE)
  LOAD_PKGCONFIG_MODULE( "grid-map"
                        PKGCONFIG_FILE_IS_WITHIN_BUNDLE
                        GRID_MAP_FOUND
                        GRID_MAP_LINKER_FLAGS
                        GRID_MAP_COMPILER_FLAGS
                        ${PKG_DIR} )

  SET(PKGCONFIG_FILE_IS_WITHIN_BUNDLE TRUE)
  LOAD_PKGCONFIG_MODULE( "nd"
                        PKGCONFIG_FILE_IS_WITHIN_BUNDLE
                        ND_FOUND
                        ND_LINKER_FLAGS
                        ND_COMPILER_FLAGS
                        ${PKG_DIR} )

  SET(PKGCONFIG_FILE_IS_WITHIN_BUNDLE TRUE)
  LOAD_PKGCONFIG_MODULE( "planner"
                        PKGCONFIG_FILE_IS_WITHIN_BUNDLE
                        PLANNER_FOUND
                        PLANNER_LINKER_FLAGS
                        PLANNER_COMPILER_FLAGS
                        ${PKG_DIR} )

  IF( 
    PLAYER_ROBOT_FOUND AND GRID_MAP_FOUND AND ND_FOUND AND PLANNER_FOUND
  )

    SET(SNS_COMPONENTS_TARGET_DEPENDENCIES TRUE CACHE INTERNAL "")
  
  ENDIF( 
    PLAYER_ROBOT_FOUND AND GRID_MAP_FOUND AND ND_FOUND AND PLANNER_FOUND
  )

ENDIF( 
  PLAYER_ROBOT_TARGET_DEPENDENCIES AND GRID_MAP_TARGET_DEPENDENCIES AND ND_TARGET_DEPENDENCIES AND PLANNER_TARGET_DEPENDENCIES
)

IF(NOT SNS_COMPONENTS_TARGET_DEPENDENCIES)
  #
  # Show a information message to user. You can use the MESSAGE command:
  #
  #     MESSAGE([STATUS|WARNING|AUTHOR_WARNING|FATAL_ERROR|SEND_ERROR]
  #             "message to display" ...)
  #
  # The optional keyword determines the type of message:
  #
  # - (none): Important information
  # - STATUS: Incidental information
  # - WARNING: CMake Warning, continue processing
  # - AUTHOR_WARNING: CMake Warning (dev), continue processing
  # - SEND_ERROR: CMake Error, continue but skip generation
  # - FATAL_ERROR: CMake Error, stop all processing
  #
  
  MESSAGE(STATUS "sns-components target can not be generated:")
  IF(NOT PLAYER_ROBOT_FOUND)
    MESSAGE(STATUS "  *   player-robot is required.")
  ENDIF(NOT PLAYER_ROBOT_FOUND)
  IF(NOT GRID_MAP_FOUND)
    MESSAGE(STATUS "  *   grid-map is required.")
  ENDIF(NOT GRID_MAP_FOUND)
  IF(NOT ND_FOUND)
    MESSAGE(STATUS "  *   nd is required.")
  ENDIF(NOT ND_FOUND)
  IF(NOT PLANNER_FOUND)
    MESSAGE(STATUS "  *   planner is required.")
  ENDIF(NOT PLANNER_FOUND)

  REGISTER_TARGET_NOT_AVAILABLE("sns-components")

ELSE(NOT SNS_COMPONENTS_TARGET_DEPENDENCIES)
  #
  # Sets the compiler and linker flags.
  #
  SET(FLAGS_BIN_COMPILER "${COOLBOT_COMPILER_FLAGS}")
  SET(FLAGS_BIN_LINKER "${COOLBOT_LINKER_FLAGS}")
  
  SET(FLAGS_BIN_COMPILER "${FLAGS_BIN_COMPILER} ${PLAYER_ROBOT_COMPILER_FLAGS}")
  SET(FLAGS_BIN_LINKER "${FLAGS_BIN_LINKER} ${PLAYER_ROBOT_LINKER_FLAGS}")

  SET(FLAGS_BIN_COMPILER "${FLAGS_BIN_COMPILER} ${GRID_MAP_COMPILER_FLAGS}")
  SET(FLAGS_BIN_LINKER "${FLAGS_BIN_LINKER} ${GRID_MAP_LINKER_FLAGS}")

  SET(FLAGS_BIN_COMPILER "${FLAGS_BIN_COMPILER} ${ND_COMPILER_FLAGS}")
  SET(FLAGS_BIN_LINKER "${FLAGS_BIN_LINKER} ${ND_LINKER_FLAGS}")

  SET(FLAGS_BIN_COMPILER "${FLAGS_BIN_COMPILER} ${PLANNER_COMPILER_FLAGS}")
  SET(FLAGS_BIN_LINKER "${FLAGS_BIN_LINKER} ${PLANNER_LINKER_FLAGS}")

  IF(SHOW_DEBUG_INFO)
    MESSAGE(STATUS "Linker flags of sns-components target:")
    MESSAGE("${FLAGS_BIN_LINKER}")
    MESSAGE(STATUS "Compiler flags of sns-components target:")
    MESSAGE("${FLAGS_BIN_COMPILER}")
  ENDIF(SHOW_DEBUG_INFO)

  #
  # You must add the INCLUDE_DIRS and TARGET_LINK_LIBRARIES who need your project:
  #
  #   INCLUDE_DIRECTORIES(${MY_INCLUDE_DIRS} ${MY_INCLUDE_DIRS_2} ...)
  #
  #   TARGET_LINK_LIBRARIES(sns-components ${MY_LIBRARY} ${MY_LIBRARY_2} ...)
  #
  # The MY_INCLUDE_DIRS contains the path where the headers file and the MY_LIBRARY
  # specifies the libraries to link or linker flags. This can also be specified
  # through the flags.
  #
  # You can also specify in the command TARGET_LINK_LIBRARIES the name of the target
  # defined in the bundle.
  #
  # NOTE: In addition, you can use the command find_package() or MY_FIND_PACKAGE
  # macro to obtain the information necessary for the required packages. In the
  # CMake modules directory you can use existing packages.
  #
  INCLUDE_DIRECTORIES(${COOLBOT_INCLUDE_DIRS})
  ADD_EXECUTABLE(sns-components ${SNS_COMPONENTS_MAIN_SOURCE_FILES})
  TARGET_LINK_LIBRARIES(sns-components
                        player-robot
                        grid-map
                        nd
                        planner
                        ${COOLBOT_LIBRARIES}
                        ${COOLBOT_LINKER_FLAGS}
                        ${PLAYER_ROBOT_LINKER_FLAGS}
                        ${GRID_MAP_LINKER_FLAGS}
                        ${ND_LINKER_FLAGS}
                        ${PLANNER_LINKER_FLAGS}
  )

  #
  # As a safeguard, you must establish dependencies to ensure that the compilations
  # at the right time. Dependencies are specified with the name of the target.
  #
  # NOTE: If the project does not have dependencies within the bundle, you must
  # comment on the ADD_DEPENDENCIES command.
  #
  ADD_DEPENDENCIES( sns
                    # target-name
                    player-robot
                    grid-map
                    nd
                    planner
  )

  SET_TARGET_PROPERTIES(sns-components PROPERTIES
                        LINK_FLAGS    ${FLAGS_BIN_LINKER}
                        COMPILE_FLAGS ${FLAGS_BIN_COMPILER})

  IF( WIN32 )
    SET_TARGET_PROPERTIES(sns-components PROPERTIES
                          RUNTIME_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
                         )
  ENDIF( WIN32 )

  REGISTER_NEW_TARGET("sns-components")
  MESSAGE(STATUS "Created sns-components target")

  IF(NOT DEBUG_MODE)
    #
    # Install settings
    #
    # Binaries -> ${PROJECT_BINARIES_INSTALL_PATH}
    #
    INSTALL( TARGETS sns-components
            DESTINATION ${PROJECT_BINARIES_INSTALL_PATH}
            PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
                        GROUP_READ             GROUP_EXECUTE
                        WORLD_READ             WORLD_EXECUTE
    )
    MESSAGE(STATUS "Generated install commands for sns-components binary")
  ENDIF(NOT DEBUG_MODE)

ENDIF(NOT SNS_COMPONENTS_TARGET_DEPENDENCIES)