当前位置: 首页 > news >正文

CMake-Cookbook 第0章 配置环境

文章目录

  • 第0章 配置环境
  • 0.1 获取代码
  • 0.2 Docker镜像
  • 0.3 安装必要的软件
    • 0.3.1 获取CMake
    • 0.3.2 编译器
    • 0.3.3 自动化构建工具
    • 0.3.4 Python
    • 0.3.5 依赖软件
      • 0.3.5.1 BLAS和LAPACk
      • 0.3.5.2 消息传递接口(MPI)
      • 0.3.5.3 线性代数模板库
      • 0.3.5.4 Boost库
        • 0.3.5.5 交叉编译器
        • 0.3.5.6 ZeroMQ, pkg-config, UUID和Doxygen
        • 0.3.5.7 Conda的构建和部署
  • 0.4 测试环境
  • 0.5 上报问题并提出改进建议

第0章 配置环境

  • 主要内容
    • 如何获取代码
    • GNU/Linux、macOS和Windows 安装示例所需工具
    • 自动化测试如何工作
    • 报告问题,提出改进建议

0.1 获取代码

  • git
    • git clone https://github.com/...git
    • 获取特定版本 --single-branch -b v1.0
      • git clone --single-branch -b v1.0 https://github.com/...git
    • 获取更新,选择库的master分支

0.2 Docker镜像

  • Docker 环境搭建
$ docker run -it devcafe/cmake-cookbook_ubuntu-18.04
$ git clone https://github.com/dev-cafe/cmake-cookbook.git
$ cd cmake-cookbook
$ pipenv install --three
$ pipenv run python testing/collect_tests.py 'chapter-*/recipe-*'

0.3 安装必要的软件

  • 主机操作系统安装依赖项,安装组件
      1. CMake
      1. 编译器
      1. 自动化构建工具
      1. Python

0.3.1 获取CMake

  • GNU/Linux
$ cmake_version="3.5.2"
$ target_path=$HOME/Deps/cmake/${cmake_version}
$ cmake_url="https://cmake.org/files/v${cmake_version%.*}/cmake-${cmake_version}-Linux-x86_64.tar.gz"
$ mkdir -p "${target_path}"
$ curl -Ls "${cmake_url}" | tar -xz -C "${target_path}" --strip-components=1
$ export PATH=$HOME/Deps/cmake/${cmake_version}/bin${PATH:+:$PATH}
$ cmake --version
  • Windows
    • Visual Studio 2017 构建CMake项目
    • 下载MSYS2安装程序,按说明更新包列表,用pacman安装CMake
$ pacman -S mingw64/mingw-w64-x86_64-cmake

0.3.2 编译器

  • C++、C和Fortran 编译器

  • 跨平台,并尽可能独立于操作系统(开源编译器)

  • GNU/Linux

    $ sudo apt-get install g++ gcc gfortran
    
  • Windows

    $ pacman -S mingw64/mingw-w64-x86_64-toolchain
    

0.3.3 自动化构建工具

  • 自动化构建工具:为项目提供构建和链接的基础设施,最终安装和使用什么,取决于操作系统
    • GNU/Linux上,GNU Make
    • macOS上,XCode将提供GNU Make
    • Windows上,Visual Studio ;MSYS2 GNU Make作为mingw64/mingw-w64-x86_64工具链包的一部分
  • 可移植性,尽量使示例不受系统相关细节影响;编译器固有特性:配置、构建和链接
  • 自动化构建工具
    • Ninja 适用于GNU/Linux、macOS和Windows
      • 注重速度,贴别是增量重构
      • Fortran
      • 安装Ninja:
$ mkdir -p ninja
$ ninja_url="https://github.com/Kitware/ninja/releases/download/v1.8.2.g3bbbe.kitware.dyndep-1.jobserver-1/ninja-1.8.2.g3bbbe.kitware.dyndep-1.jobserver-1_x86_64-linux-gnu.tar.gz"
$ curl -Ls ${ninja_url} | tar -xz -C ninja --strip-components=1
$ export PATH=$HOME/Deps/ninja${PATH:+:$PATH}
  • windows MSYS2环境
$ pacman -S mingw64/mingw-w64-x86_64-ninja

0.3.4 Python

  • Python安装
    • 解释器、头文件和库
    • Ubuntu 14.04 LTS
sudo apt-get install python3.5-dev
  • Windows MSYS2环境
