• cmake语法学习


    cmake_minimum_required(VERSION 3.5)
    
    project(hello_library)
    
    ############################################################
    # Create a library
    ############################################################
    
    #Generate the shared library from the library sources
    add_library(hello_library SHARED 
        src/Hello.cpp
    )
    add_library(hello::library ALIAS hello_library)
    
    target_include_directories(hello_library
        PUBLIC 
            ${PROJECT_SOURCE_DIR}/include
    )
    
    ############################################################
    # Create an executable
    ############################################################
    
    # Add an executable with the above sources
    add_executable(hello_binary
        src/main.cpp
    )
    
    # link the new hello_library target with the hello_binary target
    target_link_libraries( hello_binary
        PRIVATE 
            hello::library
    )

    *

    add_library(hello_library SHARED 
        src/Hello.cpp
    )

    - SHARED must be upper case, and mark to generate a shared library.

    Please note that, SHARED, do not miss the D here.

    *

    add_library(hello::library ALIAS hello_library)

    - ALIAS , upper case only, just like "typedef". 

    hello::library is the same as hello_library now. They are 2 names of the same thing.

    And please note that "hello::library" is just a name !!! NO namespace in CMake!!!!

    *

    target_link_libraries( hello_binary
        PRIVATE 
            hello::library
    )

    - PRIVATE marks the linked files only avaliable in this scope.

    In other words, within this subproject or the folder where this CMakeList.txt is.

  • 相关阅读:
    [CISCN2019 华北赛区 Day1 Web2]ikun
    [BJDCTF 2nd]简单注入
    [BJDCTF2020]ZJCTF,不过如此
    [BJDCTF2020]The mystery of ip
    [SWPU2019]Web1
    [WesternCTF2018]shrine
    [BJDCTF 2nd]假猪套天下第一
    [BJDCTF2020]Mark loves cat
    [GWCTF 2019]我有一个数据库
    C语言学习笔记_函数与函数库
  • 原文地址:https://www.cnblogs.com/alexYuin/p/12773428.html
Copyright © 2020-2023  润新知