zoukankan      html  css  js  c++  java
  • cmake语法学习

    # Set the minimum version of CMake that can be used
    # To find the cmake version run
    # $ cmake --version
    cmake_minimum_required(VERSION 3.5)
    
    # Set the project name
    project ("hello_headers")
    
    # Create a sources variable with a link to all cpp files to compile
    set(SOURCES
        src/Hello.cpp
        src/main.cpp
    )
    
    # Add an executable with the above sources
    add_executable(hello_headers ${SOURCES})
    
    message("PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR}")
    message("PROJECT_NAME = ${PROJECT_NAME}")
    
    # Set the directories that should be included in the build command for this target
    # when running g++ these will be included as -I/directory/path/
    target_include_directories(hello_headers
        PRIVATE
            ${PROJECT_SOURCE_DIR}/include
    )

    *

     set(SOURCE

            src/Hello.cpp

            src/main.cpp

    )

    - SOURCE is the variable contained the file paths you listed behind it in set().

    - src/Hello.cpp is the first file.

    - src/main.cpp is the second one.

    You can add as many as you need in this project. 

    *

    ${XXXX}

    - Get/Use the value of XXXX

    *

    message("a sentence")

    - Print a sentence to console window.

    *

    target_include_directories(hello_headers
        PRIVATE
            ${PROJECT_SOURCE_DIR}/include
    )

    - Add include file to your project

    After seting that, the #include "Hello.h" in main.cpp will be avariable.

    The true thing is, this tell CMake where to find Hello.h when compile main.cpp.

    But for some beginnners and expecially for the ones get used to Visual Studio, that will be quite abstract.

    Take the example of Visual Studio again, if you do not set include path in property, can you open the head file in editer?

    Of course not.

    So, if you are using CLion in Ubuntu ( The same as other IDEs ) and you do not set target_include_directories(), you can not open the head file also.

    That all.

  • 相关阅读:
    Max Sum of Max-K-sub-sequence(单调队列)
    Matrix Swapping II(求矩阵最大面积,dp)
    重温世界杯(贪心)
    Pie(求最小身高差,dp)
    Matrix(多线程dp)
    Python 实现自动导入缺失的库
    分布式系统session一致性解决方案
    数据结构 【链表】
    【数字图像处理】gamma变换
    【数字图像处理】顶帽变换和底帽变换
  • 原文地址:https://www.cnblogs.com/alexYuin/p/12772316.html
Copyright © 2011-2022 走看看