• 一个Cmake的例子



    命令查询列表:http://www.cmake.org/cmake/help/v3.2/manual/cmake-commands.7.html


    #
    # Official dependency number 0: CMake.
    # Obviously, we must have it if we are here but test version.
    #
    CMAKE_MINIMUM_REQUIRED( VERSION 2.6 FATAL_ERROR )

    #
    # Enter some information about the project
    # This is the only configurable part of the build system
    #
    # project name 
    PROJECT( stamp )
    SET (CMAKE_VERBOSE_MAKEFILE "1")

    #设置编译器
    SET (CMAKE_CXX_COMPILER "g++")
    #
    使用-Wno-deprecated-declarations -Wno-deprecated, 去掉对于gcc4.6的一些报警
    SET (CMAKE_CXX_FLAGS "-std=c++0x -fPIC -Wall -O2 -DNEWARCH -DPOSIX -DPOSIX-DMONGO_HAVE_STDINT -D__STDC_LIMIT_MACROS -Wno-deprecated-declarations-Wno-deprecated")
    SET (CMAKE_C_FLAGS "-fPIC -Wall -O2 -DNEWARCH -DPOSIX -DMONGO_HAVE_STDINT-fno-strict-aliasing -fwrapv -Wstrict-prototypes")
    #SET (CMAKE_SHARED_LINKER_FLAGS "-L/opt/lib/python2.7/config -lpthread-ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic")



    #设置路径
    MESSAGE ( STATUS "**************** Release ****************" )
    SET (PROJECT_ROOT_DIR "../" )
    #
    # The out-of-source building directory
    #
    #INCLUDE( "../conf/${PROJECT_NAME}.cmake" )
    GET_FILENAME_COMPONENT( PROJECT_BUILD_DIR"${${PROJECT_NAME}_SOURCE_DIR}" ABSOLUTE ) #把中间路径的值赋予第一个参数
    GET_FILENAME_COMPONENT( PROJECT_ROOT_DIR "${PROJECT_BUILD_DIR}/../"ABSOLUTE )
    GET_FILENAME_COMPONENT( PROJECT_CMAKE_DIR"${PROJECT_BUILD_DIR}/cmake/" ABSOLUTE )

    MESSAGE( STATUS "DEBUG: ${PROJECT_NAME}_SOURCE_DIR${${PROJECT_NAME}_SOURCE_DIR}" )
    MESSAGE( STATUS "DEBUG: PROJECT_ROOT_DIR ${PROJECT_ROOT_DIR}" )
    MESSAGE( STATUS "DEBUG: PROJECT_CMAKE_DIR ${PROJECT_CMAKE_DIR}")

    #包含其他cmake

    # optional cmake prepare modules
    INCLUDE( "cmake/contrib.cmake" OPTIONAL )
    INCLUDE( "cmake/UseBoost.cmake" OPTIONAL )
    INCLUDE( "cmake/UseIce.cmake" OPTIONAL )
    INCLUDE( "cmake/slice.cmake" OPTIONAL )
    INCLUDE( "cmake/UsePython.cmake" OPTIONAL )


    # -----------------------------------------------------------------------------------
    INCLUDE_DIRECTORIES( "${PROJECT_ROOT_DIR}/src/cpp/include" )

    INCLUDE_DIRECTORIES( "/opt/Python-2.7/include" )
    INCLUDE_DIRECTORIES( "/opt/Python-2.7/include/python2.7" )
    #INCLUDE_DIRECTORIES( "../../../../../common/BfdProto/trunk/release/tmp/proto/")


    #Generate a list of files that match the <globbing-expressions> and store it into the <variable>生成文件列表
    FILE( GLOB BUILD_SRC_RECOMMEND_SOURCE"${PROJECT_ROOT_DIR}/src/cpp/common/*.cpp""${PROJECT_ROOT_DIR}/src/cpp/common/*.cc" )
    FILE( GLOB BUILD_SRC_RABBIT_SOURCE"${PROJECT_ROOT_DIR}/src/cpp/stamp/*.cpp" )
    FILE( GLOB BUILD_SRC_RULE_SOURCE "${PROJECT_ROOT_DIR}/src/cpp/rule_engine/*.cpp")
    FILE( GLOB BUILD_SRC_OPERATOR_SOURCE"${PROJECT_ROOT_DIR}/src/cpp/modules/operator/*.cpp" )
    FILE( GLOB BUILD_SRC_CACHEADAPTER_SOURCE"${PROJECT_ROOT_DIR}/src/cpp/CacheAdapter/*.cpp" )
    FILE( GLOB BUILD_SRC_KAFKAADAPTER_SOURCE"${PROJECT_ROOT_DIR}/src/cpp/KafkaProducerAdapter/*.cpp" )


    #ADD_LIBRARY  Adds a library target called <name> to be built from the source files listed in the command invocation.

    TARGET_LINK Specify libraries or flags to use when linking a given target.

    ADD_LIBRARY( operator ${BUILD_SRC_OPERATOR_SOURCE} )

    ADD_LIBRARY( CacheAdapter.cm.1.0.0 SHARED ${BUILD_SRC_CACHEADAPTER_SOURCE})
    TARGET_LINK_LIBRARIES( CacheAdapter.cm.1.0.0 libBfdProto.so )

    ADD_LIBRARY( KafkaProducerAdapter ${BUILD_SRC_KAFKAADAPTER_SOURCE} )
    TARGET_LINK_LIBRARIES( KafkaProducerAdapter libKafkaSlice.a )

    ADD_LIBRARY( stampcommon ${BUILD_SRC_RECOMMEND_SOURCE} )
    TARGET_LINK_LIBRARIES( stampcommon stampSlice json log4cxx
        boost_program_options ssl)

    ADD_LIBRARY( rule_engine SHARED ${BUILD_SRC_RULE_SOURCE} )
    TARGET_LINK_LIBRARIES( rule_engine operator python2.7 Tripod json log4cxxboost_program_options dl util pthread boost_program_options IceUtil Iceboost_thread boost_system rt m stampcommon )
     
    #ADD_LIBRARY( rule_engine SHARED ${BUILD_SRC_RULE_SOURCE} )
    #TARGET_LINK_LIBRARIES( rule_engine operator python2.7 Tripod json log4cxxboost_program_options dl util pthread stampcommon boost_program_options IceUtilIce boost_thread boost_system rt m librediscluster.a  )

    #ADD_EXECUTABLE( stamp ${BUILD_SRC_RABBIT_SOURCE} )
    ADD_LIBRARY( stamp SHARED ${BUILD_SRC_RABBIT_SOURCE} )
    TARGET_LINK_LIBRARIES( stamp stampcommon util UtilCxx IceUtil Ice IceBox
        IceGrid json log4cxx boost_program_optionszookeeper_mt
    CacheAdapter.cm.1.0.0 Tripod
        memcached KafkaProducerAdapterrule_engine operator protobuf ssl)

    #=======================================================================================
    # @@service handlers@@
    # =======================================================================================

    If RELATIVE flag is specified, the results will be returned as relative paths to the given path.
    SET ( HANDLER_DIR "${PROJECT_ROOT_DIR}/src/cpp/handlers" )
    FILE( GLOB HANDLERS RELATIVE "${HANDLER_DIR}""${HANDLER_DIR}/[a-zA-Z]?*")
    FOREACH ( handler ${HANDLERS} )
      FILE( GLOB HANDLER_SOURCE
          "${PROJECT_ROOT_DIR}/src/cpp/handlers/${handler}/*.cpp")
      ADD_LIBRARY(${handler} SHARED"${HANDLER_SOURCE}")
      TARGET_LINK_LIBRARIES(${handler}log4cxx json boost_program_options UtilCxx zookeeper_mt libBfdProto.sostampcomm)

    The PREFIX and SUFFIX properties override the default target name prefix (such as “lib”) and suffix (such as ”.so”)
      SET_TARGET_PROPERTIES(${handler}PROPERTIES PREFIX "")
    ENDFOREACH ( handler )


    #-----------------------------------------------------------------------------------
    MESSAGE ( STATUS "**************** CMAKE Complete ****************")
     

  • 相关阅读:
    【原】error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string'
    【原】开发路上疑难BUG调试记录
    【转】XCode: duplicate symbol 解决方案
    【原】就IOS发布app时如何保护文本资源的一个方法
    【原】xcode5.0升级5.1遇到的clang: error: unknown argument: '-fobj-arc'错误
    【转】生产者与消费者
    安卓快速排序与冒泡排序
    数据结构之算法时间复杂度
    常见数据结构与算法整理总结(上)
    Activity的onPause()、onStop()和onDestroy()里要做的事情
  • 原文地址:https://www.cnblogs.com/catkins/p/5270375.html
Copyright © 2020-2023  润新知