CMakeLists.txt 14.7 KB
#=============================================================================
# CMakeLists.txt - Rules for building software.
#
# The CoolBOT Project (<http://www.coolbotproject.org>)
# Copyright (C) 2003,2007,2009,2010
#    Universidad de Las Palmas de Gran Canaria (ULPGC) (<http://www.ulpgc.es>)
#
#    This software is a collective project which has been designed, developed and
#    written, and is maintained by members, students and collaborators of the División
#    de Inteligencia Artificial y Sistemas (DIAS) at the Instituto Universitario de
#    Sistemas Inteligentes y Aplicaciones Numéricas en Ingeniería (SIANI)
#    (<http://www.siani.es/>), and also of the Departamento de Informática y Sistemas
#    (DIS) (<http://www.dis.ulpgc.es>) both at ULPGC. The AUTHOR file lists all
#    developers and contributors.The particular authors of each file are explicitly
#    specified on each one of them.
#
# This file is part of the CoolBOT Project.
# The CoolBOT Project is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or any
# later version.
#
# The CoolBOT Project is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy (COPYING file) of the GNU General Public License
# along with the CoolBOT Project . If not, see <http://www.gnu.org/licenses/>.
#
# In addition to the GNU General Public License, the CoolBOT Project Compiler License
# Exception is applicable to the C++ skeletons generated by the CoolBOT Compiler
# (coolbot-c). The purpose of this Exception is to allow distribution of  CoolBOT
# Compiler's (coolbot-c) typical output under terms of the recipient's choice
# (including proprietary). You should have received a copy of the CoolBOT Project
# Compiler License Exception (COPYING.EXCEPTION file) along with the CoolBOT Project.
# If not see <http://www.coolbotproject.org>.
#=============================================================================
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.4)
PROJECT(coolbot-project CXX C)

# Sets the policy CMP0017. More info: cmake --help-policy CMP0017
IF(POLICY CMP0017)
  IF(COMMAND CMAKE_POLICY)
    CMAKE_POLICY(SET CMP0017 NEW)
    CMAKE_POLICY(GET CMP0017 CMP0017_POLICY)
    MESSAGE(STATUS "CMP0017 policy is ${CMP0017_POLICY}")
  ENDIF(COMMAND CMAKE_POLICY)
ENDIF(POLICY CMP0017)

#
# Options available
#
OPTION(BUILD_DOXYGEN_API "Set to ON to generate API documentation with doxygen" OFF)
OPTION(BUILD_EXAMPLES "Set to ON to build the examples of CoolBOT framework" OFF)
OPTION(BUILD_LATEX "Set to ON to build the CoolBOT documentation with Latex" OFF)
OPTION(BUILD_SHARED_LIBS "Set to OFF to build static libraries" ON)
OPTION(DEBUG_MODE "Set to ON to activate the debug mode" ON)
OPTION(SHOW_DEBUG_INFO "Set to ON to show debug info" OFF)
OPTION(SHOW_WARNINGS "Set to ON to show the project warnings" OFF)

#
# Sets CMAKE_MODULE_PATH for use FIND_PACKAGE() in local CMake directory.
#
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH} ${CMAKE_ROOT}/Modules)

#
# Include CMake files
#
INCLUDE(${PROJECT_SOURCE_DIR}/cmake/toolkit.cmake)
INCLUDE(${PROJECT_SOURCE_DIR}/cmake/check_dependencies.cmake)
INCLUDE(${PROJECT_SOURCE_DIR}/cmake/ms_windows.cmake)
INCLUDE(${PROJECT_SOURCE_DIR}/cmake/uninstall_target.cmake)

#
# Initializes the list of targets. If you are in production mode, the list has install and uninstall target.
#
INIT_TARGETS_LIST()

IF(NOT DEBUG_MODE)
  REGISTER_NEW_TARGET("install")
  REGISTER_NEW_TARGET("uninstall")
ENDIF(NOT DEBUG_MODE)

#
# General project settings
#
SET(MAJOR    1)
SET(MINOR    0)
SET(REVISION 0)
SET(VERSION "${MAJOR}.${MINOR}.${REVISION}" CACHE STRING "coolbot project version")
SET(API_VERSION "${MAJOR}.${MINOR}" CACHE STRING "API version")

SET(BIN_DIR "${PROJECT_SOURCE_DIR}/bin")
SET(LIB_DIR "${PROJECT_SOURCE_DIR}/lib")
SET(PKG_DIR "${PROJECT_SOURCE_DIR}/pkg-config")

SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_DIR} CACHE PATH "Directory for executables")
IF(UNIX)
  SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB_DIR} CACHE PATH "Directory for module libraries")
ELSE(UNIX)
  SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB_DIR} CACHE PATH "Directory for static libraries")
