zoukankan      html  css  js  c++  java
  • CMakeList.txt 案例

    # 参考: https://www.hahack.com/codes/cmake/
    # CMake 最低版本号要求
    
    cmake_minimum_required (VERSION 2.8)
    
    # 项目信息
    project (hello)
    
    # [1]
    # 指定生成目标
    # 对于单个文件,只有写下面这一行。表示使用main.cpp生成可执行程序hello
    # ps: main.cpp 只是一个普通的hello world
    # add_executable(hello main.cpp)
    
    # [2]
    # 对于多个文件,如果在源文件中引用顺序正确,那么我们只要把所有引用文件写在后面即可
    # add_executable(hello main.cpp hello.cpp hello.h)
    
    # 目录结构如下
    # .
    # ├── build
    # ├── CMakeLists.txt
    # ├── hello.cpp
    # ├── hello.h
    # └── main.cpp
    
    # =============================================
    # [hello.cpp]
    # #include <cstdio>
    # void print()
    # {
    #     printf("Hello 
    ");
    # }
    # =============================================
    # [hello.h]
    #
    # #ifndef _HELLO_H
    # #define _HELLO_H
    
    # extern void print();
    
    # #endif
    # =============================================
    # [main.cpp]
    # #include <bits/stdc++.h>
    # #include "hello.h"
    #
    # using namespace std;
    
    # int main()
    # {
    #     print();
    #     return 0;
    # }
    # =============================================
    
    # [3]
    # 但是现在我们发现我们如果每次写一个文件就加一个源文件显然不合理
    # 当然是有集成写法到
    
    # 查找当前目录下的所有源文件
    # 并将名称保存到 DIR_SRCS 变量
    # aux_source_directory(. DIR_SRCS)
    # 指定生成目标
    # add_executable(hello ${DIR_SRCS})
    
    # =============================================
    # [4]
    # 多级别目录操作
    
    # 修改后目录如下,只简单修改了代码中到文件引用
    
    # .
    # ├── build
    # ├── CMakeLists.txt
    # ├── hello
    # │   ├── CMakeLists.txt
    # │   ├── hello.cpp
    # │   └── hello.h
    # └── main.cpp
    
    
    # 经过测试子目录到文件名不能和镜头库到名字冲突
    
    aux_source_directory(. DIR_SRCS)
    
    # 把子目录的CMakeList.txt引入
    add_subdirectory(hello)
    
    add_executable(sol main.cpp)
    
    # 添加链接库
    target_link_libraries(sol Test)
    
    # 在hello 目录下的CMakeList.txt如下
    
    # # 子目录中到CMakeList.txt
    # # 查找当前目录下的所有源文件
    # # 并将名称保存到 DIR_LIB_SRCS 变量
    # aux_source_directory(. DIR_LIB_SRCS)
    # # 生成链接库
    # add_library (Test ${DIR_LIB_SRCS})
    
  • 相关阅读:
    router.beforeEach、路由元信息、导航守卫与函数式编程
    C++传递不定参函数
    函数式编程-compose与pipe
    玩转redux--从会用到庖丁解牛
    redux沉思录:基于flux、状态管理、函数式编程的前端状态管理框架
    Laravel 框架集成 UEditor 编辑器的方法
    i18n实现前端国际化(实例)
    laravel获取当前认证用户登录
    larave5.6 引入自定义函数库时,报错不能重复定义
    2019教师证教材资料
  • 原文地址:https://www.cnblogs.com/Q1143316492/p/11047218.html
Copyright © 2011-2022 走看看