• cmake


    第一种:在项目目录写一个CMakeLists.txt

    cmake_minimum_required (VERSION 3.8)

    project ("rtsp")

    该命令会查找指定目录下的所有源文件,然后将结果存进指定变量名。

     #aux_source_directory(<dir> <variable>

    aux_source_directory(src/xop/ XOP_SRCS)
    aux_source_directory(src/net/ NET_SRCS) #遍历文件夹下的所有文件
    # 将源代码添加到此项目的可执行文件。
    link_libraries(-lrt -pthread -lpthread -ldl -lm -std=c++11) #链接系统库
    add_executable (rtsp ${XOP_SRCS} ${NET_SRCS} "src/3rdpart/md5/md5.hpp" "rtsp_h264_file.cpp")

    https://github.com/MoonXu0722/cmake_one.git

    ---------------------------------------------------------------------------------------------------------------------------------------------

    第二种:在每个子目录创建CMakeLists.txt生成库供项目目录调用

    项目目录:

    cmake_minimum_required (VERSION 3.8)

    project ("demo")
    add_subdirectory(math)#添加子文件夹
    # 将源代码添加到此项目的可执行文件。
    add_executable(demo main.cpp)
    target_link_libraries(demo add)#add为子目录生成的库名字

    子目录:

    aux_source_directory(. SRCS_DIR)
    add_library(add ${SRCS_DIR})#add为子目录生成的库名字

    https://github.com/MoonXu0722/cmake_two.git

    ------------------------------------------------------------------------------------------------------------------------------------------------

    https://github.com/MoonXu0722/share.git

    编译动态库

    cmake_minimum_required(VERSION 3.16.0)
    project(hello)
    include_directories(include)
    file(GLOB SOURCES "src/*.cpp")
    add_library(add SHARED ${SOURCES})
    install(TARGETS add DESTINATION shared)#这一步没有成功

    ------------------------------------------------------------------------------------------------------------------

    编译静态库

    cmake_minimum_required(VERSION 3.16.0)
    project(hello)
    set(CMAKE_BUILD_TYPE Release)
    include_directories(include)
    file(GLOB SOURCES "src/*.cpp")
    add_library(add STATIC ${SOURCES})
    install(TARGETS add DESTINATION static)#这一步没有成功

    -----------------------------------------------------------------

    使用动态库

    cmake_minimum_required(VERSION 3.16.0)
    project(hello)
    set(CMAKE_BUILD_TYPE Release)
    include_directories(include)
    file(GLOB SOURCES "src/*.cpp")

    set(PROJECT_LINK_LIBS libadd.so)
    link_directories(BUILD)
    add_executable(hello src/hello.cpp)
    target_link_libraries(hello ${PROJECT_LINK_LIBS})

    ----------------------------------------------------------

    使用静态库

    cmake_minimum_required(VERSION 3.16.0)
    project(hello)
    set(CMAKE_BUILD_TYPE Release)
    include_directories(include)
    file(GLOB SOURCES "src/*.cpp")

    set(PROJECT_LINK_LIBS libadd.a)

    link_directories(BUILD)
    add_executable(hello src/hello.cpp)
    target_link_libraries(hello ${PROJECT_LINK_LIBS})

    -------------------------------------------------------------------------------------

  • 相关阅读:
    ActiveMQ学习(四)——应用程序接口
    ActiveMQ学习(三)——MQ的通讯模式
    ActiveMQ学习(二)——MQ的工作原理
    ActiveMQ学习(一)——MQ的基本概念
    java获取对象属性类型、属性名称、属性值 【转】
    Java方法的参数是按值传递的.【转】
    Jquery 操作 select
    JQuery中根据属性或属性值获得元素
    XML 标记使用的特殊字符对应内置实体
    创建DBLink语句
  • 原文地址:https://www.cnblogs.com/xpylovely/p/13190878.html
Copyright © 2020-2023  润新知