ENDIF(UNIX)
SET(PKG_CONFIG_PATH_DIRECTORY ${PKG_DIR} CACHE PATH "Directory for pkg-config")

IF( DEBUG_MODE )
  SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Development mode" FORCE)
  SET(COOLBOT_INSTALL_PATH ${PROJECT_SOURCE_DIR})
  SET(COOLBOT_RESOURCE_PATH ${PROJECT_SOURCE_DIR})
ELSE( DEBUG_MODE )
  SET(CMAKE_BUILD_TYPE Release CACHE STRING "Production Mode" FORCE)
  SET(COOLBOT_INSTALL_PATH ${CMAKE_INSTALL_PREFIX})
  IF(NOT WIN32)
    SET(RESOURCE_INSTALL_PATH "/usr/share/${PROJECT_NAME}")
  ELSE(NOT WIN32)
    SET(RESOURCE_INSTALL_PATH "${COOLBOT_INSTALL_PATH}")
  ENDIF(NOT WIN32)
ENDIF( DEBUG_MODE )

IF(SHOW_WARNINGS)
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
  IF(NOT WIN32)
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-write-strings")
  ENDIF(NOT WIN32)
ELSE(SHOW_WARNINGS)
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
ENDIF(SHOW_WARNINGS)

GET_OPERATING_SYSTEM( OS )

SET(OSPLATAFORM "NOT-DEFINED")
IF( NOT WIN32 )
  SET(OSPLATAFORM "UNIX")
ELSE( NOT WIN32 )
  SET(OSPLATAFORM "WINDOWS")
ENDIF( NOT WIN32 )

#
# Install settings
#
SET(COOLBOT_RESOURCE_PATH ${RESOURCE_INSTALL_PATH})
SET(COOLBOT_INCLUDE_DIR_INSTALL_PATH "${COOLBOT_INSTALL_PATH}/include")
SET(COOLBOT_LIBRARIES_INSTALL_PATH "${COOLBOT_INSTALL_PATH}/lib")
SET(COOLBOT_BINARIES_INSTALL_PATH "${COOLBOT_INSTALL_PATH}/bin")
SET(COOLBOT_PKGCONFIG_INSTALL_PATH "${COOLBOT_INSTALL_PATH}/lib/pkgconfig")
SET(COOLBOT_RESOURCES_INSTALL_PATH "${RESOURCE_INSTALL_PATH}/resources")

#
# To generate API documentation with doxygen, we must do the following:
#
# 1. Set to ON the BUILD_DOXYGEN_API option.
#
# 2. Include the file: UseDOXYGEN.cmake
#
# 3. Use the macro:
#
# CREATE_DOXYGEN_API_DOC( <doxyge_source_file>
#                        <doxygen_working_directory>)
#
# Optionally, you can use the REGISTER_NEW_TARGET macro to register the doxygen
# target:
#
# REGISTER_NEW_TARGET( doxygen )
#
IF(BUILD_DOXYGEN_API)
  INCLUDE(UseDOXYGEN)
ENDIF(BUILD_DOXYGEN_API)
#
# To use Latex to build the documentation, we must do the following:
#
# 1. Set to ON the BUILD_LATEX option.
#
# 2. Include the file: UseLATEX.cmake
#
# 3. Use the macro:
#
# ADD_LATEX_DOCUMENT(<tex_file>
#                    [BIBFILES <bib_files>]
#                    [INPUTS <input_tex_files>]
#                    [IMAGE_DIRS] <image_directories>
#                    [IMAGES] <image_files>
#                    [CONFIGURE] <tex_files>
#                    [DEPENDS] <tex_files>
#                    [USE_INDEX] [USE_GLOSSARY] [USE_NOMENCL]
#                    [DEFAULT_PDF] [DEFAULT_SAFEPDF]
#                    [MANGLE_TARGET_NAMES])
#
# See for more information: http://www.vtk.org/Wiki/images/d/d7/UseLATEX.pdf
#
IF(BUILD_LATEX)
  INCLUDE(UseLATEX)
ENDIF(BUILD_LATEX)

#
# Sets the targets available
#
SET(COMPILER_FLAGS "" CACHE PATH "CoolBOT compiler flags")
MARK_AS_ADVANCED(COMPILER_FLAGS)

ADD_SUBDIRECTORY(coolbot-toolkit)
ADD_SUBDIRECTORY(coolbot-env)

IF( FRAMEWORK_DEPENDENCIES )
  ADD_SUBDIRECTORY(coolbot)
ENDIF( FRAMEWORK_DEPENDENCIES )

IF( COMPILER_DEPENDENCIES )
  ADD_SUBDIRECTORY(coolbot-c)
  ADD_SUBDIRECTORY(coolbot-bundle)
ENDIF( COMPILER_DEPENDENCIES )

