跳转到内容

CMake 入门/寻找套件

维基教科书,自由的教学读本

范例

[编辑]

寻找 Boost library

[编辑]

指定 Boost 所在:

export BOOST_ROOT=/path/to/boost
#
# 設定過濾條件
#
set(Boost_USE_STATIC_LIBS       ON)
set(Boost_USE_MULTITHREADED     ON)
# set(Boost_USE_STATIC_RUNTIME    OFF)

set(Boost_ADDITIONAL_VERSIONS
    1.45    1.44    1.43    1.42    1.41    1.40
    1.45.0  1.44.0  1.43.0  1.42.0  1.41.0  1.40.0)
#
# 尋找所需的程式庫
#
find_package(Boost COMPONENTS
    date_time
    thread
    REQUIRED)


if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS})

    add_definitions(-DBOOST_THREAD_USE_LIB)
    set(sources "main.cpp")
    add_executable(app ${sources})

    target_link_libraries(app ${Boost_LIBRARIES})
endif()