$ pacman -S mingw64/mingw-w64-x86_64-python3
$ pacman -S mingw64/mingw-w64-x86_64-python3-pip
$ python3 -m pip install pipenv
  • 建议使用包管理器在隔离的环境中安装这些包
    • 不影响系统环境下,进行包的清理/安装
    • 没有管理员权限的情况下安装包
    • 降低软件版本和依赖项冲突的风险
    • 复现性,可更好地控制包地依赖性
  • Pipfile 结合pipfile.lock 使用Pipenv,创建独立环境安装所有包
$ pip install --user pip pipenv --upgrade
$ pipenv install --python python3.5
  • 执行pipenv shell进入一个命令行环境,包含特定版本Python和可用的包;执行exit退出当前环境;使用pipenv run在隔离环境中直接执行命令
  • 将库中requirements.txt文件与Virtualenvpip结合使用
$ virtualenv --python=python3.5 venv
$ source venv/bin/activate
$ pip install -r requirements.txt
  • deactivate命令退出虚拟环境
  • Conda环境,安装Miniconda
$ curl -Ls https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh > miniconda.sh
$ bash miniconda.sh -b -p "$HOME"/Deps/conda &> /dev/null
$ touch "$HOME"/Deps/conda/conda-meta/pinned
$ export PATH=$HOME/Deps/conda/bin${PATH:+:$PATH}
$ conda config --set show_channel_urls True
$ conda config --set changeps1 no
$ conda update --all
$ conda clean -tipy
  • Windows 下载Miniconda(或使用PowerShell安装)
$basedir = $pwd.Path + "\"
$filepath = $basedir + "Miniconda3-latest-Windows-x86_64.exe"
$Anaconda_loc = "C:\Deps\conda"
$args = "/InstallationType=JustMe /AddToPath=0 /RegisterPython=0 /S /D=$Anaconda_loc"
Start-Process -FilePath $filepath -ArgumentList $args -Wait -Passthru
$conda_path = $Anaconda_loc + "\Scripts\conda.exe"
$args = "config --set show_channel_urls True"
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru
$args = "config --set changeps1 no"
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru
$args = "update --all"
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru
$args = "clean -tipy"
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru
  • 安装Conda后,安装Python模块
$ conda create -n cmake-cookbook python=3.5
$ conda activate cmake-cookbook
$ conda install --file requirements.txt
  • 执行conda deactivate将退出conda的环境

0.3.5 依赖软件

0.3.5.1 BLAS和LAPACk

  • Linux Ubuntu 14.04 LTS 安装BLAS和LAPACk
$ sudo apt-get install libatlas-dev liblapack-dev liblapacke-dev
  • windows MSYS2环境
$ pacman -S mingw64/mingw-w64-x86_64-openblas
  • 或者从GitHub下载 BLAS和LAPACk参考实现并从源代码编译库

0.3.5.2 消息传递接口(MPI)

  • Ubuntu 14.04 LTS 安装OpenMPI
$ sudo apt-get install openmpi-bin libopenmpi-dev
  • 可以从https://www.open-mpi.org/software/ 下载OpenMPI源码并编译

0.3.5.3 线性代数模板库

  • GNU/Linux和macOS上安装Eigen
$ eigen_version="3.3.4"
$ mkdir -p eigen
$ curl -Ls http://bitbucket.org/eigen/eigen/get/${eigen_version}.tar.gz | tar -xz -C eigen --strip-components=1
$ cd eigen
$ cmake -H. -Bbuild_eigen -
DCMAKE_INSTALL_PREFIX="$HOME/Deps/eigen" &> /dev/null
$ cmake --build build_eigen -- install &> /dev/null

0.3.5.4 Boost库

  • Ubuntu 14.04 LTS
$ sudo apt-get install libboost-filesystem-dev libboost-python-dev libboost-test-dev
  • Windows
    • 二进制发行版 从Boost网站 http://www.boost.org 下载
    • https://www.boost.org 下载源代码编译
0.3.5.5 交叉编译器
  • 类Debian/Ubuntu系统,安装交叉编译器
$ sudo apt-get install gcc-mingw-w64 g++-mingw-w64 gfortran-mingw-w64
0.3.5.6 ZeroMQ, pkg-config, UUID和Doxygen
  • Ubuntu 14.04 LTS