ADD_SUBDIRECTORY(coolbot-config)

#
# Generates the ctConfig.h file
#
RUN_PKGCONFIG( "--libs"
               "${PKG_CONFIG_PATH_DIRECTORY}/coolbot.pc"
                result_pkg
                LINKER_FLAGS)

RUN_PKGCONFIG( "--cflags"
               "${PKG_CONFIG_PATH_DIRECTORY}/coolbot.pc"
                result_pkg
                CFLAGS_FLAGS)

GENERATE_CONFIG_FILE( VERSION
                      COOLBOT_C_VERSION
                      COOLBOT_BUNDLE_VERSION
                      COOLBOT_CONFIG_VERSION
                      COOLBOT_ENV_VERSION
                      COOLBOT_RESOURCE_PATH
                      COOLBOT_RESOURCES_INSTALL_PATH
                      COOLBOT_PKGCONFIG_INSTALL_PATH
                      COOLBOT_INCLUDE_DIR_INSTALL_PATH
                      COOLBOT_LIBRARIES_INSTALL_PATH
                      COOLBOT_BINARIES_INSTALL_PATH
                      LINKER_FLAGS
                      CFLAGS_FLAGS
                      COMPILER_FLAGS
                      OSPLATAFORM)

IF(NOT DEBUG_MODE)
  #
  # Installation on UNIX environment:
  #
  # CMake files -> ${CMAKE_ROOT}/Modules/ (/usr/share/cmake-2.8/Modules)
  # GNU files   -> ${COOLBOT_RESOURCE_PATH} (/usr/share/coolbot-project/)
  # Resources   -> ${COOLBOT_RESOURCE_PATH}/resources/ (/usr/share/coolbot-project/resources)
  # Pkg-config  -> ${COOLBOT_LIBRARIES_INSTALL_PATH}/pkgconfig (/usr/local/lib/pkgconfig)
  #
  # Installation on MS-WINDOWS environment:
  #
  # CMake files -> ${CMAKE_ROOT}\Modules\ (C:\Archivos de programa\CMake 2.8\share\cmake-2.8\Modules)
  # GNU files   -> ${COOLBOT_RESOURCE_PATH} (C:\Archivos de programa\coolbot-project\)
  # Resources   -> ${COOLBOT_RESOURCE_PATH}\resources\ (C:\Archivos de programa\coolbot-project\resources)
  # Pkg-config  -> ${COOLBOT_LIBRARIES_INSTALL_PATH}/pkgconfig (C:\Archivos de programa\coolbot-project\lib\pkgconfig)
  #
  INSTALL( FILES      "${PROJECT_SOURCE_DIR}/cmake/FindCOOLBOT.cmake"
                      "${PROJECT_SOURCE_DIR}/cmake/UseCoolBOT.cmake"
          DESTINATION ${CMAKE_ROOT}/Modules/
          PERMISSIONS OWNER_READ OWNER_WRITE
                      GROUP_READ
                      WORLD_READ
  )
  MESSAGE(STATUS "Generated install commands for FindCOOLBOT and UseCoolBOT CMake module")
  INSTALL( FILES      "${PROJECT_SOURCE_DIR}/AUTHOR"
                      "${PROJECT_SOURCE_DIR}/COPYING"
                      "${PROJECT_SOURCE_DIR}/COPYING.EXCEPTION"
                      "${PROJECT_SOURCE_DIR}/README"
                      "${PROJECT_SOURCE_DIR}/INSTALL"
                      "${PROJECT_SOURCE_DIR}/coolbot-project-license-header-script"
                      "${PROJECT_SOURCE_DIR}/coolbot-project-license-header"
          DESTINATION ${COOLBOT_RESOURCE_PATH}
          PERMISSIONS OWNER_READ OWNER_WRITE
                      GROUP_READ
                      WORLD_READ
  )
  MESSAGE(STATUS "Generated install commands for GNU files")

  INSTALL( DIRECTORY  ${PROJECT_SOURCE_DIR}/resources/
           DESTINATION ${COOLBOT_RESOURCES_INSTALL_PATH}
           FILE_PERMISSIONS      OWNER_READ OWNER_WRITE GROUP_READ
                                                         WORLD_READ
           DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
                                 GROUP_READ             GROUP_EXECUTE
                                 WORLD_READ             WORLD_EXECUTE
           REGEX ".~$" EXCLUDE
  )
  MESSAGE(STATUS "Generated install commands for resources directory")
  INSTALL( DIRECTORY  ${PROJECT_SOURCE_DIR}/pkg-config/
           DESTINATION ${COOLBOT_PKGCONFIG_INSTALL_PATH}
           FILE_PERMISSIONS      OWNER_READ OWNER_WRITE GROUP_READ
                                                         WORLD_READ
           DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
                                 GROUP_READ             GROUP_EXECUTE
                                 WORLD_READ             WORLD_EXECUTE
           PATTERN ".keepme" EXCLUDE
           REGEX ".~$" EXCLUDE
  )
  MESSAGE(STATUS "Generated install commands for pkg-config files")

  #
  # CPACK settings
  #
  # NOTE: If we obtain a package with only the source code, we must run the
  # following command:
  #
  #                   make package_source
  #
  # Order to correctly generate the package, in the build folder does not add
  # any file that has not been created by CMake.
  #
  # The InstallRequiredSystemLibraries include added the compiler run time
  # libraries (MS-Windows case) by default in binary directory.
  #
  INCLUDE(InstallRequiredSystemLibraries)

  INCLUDE(${PROJECT_SOURCE_DIR}/cmake/cpack_common_config.cmake)
  INCLUDE(${PROJECT_SOURCE_DIR}/cmake/cpack_source_config.cmake)
  INCLUDE(${PROJECT_SOURCE_DIR}/cmake/cpack_debian_config.cmake)
  INCLUDE(${PROJECT_SOURCE_DIR}/cmake/cpack_redhat_config.cmake)
  INCLUDE(${PROJECT_SOURCE_DIR}/cmake/cpack_windows_config.cmake)

  #Remember to use the application "fakeroot" before running CPACK.
  INCLUDE (CPack)
  MESSAGE(STATUS "Generated CPACK configuration")

