From 0dc2435f06adce9ff62d784b73e48b800f8046b9 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Wed, 23 Mar 2011 10:39:25 +0100 Subject: [PATCH] Reorganization of cmake files - included package build - layout change (don't know why package system was complaining about white spaces in the commands) - redistribuition of the commands across the files --- CMakeLists.txt | 54 ++++++++++++++++++++++++++++++--------------------- src/CMakeLists.txt | 40 +++++++++++++++++++++++++++---------- 2 files changed, 61 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 86d0f55..124e950 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,34 +1,44 @@ -cmake_minimum_required( VERSION 2.6 ) +# IMPORTANT: Do not add whitespaces between cmake commands! This will break +# the package build! +# Do set(CONTENTS) instead of set( CONTENTS ) or set (CONTENTS) -# project definitions -project( libpingcheck CXX ) -set( MAJOR_VERSION 0 ) -set( MINOR_VERSION 1 ) -set( VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION} ) +# cmake: required version +cmake_minimum_required (VERSION 2.6) -# build type -set( CMAKE_BUILD_TYPE Debug ) +# cmake: set the directory where the executable will be placed +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -# set the directory where the executable will be placed -set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) +# cmake: set the directory where the make install places the executable +set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}) -# set the directory where the make install places the executable -#set( CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR} ) +# project: definitions +project(libpingcheck) +set(VERSION 0.1) +set(TARGET ${PROJECT_NAME}) -# enable or disable the full compiler output -set( CMAKE_VERBOSE_MAKEFILE OFF ) +# compiler: disable the full compiler output +set(CMAKE_VERBOSE_MAKEFILE OFF) -# add definitions, compiler switches, etc. +# compiler: build type +set(CMAKE_BUILD_TYPE Debug) + +# compiler: add definitions and arguments to the compiler add_definitions( - -Werror -Wall -Wextra -Weffc++ -O2 -DVERSION_STRING=${VERSION_STRING} + -Werror -Wall -Wextra -Weffc++ -O2 -DVERSION_STRING=${VERSION} -DPROJECT_NAME=\"${PROJECT_NAME}\" ) -# required boost libraries -set( Boost_USE_STATIC_LIBS ON ) -set( Boost_USE_MULTITHREADED ON ) -set( Boost_USE_STATIC_RUNTIME OFF ) -find_package( Boost COMPONENTS filesystem program_options REQUIRED ) +# package: package information +set(CPACK_PACKAGE_VERSION ${VERSION}) +set(CPACK_PACKAGE_CONTACT "Intra2net AG") +set(CPACK_PACKAGE_DESCRIPTION ${TARGET}) +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Pingcheck") +set(CPACK_SOURCE_GENERATOR TGZ) +set(CPACK_SOURCE_IGNORE_FILES "\\\\.git;build;build-rpm") +set(CPACK_SOURCE_PACKAGE_FILE_NAME "${TARGET}-${VERSION}") # build the application in the source directory -add_subdirectory( src ) +add_subdirectory(src) + +# package: ??? +include(CPack) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d76dba3..dd72446 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,11 +1,22 @@ -# include directories where the source code is located +# package: required boost libraries +set(Boost_USE_STATIC_LIBS ON) +set(Boost_USE_MULTITHREADED ON) +set(Boost_USE_STATIC_RUNTIME OFF) +find_package(Boost COMPONENTS filesystem program_options REQUIRED) + +# package: find external packages +include(FindPkgConfig) +pkg_check_modules(I2NCOMMON REQUIRED libi2ncommon) + +# compiler: include directories where the source code is located include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIRS} + ${I2NCOMMON_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR} ) -# source code files -set( SOURCES +# compiler: source code files +set(SOURCES config/configuration.cpp config/configurationreader.cpp config/host.cpp @@ -21,14 +32,21 @@ set( SOURCES main.cpp ) -# binary name -set( TARGET ${PROJECT_NAME} ) +# compiler: creates the binary +add_executable(${TARGET} ${SOURCES}) -# creates the binary -add_executable( ${TARGET} ${SOURCES} ) +# linker: libraries search path +link_directories( + ${Boost_LIBRARY_DIRS} +# ${I2NCOMMON_LIBRARY_DIRS} +) -# link the program against the libraries -target_link_libraries( ${TARGET} ${Boost_LIBRARIES} ) +# linker: link the program against the libraries +target_link_libraries( + ${TARGET} + ${Boost_LIBRARIES} +# ${I2NCOMMON_LIBRARIES} +) # creates the install rule for the binary -install( TARGETS ${TARGET} DESTINATION bin ) +install(TARGETS ${TARGET} DESTINATION bin) -- 1.7.1