美文网首页
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的一些用法记录

    遍历文件夹中的文件,分别编译 添加glog glog 为用来链接的库,使用的时候包含头文件. 添加protobuf...

  • [转]CMake 入门实战

    CMake 入门实战 从实例入手,讲解 CMake 的常见用法。 什么是 CMake All problems i...

  • Android cmake使用外部动态共享库

    官方文档分享: CMake的基本用法参考Android官方文档上的CMake教程: https://develop...

  • cmake用法

    示例源码在 linux 平台下使用 CMake 生成 Makefile 并编译的流程如下: 编写 CMake 配置...

  • CMake的用法

    前言:常用变量 1. 预定义变量 PROJECT_SOURCE_DIR:工程的根目录 PROJECT_BINARY...

  • CMake官方文档翻译(2) 命令行-cmake

    cmake 概要 描述 cmake是CMake提供的命令行工具。上面的概要列出了这个工具的许多用法,将会在后面详细...

  • CMake 常用法

    1. cmake_minimum_required() 2. project() 3. message() 4. ...

  • CMAKE 总结

    2016-5-30 cmake是要比makefile更加现代的一种工具. 这里就逐步总结一下cmake的用法. 首...

  • cmake和makefile

    cmake在语法上面有很多不同的地方,如果是想从头学习建议参考官方教程本文主要是记录一些cmake和makefil...

  • CentOS 下安装 Cmake 步骤

    最近在虚拟机中的 CentOS 中安装 Cmake。把安装步骤记录在此。 什么是 Cmake CMake 是一个跨...

网友评论

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

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