【问题标题】:Simple CMakeLists.txt that reflects typical directory structure (/src, /inc, /bin subdirectories)反映典型目录结构(/src、/inc、/bin 子目录)的简单 CMakeLists.txt
【发布时间】:2014-12-02 11:22:56
【问题描述】:

我正在努力制作一个 CMakeList.txt 文件以反映一个简单、典型的 makefile。原文在这里http://pastebin.com/S9Czr1pt

我尝试了很多方法(例如 SET(SOURCE ... 和 SET(HEADERS...) 添加 /src、/lib 和 /third-party//include ),但我没有运气。

任何人都可以帮助我或指出一个做这件事的教程吗?

【问题讨论】:

    标签: cmake


    【解决方案1】:

    这只是一个出乎意料的骨架 - 请参阅CMake documentation 了解每个功能的详细信息:

    cmake_minimum_required(VERSION 2.6)
    # Project name, can be used as target name too
    project(Example)
    
    # Search all .cpp files within src - recursive!
    # You can add all source files by hand here too
    file(GLOB_RECURSE SRCS "src/*.cpp")
    
    # Add include path (you can also add it's sub directories
    include_directories("include")
    
    # Search for packages -- PLEASE NOTE: many libraries provide alternative's to this
    # which often provide more functionality
    find_package(PkgConfig REQUIRED)
    # TODO: add proper pkg modul search info's and change the variable's name
    pkg_search_module(PACKAGE_NO1 ...)
    
    # Show some messages (optional)
    if( (PACKAGE_NO1 )
        include_directories(${(PACKAGE_NO1_INCLUDE_DIRS})
        message(STATUS "Using OpenSSL ${(PACKAGE_NO1_VERSION}")
    else()
        # do error handling
    endif()
    
    # Add compiler flags
    add_definitions(-std=c++11 -Wall) # -g O3 etc are added according to Release / Debug compilation
    
    # Build a executable target (1st param: Target name; 2nd: source files)
    add_executable(${PROJECT_NAME} ${SRCS})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多