美文网首页
cmake的一些用法记录

cmake的一些用法记录

作者: Crowley | 来源:发表于2017-10-13 19:36 被阅读0次

    遍历文件夹中的文件,分别编译

    # save all file names in src folder into var {srcs}
    file(GLOB_RECURSE srcs src/*.cpp)
    # build and link each one of them, source is the loop var
    foreach (source ${srcs})
        # get the file name, and save in {name}
        get_filename_component(name ${source} NAME_WE)
        add_executable(${name} ${source})
        target_link_libraries(${name} otherlib)
    endforeach ()
    

    添加glog

    glog 为用来链接的库,使用的时候包含头文件.

    #include <glog/logging.h>
    
    find_path(GLOG_INCLUDE_DIR glog/logging.h
            PATHS ${GLOG_ROOT_DIR}
            NO_DEFAULT_PATH)
    find_path(GLOG_INCLUDE_DIR glog/logging.h
            PATHS ${GLOG_ROOT_DIR})
    
    find_library(GLOG_LIBRARY glog
            PATHS ${GLOG_ROOT_DIR}
            PATH_SUFFIXES lib lib64
            NO_DEFAULT_PATH)
    find_library(GLOG_LIBRARY glog
            PATHS ${GLOG_ROOT_DIR}
            PATH_SUFFIXES lib lib64)
    

    添加protobuf,以caffe为例

    find_package(Protobuf REQUIRED)
    include_directories(${PROTOBUF_INCLUDE_DIRS})
    
    include_directories(${CMAKE_CURRENT_BINARY_DIR})
    PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS src/caffe.proto)
    add_library(caffeproto STATIC ${PROTO_SRCS} ${PROTO_HDRS})
    target_link_libraries(caffeproto ${PROTOBUF_LIBRARIES})
    

    caffeproto为可以链接的库

    相关文章

      网友评论

          本文标题:cmake的一些用法记录

          本文链接:https://www.haomeiwen.com/subject/tmhtuxtx.html