zoukankan      html  css  js  c++  java
  • 【cmake】Ahellocmake

    # $ cmake --version 设置cmake最小版本号
    cmake_minimum_required(VERSION 3.5)
    # 指定工程名
    PROJECT (HELLO)
    # 现阶段,你只需要了解 SET 指令可以用来显式的定义变量即可
    # 将 hello.cpp 赋值给 SRC_LIST 变量,也可以指定多个源文件,用空格隔开
    # SET(SRC_LIST hello.cpp add.cpp sub.cpp)
    SET(SRC_LIST hello.cpp)
    # 输出打印构建目录
    MESSAGE(STATUS "This is HELLO_BINARY_DIR " ${HELLO_BINARY_DIR})
    # 输出打印资源目录
    MESSAGE(STATUS "This is HELLO_SOURCE_DIR " ${HELLO_SOURCE_DIR})
    # 输出打印资源目录,与HELLO_SOURCE_DIR 一样
    MESSAGE(STATUS "This is PROJECT_SOURCE_DIR " ${PROJECT_SOURCE_DIR})
    # 输出打印 CMake 资源目录,与 PROJECT_SOURCE_DIR 一样
    MESSAGE(STATUS "This is CMAKE_SOURCE_DIR " ${CMAKE_SOURCE_DIR})
    # 生成可执行文件 hello ,${SRC_LIST}是引用变量,也就是源文件 hello.cpp
    ADD_EXECUTABLE(hello ${SRC_LIST})

    文件结构:

    [root@centos8 A-hello-cmake]# tree .
    .
    ├── CMakeLists.txt
    ├── main.cpp
    └── README.adoc

     执行:

    [root@centos8 A-hello-cmake]# mkdir build
    [root@centos8 A-hello-cmake]# cd build
    [root@centos8 build]# cmake ..
    -- The C compiler identification is GNU 8.4.1
    -- The CXX compiler identification is GNU 8.4.1
    -- Check for working C compiler: /usr/bin/cc
    -- Check for working C compiler: /usr/bin/cc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- This is HELLO_BINARY_DIR /sunbin/cmake-examples/01-basic/A-hello-cmake/build
    -- This is HELLO_SOURCE_DIR /sunbin/cmake-examples/01-basic/A-hello-cmake
    -- This is PROJECT_SOURCE_DIR /sunbin/cmake-examples/01-basic/A-hello-cmake
    -- This is CMAKE_SOURCE_DIR /sunbin/cmake-examples/01-basic/A-hello-cmake
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /sunbin/cmake-examples/01-basic/A-hello-cmake/build

    参考资料

    1. A-hello-cmake

    2. CMake 语法 - 详解 CMakeLists.txt

  • 相关阅读:
    iOS 面试题汇总
    iOS管理文件和目录
    文件管理
    Cocoapods依赖管理
    IOS开发几何类方法 CGGeometry.h文件
    CGContext
    respondsToSelector的相关使用
    Java数组5作业(2015-8-27)
    Java错误1(2015-8-27)
    Java数组4(2015-8-27)
  • 原文地址:https://www.cnblogs.com/sunbines/p/15422707.html
Copyright © 2011-2022 走看看