zoukankan      html  css  js  c++  java
  • cmake模板

    工程的目录树如下所示

    $ tree
    .
    ├── bin
    │   └── test
    ├── CMakeLists.txt
    ├── include
    │   ├── cal.h
    │   └── syslog.h
    ├── lib
    │   └── libcal.a
    └── src
        ├── cal.c
        └── main.c

    cmake编译生成静态库和可执行文件

    $ cat CMakeLists.txt 
     1 # cmake for test
     2 # author : hancq
     3 # date   : 2016-03-24
     4  
     5 # set cmake mimimum version
     6 cmake_minimum_required(VERSION 2.8.0)
     7  
     8 # project name
     9 project(test)
    10  
    11 # set cmake cross compile
    12 #set(CMAKE_CROSEECOMPILING  TRUE)
    13 #set(CMKA_SYSTRM_NAME       Linux)
    14 #set(CMAKE_C_COMPILER       arm-hisiv300-linux-gcc)
    15 #set(CMAKE_CXX_COMPILER     arm-hisiv300-linux-g++)
    16 #set(CMAKE_AUTOCONF_OPTION "--host=arm-linux CC=${CMAKE_C_COMPILER}")
    17  
    18 # add message
    19 message(STATUS "PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR})
    20 message(STATUS "PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR})
    21 #message(SEND_ERROR "this is a SEND_ERROR")
    22 #message(FATAL_ERROR "this is a FATAL_ERROR")
    23  
    24 # set source files
    25 set(SRC 
    26     ${PROJECT_SOURCE_DIR}/src/main.c)
    27  
    28 # set library source files
    29 set(LIB_SRC ${PROJECT_SOURCE_DIR}/src/cal.c)
    30  
    31 # set bin file path
    32 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
    33 # set lib file path
    34 set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
    35  
    36 # add include directories
    37 include_directories(${PROJECT_SOURCE_DIR}/include)
    38 # library files path
    39 link_directories(${PROJECT_SOURCE_DIR}/lib)
    40  
    41 # add define value
    42 add_definitions(-Wall)
    43 add_definitions(-O2)
    44 add_definitions(-DCAL_ADD)
    45 add_definitions(-DCAL_SUB)
    46 add_definitions(-DCAL_MUL)
    47 add_definitions(-DCAL_DIV)
    48  
    49 # build static library
    50 add_library(cal STATIC ${LIB_SRC})
    51  
    52 # build for test
    53 add_executable(test ${SRC})
    54 target_link_libraries(test cal)
  • 相关阅读:
    EMV内核使用中的常见问题
    SM2国密证书合法性验证
    WP8.1中C++的winodws运行时组件位移操作的差异
    [源码]Literacy 快速反射读写对象属性,字段
    Vue 单文件元件 — vTabs
    vue-router路径计算问题
    前端跨域新方案尝试
    Vue 单文件原件 — vCheckBox
    JavaScript 功能类 Url.js
    Vue 学习笔记 — 组件初始化
  • 原文地址:https://www.cnblogs.com/hancq/p/5319934.html
Copyright © 2011-2022 走看看