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.

  • 相关阅读:
    把Chrome浏览器变成文本编辑器
    pigcms 标签读不出
    全排列函数
    线性基(二
    线性基(一
    fabs() abs()
    字面量声明的函数,后边最好加一个分号,否则的话,在控制台执行有问题的
    mongo集群
    linux的查找命令
    mysql 解决Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’错误
  • 原文地址:https://www.cnblogs.com/alexYuin/p/12772316.html
Copyright © 2011-2022 走看看