ENDIF(NOT DEBUG_MODE)

#
# Displays global configuration settings
#
MESSAGE("\n----- Summary about ${PROJECT_NAME} version ${VERSION} -----\n")

MESSAGE("   * System processor: ${CMAKE_SYSTEM_PROCESSOR}")
MESSAGE("   * Operating system: ${OS}")
IF( DEBUG_MODE )
  MESSAGE("   * Build type: Development mode")
ELSE( DEBUG_MODE )
  MESSAGE("   * Build type: Production Mode")
ENDIF( DEBUG_MODE )
MESSAGE("   * Binary directory: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
IF(UNIX)
  MESSAGE("   * Library directory: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
ELSE(UNIX)
  MESSAGE("   * Library directory: ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}")
ENDIF(UNIX)
MESSAGE("   * Pkg directory: ${PKG_CONFIG_PATH_DIRECTORY}")
MESSAGE("   * Install path: ${COOLBOT_INSTALL_PATH}")
MESSAGE("   * Options available:")
IF(BUILD_DOXYGEN_API)
  MESSAGE("     ** Build API documentation with doxygen")
ELSE(BUILD_DOXYGEN_API)
  MESSAGE("     ** Don't build API documentation with doxygen")
ENDIF(BUILD_DOXYGEN_API)
IF(BUILD_EXAMPLES)
  MESSAGE("     ** Build examples of CoolBOT framework")
ELSE(BUILD_EXAMPLES)
  MESSAGE("     ** Don't build examples of CoolBOT framework")
ENDIF(BUILD_EXAMPLES)
IF(BUILD_LATEX)
  MESSAGE("     ** Build documentation with Latex")
ELSE(BUILD_LATEX)
  MESSAGE("     ** Don't build documentation with Latex")
ENDIF(BUILD_LATEX)
IF(BUILD_SHARED_LIBS)
  MESSAGE("     ** Build share libraries")
ELSE(BUILD_SHARED_LIBS)
  MESSAGE("     ** Build static libraries")
ENDIF(BUILD_SHARED_LIBS)
IF(SHOW_DEBUG_INFO)
  MESSAGE("     ** Display debug information")
ELSE(SHOW_DEBUG_INFO)
  MESSAGE("     ** Hide debug information")
ENDIF(SHOW_DEBUG_INFO)
IF(SHOW_WARNINGS)
  MESSAGE("     ** Display the C/C++ compiler warnings")
ELSE(SHOW_WARNINGS)
  MESSAGE("     ** Hide the C/C++ compiler warnings")
ENDIF(SHOW_WARNINGS)
MESSAGE("   * Targets available:")
GET_TARGETS_LIST( TARGETS_AVAILABLE )
FOREACH(the_target ${TARGETS_AVAILABLE})
  MESSAGE("     ** ${the_target}")
ENDFOREACH(the_target)

MESSAGE("\n----- Building and install/uninstall instructions -----\n")
MESSAGE("   $ make -j n (n is the number of processes you want to launch)")
IF(NOT DEBUG_MODE)
  MESSAGE("   $ make install (you might need to have administrator permissions)")
  MESSAGE("   $ make uninstall (you might need to have administrator permissions)\n")
ENDIF(NOT DEBUG_MODE)

MESSAGE("\n   For more information, see the INSTALL file\n")