$ sudo apt-get install pkg-config libzmq3-dev doxygen graphviz-dev uuid-dev
  • Windows MSYS2环境
$ pacman -S mingw64/mingw-w64-x86_64-zeromq
$ pacman -S mingw64/mingw-w64-x86_64-pkg-config
$ pacman -S mingw64/mingw-w64-x86_64-doxygen
$ pacman -S mingw64/mingw-w64-x86_64-graphviz
0.3.5.7 Conda的构建和部署
  • GNU/Linux和macOS上安装Conda构建和部署工具
$ conda install --yes --quiet conda-build anaconda-client jinja2 setuptools
$ conda clean -tipsy
$ conda info -a
  • Windows
$conda_path = "C:\Deps\conda\Scripts\conda.exe"
$args = "install --yes --quiet conda-build anaconda-client jinja2 setuptools"
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru
$args = "clean -tipsy"
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru
$args = "info -a"
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru

0.4 测试环境

  • 示例持续集成测试

    • GNU/Linux和macOS Travis( https://travis-ci.org )
      • 配置文件: travis.yml ;其他脚本 testing/dependencies
      • GNU/Linux :CMake 3.5.2和CMake 3.12.1 ;macOS :CMake 3.12.1
    • Windows Appveyor( https://www.appveyor.com )
      • .appveyor.yml ;其他脚本 testing/dependencies
      • CMake 3.11.3
    • GNU/Linux测试和商业编译器 CircleCI ( https://circleci.com )
      • .circleci/config.yml
      • CMake 3.12.1
  • 测试机制 python脚本

    • 包含在testing文件夹中
    • 脚本collect_tests.py
      • 运行测试并报告它们的状态
      • 示例可以单独测试,也可以批量测试
    • collect_tests.py
      • 接受正则表达式作为命令行输入
$ pipenv run python testing/collect_tests.py 'chapter-0[1,7]/recipe-0[1,2,5]'
  • 更详细的输出,可设置环境变量VERBOSE_OUTPUT=ON
$ env VERBOSE_OUTPUT=ON pipenv run python testing/collect_tests.py 'chapter-*/recipe-*'

0.5 上报问题并提出改进建议

  • 问题反馈
    • https://github.com/dev-cafe/cmake-cookbook/issues
  • 对源码进行贡献
    • Fork原始库 ,Pull Request提交更改
    • 原始库: https://github.com/dev-cafe/cmake-cookbook
    • 参考: https://help.github.com/articles/creating-a-pull-request-from-a-fork/
  • 非重要更改在Pull Request前创建问题描述并讨论要更改的问题
    • https://github.com/devcafe/cmake-cookbook/issues
http://www.lryc.cn/news/290350.html

相关文章:

  • 优质硬盘检测工具SMART Utility,保障您的Mac数据安全
  • Spring: alibaba代码规范校验工具checkstyle
  • c++线程thread示例
  • Compose | UI组件(十一) | Spacer - 留白
  • PyTorch的nn.Module类的详细介绍
  • python使用activemq库ActiveMQClient类的连接activemq并订阅、发送和接收消息
  • 【Flutter 面试题】Dart是什么?Dart和Flutter有什么关系?
  • 前后台分离跨域交互
  • React16源码: React中处理LegacyContext相关的源码实现
  • Boost.Test资源及示例
  • 数据结构二叉树
  • JavaScript继承与原型链
  • SouthLeetCode-打卡24年01月第4周
  • Linux——磁盘和文件系统(一)
  • EasyCVR视频智能监管系统方案设计与应用
  • Ubuntu搭建国标平台wvp-GB28181-pro
  • LC 2808. 使循环数组所有元素相等的最少秒数
  • Qt|大小端数据转换
  • 禅道添加自定义字段
  • 蓝桥杯2024/1/26笔记-----基于PCF8591的电压采集装置
  • 【一】esp32芯片开发板环境搭建
  • PyTorch2ONNX-分类模型:速度比较(固定维度、动态维度)、精度比较
  • Docker命令快车道:一票通往高效开发之旅
  • IP类接口大全,含免费次数
  • LLMs 的记忆和信息检索服务器 Motorhead
  • vue3项目中让echarts适应div的大小变化,跟随div的大小改变图表大小
  • springboot启动异常
  • 直播主播之互动率与促单
  • Android 基础技术——Bitmap
  • 数据结构奇妙旅程之七大排序