ecl_package.cmake
Go to the documentation of this file.
00001 ###############################################################################
00002 # Building ecl packages (c.f. rosbuild.cmake for ros)
00003 ###############################################################################
00004 #
00005 # NOT FOR REGULAR CONSUMPTION! THIS IS ONLY USED BY ECL PACKAGES!
00006 #
00007 
00008 #ifdef DOXYGEN_SHOULD_SKIP_THIS
00009 
00010 ###############################################################################
00011 # Version
00012 ###############################################################################
00013 
00014 # Set the ecl version.
00015 macro(ecl_version)
00016     set(PROJECT_VERSION "0.44.0")
00017     set(PROJECT_VERSION_MAJOR "0")
00018     set(PROJECT_VERSION_MINOR "44")
00019     set(PROJECT_VERSION_PATCH "0")
00020 endmacro()
00021 
00022 ###############################################################################
00023 # Source Installer
00024 ###############################################################################
00025 #
00026 # Collects all *.c, *.cpp, *.h, *.hpp files together and installs them to
00027 # CMAKE_INSTALL_PREFIX under the include/pkg_name and src/pkg_name 
00028 # directories respectively.
00029 #
00030 # This is useful for collecting sources for firmware builds in another ide.
00031 #
00032 macro(ecl_roll_source_installs)
00033   FILE(GLOB_RECURSE PACKAGE_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS *.h *.hpp)
00034   FILE(GLOB_RECURSE PACKAGE_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/lib/*.c src/lib/*.cpp)
00035   add_custom_target(sources
00036       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
00037       COMMENT "Installing sources."
00038     )
00039   foreach(_file ${PACKAGE_HEADERS})
00040     get_filename_component(_dir ${_file} PATH)
00041     get_filename_component(_filename ${_file} NAME)
00042     string(REGEX REPLACE "/" "_" _target_name ${_file})
00043     add_custom_target(include_${_target_name}
00044       ${CMAKE_COMMAND} -E make_directory ${CMAKE_INSTALL_PREFIX}/${_dir}
00045       COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_file} ${CMAKE_INSTALL_PREFIX}/${_file}
00046       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
00047     )
00048     add_dependencies(sources include_${_target_name})
00049   endforeach(_file ${PACKAGE_HEADERS})
00050   foreach(_file ${PACKAGE_SOURCES})
00051     set(_dir ${CMAKE_INSTALL_PREFIX}/src/${PROJECT_NAME})
00052     get_filename_component(_filename ${_file} NAME)
00053     string(REGEX REPLACE "/" "_" _target_name ${_file})
00054     # Should probably convert slashes to underscores instead here.
00055     add_custom_target(source_${_target_name}
00056       ${CMAKE_COMMAND} -E make_directory ${_dir}
00057       COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_file} ${_dir}/${_filename}
00058       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
00059     )
00060     add_dependencies(sources source_${_target_name})
00061   endforeach(_file ${PACKAGE_SOURCES})
00062 endmacro()
00063 
00064 ###############################################################################
00065 # CPack
00066 ###############################################################################
00067 
00068 # Currently it just builds debian packages. It needs some prerequisites to
00069 # function, currently:
00070 #
00071 # - you must include ecl_platform_detection, ecl_ros_utilities
00072 # - you must have called ecl_detect_distro (or ecl_detect_platform) first
00073 #   - this sets DISTRO_NAME, DISTRO_VERSION_STRING which is needed by this script
00074 #
00075 # Ultimately in the ecl packages, all that is needed is to call ecl_init
00076 # first (which preps all of the above), then after including your subdirectories
00077 # call this macro.
00078 #
00079 macro(ecl_roll_cpack_packages)
00080     # Distro
00081     if(NOT DISTRO_NAME STREQUAL "Ubuntu")
00082         message(STATUS "CPack configuration aborted : not ubuntu.")
00083         set(CPACK_DEBIAN_ABORT TRUE)
00084         # return() this doesn't work...automatically causes the parent macro to return as well.
00085     endif()
00086     # Build type
00087     if(NOT CPACK_DEBIAN_ABORT)
00088         if(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
00089             set(CPACK_BUILD_TYPE_POSTFIX "-debug")
00090         elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release")
00091             set(CPACK_BUILD_TYPE_POSTFIX "")
00092         else()
00093             message(STATUS "CPack configuration : aborted, invalid build mode (only RelWithDebInfo|Release).")
00094             set(CPACK_DEBIAN_ABORT TRUE)
00095         endif()
00096     endif()
00097     if(NOT CPACK_DEBIAN_ABORT)
00098         # Architecture
00099         if(PLATFORM_IS_32_BIT)
00100             set(UBUNTU_ARCH "i386")
00101         else() # 64 bit
00102             set(UBUNTU_ARCH "amd64")
00103         endif()
00104         # Description
00105         ecl_ros_manifest_brief_desc() # -> MANIFEST_SHORT_DESC
00106         # Dependencies
00107         ecl_ros_get_dependency_list() # -> ${PROJECT_NAME}_DEPENDENCIES
00108         # CPack    
00109         set(CPACK_PACKAGE_NAME ${PROJECT_NAME}${CPACK_BUILD_TYPE_POSTFIX})
00110         set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
00111         set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
00112         set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
00113         set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
00114         set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}${CPACK_BUILD_TYPE_POSTFIX}-${CPACK_PACKAGE_VERSION})
00115         set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${MANIFEST_BRIEF_DESC}")
00116         set(CPACK_INSTALL_PREFIX /usr)
00117         set(CPACK_DEBIAN_PACKAGE_SECTION "universe/libdevel")
00118         set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
00119         # Need to weed out rosbuild (used by ecl_build) from tainting this list
00120         foreach(dep ${${PROJECT_NAME}_DEPENDENCIES})
00121             if ( NOT dep STREQUAL "rosbuild")
00122                 if("${CPACK_DEBIAN_PACKAGE_DEPENDS}" STREQUAL "")
00123                     set(CPACK_DEBIAN_PACKAGE_DEPENDS "${dep}${CPACK_BUILD_TYPE_POSTFIX} (>= ${PROJECT_VERSION})")
00124                 else()
00125                     set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, ${dep}${CPACK_BUILD_TYPE_POSTFIX} (>= ${PROJECT_VERSION})")
00126                 endif()
00127             endif()
00128         endforeach()
00129         # If no dependencies, make the base dependency string.
00130         if ( CPACK_DEBIAN_PACKAGE_DEPENDS STREQUAL "")
00131             set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.9-4), libgcc1 (>= 1:4.3.3-5), libstdc++6 (>= 4.1.1)")
00132         endif() 
00133         set(CPACK_SET_DESTDIR ON)
00134         set(CPACK_GENERATOR "DEB")
00135         set(CPACK_PACKAGE_CONTACT "d.stonier@gmail.com")
00136         set(CPACK_DEBIAN_ARCHITECTURE "${UBUNTU_ARCH}")
00137         set(CPACK_INSTALL_CMAKE_PROJECTS "${CMAKE_BINARY_DIR};${CPACK_PACKAGE_NAME};ALL;/")
00138         set(CPACK_MODULE_PATH "${CMAKE_MODULE_PATH}")
00139         set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
00140         include(CPack)
00141     
00142         # Uploading
00143         set(PKG_HOST_URL "snorriheim.dnsdojo.com")
00144         set(PKG_HOST_HTTP "http://${PKG_HOST_URL}")
00145         set(PKG_HOST_SSH "snorri@${PKG_HOST_URL}")
00146         set(UBUNTU_REPO_URL "${PKG_HOST_HTTP}/packages/dists/${DISTRO_VERSION_STRING}/${UBUNTU_ARCH}")
00147         set(UBUNTU_REPO_SSH "${PKG_HOST_SSH}:/mnt/froody/servers/packages/dists/${DISTRO_VERSION_STRING}/${UBUNTU_ARCH}/")
00148         
00149         add_custom_target(upload
00150             COMMAND scp ${CMAKE_BINARY_DIR}/*.deb ${UBUNTU_REPO_SSH}
00151             COMMAND ssh ${PKG_HOST_SSH} '/mnt/froody/servers/scripts/update_ubuntu_repos'
00152             COMMENT "Uploading .debs to the package repository."
00153         )
00154         message(STATUS "CPack debian packaging configured.")
00155         message("")
00156     endif()
00157     
00158 endmacro()
00159 
00160 # A summary of the cpack results.
00161 macro(ecl_summary_cpack)
00162     if(NOT CPACK_DEBIAN_ABORT)
00163         message("-------------------------------------------------------------------")
00164         message("CPack Summary")
00165         message("-------------------------------------------------------------------")
00166         message("")
00167         # For some reason CPACK_PACKAGE_FILE_NAME gets overwritten by include(CPack)
00168         # so I can't print it correctly here...but the debian file is still correctly named 
00169         # in the long run.
00170         message("Package name....................${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
00171         message("Build mode......................${CMAKE_BUILD_TYPE}")
00172         message("Description.....................${CPACK_PACKAGE_DESCRIPTION_SUMMARY}")
00173         if(NOT ${CPACK_DEBIAN_PACKAGE_DEPENDS} STREQUAL "")
00174             message("Dependencies....................${CPACK_DEBIAN_PACKAGE_DEPENDS}")
00175         endif()
00176     endif()
00177     message("")
00178 endmacro()
00179 
00180 ###############################################################################
00181 # Custom target
00182 ###############################################################################
00183 # These are nice in that they let us have targets outside the mainstream
00184 # build process. You can either target an executable for a
00185 # example/benchmark/utility build or build all of them together under the
00186 # apps umbrella
00187 #
00188 macro(ecl_add_example exe)
00189   message(STATUS "Adding ${exe} to the examples target.")
00190   add_custom_target(apps)
00191   add_custom_target(examples)
00192   rosbuild_add_executable(${exe} EXCLUDE_FROM_ALL ${ARGN})
00193   add_dependencies(apps ${exe})
00194   add_dependencies(examples ${exe})
00195 endmacro(ecl_add_example)
00196 
00197 macro(ecl_add_benchmark exe)
00198   message(STATUS "Adding ${exe} to the benchmarks target.")
00199   add_custom_target(apps)
00200   add_custom_target(benchmarks)
00201   rosbuild_add_executable(${exe} EXCLUDE_FROM_ALL ${ARGN})
00202   add_dependencies(apps ${exe})
00203   add_dependencies(benchmarks ${exe})
00204 endmacro(ecl_add_benchmark)
00205 
00206 macro(ecl_add_utility exe)
00207   message(STATUS "Adding ${exe} to the utilities target.")
00208   add_custom_target(apps)
00209   add_custom_target(utilities)
00210   rosbuild_add_executable(${exe} EXCLUDE_FROM_ALL ${ARGN})
00211   add_dependencies(apps ${exe})
00212   add_dependencies(utilities ${exe})
00213 endmacro(ecl_add_utility)
00214 
00215 
00216 ###############################################################################
00217 # Libraries
00218 ###############################################################################
00219 
00220 macro(ecl_add_library lib_target)
00221   message(STATUS "Building library ${lib}.")
00222   rosbuild_add_library(${lib_target} ${ARGN})
00223   # Visibility support
00224   if(ROS_BUILD_SHARED_LIBS)
00225     if(CMAKE_COMPILER_IS_GNUCXX)
00226       rosbuild_add_compile_flags(${lib_target} -DECL_BUILDING_SHARED_LIB -fvisibility=hidden)
00227     endif()
00228     if(MSVC)
00229       rosbuild_add_compile_flags(${lib_target} -DECL_BUILDING_SHARED_LIB)
00230     endif()
00231   endif()
00232 endmacro()
00233 
00234 ###############################################################################
00235 # Init for a generic ecl package (aka rosbuild_init())
00236 ###############################################################################
00237 # This must be called after rosbuild_init has been called - i.e. usually
00238 #
00239 # include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
00240 # rosbuild_init()
00241 # rosbuild_include(ecl_build eclbuild.cmake)
00242 #
00243 macro(ecl_package_init)
00244 
00245     # Modules
00246     rosbuild_find_ros_package(ecl_build)
00247     set(CMAKE_MODULE_PATH ${ecl_build_PACKAGE_PATH}/cmake/modules)
00248     include(ecl_platform_detection)
00249     include(ecl_build_utilities)
00250     include(ecl_ros_utilities)
00251 
00252     # Ecl configuration
00253     ecl_version()
00254     ecl_detect_platform()
00255     ecl_set_platform_cflags()
00256     ecl_link_as_needed(ECL_LINK_AS_NEEDED_FLAG)
00257     set(ROS_LINK_FLAGS "${ROS_LINK_FLAGS} ${ECL_LINK_AS_NEEDED_FLAG}")
00258     ecl_add_uninstall_target()
00259     ecl_roll_source_installs()
00260     ecl_roll_cpack_packages()
00261     ecl_ros_output_paths()
00262 endmacro()
00263 
00264 macro(ecl_package_finalise)
00265     ecl_summary_platform()
00266     ecl_summary_cpack()
00267 endmacro()
00268 
00269 #endif DOXYGEN_SHOULD_SKIP_THIS
00270 


ecl_build
Author(s): Daniel Stonier (d.stonier@gmail.com)
autogenerated on Thu Jan 2 2014 11:13:41